Permalink
Browse files

build: Support for custom scripts in package build process

You can now define an array with 'before' and 'after' scripts to run
in the build process via `grunt packages`. To display the output of the
commands add the `--verbose` parameter. Working directory is set to the
**package source**.

Example:
```
{
  "build": {
    "scripts": {
      "before": ["echo 1"],
      "after": ["echo 2"]
    }
  }
}

```
  • Loading branch information...
andersevenrud committed Jun 15, 2016
1 parent d118cfd commit 3a709b726ae21fb70bb13a837473cc05f91253e7
Showing with 41 additions and 13 deletions.
  1. +41 −13 src/build.js
@@ -1514,6 +1514,24 @@
});
}
function runPackageScript(type, pn, cmd, src, dst, cb) {
if ( cmd ) {
console.log('CMD', type + '@' + pn, '$', cmd);
require('child_process').exec(cmd, {cwd: src}, function(err, stdout, stderr) {
if ( grunt.option('verbose') ) {
console.log(stdout);
}
if ( stderr ) {
console.error(stderr);
}
cb();
});
} else {
cb();
}
}
var packages = readPackageMetadata(grunt);
aQueue(Object.keys(packages), function(p, next) {
if ( arg && arg !== p ) {
@@ -1525,27 +1543,37 @@
var iter = packages[p];
var src = _path.join(PATHS.packages, p);
var dst = _path.join(PATHS.out_client_packages, p);
var copy = iter.build.copy || [];
var scripts = iter.build.scripts || {};
function _proceed(additions) {
additions = additions.filter(function(iter) {
return copy.indexOf(iter) < 0;
});
function _compile() {
var copy = iter.build.copy || [];
if ( additions.length ) {
copy = copy.concat(additions);
}
function _proceed(additions) {
additions = additions.filter(function(iter) {
return copy.indexOf(iter) < 0;
});
copyFiles(src, dst, p, copy);
if ( additions.length ) {
copy = copy.concat(additions);
}
if ( iter.type !== 'extension' ) {
combineFiles(src, dst, p, iter);
copyFiles(src, dst, p, copy);
if ( iter.type !== 'extension' ) {
combineFiles(src, dst, p, iter);
}
aQueue(scripts.after || [], function(cmd, nxt) {
runPackageScript('after', p, cmd, src, dst, nxt);
}, next);
}
return next();
compileLess(src, iter.build.less, _proceed);
}
compileLess(src, iter.build.less, _proceed);
aQueue(scripts.before || [], function(cmd, nxt) {
runPackageScript('before', p, cmd, src, dst, nxt);
}, _compile);
}, function() {
onfinished();
});

0 comments on commit 3a709b7

Please sign in to comment.