-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cakefile
86 lines (76 loc) · 2.24 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
# guts taken from [cakefile-template](https://github.com/twilson63/cakefile-template)
# and then modified.
fs = require "fs"
{spawn, exec} = require 'child_process'
cp = (src, dst)-> fs.createReadStream(src).pipe(fs.createWriteStream(dst))
try
which = require('which').sync
catch err
if process.platform.match(/^win/)?
console.log 'WARNING: the which module is required for windows\ntry: npm install which'
which = null
files = [
'domCursor.litcoffee',
'editor.litcoffee'
]
# ANSI Terminal Colors
bold = '\x1b[0;1m'
green = '\x1b[0;32m'
reset = '\x1b[0m'
red = '\x1b[0;31m'
task 'build', 'compile source', (options) ->
build false, (-> log ":-)", green)
cp 'adiff.js', 'build/adiff.js'
cp 'editor.litcoffee', 'README.md'
for f in files
cp f, "build/#{f}"
files = [
'external/docOrg.litcoffee',
'external/org.coffee',
'external/example.litcoffee',
]
build false, (-> log ":-)", green), 'external'
# ## *log*
#
# **given** string as a message
# **and** string as a color
# **and** optional string as an explanation
# **then** builds a statement and logs to console.
#
log = (message, color, explanation) -> console.log color + message + reset + ' ' + (explanation or '')
# ## *launch*
#
# **given** string as a cmd
# **and** optional array and option flags
# **and** optional callback
# **then** spawn cmd with options
# **and** pipe to process stdout and stderr respectively
# **and** on child process exit emit callback if set and status is 0
launch = (cmd, options=[], callback) ->
cmd = which(cmd) if which
app = spawn cmd, options
app.stdout.pipe(process.stdout)
app.stderr.pipe(process.stderr)
app.on 'exit', (status) ->
if status is 0
callback()
else
process.exit(status)
# ## *build*
#
# **given** optional boolean as watch
# **and** optional function as callback
# **then** invoke launch passing coffee command
# **and** defaulted options to compile src to lib
build = (watch, callback, output = 'build') ->
if typeof watch is 'function'
callback = watch
watch = false
#options = ['-c', '-b']
options = ['-c']
options.push("--map")
options.push("-o")
options.push output
options = options.concat files
options.unshift '-w' if watch
launch 'coffee', options, callback