Cakefile 4.2 KB

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