summaryrefslogtreecommitdiff
path: root/Cakefile
diff options
context:
space:
mode:
authorJeremy Faivre <jeremy.faivre@gmail.com>2014-07-22 10:19:12 +0200
committerJeremy Faivre <jeremy.faivre@gmail.com>2014-07-22 10:21:17 +0200
commitc6cbcf0326723c5f0013490d1fea489694790775 (patch)
treefa735c3ee627b64bd546165aed093d1f6cfce055 /Cakefile
parentc5a6a8601d31508bb3e5880b310b2918834e89c9 (diff)
downloadyamljs-c6cbcf0326723c5f0013490d1fea489694790775.tar.gz
Improve performances (more than 2 times faster), rewrite in coffee-script, fix various bugs.
This is the first pass of rewrite of the YAML library (in progress). The focus was on improving code readability, make it well-documented and fix most of the current issues. It didn't focus on the performances yet, even though they are better than the previous version. The next big step (not included in this first pass in progress) will focus on removing most RegExps because they are time consuming and they make the code working on a "line by line" basis. The code will move to a "character by character" parsing, allowing us to deeply improve performances, and add new features from the 1.2 Yaml spec.
Diffstat (limited to 'Cakefile')
-rw-r--r--Cakefile117
1 files changed, 117 insertions, 0 deletions
diff --git a/Cakefile b/Cakefile
new file mode 100644
index 0000000..0449803
--- /dev/null
+++ b/Cakefile
@@ -0,0 +1,117 @@
+
+{exec, spawn} = require 'child_process'
+fs = require 'fs'
+path = require 'path'
+esc = (arg) -> (''+arg).replace(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/gm, '\\').replace(/\n/g, "'\n'").replace(/^$/, "''")
+
+srcDir = path.normalize __dirname+'/src'
+libDir = path.normalize __dirname+'/lib'
+libDebugDir = path.normalize __dirname+'/lib/debug'
+distDir = path.normalize __dirname+'/dist'
+cliDir = path.normalize __dirname+'/cli'
+binDir = path.normalize __dirname+'/bin'
+specDir = path.normalize __dirname+'/test/spec'
+modulesDir = path.normalize __dirname+'/node_modules'
+
+task 'build', 'build project', ->
+
+ # Compile
+ do compile = ->
+ unless fs.existsSync libDir
+ fs.mkdirSync libDir
+ unless fs.existsSync libDir+'/Exception'
+ fs.mkdirSync libDir+'/Exception'
+ toCompile = 'Yaml Utils Unescaper Pattern Parser Inline Escaper Dumper Exception/ParseException Exception/DumpException'.split ' '
+ do compileOne = ->
+ name = toCompile.shift()
+ outputDir = (if '/' in name then libDir+'/Exception' else libDir)
+ exec 'coffee -b -o '+esc(outputDir)+' -c '+esc(srcDir+'/'+name+'.coffee'), (err, res) ->
+ if err then throw err
+
+ console.log "Compiled #{name}.js"
+ if toCompile.length
+ compileOne()
+ else
+ debugCompile()
+
+ # Debug compile
+ debugCompile = ->
+ unless fs.existsSync libDebugDir
+ fs.mkdirSync libDebugDir
+ unless fs.existsSync libDebugDir+'/Exception'
+ fs.mkdirSync libDebugDir+'/Exception'
+ toCompile = 'Yaml Utils Unescaper Pattern Parser Inline Escaper Dumper Exception/ParseException Exception/DumpException'.split ' '
+ do compileOne = ->
+ name = toCompile.shift()
+ outputDir = (if '/' in name then libDebugDir+'/Exception' else libDebugDir)
+ exec 'coffee -m -b -o '+esc(outputDir)+' -c '+esc(srcDir+'/'+name+'.coffee'), (err, res) ->
+ if err then throw err
+
+ console.log "Compiled #{name}.js (debug)"
+ if toCompile.length
+ compileOne()
+ else
+ browserify()
+
+ # Browserify
+ unless fs.existsSync distDir
+ fs.mkdirSync distDir
+ browserify = ->
+ exec 'browserify -t coffeeify --extension=".coffee" '+esc(srcDir+'/Yaml.coffee')+' > '+esc(distDir+'/yaml.js'), (err, res) ->
+ if err then throw err
+
+ console.log "Browserified yaml.js"
+ exec 'browserify --debug -t coffeeify --extension=".coffee" '+esc(srcDir+'/Yaml.coffee')+' > '+esc(distDir+'/yaml.debug.js'), (err, res) ->
+ if err then throw err
+
+ console.log "Browserified yaml.js (debug)"
+ minify()
+
+ # Minify
+ minify = ->
+ exec 'uglifyjs --mangle sort '+esc(distDir+'/yaml.js')+' > '+esc(distDir+'/yaml.min.js'), (err, res) ->
+ if err then throw err
+
+ console.log "Minified yaml.min.js"
+ compileSpec()
+
+ # Compile spec
+ compileSpec = ->
+ exec 'coffee -b -c '+esc(specDir+'/YamlSpec.coffee'), (err, res) ->
+ if err then throw err
+
+ console.log "Compiled YamlSpec.js"
+ compileCLI()
+
+ # Compile CLI
+ compileCLI = ->
+ unless fs.existsSync binDir
+ fs.mkdirSync binDir
+
+ # yaml2json
+ str = fs.readFileSync cliDir+'/yaml2json.js'
+ str = "#!/usr/bin/env node\n" + str
+ fs.writeFileSync binDir+'/yaml2json', str
+ fs.chmodSync binDir+'/yaml2json', '755'
+ console.log "Bundled yaml2json"
+
+ # json2yaml
+ str = fs.readFileSync cliDir+'/json2yaml.js'
+ str = "#!/usr/bin/env node\n" + str
+ fs.writeFileSync binDir+'/json2yaml', str
+ fs.chmodSync binDir+'/json2yaml', '755'
+ console.log "Bundled json2yaml"
+
+
+task 'test', 'test project', ->
+
+ # Test
+ spawn 'node', [modulesDir+'/jasmine-node/lib/jasmine-node/cli.js', '--verbose', '--coffee', specDir+'/YamlSpec.coffee'], stdio: "inherit"
+
+
+task 'doc', 'generate documentation', ->
+
+ # Generate
+ spawn 'codo', [srcDir], stdio: "inherit"
+
+