Created
November 11, 2012 13:27
-
-
Save bengourley/4054877 to your computer and use it in GitHub Desktop.
Application level build script
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
/** build.js **/ | |
var piler = require('piler') | |
, bundles = require('bundles.json') | |
, bundleTasks = [] | |
// Try to load a build script for all of | |
// the bundles specified in bundles.json | |
bundles.forEach(function (bundle) { | |
try { | |
var build = require(bundle + '/build') | |
bundleTasks.push(build) | |
} catch (e) { | |
// No build script for bundle | |
} | |
}) | |
piler | |
.set('watch', true) | |
.set('env', 'development') | |
piler.task({ | |
// ... some application level task | |
}) | |
// Loop over the build scripts | |
// and load in their tasks | |
bundleTasks.forEach(function (tasks) { | |
tasks(piler) | |
}) | |
piler.run() |
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
/** bundles/admin/build.js **/ | |
module.exports = tasks | |
var processStylus = require('piler-process-stylus') | |
, processJS = require('piler-process-js') | |
function tasks(piler) { | |
piler.task('css', | |
{ items: | |
[ { src: 'public/css/screen.styl' | |
, dest: 'public/css/screen.css' | |
} | |
] | |
, process: processStylus | |
}) | |
piler.task('js', | |
{ items: | |
[ { dest: 'public/js/app.js' | |
, srcs: [ 'public/js/a.js', 'public/js/b.js' ] | |
} | |
] | |
, process: processJS | |
}) | |
piler.watch('public/css/*.styl', 'css') | |
piler.watch('public/js/*.js', 'js') | |
} |
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
$ node build | |
// And maybe use an options parser, eg: https://github.com/substack/node-optimist | |
// to configure piler through `piler.set('key', val)` options through cli: | |
$ node build --watch | |
$ node build --env development |
I also like the way you bring the bundles in from the json. It is likely that the build order in the application will also be a build order for an application. I can't imagine how it might work, but at some point bundles may want to contribute to a global js file that the whole application uses.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the ideal of namespacing tasks. That could really help simplify the concept of sub-project builds.