UNPKG

3.2 kBPlain TextView Raw
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
13WINDOWS = process.platform.indexOf('win') is 0
14NODE = process.execPath
15NPM = if WINDOWS then process.execPath.replace('node.exe','npm.cmd') else 'npm'
16EXT = (if WINDOWS then '.cmd' else '')
17APP = process.cwd()
18BIN = "#{APP}/node_modules/.bin"
19CAKE = "#{BIN}/cake#{EXT}"
20COFFEE = "#{BIN}/coffee#{EXT}"
21OUT = "#{APP}/out"
22SRC = "#{APP}/src"
23
24
25# -----------------
26# Requires
27
28pathUtil = require('path')
29{exec,spawn} = require('child_process')
30safe = (next,fn) ->
31 return (err) ->
32 return next(err) if err
33 return fn()
34
35
36# -----------------
37# Actions
38
39clean = (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
50compile = (opts,next) ->
51 (next = opts; opts = {}) unless next?
52 spawn(COFFEE, ['-bco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
53
54example = (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
60watch = (opts,next) ->
61 (next = opts; opts = {}) unless next?
62 spawn(COFFEE, ['-bwco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
63
64install = (opts,next) ->
65 (next = opts; opts = {}) unless next?
66 spawn(NPM, ['install'], {stdio:'inherit',cwd:APP}).on('exit',next)
67
68reset = (opts,next) ->
69 (next = opts; opts = {}) unless next?
70 clean opts, safe next, ->
71 install opts, safe next, ->
72 compile opts, next
73
74setup = (opts,next) ->
75 (next = opts; opts = {}) unless next?
76 install opts, safe next, ->
77 compile opts, next
78
79test = (opts,next) ->
80 (next = opts; opts = {}) unless next?
81 spawn(NPM, ['test'], {stdio:'inherit',cwd:APP}).on('exit',next)
82
83finish = (err) ->
84 throw err if err
85 console.log('OK')
86
87
88# -----------------
89# Commands
90
91# clean
92task 'clean', 'clean up instance', ->
93 clean finish
94
95# compile
96task 'compile', 'compile our files', ->
97 compile finish
98
99# dev/watch
100task 'dev', 'watch and recompile our files', ->
101 watch finish
102task 'watch', 'watch and recompile our files', ->
103 watch finish
104
105# example
106task 'example', 'run the example file', ->
107 example finish
108
109# install
110task 'install', 'install dependencies', ->
111 install finish
112
113# reset
114task 'reset', 'reset instance', ->
115 reset finish
116
117# setup
118task 'setup', 'setup for development', ->
119 setup finish
120
121# test
122task 'test', 'run our tests', ->
123 test finish
124
125# test-debug
126task 'test-debug', 'run our tests in debug mode', ->
127 test {debug:true}, finish
128
129# test-prepare
130task 'test-prepare', 'prepare out tests', ->
131 setup finish
132