compile.js 805 B

12345678910111213141516171819202122232425262728293031
  1. const chalk = require('chalk');
  2. const log = require('./log');
  3. const babel = require('babel-core');
  4. module.exports = (filePath, callback) => {
  5. // Transform the file.
  6. // Check process.env.NODE_ENV to see if we should create sourcemaps.
  7. babel.transformFile(
  8. filePath,
  9. {
  10. sourceMaps: process.env.NODE_ENV === 'development' ? 'inline' : false,
  11. comments: false,
  12. plugins: [
  13. ['add-header-comment', {
  14. 'header': [
  15. `DO NOT EDIT THIS FILE.\nSee the following change record for more information,\nhttps://www.drupal.org/node/2815083\n@preserve`
  16. ]
  17. }]
  18. ]
  19. },
  20. (err, result) => {
  21. if (err) {
  22. log(chalk.red(err));
  23. process.exitCode = 1;
  24. }
  25. else {
  26. callback(result.code);
  27. }
  28. }
  29. );
  30. };