-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
72 lines (63 loc) · 2 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
fs = require 'fs'
{spawn, exec} = require 'child_process'
util = require 'util'
async = require 'async'
_ = require 'underscore'
mainDir = './'
excludedHintFiles = []
excludedHintDirs = ['node_modules']
task 'spec', 'run vows specs', ->
vowsFiles = []
specFetch = (dir) ->
files = fs.readdirSync dir
for filename in files
filepath = dir + '/' + filename
if ((/^(\w+)\_spec.js$/).test filename)
vowsFiles.push(filepath)
else
try
specFetch filepath
catch error
specFetch('./spec')
console.log('Running:\n vows ');
vowsFiles.forEach (file, index) ->
console.log('\t' + file)
vowsFiles.push('-spec')
proc = spawn 'vows', vowsFiles
proc.stdout.on 'data', (data) ->
process.stdout.write data
proc.stderr.on 'data', (data) ->
process.stderr.write data
proc.on 'exit', (code) ->
console.log('Done.')
task 'hint', 'run jshint on all files in the main directory', ->
tasks = {}
hint mainDir, tasks
async.series tasks,(err, results) ->
output = _.map results, (log, path) ->
return log
console.log output.join ''
hint = (dir, tasks) ->
if dir == './'
dir = __dirname+'/'
for filename in fs.readdirSync dir
name = filename.match /^(\w+)\.js$/
excluded = _.detect excludedHintFiles, (exclude) ->
return exclude == filename
if name and name.length > 1 and excluded == undefined
tasks[dir+filename] = addToTasks dir+filename
else if (filename.indexOf '.') == -1 && excludedHintDirs.indexOf(filename) == -1
try
hint dir+filename+'/', tasks
catch error
addToTasks = (filepath) ->
return (callback) ->
hintProcess = spawn 'jshint', [filepath, '--config', 'jshint_config.json']
hintProcess.stdout.on 'data', (result) ->
console.log result.toString()
hintProcess.stderr.on 'data', (result) ->
console.error result.toString()
hintProcess.on 'exit', (code) ->
result = if code == 0 then '.' else 'x'
process.stdout.write result
callback(null)