Skip to content

Commit

Permalink
chore: allow package-specific extra build scripts
Browse files Browse the repository at this point in the history
If a package has a custom build scripts (`scripts/build.js`), this script
will be run during the main build task.
  • Loading branch information
rdeltour committed Dec 13, 2017
1 parent ae1d814 commit 2fbac7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions scripts/build-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -13,6 +20,7 @@ function listPackages() {
}

module.exports = {
config,
listPackages,
PACKAGES_DIR,
};
14 changes: 7 additions & 7 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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`);
}

Expand Down

0 comments on commit 2fbac7e

Please sign in to comment.