diff --git a/core/package.json b/core/package.json index 57f000188c..5ef20f6e09 100644 --- a/core/package.json +++ b/core/package.json @@ -5,7 +5,6 @@ "private": true, "scripts": { "build:js": "node ./scripts/js/babel-es6-build.js", - "check:js": "node ./scripts/js/babel-es6-check.js", "watch:js": "cross-env NODE_ENV=development node ./scripts/js/babel-es6-watch.js", "lint:core-js": "node ./node_modules/eslint/bin/eslint.js --ext=.es6.js . --fix || exit 0", "lint:css": "stylelint \"**/*.css\" || exit 0", @@ -23,9 +22,10 @@ "eslint-plugin-jsx-a11y": "4.0.0", "eslint-plugin-react": "6.10.3", "glob": "7.1.1", + "minimist": "^1.2.0", "stylelint": "^7.10.1", - "stylelint-config-standard": "^16.0.0", "stylelint-checkstyle-formatter": "^0.1.0", + "stylelint-config-standard": "^16.0.0", "stylelint-no-browser-hacks": "^1.0.2" }, "babel": { diff --git a/core/scripts/js/babel-es6-build.js b/core/scripts/js/babel-es6-build.js index 0178d44ec5..af25203336 100644 --- a/core/scripts/js/babel-es6-build.js +++ b/core/scripts/js/babel-es6-build.js @@ -9,10 +9,8 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); const glob = require('glob'); - +const argv = require('minimist')(process.argv.slice(2)); const changeOrAdded = require('./changeOrAdded'); const log = require('./log'); @@ -31,10 +29,10 @@ const processFiles = (error, filePaths) => { }; // Run build:js with some special arguments to only parse specific files. -// npm run build:js -- --files misc/drupal.es6.js misc/drupal.init.es6.js +// npm run build:js -- --file misc/drupal.es6.js --file misc/drupal.init.es6.js // Only misc/drupal.es6.js misc/drupal.init.es6.js will be processed. -if (process.argv.length > 2 && process.argv[2] === '--files') { - processFiles(null, process.argv.splice(3, process.argv.length)); +if (argv.file) { + processFiles(null, [].concat(argv.file)); } else { glob(fileMatch, globOptions, processFiles); diff --git a/core/scripts/js/changeOrAdded.js b/core/scripts/js/changeOrAdded.js index c791ee5216..db8c3046f9 100644 --- a/core/scripts/js/changeOrAdded.js +++ b/core/scripts/js/changeOrAdded.js @@ -1,14 +1,28 @@ const fs = require('fs'); - const log = require('./log'); const transpile = require('./transpile'); +const argv = require('minimist')(process.argv.slice(2)); module.exports = (filePath) => { - const moduleName = filePath.slice(0, -7); log(`'${filePath}' is being processed.`); // Transform the file. transpile(filePath, function check(code) { const fileName = filePath.slice(0, -7); + + if(argv.check) { + fs.readFile(`${fileName}.js`, function read(err, data) { + if (err) { + throw err; + } + if (code != data) { + log(`${fileName}.js`); + throw new Error(`'${filePath}' is not updated.`); + } + }); + + return; + } + // Write the result to the filesystem. fs.writeFile(`${fileName}.js`, code, () => { log(`'${filePath}' is finished.`); diff --git a/core/scripts/js/transpile.js b/core/scripts/js/transpile.js index b7e89ff2a9..018ec37692 100644 --- a/core/scripts/js/transpile.js +++ b/core/scripts/js/transpile.js @@ -1,4 +1,3 @@ -const fs = require('fs'); const babel = require('babel-core'); module.exports = (filePath, callback) => {