Skip to content

Instantly share code, notes, and snippets.

@mihaisucan
Created January 7, 2011 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihaisucan/770116 to your computer and use it in GitHub Desktop.
Save mihaisucan/770116 to your computer and use it in GitHub Desktop.
imaginary build script
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
Copy link

copy({
  source: ["changes.txt", "readme.txt", "license.txt", "docs", "styles", "images" ],
  dest: "/path/to/the/target/build/folder"
});

copy({
  source: [ "scripts/**/*.js" ],
  inputFilter: myCustomFilter,
  outputFilter: uglifyjs,
  dest: "output-file.js"
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment