gulpfile.js 3.3 KB

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