1 | # This file was originally created by Benjamin Lupton <b@lupton.cc> (http://balupton.com)
|
2 | # and is currently licensed under the Creative Commons Zero (http://creativecommons.org/publicdomain/zero/1.0/)
|
3 | # making it public domain so you can do whatever you wish with it without worry (you can even remove this notice!)
|
4 | #
|
5 | # If you change something here, be sure to reflect the changes in:
|
6 | # - the scripts section of the package.json file
|
7 | # - the .travis.yml file
|
8 |
|
9 |
|
10 | # -----------------
|
11 | # Variables
|
12 |
|
13 | WINDOWS = process.platform.indexOf('win') is 0
|
14 | NODE = process.execPath
|
15 | NPM = if WINDOWS then process.execPath.replace('node.exe','npm.cmd') else 'npm'
|
16 | EXT = (if WINDOWS then '.cmd' else '')
|
17 | APP = process.cwd()
|
18 | BIN = "#{APP}/node_modules/.bin"
|
19 | CAKE = "#{BIN}/cake#{EXT}"
|
20 | COFFEE = "#{BIN}/coffee#{EXT}"
|
21 | OUT = "#{APP}/out"
|
22 | SRC = "#{APP}/src"
|
23 |
|
24 |
|
25 | # -----------------
|
26 | # Requires
|
27 |
|
28 | pathUtil = require('path')
|
29 | {exec,spawn} = require('child_process')
|
30 | safe = (next,fn) ->
|
31 | return (err) ->
|
32 | return next(err) if err
|
33 | return fn()
|
34 |
|
35 |
|
36 | # -----------------
|
37 | # Actions
|
38 |
|
39 | clean = (opts,next) ->
|
40 | (next = opts; opts = {}) unless next?
|
41 | args = [
|
42 | '-Rf'
|
43 | OUT
|
44 | pathUtil.join(APP,'node_modules')
|
45 | pathUtil.join(APP,'*out')
|
46 | pathUtil.join(APP,'*log')
|
47 | ]
|
48 | spawn('rm', args, {stdio:'inherit',cwd:APP}).on('exit',next)
|
49 |
|
50 | compile = (opts,next) ->
|
51 | (next = opts; opts = {}) unless next?
|
52 | spawn(COFFEE, ['-bco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
|
53 |
|
54 | example = (opts,next) ->
|
55 | (next = opts; opts = {}) unless next?
|
56 | compile opts, safe next, ->
|
57 | command = pathUtil.resolve("#{__dirname}/bin/watchr")
|
58 | spawn(command, [], {stdio:'inherit',cwd:APP,env:process.env}).on('exit',next)
|
59 |
|
60 | watch = (opts,next) ->
|
61 | (next = opts; opts = {}) unless next?
|
62 | spawn(COFFEE, ['-bwco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
|
63 |
|
64 | install = (opts,next) ->
|
65 | (next = opts; opts = {}) unless next?
|
66 | spawn(NPM, ['install'], {stdio:'inherit',cwd:APP}).on('exit',next)
|
67 |
|
68 | reset = (opts,next) ->
|
69 | (next = opts; opts = {}) unless next?
|
70 | clean opts, safe next, ->
|
71 | install opts, safe next, ->
|
72 | compile opts, next
|
73 |
|
74 | setup = (opts,next) ->
|
75 | (next = opts; opts = {}) unless next?
|
76 | install opts, safe next, ->
|
77 | compile opts, next
|
78 |
|
79 | test = (opts,next) ->
|
80 | (next = opts; opts = {}) unless next?
|
81 | spawn(NPM, ['test'], {stdio:'inherit',cwd:APP}).on('exit',next)
|
82 |
|
83 | finish = (err) ->
|
84 | throw err if err
|
85 | console.log('OK')
|
86 |
|
87 |
|
88 | # -----------------
|
89 | # Commands
|
90 |
|
91 | # clean
|
92 | task 'clean', 'clean up instance', ->
|
93 | clean finish
|
94 |
|
95 | # compile
|
96 | task 'compile', 'compile our files', ->
|
97 | compile finish
|
98 |
|
99 | # dev/watch
|
100 | task 'dev', 'watch and recompile our files', ->
|
101 | watch finish
|
102 | task 'watch', 'watch and recompile our files', ->
|
103 | watch finish
|
104 |
|
105 | # example
|
106 | task 'example', 'run the example file', ->
|
107 | example finish
|
108 |
|
109 | # install
|
110 | task 'install', 'install dependencies', ->
|
111 | install finish
|
112 |
|
113 | # reset
|
114 | task 'reset', 'reset instance', ->
|
115 | reset finish
|
116 |
|
117 | # setup
|
118 | task 'setup', 'setup for development', ->
|
119 | setup finish
|
120 |
|
121 | # test
|
122 | task 'test', 'run our tests', ->
|
123 | test finish
|
124 |
|
125 | # test-debug
|
126 | task 'test-debug', 'run our tests in debug mode', ->
|
127 | test {debug:true}, finish
|
128 |
|
129 | # test-prepare
|
130 | task 'test-prepare', 'prepare out tests', ->
|
131 | setup finish
|
132 |
|