This repository was archived by the owner on Mar 12, 2018. It is now read-only.
forked from TZM/tzm-blade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
235 lines (200 loc) · 7.04 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
require 'coffee-script/register'
fs = require 'fs'
wrench = require 'wrench'
{print} = require 'util'
which = require 'which'
{spawn, exec} = require 'child_process'
# ANSI Terminal Colors
bold = '\x1B[0;1m'
red = '\x1B[0;31m'
green = '\x1B[0;32m'
reset = '\x1B[0m'
pkg = JSON.parse fs.readFileSync('./package.json')
testCmd = pkg.scripts.test
startCmd = pkg.scripts.start
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
# Compiles app.coffee and src directory to the .app directory
build = (callback) ->
# options = ['-c','-b', '-o', '.app', 'src']
# cmd = which.sync 'coffee'
# coffee = spawn cmd, options
# coffee.stdout.pipe process.stdout
# coffee.stderr.pipe process.stderr
# coffee.on 'exit', (status) -> callback?() if status is 0
exec 'npm shrinkwrap'
callback?()
# mocha test
test = (callback) ->
process.env["NODE_ENV"] = "test"
options = [
'--globals'
'hasCert,res'
'--reporter'
'spec'
'--compilers'
'coffee:coffee-script'
'--colors'
'--require'
'should'
'--require'
'./run'
]
try
cmd = which.sync 'mocha'
spec = spawn cmd, options
spec.stdout.pipe process.stdout
spec.stderr.pipe process.stderr
spec.on 'exit', (status) -> callback?() if status is 0
catch err
log err.message, red
log 'Mocha is not installed - try npm install mocha -g', red
task 'coffeelint', 'check code style with coffeelint', ->
try
cmd ='./node_modules/coffeelint/bin/coffeelint'
options = ['-f', 'test/lint.json', '-r', 'app']
coffeelint = spawn cmd, options
coffeelint.stdout.pipe process.stdout
coffeelint.stderr.pipe process.stderr
coffeelint.on 'exit', (status) -> callback?() if status is 0
catch err
log err.message, red
log 'Coffeelint is not installed - try npm install coffeelint -g', red
task 'apidoc', 'generate API documentation', ->
exec "./node_modules/coffeedoc/bin/coffeedoc -o docs html src"
task 'docs', 'Generate annotated source code with Doccco-Husky', ->
files = wrench.readdirSyncRecursive("src")
files = ("src/#{file}" for file in files when /\.coffee$/.test file)
log files
try
cmd ='./node_modules/.bin/docco-husky'
docco = spawn cmd, files
docco.stdout.pipe process.stdout
docco.stderr.pipe process.stderr
docco.on 'exit', (status) -> callback?() if status is 0
catch err
log err.message, red
log 'Docco is not installed - try npm install docco -g', red
task 'build', ->
build -> log "✓ Build complete, now run `cake dev`", green
task 'spec', 'Run Mocha tests', ->
build -> test -> log "✓ Mocha spec complete", green
task 'test', 'Run Mocha tests', ->
build -> test -> log "✓ Mocha tests complete", green
option '-a', '--admin [ADMIN]', "Create a new admin account or upgrade existing one"
option '-w', '--password [PASSWORD]', 'Flag to overwrite any existing password'
task 'setup', 'Create a new administrator account', (options) ->
return console.log 'Set the -a flag to setup a new admin' unless options.admin
prompt = require 'prompt'
pEma =
name:'email'
validator: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
pPas =
name:'password', hidden:true
validator: /.{6}/
warning: 'Password must be at least 6 characters long'
args = [];
pass = options.password
email = options.admin
if typeof email is 'string'
return console.log pEma.warning unless email.match pEma.validator
else
args.push pEma;
if typeof pass is 'string'
return console.log pPas.warning unless pass.match pPas.validator
else if pass
args.push pPas
dbconnect = require (__dirname + '/app/utils/dbconnect')
prompt = false
handleInput = (err, result) ->
email = result.email.toLowerCase()
pass = result.password
dbconnect.init (err) ->
return console.log 'setup error', err if err
User = require (__dirname + '/app/models/user/user')
User.findOne {email:email}, (err, user) ->
return setupFinish err if err
if user
return setupFinish null, user if user.groups is 'admin' and user.active and !pass
user.groups = 'admin'
user.password = pass if pass
user.active = true
user.provider.push 'local' if pass and !('local' in user.provider)
return user.save setupFinish
else
return setupFinish new Error('Password required when creating new user') unless pass
console.log 'creating user'
user = new User email:email, password:pass, groups:'admin', active:true, provider:['local']
return user.save setupFinish
if args.length
prompt = require 'prompt'
prompt.start()
prompt.get args, handleInput
else
handleInput null, email:email, password:pass
setupFinish = (err, user) ->
console.log 'setup error', err.message || err if err
dbconnect.db_mongo?.close()
return if err
msg = 'user '+user.email+' is now '+user.groups
msg += ': password set' if pass
console.log msg
option '-v', '--version', "show app's version number"
option '-p', '--port [PORT]', "listen on a specific port for `cake dev`"
task 'dev', 'Creates a new instance of zmgc.', (options) ->
console.log 'dev options', options
return console.log 'tzm-blade version ' + pkg.version if options.version
# watch_coffee
# options = ['-c', '-b', '-w', '-o', '.app', 'src']
# cmd = which.sync 'coffee'
# coffee = spawn cmd, options
# coffee.stdout.pipe process.stdout
# coffee.stderr.pipe process.stderr
log 'Watching coffee files', green
# watch_js
process.env.EMAIL = options.email if options.email
process.env.PORT = options.port if options.port
supervisor = spawn 'node', [
'./node_modules/supervisor/lib/cli-wrapper.js',
'-w',
'app,views',
'-e',
'js|blade',
'run',
]
supervisor.stdout.pipe process.stdout
supervisor.stderr.pipe process.stderr
log 'Watching js files and running server', green
task 'debug', 'start debug env', ->
# watch_coffee
options = ['-c', '-b', '-w', '-o', '.app', 'src']
cmd = which.sync 'coffee'
coffee = spawn cmd, options
coffee.stdout.pipe process.stdout
coffee.stderr.pipe process.stderr
log 'Watching coffee files', green
# run debug mode
app = spawn 'node', [
'--debug',
'run'
]
app.stdout.pipe process.stdout
app.stderr.pipe process.stderr
# run node-inspector
inspector = spawn 'node-inspector'
inspector.stdout.pipe process.stdout
inspector.stderr.pipe process.stderr
# run google chrome
chrome = spawn 'google-chrome', ['http://0.0.0.0:8080/debug?port=5858']
chrome.stdout.pipe process.stdout
chrome.stderr.pipe process.stderr
log 'Debugging server', green
option '-n', '--name [NAME]', 'name of model to `scaffold`'
task 'scaffold', 'scaffold model/controller/test', (options) ->
if not options.name?
log "Please specify model name", red
process.exit(1)
log "Scaffolding `#{options.name}`", green
scaffold = require './scaffold'
scaffold options.name