Skip to content

Instantly share code, notes, and snippets.

@waghcwb
Forked from BaseCase/gist:2139106
Created August 31, 2017 20:50
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 waghcwb/e5de09fc12bd5363fbf44a5f331645ed to your computer and use it in GitHub Desktop.
Save waghcwb/e5de09fc12bd5363fbf44a5f331645ed to your computer and use it in GitHub Desktop.
A sample Cakefile
{exec} = require 'child_process'
task 'test', 'Runs all Jasmine specs in spec/ folder', ->
test()
task 'compile', 'Compiles coffee in src/ to js in bin/', ->
compile()
task 'stitch', 'Stitches all app .js files', ->
stitch()
task 'compress', 'Runs UglifyJS on stitched file in order to compress it', ->
compress()
task 'build', 'Does the full build magic', ->
test -> compile -> stitch -> compress()
task 'develop', 'Only compile and stitch, don\'t test or compress', ->
compile -> stitch()
test = (callback) ->
console.log "Running Jasmine specs"
exec 'jasmine-node --coffee spec/', (err, stdout, stderr) =>
console.log stdout + stderr
# hack to work around jasmine-node's bad return vals:
throw "Tests fail. Build fails. You fail." if ~stdout.indexOf "Expected"
callback?()
compile = (callback) ->
exec 'coffee -o bin/ -c src/', (err, stdout, stderr) ->
throw err if err
console.log "Compiled coffee files"
callback?()
stitch = (callback) ->
stitch = require 'stitch'
fs = require 'fs'
myPackage = stitch.createPackage paths: [__dirname + '/bin', __dirname + '/vendor']
myPackage.compile (err, source) ->
fs.writeFile 'app.js', source, (err) ->
throw err if err
console.log "Stitched js files"
callback?()
compress = (callback) ->
exec 'uglifyjs --overwrite app.js', (err, stdout, stderr) ->
throw err if err
console.log "Compressed app.js"
callback?()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment