-
Notifications
You must be signed in to change notification settings - Fork 19
/
Cakefile
35 lines (29 loc) · 1.08 KB
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# CakeFile inspired by chosen:
# https://raw.github.com/harvesthq/chosen/master/Cakefile
#
fs = require 'fs'
path = require 'path'
{spawn, exec} = require 'child_process'
CoffeeScript = require 'coffee-script'
handlebars = require "handlebars"
uglify = require 'uglify-js'
wrapper = handlebars.compile fs.readFileSync("build/wrapper.js").toString()
output =
'lib/underscore-query.js': ["src/underscore-query.coffee"]
'lib/underscore-query.amd.js': ["src/underscore-query.coffee"]
wrap = (code) -> wrapper({code})
task 'build', 'build from source', ->
for js, sources of output
isAMD = js.indexOf("amd") isnt -1
js = path.join(__dirname, js)
code = ''
for source in sources
source = path.join(__dirname, source)
file_contents = "#{fs.readFileSync source}"
code += CoffeeScript.compile file_contents, {bare:isAMD}
if isAMD
code = wrap(code)
fs.writeFileSync js, code
minName = js.replace(/\.js$/,'.min.js')
minCode = uglify.minify(code, {fromString:true})
fs.writeFileSync minName, minCode.code