gulpfile.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var gulp = require('gulp');
  2. var exec = require('child_process').exec;
  3. var glob = require('glob');
  4. gulp.task('genproto_closure', function (cb) {
  5. exec('../src/protoc --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto',
  6. function (err, stdout, stderr) {
  7. console.log(stdout);
  8. console.log(stderr);
  9. cb(err);
  10. });
  11. });
  12. gulp.task('genproto_commonjs', function (cb) {
  13. exec('mkdir -p commonjs_out && ../src/protoc --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto',
  14. function (err, stdout, stderr) {
  15. console.log(stdout);
  16. console.log(stderr);
  17. cb(err);
  18. });
  19. });
  20. gulp.task('dist', function (cb) {
  21. // TODO(haberman): minify this more aggressively.
  22. // Will require proper externs/exports.
  23. exec('./node_modules/google-closure-library/closure/bin/calcdeps.py -i message.js -i binary/reader.js -i binary/writer.js -i commonjs/export.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > google-protobuf.js',
  24. function (err, stdout, stderr) {
  25. console.log(stdout);
  26. console.log(stderr);
  27. cb(err);
  28. });
  29. });
  30. gulp.task('commonjs_asserts', function (cb) {
  31. exec('mkdir -p commonjs_out && ./node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_asserts.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > commonjs_out/closure_asserts_commonjs.js',
  32. function (err, stdout, stderr) {
  33. console.log(stdout);
  34. console.log(stderr);
  35. cb(err);
  36. });
  37. });
  38. gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'commonjs_asserts'], function (cb) {
  39. // TODO(haberman): minify this more aggressively.
  40. // Will require proper externs/exports.
  41. var cmd = "mkdir -p commonjs_out/binary && ";
  42. function addTestFile(file) {
  43. cmd += 'nodejs commonjs/rewrite_tests_for_commonjs.js < ' + file +
  44. ' > commonjs_out/' + file + '&& ';
  45. }
  46. glob.sync('*_test.js').forEach(addTestFile);
  47. glob.sync('binary/*_test.js').forEach(addTestFile);
  48. exec(cmd +
  49. 'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' +
  50. 'cp google-protobuf.js commonjs_out',
  51. function (err, stdout, stderr) {
  52. console.log(stdout);
  53. console.log(stderr);
  54. cb(err);
  55. });
  56. });
  57. gulp.task('deps', ['genproto_closure'], function (cb) {
  58. exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py *.js binary/*.js > deps.js',
  59. function (err, stdout, stderr) {
  60. console.log(stdout);
  61. console.log(stderr);
  62. cb(err);
  63. });
  64. });
  65. gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) {
  66. exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
  67. function (err, stdout, stderr) {
  68. console.log(stdout);
  69. console.log(stderr);
  70. cb(err);
  71. });
  72. });
  73. gulp.task('test_commonjs', ['make_commonjs_out'], function (cb) {
  74. exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=. ../node_modules/.bin/jasmine',
  75. function (err, stdout, stderr) {
  76. console.log(stdout);
  77. console.log(stderr);
  78. cb(err);
  79. });
  80. });