forked from jeremyfa/node-exec-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
38 lines (30 loc) · 1.32 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
fs = require 'fs'
findit = require 'findit'
exec = require('child_process').exec
coffee = require 'coffee-script'
path = require 'path'
escapeShell = (arg) -> "'" + arg.replace(/[^\\]'/g, (m, i, s) -> m.slice(0, 1) + "\\'") + "'"
src = __dirname + '/src'
bin = __dirname + '/bin'
task 'build', 'build project', (options) ->
# Remove bin contents
exec "rm -rf #{escapeShell bin}", (err, stdout, stderr) ->
if err? then throw err
# Copy src content into bin
exec "cp -R #{escapeShell src} #{escapeShell bin}", (err, stdout, stderr) ->
if err? then throw err
# Compile coffee files
for filename in findit.sync bin
if filename.substring(filename.length-7) is '.coffee'
# Get script from coffee file
script = fs.readFileSync filename, 'utf8'
# Compile into js code
js = coffee.compile script
# Write js file with compiled code
file = fs.openSync filename.substring(0, filename.length-7)+'.js', 'w+'
fs.writeSync file, js
fs.closeSync file
# Delete coffee file
fs.unlinkSync filename
# Finish
console.log 'built exec-sync.'