Josh Haberman | e9cf31e | 2015-12-21 15:18:17 -0800 | [diff] [blame] | 1 | var gulp = require('gulp'); |
Nikolai Vavilov | 7ff229f | 2016-04-15 23:23:33 +0200 | [diff] [blame] | 2 | var execFile = require('child_process').execFile; |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 3 | var glob = require('glob'); |
Josh Haberman | e9cf31e | 2015-12-21 15:18:17 -0800 | [diff] [blame] | 4 | |
Nikolai Vavilov | 7ff229f | 2016-04-15 23:23:33 +0200 | [diff] [blame] | 5 | function exec(command, cb) { |
| 6 | execFile('sh', ['-c', command], cb); |
| 7 | } |
| 8 | |
Josh Haberman | 24c5424 | 2016-02-19 11:46:03 -0800 | [diff] [blame] | 9 | var protoc = process.env.PROTOC || '../src/protoc'; |
| 10 | |
Josh Haberman | 1337486 | 2016-06-16 11:59:08 -0700 | [diff] [blame] | 11 | var wellKnownTypes = [ |
| 12 | '../src/google/protobuf/any.proto', |
| 13 | '../src/google/protobuf/api.proto', |
Josh Haberman | 4308cc4 | 2016-06-16 16:05:47 -0700 | [diff] [blame] | 14 | '../src/google/protobuf/compiler/plugin.proto', |
Josh Haberman | 1337486 | 2016-06-16 11:59:08 -0700 | [diff] [blame] | 15 | '../src/google/protobuf/descriptor.proto', |
| 16 | '../src/google/protobuf/duration.proto', |
| 17 | '../src/google/protobuf/empty.proto', |
| 18 | '../src/google/protobuf/field_mask.proto', |
| 19 | '../src/google/protobuf/source_context.proto', |
| 20 | '../src/google/protobuf/struct.proto', |
| 21 | '../src/google/protobuf/timestamp.proto', |
| 22 | '../src/google/protobuf/type.proto', |
| 23 | '../src/google/protobuf/wrappers.proto', |
| 24 | ]; |
| 25 | |
Adam Cozzette | 7e5f980 | 2017-02-28 14:20:56 -0800 | [diff] [blame] | 26 | var group1Protos = [ |
| 27 | 'data.proto', |
| 28 | 'test3.proto', |
| 29 | 'test5.proto', |
| 30 | 'commonjs/test6/test6.proto', |
| 31 | 'test8.proto', |
Adam Cozzette | 24204c9 | 2018-11-07 20:56:18 -0800 | [diff] [blame] | 32 | 'test11.proto', |
| 33 | 'test12.proto', |
| 34 | 'test13.proto', |
| 35 | 'test14.proto', |
| 36 | 'test15.proto', |
Adam Cozzette | 7e5f980 | 2017-02-28 14:20:56 -0800 | [diff] [blame] | 37 | 'testbinary.proto', |
| 38 | 'testempty.proto', |
| 39 | 'test.proto', |
Artem Kustikov | 743a432 | 2020-02-27 20:10:16 +0300 | [diff] [blame] | 40 | 'testlargenumbers.proto', |
Adam Cozzette | 7e5f980 | 2017-02-28 14:20:56 -0800 | [diff] [blame] | 41 | ]; |
| 42 | |
| 43 | var group2Protos = [ |
| 44 | 'proto3_test.proto', |
| 45 | 'test2.proto', |
| 46 | 'test4.proto', |
| 47 | 'commonjs/test7/test7.proto', |
| 48 | ]; |
| 49 | |
Peter Marton | 3c4e368 | 2018-03-01 16:05:19 -0800 | [diff] [blame] | 50 | var group3Protos = [ |
Peter Marton | 13f94b4 | 2018-03-26 16:07:45 -0700 | [diff] [blame] | 51 | 'test9.proto', |
| 52 | 'test10.proto' |
Peter Marton | 3c4e368 | 2018-03-01 16:05:19 -0800 | [diff] [blame] | 53 | ]; |
| 54 | |
| 55 | |
Adam Cozzette | 7e5f980 | 2017-02-28 14:20:56 -0800 | [diff] [blame] | 56 | gulp.task('genproto_well_known_types_closure', function (cb) { |
| 57 | exec(protoc + ' --js_out=one_output_file_per_input_file,binary:. -I ../src -I . ' + wellKnownTypes.join(' '), |
Josh Haberman | e9cf31e | 2015-12-21 15:18:17 -0800 | [diff] [blame] | 58 | function (err, stdout, stderr) { |
| 59 | console.log(stdout); |
| 60 | console.log(stderr); |
| 61 | cb(err); |
| 62 | }); |
Josh Haberman | 55cc3aa | 2016-02-02 15:18:34 -0800 | [diff] [blame] | 63 | }); |
Josh Haberman | e9cf31e | 2015-12-21 15:18:17 -0800 | [diff] [blame] | 64 | |
Adam Cozzette | 7e5f980 | 2017-02-28 14:20:56 -0800 | [diff] [blame] | 65 | gulp.task('genproto_group1_closure', function (cb) { |
| 66 | exec(protoc + ' --js_out=library=testproto_libs1,binary:. -I ../src -I . ' + group1Protos.join(' '), |
| 67 | function (err, stdout, stderr) { |
| 68 | console.log(stdout); |
| 69 | console.log(stderr); |
| 70 | cb(err); |
| 71 | }); |
| 72 | }); |
| 73 | |
Joshua Haberman | 6ba5241 | 2020-07-09 18:17:47 -0700 | [diff] [blame] | 74 | gulp.task('genproto_group2_closure', function(cb) { |
| 75 | exec( |
| 76 | protoc + |
| 77 | ' --experimental_allow_proto3_optional --js_out=library=testproto_libs2,binary:. -I ../src -I . -I commonjs ' + |
| 78 | group2Protos.join(' '), |
| 79 | function(err, stdout, stderr) { |
| 80 | console.log(stdout); |
| 81 | console.log(stderr); |
| 82 | cb(err); |
| 83 | }); |
Adam Cozzette | 7e5f980 | 2017-02-28 14:20:56 -0800 | [diff] [blame] | 84 | }); |
| 85 | |
| 86 | gulp.task('genproto_well_known_types_commonjs', function (cb) { |
| 87 | exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src ' + wellKnownTypes.join(' '), |
| 88 | function (err, stdout, stderr) { |
| 89 | console.log(stdout); |
| 90 | console.log(stderr); |
| 91 | cb(err); |
| 92 | }); |
| 93 | }); |
| 94 | |
| 95 | gulp.task('genproto_group1_commonjs', function (cb) { |
| 96 | exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . ' + group1Protos.join(' '), |
| 97 | function (err, stdout, stderr) { |
| 98 | console.log(stdout); |
| 99 | console.log(stderr); |
| 100 | cb(err); |
| 101 | }); |
| 102 | }); |
| 103 | |
Joshua Haberman | 6ba5241 | 2020-07-09 18:17:47 -0700 | [diff] [blame] | 104 | gulp.task('genproto_group2_commonjs', function(cb) { |
| 105 | exec( |
| 106 | 'mkdir -p commonjs_out && ' + protoc + |
| 107 | ' --experimental_allow_proto3_optional --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . ' + |
| 108 | group2Protos.join(' '), |
| 109 | function(err, stdout, stderr) { |
| 110 | console.log(stdout); |
| 111 | console.log(stderr); |
| 112 | cb(err); |
| 113 | }); |
Josh Haberman | 104723f | 2016-06-16 18:40:07 -0700 | [diff] [blame] | 114 | }); |
| 115 | |
| 116 | gulp.task('genproto_commonjs_wellknowntypes', function (cb) { |
Adam Cozzette | 40f3586 | 2016-11-18 12:32:52 -0800 | [diff] [blame] | 117 | exec('mkdir -p commonjs_out/node_modules/google-protobuf && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out/node_modules/google-protobuf -I ../src ' + wellKnownTypes.join(' '), |
Josh Haberman | 55cc3aa | 2016-02-02 15:18:34 -0800 | [diff] [blame] | 118 | function (err, stdout, stderr) { |
| 119 | console.log(stdout); |
| 120 | console.log(stderr); |
| 121 | cb(err); |
| 122 | }); |
| 123 | }); |
| 124 | |
Josh Haberman | 1337486 | 2016-06-16 11:59:08 -0700 | [diff] [blame] | 125 | gulp.task('genproto_wellknowntypes', function (cb) { |
| 126 | exec(protoc + ' --js_out=import_style=commonjs,binary:. -I ../src ' + wellKnownTypes.join(' '), |
| 127 | function (err, stdout, stderr) { |
| 128 | console.log(stdout); |
| 129 | console.log(stderr); |
| 130 | cb(err); |
| 131 | }); |
| 132 | }); |
Peter Marton | 3c4e368 | 2018-03-01 16:05:19 -0800 | [diff] [blame] | 133 | gulp.task('genproto_group3_commonjs_strict', function (cb) { |
| 134 | exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs_strict,binary:commonjs_out -I ../src -I commonjs -I . ' + group3Protos.join(' '), |
| 135 | function (err, stdout, stderr) { |
| 136 | console.log(stdout); |
| 137 | console.log(stderr); |
| 138 | cb(err); |
| 139 | }); |
| 140 | }); |
| 141 | |
Josh Haberman | 1337486 | 2016-06-16 11:59:08 -0700 | [diff] [blame] | 142 | |
Adam Cozzette | 671e075 | 2017-02-23 11:32:16 -0800 | [diff] [blame] | 143 | function getClosureBuilderCommand(exportsFile, outputFile) { |
| 144 | return './node_modules/google-closure-library/closure/bin/build/closurebuilder.py ' + |
| 145 | '--root node_modules ' + |
| 146 | '-o compiled ' + |
Hao Nguyen | 3efc3fd | 2019-03-28 09:54:13 -0700 | [diff] [blame] | 147 | '--compiler_jar node_modules/google-closure-compiler-java/compiler.jar ' + |
Adam Cozzette | 671e075 | 2017-02-23 11:32:16 -0800 | [diff] [blame] | 148 | '-i ' + exportsFile + ' ' + |
| 149 | 'map.js message.js binary/arith.js binary/constants.js binary/decoder.js ' + |
| 150 | 'binary/encoder.js binary/reader.js binary/utils.js binary/writer.js ' + |
| 151 | exportsFile + ' > ' + outputFile; |
| 152 | } |
| 153 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 154 | gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) { |
Josh Haberman | 55cc3aa | 2016-02-02 15:18:34 -0800 | [diff] [blame] | 155 | // TODO(haberman): minify this more aggressively. |
| 156 | // Will require proper externs/exports. |
Adam Cozzette | 671e075 | 2017-02-23 11:32:16 -0800 | [diff] [blame] | 157 | exec(getClosureBuilderCommand('commonjs/export.js', 'google-protobuf.js'), |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 158 | function (err, stdout, stderr) { |
| 159 | console.log(stdout); |
| 160 | console.log(stderr); |
| 161 | cb(err); |
| 162 | }); |
Hao Nguyen | 9276cb5 | 2019-05-01 13:22:07 -0700 | [diff] [blame] | 163 | })); |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 164 | |
| 165 | gulp.task('commonjs_asserts', function (cb) { |
Adam Cozzette | 671e075 | 2017-02-23 11:32:16 -0800 | [diff] [blame] | 166 | exec('mkdir -p commonjs_out/test_node_modules && ' + |
| 167 | getClosureBuilderCommand( |
| 168 | 'commonjs/export_asserts.js', |
| 169 | 'commonjs_out/test_node_modules/closure_asserts_commonjs.js'), |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 170 | function (err, stdout, stderr) { |
| 171 | console.log(stdout); |
| 172 | console.log(stderr); |
| 173 | cb(err); |
| 174 | }); |
| 175 | }); |
| 176 | |
Josh Haberman | 3c4ce52 | 2016-04-11 15:53:25 -0700 | [diff] [blame] | 177 | gulp.task('commonjs_testdeps', function (cb) { |
Adam Cozzette | 671e075 | 2017-02-23 11:32:16 -0800 | [diff] [blame] | 178 | exec('mkdir -p commonjs_out/test_node_modules && ' + |
| 179 | getClosureBuilderCommand( |
| 180 | 'commonjs/export_testdeps.js', |
| 181 | 'commonjs_out/test_node_modules/testdeps_commonjs.js'), |
Josh Haberman | 3c4ce52 | 2016-04-11 15:53:25 -0700 | [diff] [blame] | 182 | function (err, stdout, stderr) { |
| 183 | console.log(stdout); |
| 184 | console.log(stderr); |
| 185 | cb(err); |
| 186 | }); |
| 187 | }); |
| 188 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 189 | gulp.task( |
| 190 | 'make_commonjs_out', |
| 191 | gulp.series( |
| 192 | [ |
| 193 | 'dist', 'genproto_well_known_types_commonjs', |
| 194 | 'genproto_group1_commonjs', 'genproto_group2_commonjs', |
| 195 | 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', |
| 196 | 'commonjs_testdeps', 'genproto_group3_commonjs_strict' |
| 197 | ], |
| 198 | function(cb) { |
| 199 | // TODO(haberman): minify this more aggressively. |
| 200 | // Will require proper externs/exports. |
| 201 | var cmd = |
| 202 | 'mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && '; |
| 203 | function addTestFile(file) { |
| 204 | cmd += 'node commonjs/rewrite_tests_for_commonjs.js < ' + file + |
| 205 | ' > commonjs_out/' + file + '&& '; |
| 206 | } |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 207 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 208 | glob.sync('*_test.js').forEach(addTestFile); |
| 209 | glob.sync('binary/*_test.js').forEach(addTestFile); |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 210 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 211 | exec( |
| 212 | cmd + 'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' + |
| 213 | 'cp google-protobuf.js commonjs_out/test_node_modules && ' + |
| 214 | 'cp commonjs/strict_test.js commonjs_out/strict_test.js &&' + |
| 215 | 'cp commonjs/import_test.js commonjs_out/import_test.js', |
| 216 | function(err, stdout, stderr) { |
| 217 | console.log(stdout); |
| 218 | console.log(stderr); |
| 219 | cb(err); |
| 220 | }); |
| 221 | })); |
Josh Haberman | 55cc3aa | 2016-02-02 15:18:34 -0800 | [diff] [blame] | 222 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 223 | gulp.task( |
| 224 | 'deps', |
| 225 | gulp.series( |
| 226 | [ |
| 227 | 'genproto_well_known_types_closure', 'genproto_group1_closure', |
| 228 | 'genproto_group2_closure' |
| 229 | ], |
| 230 | function(cb) { |
| 231 | exec( |
| 232 | './node_modules/google-closure-library/closure/bin/build/depswriter.py binary/arith.js binary/constants.js binary/decoder.js binary/encoder.js binary/reader.js binary/utils.js binary/writer.js debug.js map.js message.js node_loader.js test_bootstrap.js > deps.js', |
| 233 | function(err, stdout, stderr) { |
| 234 | console.log(stdout); |
| 235 | console.log(stderr); |
| 236 | cb(err); |
| 237 | }); |
| 238 | })); |
Josh Haberman | e9cf31e | 2015-12-21 15:18:17 -0800 | [diff] [blame] | 239 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 240 | gulp.task( |
| 241 | 'test_closure', |
| 242 | gulp.series( |
| 243 | [ |
| 244 | 'genproto_well_known_types_closure', 'genproto_group1_closure', |
| 245 | 'genproto_group2_closure', 'deps' |
| 246 | ], |
| 247 | function(cb) { |
| 248 | exec( |
| 249 | 'JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine', |
| 250 | function(err, stdout, stderr) { |
| 251 | console.log(stdout); |
| 252 | console.log(stderr); |
| 253 | cb(err); |
| 254 | }); |
| 255 | })); |
Josh Haberman | 55cc3aa | 2016-02-02 15:18:34 -0800 | [diff] [blame] | 256 | |
Hao Nguyen | 1d4e959 | 2019-05-03 14:33:43 -0700 | [diff] [blame] | 257 | gulp.task('test_commonjs', gulp.series(['make_commonjs_out'], function(cb) { |
murgatroid99 | a862b6b | 2016-02-24 13:44:57 -0800 | [diff] [blame] | 258 | exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../node_modules/.bin/jasmine', |
Josh Haberman | 55cc3aa | 2016-02-02 15:18:34 -0800 | [diff] [blame] | 259 | function (err, stdout, stderr) { |
| 260 | console.log(stdout); |
| 261 | console.log(stderr); |
| 262 | cb(err); |
| 263 | }); |
Hao Nguyen | 9276cb5 | 2019-05-01 13:22:07 -0700 | [diff] [blame] | 264 | })); |
Josh Haberman | 35298f9 | 2016-02-04 17:01:33 -0800 | [diff] [blame] | 265 | |
Hao Nguyen | 9276cb5 | 2019-05-01 13:22:07 -0700 | [diff] [blame] | 266 | gulp.task('test', gulp.series(['test_closure', 'test_commonjs'], function(cb) { |
Josh Haberman | 35298f9 | 2016-02-04 17:01:33 -0800 | [diff] [blame] | 267 | cb(); |
Hao Nguyen | 9276cb5 | 2019-05-01 13:22:07 -0700 | [diff] [blame] | 268 | })); |