Skip to content

Commit

Permalink
Added a build system via Cake (but see also issue #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rehno-lindeque committed Nov 1, 2011
1 parent a29bc92 commit 01439de
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
fs = require 'fs'
path = require 'path'
{exec} = require 'child_process'

libFiles = [
# omit src/ and .js to make the below lines a little shorter
'header'
'core'
]

task 'build', "Concatenate source files into a single library file", ->
exec "mkdir -p 'build'", (err, stdout, stderr) ->
# Concatenate files
libContents = new Array remaining = libFiles.length
for file, index in libFiles then do (file, index) ->
fs.readFile "src/#{file}.js", 'utf8', (err, fileContents) ->
throw err if err
libContents[index] = fileContents
process() if --remaining is 0
# Translate concatenated file
process = ->
fs.writeFile 'dist/glquery.js', libContents.join('\n\n'), 'utf8', (err) ->
throw err if err
console.log "Done."

task 'fetch:npm', "Fetch the npm package manager", ->
exec "curl http://npmjs.org/install.sh | sudo sh", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "Done."

task 'fetch:uglifyjs', "Fetch the UglifyJS minification tool", ->
exec "npm install uglify-js", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "Done."

task 'minify', "Minify the resulting application file after build", ->
path.exists 'node_modules/.bin/uglifyjs', (exists) ->
if exists
exec "node_modules/.bin/uglifyjs dist/glquery.js > dist/glquery.min.js", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "Done."
else
exec "uglifyjs dist/glquery.js > dist/glquery.min.js", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "Done."

task 'clean', "Cleanup all build files and distribution files", ->
exec "rm -rf build;rm dist/glquery.js;rm dist/glquery.min.js", (err, stdout, stderr) ->
console.log stdout + stderr
console.log "Done."

0 comments on commit 01439de

Please sign in to comment.