Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 79 lines (69 sloc) 2.765 kb
f797be0 @kgn Modifying all tasks to print the files.
authored
1 # Require libraries
84887a3 @kgn Adding a cake file.
authored
2 {spawn, exec} = require 'child_process'
3 {log, error} = console; print = log
077c127 @kgn Switching to use an install of uglifyjs.
authored
4 fs = require 'fs'
84887a3 @kgn Adding a cake file.
authored
5
f797be0 @kgn Modifying all tasks to print the files.
authored
6 # Start a subproc.
84887a3 @kgn Adding a cake file.
authored
7 run = (name, args...) ->
cb8d2ca @kgn Fix indent, add comments
authored
8 proc = spawn(name, args)
9 proc.stdout.on('data', (buffer) -> print buffer if buffer = buffer.toString().trim())
10 proc.stderr.on('data', (buffer) -> error buffer if buffer = buffer.toString().trim())
11 proc.on('exit', (status) -> process.exit(1) if status isnt 0)
84887a3 @kgn Adding a cake file.
authored
12
f797be0 @kgn Modifying all tasks to print the files.
authored
13 # Run a shell command.
14 shell = (cmds, callback) ->
cb8d2ca @kgn Fix indent, add comments
authored
15 cmds = [cmds] if Object::toString.apply(cmds) isnt '[object Array]'
16 exec(cmds.join(' && '), (err, stdout, stderr) ->
17 print trimStdout if trimStdout = stdout.trim()
18 error stderr.trim() if err
f797be0 @kgn Modifying all tasks to print the files.
authored
19 callback() if callback
cb8d2ca @kgn Fix indent, add comments
authored
20 )
84887a3 @kgn Adding a cake file.
authored
21
f797be0 @kgn Modifying all tasks to print the files.
authored
22 # **watch**: continually compile the coffee scripts
84887a3 @kgn Adding a cake file.
authored
23 task('watch', 'continually compile the coffee scripts', (options) ->
cb8d2ca @kgn Fix indent, add comments
authored
24 run('coffee', '-wc', '.')
84887a3 @kgn Adding a cake file.
authored
25 )
26
f797be0 @kgn Modifying all tasks to print the files.
authored
27 # **coffee**: compile the coffee scripts
84887a3 @kgn Adding a cake file.
authored
28 task('coffee', 'compile the coffee scripts', (options) ->
f797be0 @kgn Modifying all tasks to print the files.
authored
29 fs.readdir('.', (err, files) ->
30 throw err if err
31 for file in files
32 continue if not /\.coffee$/.test(file)
33 print "compile: #{file} -> #{file.replace(/\.coffee$/, '.js')}"
34 shell("coffee --compile #{file}")
35 )
84887a3 @kgn Adding a cake file.
authored
36 )
37
f797be0 @kgn Modifying all tasks to print the files.
authored
38 # **docco**: build the docs
84887a3 @kgn Adding a cake file.
authored
39 task('docco', 'build the docs', (options) ->
f797be0 @kgn Modifying all tasks to print the files.
authored
40 # docco only builds docs for .coffee files, so make a copy of Cakefile as Cakefile.coffee
41 fs.readFile('Cakefile', 'utf8', (readerr, text) ->
42 throw readerr if readerr
43 fs.writeFile('Cakefile.coffee', text, (writeerr) ->
44 throw writeerr if writeerr
45 shell('docco *.coffee', ->
46 # Delete Cakefile.coffee
47 fs.unlink('Cakefile.coffee', (linkerr) ->
48 throw linkerr if linkerr
49 )
50 )
51 )
52 )
84887a3 @kgn Adding a cake file.
authored
53 )
54
f797be0 @kgn Modifying all tasks to print the files.
authored
55 # **minify**: compile the coffee scripts and minify the javascript files
56 task('minify', 'compile the coffee scripts and minify the javascript files', (options) ->
57 invoke 'coffee'
58 fs.readdir('.', (err, files) ->
59 throw err if err
60 for file in files
61 continue if not /\.js$/.test(file) or /\.min\.js$/.test(file)
077c127 @kgn Switching to use an install of uglifyjs.
authored
62
63 # Create min.js filename
64 nameparts = file.split('.')
65 nameparts[nameparts.length-1] = 'min'
66 nameparts.push('js')
67 newname = nameparts.join('.')
68 print "minify: #{file} -> #{newname}"
69
70 shell("uglifyjs --output #{newname} #{file}")
f797be0 @kgn Modifying all tasks to print the files.
authored
71 )
de9bdc7 @kgn trying to use google to minify js, but the files are too large
authored
72 )
73
f797be0 @kgn Modifying all tasks to print the files.
authored
74 # **build**: compile the coffee scripts, minify the javascript and build the docs
de9bdc7 @kgn trying to use google to minify js, but the files are too large
authored
75 task('build', 'compile the coffee scripts, minify the javascript and build the docs', (options) ->
76 invoke 'minify'
cb8d2ca @kgn Fix indent, add comments
authored
77 invoke 'docco'
de9bdc7 @kgn trying to use google to minify js, but the files are too large
authored
78 )
Something went wrong with that request. Please try again.