This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/core/scripts/js/babel-es6-build.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-04-13 14:53:35 +00:00
/**
* @file
*
2018-11-23 12:29:20 +00:00
* Provides the build:js command to compile *.es6.js files to ES5.
*
* Run build:js with --file to only parse a specific file. Using the --check
* flag build:js can be run to check if files are compiled correctly.
* @example <caption>Only process misc/drupal.es6.js and misc/drupal.init.es6.js</caption
* yarn run build:js -- --file misc/drupal.es6.js --file misc/drupal.init.es6.js
* @example <caption>Check if all files have been compiled correctly</caption
* yarn run build:js -- --check
2017-04-13 14:53:35 +00:00
*
* @internal This file is part of the core javascript build process and is only
* meant to be used in that context.
*/
'use strict';
const glob = require('glob');
2018-11-23 12:29:20 +00:00
const argv = require('minimist')(process.argv.slice(2));
const changeOrAdded = require('./changeOrAdded');
const check = require('./check');
const log = require('./log');
2017-04-13 14:53:35 +00:00
2018-11-23 12:29:20 +00:00
// Match only on .es6.js files.
2017-04-13 14:53:35 +00:00
const fileMatch = './**/*.es6.js';
2018-11-23 12:29:20 +00:00
// Ignore everything in node_modules
2017-04-13 14:53:35 +00:00
const globOptions = {
2018-11-23 12:29:20 +00:00
ignore: './node_modules/**'
2017-04-13 14:53:35 +00:00
};
const processFiles = (error, filePaths) => {
if (error) {
process.exitCode = 1;
}
2018-11-23 12:29:20 +00:00
// Process all the found files.
let callback = changeOrAdded;
if (argv.check) {
callback = check;
}
filePaths.forEach(callback);
2017-04-13 14:53:35 +00:00
};
2018-11-23 12:29:20 +00:00
if (argv.file) {
processFiles(null, [].concat(argv.file));
}
else {
glob(fileMatch, globOptions, processFiles);
}
2017-04-13 14:53:35 +00:00
process.exitCode = 0;