1 | fs = require 'fs'
|
2 | CoffeeScript = require 'coffee-script'
|
3 | {spawn, exec} = require 'child_process'
|
4 |
|
5 | # ANSI Terminal Colors.
|
6 | enableColors = no
|
7 | unless process.platform is 'win32'
|
8 | enableColors = not process.env.NODE_DISABLE_COLORS
|
9 |
|
10 | bold = red = green = reset = ''
|
11 | if enableColors
|
12 | bold = '\x1B[0;1m'
|
13 | red = '\x1B[0;31m'
|
14 | green = '\x1B[0;32m'
|
15 | reset = '\x1B[0m'
|
16 |
|
17 |
|
18 | ###
|
19 | Just proc extender
|
20 | ###
|
21 | proc_extender = (cb, proc) =>
|
22 | proc.stderr.on 'data', (buffer) -> console.log "#{buffer}"
|
23 | # proc.stdout.on 'data', (buffer) -> console.log "#{buffer}".info
|
24 | proc.on 'exit', (status) ->
|
25 | process.exit(1) if status != 0
|
26 | cb() if typeof cb is 'function'
|
27 | null
|
28 |
|
29 | # Run a CoffeeScript through our node/coffee interpreter.
|
30 | run_coffee = (args, cb) =>
|
31 | proc_extender cb, spawn 'node', ['./node_modules/.bin/coffee'].concat(args)
|
32 |
|
33 | # Run a mocha tests
|
34 | run_mocha = (args, cb) =>
|
35 | proc_extender cb, spawn 'node', ['./node_modules/.bin/mocha'].concat(args)
|
36 |
|
37 | # Log a message with a color.
|
38 | log = (message, color, explanation) ->
|
39 | console.log color + message + reset + ' ' + (explanation or '')
|
40 |
|
41 |
|
42 | task 'build', 'build module from source', build = (cb) ->
|
43 | files = fs.readdirSync 'src'
|
44 | files = ('src/' + file for file in files when file.match(/\.coffee$/))
|
45 | run_coffee ['-c', '-o', 'lib/'].concat(files), cb
|
46 | log ' -> build done', green
|
47 |
|
48 | task 'test', 'test builded module', ->
|
49 | build ->
|
50 | test_file = './test/extend_test.coffee'
|
51 | run_mocha test_file, -> log ' -> all tests passed :)', green
|
52 |
|