Skip to content

Instantly share code, notes, and snippets.

@bengourley
Created November 11, 2012 13:27
Show Gist options
  • Save bengourley/4054877 to your computer and use it in GitHub Desktop.
Save bengourley/4054877 to your computer and use it in GitHub Desktop.
Application level build script
/** 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()
/** 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')
}
$ 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
@bengourley
Copy link
Author

I think a nice extension to this would be the ability to name and namespace tasks, so that you can specify which to run from the cli, eg:

// Only process the tasked named 'js' in the 'admin' namespace
node build admin:js

// Process a task named 'js' in any namespace
node build :js

// Process all of the tasks in the 'admin' namespace
node build admin:

Namespace API:

piler.namespace('admin', function (ns) {

  ns.task(
    { name: 'js'
    , items:
      [ { dest: 'public/js/app.js'
        , srcs: [ 'public/js/a.js', 'public/js/b.js' ]
        }
      ]
    , process: processJS
    , watch: 'public/js/*.js'
    })

})

@serby
Copy link

serby commented Nov 11, 2012

I like the ideal of namespacing tasks. That could really help simplify the concept of sub-project builds.

@serby
Copy link

serby commented Nov 11, 2012

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