babel-es6-build.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @file
  3. *
  4. * Provides the build:js command to compile *.es6.js files to ES5.
  5. *
  6. * Run build:js with --file to only parse a specific file. Using the --check
  7. * flag build:js can be run to check if files are compiled correctly.
  8. * @example <caption>Only process misc/drupal.es6.js and misc/drupal.init.es6.js</caption
  9. * yarn run build:js -- --file misc/drupal.es6.js --file misc/drupal.init.es6.js
  10. * @example <caption>Check if all files have been compiled correctly</caption
  11. * yarn run build:js -- --check
  12. *
  13. * @internal This file is part of the core javascript build process and is only
  14. * meant to be used in that context.
  15. */
  16. 'use strict';
  17. const glob = require('glob');
  18. const argv = require('minimist')(process.argv.slice(2));
  19. const changeOrAdded = require('./changeOrAdded');
  20. const check = require('./check');
  21. const log = require('./log');
  22. // Match only on .es6.js files.
  23. const fileMatch = './**/*.es6.js';
  24. // Ignore everything in node_modules
  25. const globOptions = {
  26. ignore: './node_modules/**'
  27. };
  28. const processFiles = (error, filePaths) => {
  29. if (error) {
  30. process.exitCode = 1;
  31. }
  32. // Process all the found files.
  33. let callback = changeOrAdded;
  34. if (argv.check) {
  35. callback = check;
  36. }
  37. filePaths.forEach(callback);
  38. };
  39. if (argv.file) {
  40. processFiles(null, [].concat(argv.file));
  41. }
  42. else {
  43. glob(fileMatch, globOptions, processFiles);
  44. }
  45. process.exitCode = 0;