babel-es6-build.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. console.warn('⚠️ yarn `build:js` command is deprecated in drupal:9.4.0 and will be removed from drupal:10.0.0. This command is no longer needed in Drupal 10.0.0 once https://www.drupal.org/project/drupal/issues/3278415 is committed.️');
  23. // Match only on .es6.js files.
  24. const fileMatch = './**/*.es6.js';
  25. // Ignore everything in node_modules
  26. const globOptions = {
  27. ignore: './node_modules/**'
  28. };
  29. const processFiles = (error, filePaths) => {
  30. if (error) {
  31. process.exitCode = 1;
  32. }
  33. // Process all the found files.
  34. let callback = changeOrAdded;
  35. if (argv.check) {
  36. callback = check;
  37. }
  38. filePaths.forEach(callback);
  39. };
  40. if (argv.file) {
  41. processFiles(null, [].concat(argv.file));
  42. }
  43. else {
  44. glob(fileMatch, globOptions, processFiles);
  45. }
  46. process.exitCode = 0;