jakefile.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. let fs = require('fs')
  2. let path = require('path');
  3. let proc = require('child_process');
  4. const PROJECT_DIR = process.cwd();
  5. process.env.PROJECT_DIR = PROJECT_DIR;
  6. namespace('doc', function () {
  7. task('generate', ['doc:clobber'], function () {
  8. var cmd = '../node-jsdoc-toolkit/app/run.js -n -r=100 ' +
  9. '-t=../node-jsdoc-toolkit/templates/codeview -d=./doc/ ./lib';
  10. jake.logger.log('Generating docs ...');
  11. jake.exec([cmd], function () {
  12. jake.logger.log('Done.');
  13. complete();
  14. });
  15. }, {async: true});
  16. task('clobber', function () {
  17. var cmd = 'rm -fr ./doc/*';
  18. jake.exec([cmd], function () {
  19. jake.logger.log('Clobbered old docs.');
  20. complete();
  21. });
  22. }, {async: true});
  23. });
  24. desc('Generate docs for Jake');
  25. task('doc', ['doc:generate']);
  26. npmPublishTask('jake', function () {
  27. this.packageFiles.include([
  28. 'Makefile',
  29. 'jakefile.js',
  30. 'README.md',
  31. 'package.json',
  32. 'usage.txt',
  33. 'lib/**',
  34. 'bin/**',
  35. 'test/**'
  36. ]);
  37. this.packageFiles.exclude([
  38. 'test/tmp'
  39. ]);
  40. });
  41. jake.Task['publish:package'].directory = PROJECT_DIR;
  42. namespace('test', function () {
  43. let integrationTest = task('integration', ['publish:package'], async function () {
  44. let pkg = JSON.parse(fs.readFileSync(`${PROJECT_DIR}/package.json`).toString());
  45. let version = pkg.version;
  46. proc.execSync('rm -rf ./node_modules');
  47. // Install from the actual package, run tests from the packaged binary
  48. proc.execSync(`mkdir -p node_modules/.bin && mv ${PROJECT_DIR}/pkg/jake-v` +
  49. `${version} node_modules/jake && ln -s ${process.cwd()}` +
  50. '/node_modules/jake/bin/cli.js ./node_modules/.bin/jake');
  51. let testArgs = [];
  52. if (process.env.filter) {
  53. testArgs.push(process.env.filter);
  54. }
  55. else {
  56. testArgs.push('*.js');
  57. }
  58. let spawned = proc.spawn(`${PROJECT_DIR}/node_modules/.bin/mocha`, testArgs, {
  59. stdio: 'inherit'
  60. });
  61. return new Promise((resolve, reject) => {
  62. spawned.on('exit', () => {
  63. if (!(process.env.noclobber || process.env.noClobber)) {
  64. proc.execSync('rm -rf tmp_publish && rm -rf package.json' +
  65. ' && rm -rf package-lock.json && rm -rf node_modules');
  66. // Rather than invoking 'clobber' task
  67. jake.rmRf(`${PROJECT_DIR}/pkg`);
  68. }
  69. resolve();
  70. });
  71. });
  72. });
  73. integrationTest.directory = `${PROJECT_DIR}/test/integration`;
  74. let unitTest = task('unit', async function () {
  75. let testArgs = [];
  76. if (process.env.filter) {
  77. testArgs.push(process.env.filter);
  78. }
  79. else {
  80. testArgs.push('*.js');
  81. }
  82. let spawned = proc.spawn(`${PROJECT_DIR}/node_modules/.bin/mocha`, testArgs, {
  83. stdio: 'inherit'
  84. });
  85. });
  86. unitTest.directory = `${PROJECT_DIR}/test/unit`;
  87. });
  88. desc('Runs all tests');
  89. task('test', ['test:unit', 'test:integration']);