Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 273 lines (224 sloc) 8.413 kb
faed8a9 @balupton updated base files
balupton authored
1 # February 2, 2015
c1bcf8f @RobLoach Initial commit
RobLoach authored
2 # https://github.com/bevry/base
3
4
5 # =====================================
6 # Imports
7
8 fsUtil = require('fs')
9 pathUtil = require('path')
10
11
12 # =====================================
13 # Variables
14
48d30bc @RobLoach Update to 2.1.0
RobLoach authored
15 WINDOWS = process.platform.indexOf('win') is 0
16 NODE = process.execPath
17 NPM = (if WINDOWS then process.execPath.replace('node.exe', 'npm.cmd') else 'npm')
18 EXT = (if WINDOWS then '.cmd' else '')
19 GIT = "git"
20
5513f4e @balupton updated base files
balupton authored
21 APP_PATH = process.cwd()
48d30bc @RobLoach Update to 2.1.0
RobLoach authored
22 PACKAGE_PATH = pathUtil.join(APP_PATH, "package.json")
23 PACKAGE_DATA = require(PACKAGE_PATH)
24
25 MODULES_PATH = pathUtil.join(APP_PATH, "node_modules")
26 DOCPAD_PATH = pathUtil.join(MODULES_PATH, "docpad")
5513f4e @balupton updated base files
balupton authored
27 CAKE = pathUtil.join(MODULES_PATH, "coffee-script/bin/cake")
28 COFFEE = pathUtil.join(MODULES_PATH, "coffee-script/bin/coffee")
29 PROJECTZ = pathUtil.join(MODULES_PATH, "projectz/bin/projectz")
30 DOCCO = pathUtil.join(MODULES_PATH, "docco/bin/docco")
31 DOCPAD = pathUtil.join(MODULES_PATH, "docpad/bin/docpad")
32 BISCOTTO = pathUtil.join(MODULES_PATH, "biscotto/bin/biscotto")
48d30bc @RobLoach Update to 2.1.0
RobLoach authored
33
34 config = {}
5513f4e @balupton updated base files
balupton authored
35 config.TEST_PATH = "test"
36 config.DOCCO_SRC_PATH = null
37 config.DOCCO_OUT_PATH = "docs"
38 config.BISCOTTO_SRC_PATH = null
39 config.BISCOTTO_OUT_PATH = "docs"
40 config.COFFEE_SRC_PATH = null
41 config.COFFEE_OUT_PATH = "out"
42 config.DOCPAD_SRC_PATH = null
43 config.DOCPAD_OUT_PATH = "out"
48d30bc @RobLoach Update to 2.1.0
RobLoach authored
44
45 for own key,value of (PACKAGE_DATA.cakeConfiguration or {})
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
46 config[key] = value
48d30bc @RobLoach Update to 2.1.0
RobLoach authored
47
faed8a9 @balupton updated base files
balupton authored
48 #for own key,value of config
49 # config[key] = pathUtil.resolve(APP_PATH, value) if value
50 # ^ causes issues with biscotto, as it just wants relative paths
c1bcf8f @RobLoach Initial commit
RobLoach authored
51
52
53 # =====================================
54 # Generic
55
faed8a9 @balupton updated base files
balupton authored
56 child_process = require('child_process')
57
58 spawn = (command, args, opts) ->
59 if opts.output is true
60 console.log(command, args.join(' '))
61 opts.stdio = 'inherit'
62 return child_process.spawn(command, args, opts)
63 exec = (command, opts, next) ->
64 if opts.output is true
65 console.log(command)
66 return child_process.exec command, opts, (err, stdout, stderr) ->
67 console.log(stdout)
68 console.log(stderr)
69 next()
70 else
71 return child_process.exec(command, opts, next)
95131cf @RobLoach Update to 2.1.1
RobLoach authored
72
c1bcf8f @RobLoach Initial commit
RobLoach authored
73 safe = (next,fn) ->
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
74 next ?= (err) -> console.log(err.stack ? err)
75 fn ?= next # support only one argument
76 return (err) ->
77 # success status code
78 if err is 0
79 err = null
c1bcf8f @RobLoach Initial commit
RobLoach authored
80
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
81 # error status code
82 else if err is 1
83 err = new Error('Process exited with error status code')
c1bcf8f @RobLoach Initial commit
RobLoach authored
84
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
85 # Error
86 return next(err) if err
c1bcf8f @RobLoach Initial commit
RobLoach authored
87
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
88 # Continue
89 return fn()
c1bcf8f @RobLoach Initial commit
RobLoach authored
90
91 finish = (err) ->
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
92 throw err if err
93 console.log('OK')
c1bcf8f @RobLoach Initial commit
RobLoach authored
94
95
96 # =====================================
97 # Actions
98
99 actions =
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
100 clean: (opts,next) ->
101 # Prepare
102 (next = opts; opts = {}) unless next?
aceafec @balupton updated base files
balupton authored
103
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
104 # Add compilation paths
105 args = ['-Rf', config.COFFEE_OUT_PATH, config.DOCPAD_OUT_PATH, config.DOCCO_OUT_PATH]
aceafec @balupton updated base files
balupton authored
106
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
107 # Add common ignore paths
108 for path in [APP_PATH, config.TEST_PATH]
109 args.push(
110 pathUtil.join(path, 'build')
111 pathUtil.join(path, 'components')
112 pathUtil.join(path, 'bower_components')
113 pathUtil.join(path, 'node_modules')
114 pathUtil.join(path, '*out')
115 pathUtil.join(path, '*log')
116 )
117
118 # rm
faed8a9 @balupton updated base files
balupton authored
119 console.log('\nclean:')
120 spawn('rm', args, {output:true, cwd:APP_PATH}).on('close', safe next)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
121
122 install: (opts,next) ->
123 # Prepare
124 (next = opts; opts = {}) unless next?
125
126 # Steps
127 step1 = ->
faed8a9 @balupton updated base files
balupton authored
128 console.log('\nnpm install (for app):')
129 spawn(NPM, ['install'], {output:true, cwd:APP_PATH}).on('close', safe next, step2)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
130 step2 = ->
131 return step3() if !config.TEST_PATH or !fsUtil.existsSync(config.TEST_PATH)
faed8a9 @balupton updated base files
balupton authored
132 console.log('\nnpm install (for test):')
133 spawn(NPM, ['install'], {output:true, cwd:config.TEST_PATH}).on('close', safe next, step3)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
134 step3 = ->
135 return step4() if !fsUtil.existsSync(DOCPAD_PATH)
faed8a9 @balupton updated base files
balupton authored
136 console.log('\nnpm install (for docpad tests):')
137 spawn(NPM, ['install'], {output:true, cwd:DOCPAD_PATH}).on('close', safe next, step4)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
138 step4 = next
139
140 # Start
141 step1()
142
143 compile: (opts,next) ->
144 # Prepare
145 (next = opts; opts = {}) unless next?
146
147 # Steps
148 step1 = ->
faed8a9 @balupton updated base files
balupton authored
149 console.log('\ncake install')
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
150 actions.install(opts, safe next, step2)
151 step2 = ->
152 return step3() if !config.COFFEE_SRC_PATH or !fsUtil.existsSync(COFFEE)
faed8a9 @balupton updated base files
balupton authored
153 console.log('\ncoffee compile:')
154 spawn(NODE, [COFFEE, '-co', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {output:true, cwd:APP_PATH}).on('close', safe next, step3)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
155 step3 = ->
156 return step4() if !config.DOCPAD_SRC_PATH or !fsUtil.existsSync(DOCPAD)
faed8a9 @balupton updated base files
balupton authored
157 console.log('\ndocpad generate:')
158 spawn(NODE, [DOCPAD, 'generate'], {output:true, cwd:APP_PATH}).on('close', safe next, step4)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
159 step4 = next
160
161 # Start
162 step1()
163
164 watch: (opts,next) ->
165 # Prepare
166 (next = opts; opts = {}) unless next?
167
168 # Steps
169 step1 = ->
faed8a9 @balupton updated base files
balupton authored
170 console.log('\ncake install')
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
171 actions.install(opts, safe next, step2)
172 step2 = ->
173 return step3() if !config.COFFEE_SRC_PATH or !fsUtil.existsSync(COFFEE)
faed8a9 @balupton updated base files
balupton authored
174 console.log('\ncoffee watch:')
175 spawn(NODE, [COFFEE, '-wco', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {output:true, cwd:APP_PATH}).on('close', safe) # background
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
176 step3() # continue while coffee runs in background
177 step3 = ->
178 return step4() if !config.DOCPAD_SRC_PATH or !fsUtil.existsSync(DOCPAD)
faed8a9 @balupton updated base files
balupton authored
179 console.log('\ndocpad run:')
180 spawn(NODE, [DOCPAD, 'run'], {output:true, cwd:APP_PATH}).on('close', safe) # background
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
181 step4() # continue while docpad runs in background
182 step4 = next
183
184 # Start
185 step1()
186
187 test: (opts,next) ->
188 # Prepare
189 (next = opts; opts = {}) unless next?
190
191 # Steps
192 step1 = ->
faed8a9 @balupton updated base files
balupton authored
193 console.log('\ncake compile')
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
194 actions.compile(opts, safe next, step2)
195 step2 = ->
faed8a9 @balupton updated base files
balupton authored
196 console.log('\nnpm test:')
197 spawn(NPM, ['test'], {output:true, cwd:APP_PATH}).on('close', safe next, step3)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
198 step3 = next
199
200 # Start
201 step1()
202
203 prepublish: (opts,next) ->
204 # Prepare
205 (next = opts; opts = {}) unless next?
206
207 # Steps
208 step1 = ->
faed8a9 @balupton updated base files
balupton authored
209 console.log('\ncake compile')
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
210 actions.compile(opts, safe next, step2)
211 step2 = ->
212 return step3() if !fsUtil.existsSync(PROJECTZ)
faed8a9 @balupton updated base files
balupton authored
213 console.log('\nprojectz compile')
214 spawn(NODE, [PROJECTZ, 'compile'], {output:true, cwd:APP_PATH}).on('close', safe next, step3)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
215 step3 = ->
216 return step4() if !config.DOCCO_SRC_PATH or !fsUtil.existsSync(DOCCO)
faed8a9 @balupton updated base files
balupton authored
217 console.log('\ndocco compile:')
218 exec("#{NODE} #{DOCCO} -o #{config.DOCCO_OUT_PATH} #{config.DOCCO_SRC_PATH}", {output:true, cwd:APP_PATH}, safe next, step4)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
219 step4 = ->
5513f4e @balupton updated base files
balupton authored
220 return step5() if !config.BISCOTTO_SRC_PATH or !fsUtil.existsSync(BISCOTTO)
faed8a9 @balupton updated base files
balupton authored
221 console.log('\nbiscotto compile:')
222 exec("""#{BISCOTTO} -n #{PACKAGE_DATA.title or PACKAGE_DATA.name} --title "#{PACKAGE_DATA.title or PACKAGE_DATA.name} API Documentation" -r README.md -o #{config.BISCOTTO_OUT_PATH} #{config.BISCOTTO_SRC_PATH} - LICENSE.md HISTORY.md""", {output:true, cwd:APP_PATH}, safe next, step5)
5513f4e @balupton updated base files
balupton authored
223 step5 = ->
faed8a9 @balupton updated base files
balupton authored
224 console.log('\ncake test')
225 actions.test(opts, safe next, step6)
226 step6 = next
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
227
228 # Start
229 step1()
230
231 publish: (opts,next) ->
232 # Prepare
233 (next = opts; opts = {}) unless next?
234
235 # Steps
236 step1 = ->
faed8a9 @balupton updated base files
balupton authored
237 console.log('\ncake prepublish')
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
238 actions.prepublish(opts, safe next, step2)
239 step2 = ->
faed8a9 @balupton updated base files
balupton authored
240 console.log('\nnpm publish:')
241 spawn(NPM, ['publish'], {output:true, cwd:APP_PATH}).on('close', safe next, step3)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
242 step3 = ->
faed8a9 @balupton updated base files
balupton authored
243 console.log('\ngit tag:')
244 spawn(GIT, ['tag', 'v'+PACKAGE_DATA.version, '-a'], {output:true, cwd:APP_PATH}).on('close', safe next, step4)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
245 step4 = ->
faed8a9 @balupton updated base files
balupton authored
246 console.log('\ngit push origin master:')
247 spawn(GIT, ['push', 'origin', 'master'], {output:true, cwd:APP_PATH}).on('close', safe next, step5)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
248 step5 = ->
faed8a9 @balupton updated base files
balupton authored
249 console.log('\ngit push tags:')
250 spawn(GIT, ['push', 'origin', '--tags'], {output:true, cwd:APP_PATH}).on('close', safe next, step6)
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
251 step6 = next
252
253 # Start
254 step1()
c1bcf8f @RobLoach Initial commit
RobLoach authored
255
256
257 # =====================================
258 # Commands
259
260 commands =
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
261 clean: 'clean up instance'
262 install: 'install dependencies'
263 compile: 'compile our files (runs install)'
264 watch: 'compile our files initially, and again for each change (runs install)'
265 test: 'run our tests (runs compile)'
266 prepublish: 'prepare our package for publishing'
267 publish: 'publish our package (runs prepublish)'
c1bcf8f @RobLoach Initial commit
RobLoach authored
268
269 Object.keys(commands).forEach (key) ->
6bacd43 @RobLoach v2.0.0. Initial fork.
RobLoach authored
270 description = commands[key]
271 fn = actions[key]
272 task key, description, (opts) -> fn(opts, finish)
Something went wrong with that request. Please try again.