Created
January 7, 2011 21:18
-
-
Save mihaisucan/770116 to your computer and use it in GitHub Desktop.
imaginary build script
This file contains 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
var dryice = require("dryice"); | |
var Step = require("step"); | |
var build; | |
var script; | |
var appFolder = "/path/to/the/webapp"; | |
var buildFolder = "/path/to/the/target/build/folder"; | |
// filters should also be allowed to be async. they can call onReady() when they are done, if they return undefined. | |
function myCustomFilter(data, filename, onReady, script) { | |
return data.replace("foobar", "foobaz-" + filename); | |
} | |
Step( | |
function startBuilding() { | |
build = new dryice.Builder(appFolder); | |
build.setBuildFolder(buildFolder, this); | |
}, | |
function copyResources(err) { | |
if (err) throw err; | |
var group = this.group(); | |
// Builder allows you to manage the general aspects of your packaging needs: copy files, folders, and friends, from your web app source folder to the build folder. | |
build.copyFiles(["changes.txt", "readme.txt", "license.txt"], group()); | |
build.copyFolders(["docs", "styles", "images"], group()); | |
}, | |
function buildScript(err) { | |
if (err) throw err; | |
// create a compiled script object | |
script = new dryice.Script(build, "output-file.js"); | |
script.addFileFilters(myCustomFilter); | |
script.addFolders("scripts", this); | |
}, | |
function scriptBoot(err) { | |
if (err) throw err; | |
script.removeFileFilters(myCustomFilter); | |
// this finds the module according to requirejs rules. | |
// it should be able to handle package.json metadata and find dependencies as well. | |
// similar to how Dryice for Python did with "plugins". | |
script.addModules("someBootModule", this); | |
}, | |
function saveScript(err) { | |
if (err) throw err; | |
// use uglifyjs to compress the script. | |
script.addOutputFilters("uglifyjs"); | |
// now save the compiled script into the build. | |
// on save, the output filters are executed. | |
script.save(this); | |
}, | |
function buildDone(err) { | |
console.log(err ? "build failed": "build done"); | |
// optionally we could call build.saveAsArchive("package.zip", callback) to make an archive of the build folder. | |
} | |
); |
joewalker
commented
Jan 10, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment