2015-12-21 23:18:17 +00:00
|
|
|
var gulp = require('gulp');
|
2016-04-15 21:23:33 +00:00
|
|
|
var execFile = require('child_process').execFile;
|
2016-02-04 18:29:27 +00:00
|
|
|
var glob = require('glob');
|
2015-12-21 23:18:17 +00:00
|
|
|
|
2016-04-15 21:23:33 +00:00
|
|
|
function exec(command, cb) {
|
|
|
|
execFile('sh', ['-c', command], cb);
|
|
|
|
}
|
|
|
|
|
2016-02-19 19:46:03 +00:00
|
|
|
var protoc = process.env.PROTOC || '../src/protoc';
|
|
|
|
|
2016-06-16 18:59:08 +00:00
|
|
|
var wellKnownTypes = [
|
|
|
|
'../src/google/protobuf/any.proto',
|
|
|
|
'../src/google/protobuf/api.proto',
|
2016-06-16 23:05:47 +00:00
|
|
|
'../src/google/protobuf/compiler/plugin.proto',
|
2016-06-16 18:59:08 +00:00
|
|
|
'../src/google/protobuf/descriptor.proto',
|
|
|
|
'../src/google/protobuf/duration.proto',
|
|
|
|
'../src/google/protobuf/empty.proto',
|
|
|
|
'../src/google/protobuf/field_mask.proto',
|
|
|
|
'../src/google/protobuf/source_context.proto',
|
|
|
|
'../src/google/protobuf/struct.proto',
|
|
|
|
'../src/google/protobuf/timestamp.proto',
|
|
|
|
'../src/google/protobuf/type.proto',
|
|
|
|
'../src/google/protobuf/wrappers.proto',
|
|
|
|
];
|
|
|
|
|
2016-02-02 23:18:34 +00:00
|
|
|
gulp.task('genproto_closure', function (cb) {
|
2016-02-24 22:23:08 +00:00
|
|
|
exec(protoc + ' --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto',
|
2015-12-21 23:18:17 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
2016-02-02 23:18:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('genproto_commonjs', function (cb) {
|
2016-06-17 01:40:07 +00:00
|
|
|
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',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('genproto_commonjs_wellknowntypes', function (cb) {
|
|
|
|
exec('mkdir -p commonjs_out/node_modules/google-protobuf && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out/node_modules/google-protobuf -I ../src ../src/google/protobuf/descriptor.proto',
|
2016-06-16 18:59:08 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('genproto_wellknowntypes', function (cb) {
|
|
|
|
exec(protoc + ' --js_out=import_style=commonjs,binary:. -I ../src ' + wellKnownTypes.join(' '),
|
2016-02-02 23:18:34 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
2015-12-21 23:18:17 +00:00
|
|
|
|
2016-06-16 18:59:08 +00:00
|
|
|
gulp.task('dist', ['genproto_wellknowntypes'], function (cb) {
|
2016-02-02 23:18:34 +00:00
|
|
|
// TODO(haberman): minify this more aggressively.
|
|
|
|
// Will require proper externs/exports.
|
2016-02-04 18:38:06 +00:00
|
|
|
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',
|
2016-02-04 18:29:27 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('commonjs_asserts', function (cb) {
|
2016-02-24 21:44:57 +00:00
|
|
|
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',
|
2016-02-04 18:29:27 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-11 22:53:25 +00:00
|
|
|
gulp.task('commonjs_testdeps', function (cb) {
|
|
|
|
exec('mkdir -p commonjs_out/test_node_modules && ./node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_testdeps.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/testdeps_commonjs.js',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-17 01:40:07 +00:00
|
|
|
gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) {
|
2016-02-04 18:29:27 +00:00
|
|
|
// TODO(haberman): minify this more aggressively.
|
|
|
|
// Will require proper externs/exports.
|
2016-02-24 21:44:57 +00:00
|
|
|
var cmd = "mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && ";
|
2016-02-04 18:29:27 +00:00
|
|
|
function addTestFile(file) {
|
2016-02-05 23:07:15 +00:00
|
|
|
cmd += 'node commonjs/rewrite_tests_for_commonjs.js < ' + file +
|
2016-02-04 18:29:27 +00:00
|
|
|
' > commonjs_out/' + file + '&& ';
|
|
|
|
}
|
|
|
|
|
|
|
|
glob.sync('*_test.js').forEach(addTestFile);
|
|
|
|
glob.sync('binary/*_test.js').forEach(addTestFile);
|
|
|
|
|
|
|
|
exec(cmd +
|
2016-02-04 18:38:06 +00:00
|
|
|
'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' +
|
2016-02-24 22:23:08 +00:00
|
|
|
'cp google-protobuf.js commonjs_out/test_node_modules && ' +
|
|
|
|
'cp commonjs/import_test.js commonjs_out/import_test.js',
|
2016-02-02 23:18:34 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('deps', ['genproto_closure'], function (cb) {
|
2015-12-21 23:18:17 +00:00
|
|
|
exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py *.js binary/*.js > deps.js',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
2016-02-02 23:18:34 +00:00
|
|
|
});
|
2015-12-21 23:18:17 +00:00
|
|
|
|
2016-02-02 23:18:34 +00:00
|
|
|
gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) {
|
2015-12-21 23:18:17 +00:00
|
|
|
exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
2016-02-02 23:18:34 +00:00
|
|
|
|
2016-02-04 18:29:27 +00:00
|
|
|
gulp.task('test_commonjs', ['make_commonjs_out'], function (cb) {
|
2016-02-24 21:44:57 +00:00
|
|
|
exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../node_modules/.bin/jasmine',
|
2016-02-02 23:18:34 +00:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
console.log(stdout);
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
2016-02-05 01:01:33 +00:00
|
|
|
|
|
|
|
gulp.task('test', ['test_closure', 'test_commonjs'], function(cb) {
|
|
|
|
cb();
|
|
|
|
});
|