From 2fbac7e7a7e41d2c00287605385a185ad71e628d Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Tue, 12 Dec 2017 03:41:57 +0100 Subject: [PATCH] chore: allow package-specific extra build scripts If a package has a custom build scripts (`scripts/build.js`), this script will be run during the main build task. --- scripts/build-utils.js | 8 ++++++++ scripts/build.js | 14 +++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/build-utils.js b/scripts/build-utils.js index 1b5384e4..83b8cbef 100644 --- a/scripts/build-utils.js +++ b/scripts/build-utils.js @@ -5,6 +5,13 @@ const path = require('path'); const PACKAGES_DIR = path.resolve(__dirname, '../packages'); +const config = { + srcDir: 'src', + buildDir: 'lib', + jsPattern: '**/*.js', + ignorePattern: '**/*.test.js', +}; + function listPackages() { return fs .readdirSync(PACKAGES_DIR) @@ -13,6 +20,7 @@ function listPackages() { } module.exports = { + config, listPackages, PACKAGES_DIR, }; diff --git a/scripts/build.js b/scripts/build.js index a99fb7ce..f99a09e2 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -16,15 +16,10 @@ const glob = require('glob'); const micromatch = require('micromatch'); const mkdirp = require('mkdirp'); const path = require('path'); +const spawn = require('cross-spawn'); -const { listPackages, PACKAGES_DIR } = require('./build-utils'); -const config = { - srcDir: 'src', - buildDir: 'lib', - jsPattern: '**/*.js', - ignorePattern: '**/*.test.js', -}; +const { config, listPackages, PACKAGES_DIR } = require('./build-utils'); const babelConfig = JSON.parse( fs.readFileSync(path.resolve(__dirname, '..', '.babelrc'), 'utf8')); @@ -80,6 +75,11 @@ function buildPackage(pkg) { process.stdout.write(` ${path.basename(pkg)} ${chalk.dim('...')}`); files.forEach(file => buildFile(file, true)); + + const buildScript = path.resolve(pkg, 'scripts/build.js'); + if (fs.existsSync(buildScript)) { + spawn.sync('node', [buildScript], { stdio: 'inherit' }); + } process.stdout.write(`${chalk.reset.bold.green(' ✓ Done')}\n`); }