scratch – Diff between revs 75 and 125

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