_Cakefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # This file was originally created by Benjamin Lupton <b@lupton.cc> (http://balupton.com)
  2. # and is currently licensed under the Creative Commons Zero (http://creativecommons.org/publicdomain/zero/1.0/)
  3. # making it public domain so you can do whatever you wish with it without worry (you can even remove this notice!)
  4. #
  5. # If you change something here, be sure to reflect the changes in:
  6. # - the scripts section of the package.json file
  7. # - the .travis.yml file
  8. # -----------------
  9. # Variables
  10. WINDOWS = process.platform.indexOf('win') is 0
  11. NODE = process.execPath
  12. NPM = if WINDOWS then process.execPath.replace('node.exe','npm.cmd') else 'npm'
  13. EXT = (if WINDOWS then '.cmd' else '')
  14. APP = process.cwd()
  15. BIN = "#{APP}/node_modules/.bin"
  16. CAKE = "#{BIN}/cake#{EXT}"
  17. COFFEE = "#{BIN}/coffee#{EXT}"
  18. DOCPAD = "#{BIN}/docpad#{EXT}"
  19. UGLIFY = "#{BIN}/uglifyjs#{EXT}"
  20. OUT = "#{APP}/out"
  21. SRC = "#{APP}/src"
  22. BROWSERIFY = "#{BIN}/browserify#{EXT}"
  23. # -----------------
  24. # Requires
  25. pathUtil = require('path')
  26. {exec,spawn} = require('child_process')
  27. safe = (next,fn) ->
  28. return (err) ->
  29. return next(err) if err
  30. return fn()
  31. # -----------------
  32. # Actions
  33. bench = (opts,next) ->
  34. (next = opts; opts = {}) unless next?
  35. spawn(NODE, ["#{OUT}/test/benchmark.js"], {stdio:'inherit',cwd:APP}).on('close',next)
  36. clean = (opts,next) ->
  37. (next = opts; opts = {}) unless next?
  38. args = [
  39. '-Rf'
  40. OUT
  41. pathUtil.join(APP, 'node_modules')
  42. pathUtil.join(APP, '*out')
  43. pathUtil.join(APP, '*log')
  44. ]
  45. spawn('rm', args, {stdio:'inherit',cwd:APP}).on('close',next)
  46. browserify = (opts,next) ->
  47. (next = opts; opts = {}) unless next?
  48. spawn(
  49. BROWSERIFY,
  50. ["#{OUT}/lib/js2coffee.js", '-s', 'js2coffee', '-o', "#{OUT}/lib/browser.js"],
  51. {stdio:'inherit',cwd:APP}
  52. ).on('close',next)
  53. uglify = (opts,next) ->
  54. (next = opts; opts = {}) unless next?
  55. spawn(UGLIFY, ["#{OUT}/lib/browser.js", '-ms'], {stdio:'inherit',cwd:APP}).on('close',next)
  56. compile = (opts,next) ->
  57. (next = opts; opts = {}) unless next?
  58. spawn(DOCPAD, ['generate'], {stdio:'inherit',cwd:APP}).on('close',next)
  59. watch = (opts,next) ->
  60. (next = opts; opts = {}) unless next?
  61. spawn(DOCPAD, ['watch'], {stdio:'inherit',cwd:APP}).on('close',next)
  62. install = (opts,next) ->
  63. (next = opts; opts = {}) unless next?
  64. spawn(NPM, ['install'], {stdio:'inherit',cwd:APP}).on('close',next)
  65. reset = (opts,next) ->
  66. (next = opts; opts = {}) unless next?
  67. clean opts, safe next, -> install opts, safe next, -> compile opts, next
  68. setup = (opts,next) ->
  69. (next = opts; opts = {}) unless next?
  70. install opts, safe next, ->
  71. compile opts, next
  72. test = (opts,next) ->
  73. (next = opts; opts = {}) unless next?
  74. args = []
  75. args.push("--debug-brk") if opts.debug
  76. args.push("#{OUT}/test/everything.js")
  77. spawn(NODE, args, {stdio:'inherit',cwd:APP}, next)
  78. finish = (err) ->
  79. throw err if err
  80. console.log('OK')
  81. # -----------------
  82. # Commands
  83. # bench
  84. task 'bench', 'benchmark our project', ->
  85. bench finish
  86. # clean
  87. task 'clean', 'clean up instance', ->
  88. clean finish
  89. # compile
  90. task 'compile', 'compile our files', ->
  91. compile finish
  92. # browserify
  93. task 'browserify', 'browserify', ->
  94. browserify finish
  95. # uglify
  96. task 'uglify', 'minify browser.js and dump to stdout', ->
  97. uglify ->
  98. # dev/watch
  99. task 'dev', 'watch and recompile our files', ->
  100. watch finish
  101. task 'watch', 'watch and recompile our files', ->
  102. watch finish
  103. # install
  104. task 'install', 'install dependencies', ->
  105. install finish
  106. # reset
  107. task 'reset', 'reset instance', ->
  108. reset finish
  109. # setup
  110. task 'setup', 'setup for development', ->
  111. setup finish
  112. # test
  113. task 'test', 'run our tests', ->
  114. test finish
  115. # test-debug
  116. task 'test-debug', 'run our tests in debug mode', ->
  117. test {debug:true}, finish
  118. # test-prepare
  119. task 'test-prepare', 'prepare out tests', ->
  120. setup finish