This repository has been archived by the owner on Apr 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
51 lines (43 loc) · 1.64 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
coffee: require "/usr/local/lib/coffee-script/lib/coffee-script"
fs: require "fs"
sys: require "sys"
puts: sys.puts
{spawn, exec}: require "child_process"
fs: require 'fs'
path: require 'path'
COFFEE_ARGS: ['--no-wrap', '-c']
BUILD_DIR: 'lib'
SOURCE_DIR: 'src'
directoryWalker: (dir, callback, maxLevels, currentLevel, fromRoot) ->
maxLevels: if 'number' is typeof maxLevels then maxLevels else 0
currentLevel: if 'number' is typeof currentLevel then currentLevel else 1
fromRoot: if 'string' is typeof fromRoot then fromRoot else ''
fs.readdir dir, (error, files) ->
if error
puts error.message
return
files.forEach (file) ->
fs.stat path.join(dir, file), (error, stats) ->
if error
puts error.message
return
if stats.isDirectory()
if 0 is maxLevels or maxLevels > currentLevel
directoryWalker path.join(dir, file), callback,
maxLevels, 1 + currentLevel,
fromRoot + file + '/'
callback.call stats, file, fromRoot, path.join(dir, file), stats
run: (cmd, args) ->
proc: spawn cmd, args
proc.addListener 'error', (err) -> if err then puts err
task 'build', 'Build from source', ->
dirs: {}
directoryWalker SOURCE_DIR, (file, shortPath, fullPath) ->
if @isDirectory()
run 'mkdir', [BUILD_DIR + '/' + shortPath + file]
else if /\.coffee$/.test file
args: Array::slice.call COFFEE_ARGS
args.push.apply args, ['-o', BUILD_DIR + '/' + shortPath, fullPath]
run 'coffee', args
else if /\.(js|node|addon)$/.test file
run 'cp', [fullPath, BUILD_DIR + '/' + shortPath + file]