Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

Cakefile 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. fs = require 'fs'
  2. {print} = require 'util'
  3. {spawn, exec} = require 'child_process'
  4. watchit = require 'watchit'
  5. build = (watch, callback) ->
  6. if typeof watch is 'function'
  7. callback = watch
  8. watch = false
  9. options = ['-c', '-o', 'lib', 'src']
  10. options.unshift '-w' if watch
  11. coffee = spawn 'coffee', options
  12. coffee.stdout.on 'data', (data) -> print data.toString()
  13. coffee.stderr.on 'data', (data) -> print data.toString()
  14. coffee.on 'exit', (status) -> callback?() if status is 0
  15. task 'docs', 'Generate annotated source code with Docco', ->
  16. fs.readdir 'src', (err, contents) ->
  17. files = ("src/#{file}" for file in contents when /\.coffee$/.test file)
  18. docco = spawn 'docco', files
  19. docco.stdout.on 'data', (data) -> print data.toString()
  20. docco.stderr.on 'data', (data) -> print data.toString()
  21. docco.on 'exit', (status) -> callback?() if status is 0
  22. task 'build', 'Compile CoffeeScript source files', ->
  23. build()
  24. task 'watch', 'Recompile CoffeeScript source files when modified', ->
  25. build true
  26. task 'test', 'Run the test suite (and re-run if anything changes)', ->
  27. suite = null
  28. build ->
  29. do runTests = ->
  30. suite?.kill()
  31. suiteNames = ['test']
  32. suiteIndex = 0
  33. do runNextTestSuite = ->
  34. return unless suiteName = suiteNames[suiteIndex]
  35. suite = spawn "coffee", ["-e", "{reporters} = require 'nodeunit'; reporters.default.run ['#{suiteName}.coffee']"], cwd: 'test'
  36. suite.stdout.on 'data', (data) -> print data.toString()
  37. suite.stderr.on 'data', (data) -> print data.toString()
  38. suite.on 'exit', -> suiteIndex++; runNextTestSuite()
  39. invoke 'docs' # lest I forget
  40. watchTargets = (targets..., callback) ->
  41. for target in targets
  42. watchit target, include: true, (event) ->
  43. callback() unless event is 'success'
  44. watchTargets 'src', -> build runTests
  45. watchTargets 'test', 'Cakefile', runTests