scratch – Blame information for rev 127
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
75 | office | 1 | |
2 | {exec, spawn} = require 'child_process' |
||
3 | fs = require 'fs' |
||
4 | path = require 'path' |
||
5 | esc = (arg) -> (''+arg).replace(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/gm, '\\').replace(/\n/g, "'\n'").replace(/^$/, "''") |
||
6 | |||
7 | srcDir = path.normalize __dirname+'/src' |
||
8 | libDir = path.normalize __dirname+'/lib' |
||
9 | libDebugDir = path.normalize __dirname+'/lib/debug' |
||
10 | distDir = path.normalize __dirname+'/dist' |
||
11 | cliDir = path.normalize __dirname+'/cli' |
||
12 | binDir = path.normalize __dirname+'/bin' |
||
13 | specDir = path.normalize __dirname+'/test/spec' |
||
14 | modulesDir = path.normalize __dirname+'/node_modules' |
||
15 | |||
16 | task 'build', 'build project', -> |
||
17 | |||
18 | # Compile |
||
19 | do compile = -> |
||
20 | unless fs.existsSync libDir |
||
21 | fs.mkdirSync libDir |
||
22 | unless fs.existsSync libDir+'/Exception' |
||
23 | fs.mkdirSync libDir+'/Exception' |
||
125 | office | 24 | toCompile = 'Yaml Utils Unescaper Pattern Parser Inline Escaper Dumper Exception/ParseException Exception/ParseMore Exception/DumpException'.split ' ' |
75 | office | 25 | do compileOne = -> |
26 | name = toCompile.shift() |
||
27 | outputDir = (if '/' in name then libDir+'/Exception' else libDir) |
||
28 | exec 'coffee -b -o '+esc(outputDir)+' -c '+esc(srcDir+'/'+name+'.coffee'), (err, res) -> |
||
29 | if err then throw err |
||
30 | |||
31 | console.log "Compiled #{name}.js" |
||
32 | if toCompile.length |
||
33 | compileOne() |
||
34 | else |
||
35 | debugCompile() |
||
36 | |||
37 | # Debug compile |
||
38 | debugCompile = -> |
||
39 | unless fs.existsSync libDebugDir |
||
40 | fs.mkdirSync libDebugDir |
||
41 | unless fs.existsSync libDebugDir+'/Exception' |
||
42 | fs.mkdirSync libDebugDir+'/Exception' |
||
125 | office | 43 | toCompile = 'Yaml Utils Unescaper Pattern Parser Inline Escaper Dumper Exception/ParseException Exception/ParseMore Exception/DumpException'.split ' ' |
75 | office | 44 | do compileOne = -> |
45 | name = toCompile.shift() |
||
46 | outputDir = (if '/' in name then libDebugDir+'/Exception' else libDebugDir) |
||
47 | exec 'coffee -m -b -o '+esc(outputDir)+' -c '+esc(srcDir+'/'+name+'.coffee'), (err, res) -> |
||
48 | if err then throw err |
||
49 | |||
50 | console.log "Compiled #{name}.js (debug)" |
||
51 | if toCompile.length |
||
52 | compileOne() |
||
53 | else |
||
54 | browserify() |
||
55 | |||
56 | # Browserify |
||
57 | unless fs.existsSync distDir |
||
58 | fs.mkdirSync distDir |
||
59 | browserify = -> |
||
60 | exec 'browserify -t coffeeify --extension=".coffee" '+esc(srcDir+'/Yaml.coffee')+' > '+esc(distDir+'/yaml.js'), (err, res) -> |
||
61 | if err then throw err |
||
62 | |||
63 | console.log "Browserified yaml.js" |
||
64 | exec 'browserify --debug -t coffeeify --extension=".coffee" '+esc(srcDir+'/Yaml.coffee')+' > '+esc(distDir+'/yaml.debug.js'), (err, res) -> |
||
65 | if err then throw err |
||
66 | |||
67 | console.log "Browserified yaml.js (debug)" |
||
68 | minify() |
||
69 | |||
70 | # Minify |
||
71 | minify = -> |
||
72 | exec 'uglifyjs --mangle sort '+esc(distDir+'/yaml.js')+' > '+esc(distDir+'/yaml.min.js'), (err, res) -> |
||
73 | if err then throw err |
||
74 | |||
75 | console.log "Minified yaml.min.js" |
||
76 | compileSpec() |
||
77 | |||
78 | # Compile spec |
||
79 | compileSpec = -> |
||
80 | exec 'coffee -b -c '+esc(specDir+'/YamlSpec.coffee'), (err, res) -> |
||
81 | if err then throw err |
||
82 | |||
83 | console.log "Compiled YamlSpec.js" |
||
84 | compileCLI() |
||
85 | |||
86 | # Compile CLI |
||
87 | compileCLI = -> |
||
88 | unless fs.existsSync binDir |
||
89 | fs.mkdirSync binDir |
||
90 | |||
91 | # yaml2json |
||
92 | str = fs.readFileSync cliDir+'/yaml2json.js' |
||
93 | str = "#!/usr/bin/env node\n" + str |
||
94 | fs.writeFileSync binDir+'/yaml2json', str |
||
95 | fs.chmodSync binDir+'/yaml2json', '755' |
||
96 | console.log "Bundled yaml2json" |
||
97 | |||
98 | # json2yaml |
||
99 | str = fs.readFileSync cliDir+'/json2yaml.js' |
||
100 | str = "#!/usr/bin/env node\n" + str |
||
101 | fs.writeFileSync binDir+'/json2yaml', str |
||
102 | fs.chmodSync binDir+'/json2yaml', '755' |
||
103 | console.log "Bundled json2yaml" |
||
104 | |||
105 | |||
106 | task 'test', 'test project', -> |
||
107 | |||
108 | # Test |
||
109 | spawn 'node', [modulesDir+'/jasmine-node/lib/jasmine-node/cli.js', '--verbose', '--coffee', specDir+'/YamlSpec.coffee'], stdio: "inherit" |
||
110 | |||
111 | |||
112 | task 'doc', 'generate documentation', -> |
||
113 | |||
114 | # Generate |
||
115 | spawn 'codo', [srcDir], stdio: "inherit" |
||
116 | |||
117 |