UNPKG

1.65 kBPlain TextView Raw
1fs = require('fs')
2path = require('path')
3{print} = require('sys')
4{spawn, exec} = require('child_process')
5
6
7run = (command, options, next) ->
8 if options? and options.length > 0
9 command += ' ' + options.join(' ')
10 exec(command, (error, stdout, stderr) ->
11 if stderr.length > 0
12 console.log("Stderr exec'ing command '#{command}'...\n" + stderr)
13 if error?
14 console.log('exec error: ' + error)
15 if next?
16 next(stdout)
17 else
18 if stdout.length > 0
19 console.log("Stdout exec'ing command '#{command}'...\n" + stdout)
20 )
21
22task('compile', 'Compile CoffeeScript source files to JavaScript', () ->
23 process.chdir(__dirname)
24 fs.readdir('./', (err, contents) ->
25 files = ("#{file}" for file in contents when (file.indexOf('.coffee') > 0))
26 run('coffee', ['-c'].concat(files))
27 )
28)
29
30task('doctest', 'Runs doctests found in documentation', () ->
31 process.chdir(__dirname)
32 fs.readdir('./', (err, contents) ->
33 files = ("#{file}" for file in contents when (file.indexOf('.coffee') > 0))
34# run('coffeedoc', ['-o', './docs', '-p', './package.json'].concat(files))
35 run('coffeedoctest', ['--readme'].concat(files))
36 )
37)
38
39task('publish', 'Publish to npm', () ->
40 process.chdir(__dirname)
41 run('npm publish .')
42)
43
44task('test', 'Run the CoffeeScript test suite with nodeunit', () ->
45 {reporters} = require('nodeunit')
46 process.chdir(__dirname)
47 reporters.default.run(['test'], undefined, (failure) ->
48 if failure?
49 console.log(failure)
50 process.exit(1)
51 )
52)
53
54task('testall', 'Runs both tests and doctests', () ->
55 invoke('test')
56 invoke('doctest')
57)