Created
June 23, 2014 14:02
-
-
Save stephenmathieson/5e3ce1a7c88ad393f6c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var builder = require('component-builder'); | |
var resolve = require('component-resolver'); | |
var consoler = require('component-consoler'); | |
var log = consoler.log; | |
var fatal = consoler.fatal; | |
var Batch = require('batch'); | |
var c8 = require('./component.json'); | |
var bundles = c8.locals; | |
console.log(); | |
resolve(__dirname, { install: true, verbose: true }, function (err, tree) { | |
var pending = bundles.length; | |
bundles.forEach(function (name) { | |
var bundle = tree.locals[name]; | |
var batch = new Batch; | |
[ | |
buildStyles, | |
buildScripts, | |
].forEach(function (fn) { | |
batch.push(function (done) { | |
fn(bundle, done); | |
}); | |
}); | |
batch.end(function (err) { | |
if (err) return fatal(err); | |
if (!--pending) { | |
log('built', bundles.length + ' bundles'); | |
console.log(); | |
process.exit(0); | |
} | |
}); | |
}); | |
}); | |
function buildStyles(bundle, fn) { | |
builder.styles(bundle) | |
.use('styles', builder.plugins.css()) | |
.end(fn); | |
} | |
function buildScripts(bundle, fn) { | |
builder.scripts(bundle) | |
.use('scripts', builder.plugins.js()) | |
.use('json', builder.plugins.json()) | |
.end(fn); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@stephanmatthieson you may want to try
To get the locals of the
component.json
this saves you a second read as resolve does this already :)