jakefile.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. let proc = require('child_process');
  2. const PROJECT_DIR = process.cwd();
  3. process.env.PROJECT_DIR = PROJECT_DIR;
  4. namespace('doc', function () {
  5. task('generate', ['doc:clobber'], function () {
  6. var cmd = '../node-jsdoc-toolkit/app/run.js -n -r=100 ' +
  7. '-t=../node-jsdoc-toolkit/templates/codeview -d=./doc/ ./lib';
  8. jake.logger.log('Generating docs ...');
  9. jake.exec([cmd], function () {
  10. jake.logger.log('Done.');
  11. complete();
  12. });
  13. }, {async: true});
  14. task('clobber', function () {
  15. var cmd = 'rm -fr ./doc/*';
  16. jake.exec([cmd], function () {
  17. jake.logger.log('Clobbered old docs.');
  18. complete();
  19. });
  20. }, {async: true});
  21. });
  22. desc('Generate docs for Jake');
  23. task('doc', ['doc:generate']);
  24. npmPublishTask('jake', function () {
  25. this.packageFiles.include([
  26. 'Makefile',
  27. 'jakefile.js',
  28. 'README.md',
  29. 'package.json',
  30. 'usage.txt',
  31. 'lib/**',
  32. 'bin/**',
  33. 'test/**'
  34. ]);
  35. this.packageFiles.exclude([
  36. 'test/tmp'
  37. ]);
  38. });
  39. jake.Task['publish:package'].directory = PROJECT_DIR;
  40. namespace('test', function () {
  41. let integrationTest = task('integration', async function () {
  42. let testArgs = [];
  43. if (process.env.filter) {
  44. testArgs.push(process.env.filter);
  45. }
  46. else {
  47. testArgs.push('*.js');
  48. }
  49. let spawned = proc.spawn(`${PROJECT_DIR}/node_modules/.bin/mocha`, testArgs, {
  50. stdio: 'inherit'
  51. });
  52. return new Promise((resolve, reject) => {
  53. spawned.on('exit', () => {
  54. resolve();
  55. });
  56. });
  57. });
  58. integrationTest.directory = `${PROJECT_DIR}/test/integration`;
  59. let integrationClobber = task('integrationClobber', function () {
  60. proc.execSync('rm -rf package.json pkg tmp_publish');
  61. });
  62. integrationClobber.directory = `${PROJECT_DIR}/test/integration`;
  63. let unitTest = task('unit', async function () {
  64. let testArgs = [];
  65. if (process.env.filter) {
  66. testArgs.push(process.env.filter);
  67. }
  68. else {
  69. testArgs.push('*.js');
  70. }
  71. let spawned = proc.spawn(`${PROJECT_DIR}/node_modules/.bin/mocha`, testArgs, {
  72. stdio: 'inherit'
  73. });
  74. });
  75. unitTest.directory = `${PROJECT_DIR}/test/unit`;
  76. });
  77. desc('Runs all tests');
  78. task('test', ['test:unit', 'test:integration', 'test:integrationClobber']);
  79. desc('Runs eslint for both lib and test directories');
  80. task('lint', function (doFix) {
  81. let cmd = 'eslint --format codeframe "lib/**/*.js" "test/**/*.js"';
  82. if (doFix) {
  83. cmd += ' --fix';
  84. }
  85. try {
  86. proc.execSync(cmd);
  87. }
  88. catch (err) {
  89. console.log(err.message);
  90. console.log(err.stderr.toString());
  91. console.log(err.stdout.toString());
  92. fail('eslint failed');
  93. }
  94. });