Chris@0
|
1 /**
|
Chris@0
|
2 * @file
|
Chris@0
|
3 *
|
Chris@0
|
4 * Provides the build:js command to compile *.es6.js files to ES5.
|
Chris@0
|
5 *
|
Chris@0
|
6 * Run build:js with --file to only parse a specific file. Using the --check
|
Chris@0
|
7 * flag build:js can be run to check if files are compiled correctly.
|
Chris@0
|
8 * @example <caption>Only process misc/drupal.es6.js and misc/drupal.init.es6.js</caption
|
Chris@0
|
9 * yarn run build:js -- --file misc/drupal.es6.js --file misc/drupal.init.es6.js
|
Chris@0
|
10 * @example <caption>Check if all files have been compiled correctly</caption
|
Chris@0
|
11 * yarn run build:js -- --check
|
Chris@0
|
12 *
|
Chris@0
|
13 * @internal This file is part of the core javascript build process and is only
|
Chris@0
|
14 * meant to be used in that context.
|
Chris@0
|
15 */
|
Chris@0
|
16
|
Chris@0
|
17 'use strict';
|
Chris@0
|
18
|
Chris@0
|
19 const glob = require('glob');
|
Chris@0
|
20 const argv = require('minimist')(process.argv.slice(2));
|
Chris@0
|
21 const changeOrAdded = require('./changeOrAdded');
|
Chris@0
|
22 const check = require('./check');
|
Chris@0
|
23 const log = require('./log');
|
Chris@0
|
24
|
Chris@0
|
25 // Match only on .es6.js files.
|
Chris@0
|
26 const fileMatch = './**/*.es6.js';
|
Chris@0
|
27 // Ignore everything in node_modules
|
Chris@0
|
28 const globOptions = {
|
Chris@0
|
29 ignore: './node_modules/**'
|
Chris@0
|
30 };
|
Chris@0
|
31 const processFiles = (error, filePaths) => {
|
Chris@0
|
32 if (error) {
|
Chris@0
|
33 process.exitCode = 1;
|
Chris@0
|
34 }
|
Chris@0
|
35 // Process all the found files.
|
Chris@0
|
36 let callback = changeOrAdded;
|
Chris@0
|
37 if (argv.check) {
|
Chris@0
|
38 callback = check;
|
Chris@0
|
39 }
|
Chris@0
|
40 filePaths.forEach(callback);
|
Chris@0
|
41 };
|
Chris@0
|
42
|
Chris@0
|
43 if (argv.file) {
|
Chris@0
|
44 processFiles(null, [].concat(argv.file));
|
Chris@0
|
45 }
|
Chris@0
|
46 else {
|
Chris@0
|
47 glob(fileMatch, globOptions, processFiles);
|
Chris@0
|
48 }
|
Chris@0
|
49 process.exitCode = 0;
|