gulpfile.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 commonjs -I . *.proto commonjs/test*/*.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/test_node_modules && ./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/test_node_modules/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 && mkdir -p commonjs_out/test_node_modules && ";
  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/test_node_modules && ' +
  52. 'cp commonjs/import_test.js commonjs_out/import_test.js',
  53. function (err, stdout, stderr) {
  54. console.log(stdout);
  55. console.log(stderr);
  56. cb(err);
  57. });
  58. });
  59. gulp.task('deps', ['genproto_closure'], function (cb) {
  60. exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py *.js binary/*.js > deps.js',
  61. function (err, stdout, stderr) {
  62. console.log(stdout);
  63. console.log(stderr);
  64. cb(err);
  65. });
  66. });
  67. gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) {
  68. exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
  69. function (err, stdout, stderr) {
  70. console.log(stdout);
  71. console.log(stderr);
  72. cb(err);
  73. });
  74. });
  75. gulp.task('test_commonjs', ['make_commonjs_out'], function (cb) {
  76. exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../node_modules/.bin/jasmine',
  77. function (err, stdout, stderr) {
  78. console.log(stdout);
  79. console.log(stderr);
  80. cb(err);
  81. });
  82. });
  83. gulp.task('test', ['test_closure', 'test_commonjs'], function(cb) {
  84. cb();
  85. });