Skip to content

Instantly share code, notes, and snippets.

@mrjjwright
Created May 15, 2011 17:05
Show Gist options
  • Select an option

  • Save mrjjwright/973311 to your computer and use it in GitHub Desktop.

Select an option

Save mrjjwright/973311 to your computer and use it in GitHub Desktop.
Cake file that packages files from npm or locally. Looks in local node_modules for npm packages.
exports.js_local = 'frontend/js/libs'
exports.js =
underscore: 'npm'
jquery: 'local'
'jquery.cookie': 'local'
'jquery.easing': 'local'
'jquery.extend': 'local'
'jquery.reveal': 'local'
'jquery.simplemodal': 'local'
backbone: 'npm'
store: 'npm'
'date': 'local'
'hashgrid': 'local'
'backbone.history.html5': 'local'
'minpubsub': 'local'
exports.js_target = 'frontend/js/libs.js'
fs = require 'fs'
assets = require './frontend/js/assets'
exec = require('child_process').exec
task 'dev:js_lib', 'Rebuild the js libs', (options) ->
js = ''
js_local = assets.js_local
for key of assets.js
if assets.js[key] is "npm"
try
js += fs.readFileSync("node_modules/#{key}/#{key}.js", 'utf-8')
catch e
try
# Try the lib dir
js += fs.readFileSync("node_modules/#{key}/lib/#{key}.js", 'utf-8')
catch e1
log "unable to find package #{key} in node_modules"
else
js += fs.readFileSync("#{js_local}/#{key}.js", 'utf-8')
fs.writeFileSync assets.js_target, js
console.log("Successfuly created #{assets.js_target}")
task 'prod:js_lib', 'Build and uglify', ->
invoke 'dev:js_lib'
exec "uglifyjs --overwrite #{assets.js_target}", (err, stdout, stderr) ->
if err then console.log stderr.trim() else console.log 'done'
@wookiehangover
Copy link

have you thought about integrating uglify here too?

@mrjjwright
Copy link
Author

Oh ok boss :). Added above.

@mrjjwright
Copy link
Author

Btw, I dropped ender.js in favor of this. This is all I really need for the most part except for a little file watching when my app files change (just not packaging them for now).

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