You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.0 KiB

  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. OUT = "#{APP}/out"
  19. SRC = "#{APP}/src"
  20. TEST = "#{APP}/test"
  21. # -----------------
  22. # Requires
  23. pathUtil = require('path')
  24. {exec,spawn} = require('child_process')
  25. safe = (next,fn) ->
  26. return (err) ->
  27. return next(err) if err
  28. return fn()
  29. # -----------------
  30. # Actions
  31. clean = (opts,next) ->
  32. (next = opts; opts = {}) unless next?
  33. args = [
  34. '-Rf'
  35. OUT
  36. pathUtil.join(APP,'node_modules')
  37. pathUtil.join(APP,'*out')
  38. pathUtil.join(APP,'*log')
  39. pathUtil.join(TEST,'node_modules')
  40. pathUtil.join(TEST,'*out')
  41. pathUtil.join(TEST,'*log')
  42. ]
  43. spawn('rm', args, {stdio:'inherit',cwd:APP}).on('exit',next)
  44. compile = (opts,next) ->
  45. (next = opts; opts = {}) unless next?
  46. spawn(COFFEE, ['-bco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
  47. watch = (opts,next) ->
  48. (next = opts; opts = {}) unless next?
  49. spawn(COFFEE, ['-bwco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
  50. install = (opts,next) ->
  51. (next = opts; opts = {}) unless next?
  52. spawn(NPM, ['install'], {stdio:'inherit',cwd:APP}).on 'exit', safe next, ->
  53. spawn(NPM, ['install'], {stdio:'inherit',cwd:TEST}).on('exit',next)
  54. reset = (opts,next) ->
  55. (next = opts; opts = {}) unless next?
  56. clean opts, safe next, -> install opts, safe next, -> compile opts, next
  57. setup = (opts,next) ->
  58. (next = opts; opts = {}) unless next?
  59. install opts, safe next, ->
  60. compile opts, next
  61. test = (opts,next) ->
  62. (next = opts; opts = {}) unless next?
  63. spawn(NPM, ['test'], {stdio:'inherit',cwd:APP}).on('exit',next)
  64. finish = (err) ->
  65. throw err if err
  66. console.log('OK')
  67. # -----------------
  68. # Commands
  69. # clean
  70. task 'clean', 'clean up instance', ->
  71. clean finish
  72. # compile
  73. task 'compile', 'compile our files', ->
  74. compile finish
  75. # dev/watch
  76. task 'dev', 'watch and recompile our files', ->
  77. watch finish
  78. task 'watch', 'watch and recompile our files', ->
  79. watch finish
  80. # install
  81. task 'install', 'install dependencies', ->
  82. install finish
  83. # reset
  84. task 'reset', 'reset instance', ->
  85. reset finish
  86. # setup
  87. task 'setup', 'setup for development', ->
  88. setup finish
  89. # test
  90. task 'test', 'run our tests', ->
  91. test finish
  92. # test-debug
  93. task 'test-debug', 'run our tests in debug mode', ->
  94. test {debug:true}, finish
  95. # test-prepare
  96. task 'test-prepare', 'prepare out tests', ->
  97. setup finish