Cakefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. fs = require('fs')
  2. spawnSync = require('child_process').spawnSync
  3. path = require('path')
  4. _ = require('lodash')
  5. isWindows = (process.platform.lastIndexOf('win') == 0)
  6. runSync = (command) ->
  7. # Spawn things in a sub-shell so things like io redirection and gsutil work
  8. if isWindows
  9. shell = 'cmd.exe'
  10. args = ['/c', command]
  11. else
  12. shell = 'sh'
  13. args = ['-c', command]
  14. {status, stdout, stderr} = spawnSync(shell, args, {encoding: 'utf8'})
  15. if stderr?.length > 0 or status > 0
  16. console.error("Error running: '#{command}'\n#{stderr}\n#{stdout}\n")
  17. process.exit(status)
  18. else
  19. console.log("Output of running '#{command}'\n#{stdout}\n")
  20. return stdout
  21. task('clean', 'Deletes .js and .map files', () ->
  22. folders = ['.']
  23. for folder in folders
  24. pathToClean = path.join(__dirname, folder)
  25. contents = fs.readdirSync(pathToClean)
  26. for file in contents when (_.endsWith(file, '.js') or _.endsWith(file, '.map'))
  27. fs.unlinkSync(path.join(pathToClean, file))
  28. )
  29. task('compile', 'Compile CoffeeScript source files to JavaScript', () ->
  30. process.chdir(__dirname)
  31. fs.readdir('./', (err, contents) ->
  32. files = ("#{file}" for file in contents when (file.indexOf('.coffee') > 0))
  33. command = ['coffee', '-c'].concat(files).join(' ')
  34. runSync(command)
  35. )
  36. )
  37. task('test', 'Run the CoffeeScript test suite with nodeunit', () ->
  38. # invoke('testES6') # Commented out for now until we use Proxy support in later versions to enable array/
  39. {reporters} = require('nodeunit')
  40. process.chdir(__dirname)
  41. reporters.default.run(['test'], undefined, (failure) ->
  42. if failure?
  43. console.log(failure)
  44. process.exit(1)
  45. )
  46. )
  47. task('testES6', 'Run tests in testES6 folder with --harmony-proxies flag', () ->
  48. # runSync("node --harmony-proxies node_modules/nodeunit/bin/nodeunit testES6/es6Test.coffee")
  49. runSync("node node_modules/nodeunit/bin/nodeunit testES6/es6Test.coffee")
  50. )
  51. task('publish', 'Publish to npm and add git tags', () ->
  52. process.chdir(__dirname)
  53. runSync('cake test') # Doing this externally to make it synchronous
  54. process.chdir(__dirname)
  55. runSync('cake compile')
  56. console.log('checking git status --porcelain')
  57. stdout = runSync('git status --porcelain')
  58. if stdout.length > 0
  59. console.error('`git status --porcelain` was not clean. Not publishing.')
  60. else
  61. console.log('checking origin/master')
  62. stdout = runSync('git rev-parse origin/master')
  63. console.log('checking master')
  64. stdoutOrigin = stdout
  65. stdout = runSync('git rev-parse master')
  66. stdoutMaster = stdout
  67. if stdoutOrigin == stdoutMaster
  68. console.log('running npm publish')
  69. runSync('npm publish .')
  70. try
  71. stat = fs.statSync('npm-debug.log')
  72. console.error('`npm publish` failed. See npm-debug.log for details.')
  73. process.exit(1)
  74. console.log('creating git tag')
  75. runSync("git tag v#{require('./package.json').version}")
  76. runSync("git push --tags")
  77. invoke("clean")
  78. else
  79. console.error('Origin and master out of sync. Not publishing.')
  80. )