forked from rochappy/layout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
106 lines (89 loc) · 2.72 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
process.env.NODE_ENV = 'development'
require 'coffee-script/register'
nobone = require 'nobone'
{ kit } = nobone()
stylus = require 'stylus'
{ Q, _ } = kit
os_path = kit.path
relative = os_path.relative
coffee_bin = './node_modules/.bin/coffee'
root_path = root_path = "#{__dirname}/"
src_path = "#{root_path}/src"
js_path = "#{src_path}/js"
css_path = "#{src_path}/css"
dist_path = "#{root_path}/dist"
copy= (from, to) =>
kit.copy(from, to).then =>
console.log '>> Copy: '.cyan + relative(root_path, from) + ' -> '.green + relative(root_path, to)
build= ->
kit.remove dist_path
Q.fcall =>
console.log '>> Build start.'.cyan
.then =>
Q.all [
compile_all_coffee()
compile_all_stylus()
]
.then =>
Q.all([
kit.glob os_path.join(js_path, '**', '*.js')
kit.glob os_path.join(css_path, '**', '*.css')
kit.glob os_path.join(src_path, '**', '*.html')
])
.then (file_list) =>
Q.all _.flatten(file_list).map (file) =>
copy file, dist_path + '/' + relative(src_path, file)
.then ->
console.log '>> Build Done.'.green
clean = ->
Q.fcall =>
console.log 'Clean start'.cyan
.then =>
Q.all([
kit.glob os_path.join(js_path, '**', '*.js')
kit.glob os_path.join(css_path, '**', '*.css')
])
.then (file_list) =>
Q.all _.flatten(file_list).map (p) ->
kit.remove p
.then ->
console.log 'Clean done.'.green
compile_coffee= (path) =>
try
kit.spawn coffee_bin, [
'-c'
'-b'
path
]
console.log '>> Compiled: '.cyan + relative(root_path, path)
catch e
console.log ">> Error: #{relative(root_path, path)} \n#{e}".red
compile_all_coffee= ->
Q.fcall =>
kit.glob os_path.join(js_path, '**', "*.coffee")
.then (file_list) =>
Q.all(
_.flatten(file_list).map compile_coffee
)
find_all= (file_type, callback) ->
compile_all_stylus= (path) ->
rootPath = root_path
kit.glob css_path + "/**/*.styl"
.then (paths) ->
if path
paths = []
paths.push path
Q.all paths.map (path) ->
console.log '>> Compiled: '.cyan + relative(rootPath, path)
kit.readFile path, 'utf8'
.then (str) ->
Q.invoke stylus, 'render', str, { filename: path }
.then (code) ->
kit.outputFile path.replace(/\.styl$/, '.css'), code if code
.catch (error) ->
console.log error
.catch (error) ->
console.log error
task 'build', 'Build all source code.', ->
build().then ->
clean()