postcss-build.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @file
  3. *
  4. * Provides the build:css command to compile *.pcss.css files to CSS.
  5. *
  6. * Run build:css with --file to only parse a specific file. Using the --check
  7. * flag build:css 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:css -- --file misc/drupal.pcss.css --file misc/drupal.init.pcss.css
  10. * @example <caption>Check if all files have been compiled correctly</caption
  11. * yarn run build:css -- --check
  12. *
  13. * @internal This file is part of the core CSS build process and is only
  14. * designed 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 .pcss.css files.
  23. const fileMatch = './**/*.pcss.css';
  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;