Security update for Core, with self-updated composer
[yaffs-website] / web / core / scripts / js / babel-es6-build.js
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
17 'use strict';
18
19 const glob = require('glob');
20 const argv = require('minimist')(process.argv.slice(2));
21 const changeOrAdded = require('./changeOrAdded');
22 const check = require('./check');
23 const log = require('./log');
24
25 // Match only on .es6.js files.
26 const fileMatch = './**/*.es6.js';
27 // Ignore everything in node_modules
28 const globOptions = {
29   ignore: './node_modules/**'
30 };
31 const processFiles = (error, filePaths) => {
32   if (error) {
33     process.exitCode = 1;
34   }
35   // Process all the found files.
36   let callback = changeOrAdded;
37   if (argv.check) {
38     callback = check;
39   }
40   filePaths.forEach(callback);
41 };
42
43 if (argv.file) {
44   processFiles(null, [].concat(argv.file));
45 }
46 else {
47   glob(fileMatch, globOptions, processFiles);
48 }
49 process.exitCode = 0;