forked from shepherdwind/velocity.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
executable file
·72 lines (61 loc) · 2.38 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
fs = require 'fs'
exec = (require 'child_process').exec
path = require 'path'
buildCompile = (tplfile)->
files = fs.readdirSync 'src/compile'
velocity = ''
files.forEach (file) ->
if file isnt 'index.js'
text = (fs.readFileSync "./src/compile/#{file}").toString()
text = text.replace 'module.exports = ', "/** file: ./src/compile/#{file}*/\n!"
text = text.replace /;\s*$/ , "(Velocity, utils);\n\n"
velocity += text
helper = (fs.readFileSync "./src/helper/text.js").toString()
helper = helper.replace 'module.exports = ', '!'
helper = helper.replace /;\s*$/, "(Velocity.Helper, utils);"
tpl = (fs.readFileSync tplfile).toString()
tpl = tpl.replace '{helper}', helper
tpl = tpl.replace '{velocity}', velocity
fs.writeFileSync 'build/velocity/index.js', tpl
console.log 'build compile success, file at build/velocity/ by ' + tplfile
buildParseFile = (tplfile)->
do buildParse
parseStr = (fs.readFileSync './src/parse/index.js').toString()
tpl = (fs.readFileSync tplfile).toString()
tpl = tpl.replace '{parseStr}', parseStr
fs.writeFileSync './build/velocity/parse.js', tpl
console.log 'build parse to build/velocity/parse.js by ' + tplfile
buildParse = ()->
comd = 'jison velocity.yy velocity.l && mv velocity.js index.js'
parse = exec comd, {cwd: "./src/parse/"}, (error, stdout, stderr)->
console.log 'finish parse'
if error isnt null
console.log 'exec error: ' + error
#编译为velocity语法分析器
task 'parse', 'rebuild the Jison parser', (options) ->
do buildParse
#编译为kissy的模块
task 'build', 'build velocity for kissy', (options) ->
buildCompile "./build/tpl.js"
do buildParse
parseStr = (fs.readFileSync './src/parse/index.js').toString()
fs.writeFileSync './build/velocity/parse.js', "
KISSY.add(function(S){
#{parseStr}
return velocity;
});
"
console.log 'build parse to build/velocity/parse.js'
#编译为CMD的模块
task 'build-amd', 'build velocity for CMD', (options) ->
buildCompile "./src/compile/tpl.js"
buildParseFile "./src/parse/tpl.js"
task 'runner', 'build runner', (options) ->
files = fs.readdirSync 'tests'
ret = ''
files.forEach (file) ->
if (path.extname file) is '.js'
str = fs.readFileSync "./tests/#{file}"
ret += str.toString().replace /^[\S\s]*?describe/, 'describe'
fs.writeFileSync "./tests/runner/spec.js", ret
console.log 'build runner finish'