Commit 55cc3aa9 authored by Josh Haberman's avatar Josh Haberman

WIP.

parent c40f8c1f
/**
* @fileoverview Export symbols needed by generated code in CommonJS style.
*/
exports = {
Message: jspb.Message,
BinaryReader: jspb.BinaryReader,
BinaryWriter: jspb.BinaryWriter,
ExtensionFieldInfo: jspb.ExtensionFieldInfo,
};
var gulp = require('gulp');
var exec = require('child_process').exec;
gulp.task('genproto', function (cb) {
gulp.task('genproto_closure', function (cb) {
exec('../src/protoc --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
});
gulp.task('genproto_commonjs', function (cb) {
exec('mkdir -p commonjs_out && ../src/protoc --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('deps', ['genproto'], function (cb) {
gulp.task('dist', function (cb) {
// TODO(haberman): minify this more aggressively.
// Will require proper externs/exports.
exec('./node_modules/google-closure-library/closure/bin/calcdeps.py -i message.js -i binary/reader.js -i binary/writer.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > google-protobuf.js',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('deps', ['genproto_closure'], function (cb) {
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);
});
})
});
gulp.task('test', ['genproto', 'deps'], function (cb) {
gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) {
exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
function (err, stdout, stderr) {
console.log(stdout);
......@@ -27,3 +47,12 @@ gulp.task('test', ['genproto', 'deps'], function (cb) {
cb(err);
});
});
gulp.task('test_commonjs', ['genproto_commonjs', 'dist'], function (cb) {
exec('JASMINE_CONFIG_PATH=jasmine.json cp jasmine_commonjs.json commonjs_out/jasmine.json && cd commonjs_out && ../node_modules/.bin/jasmine',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
{
"spec_dir": "",
"spec_files": [
"*_test.js"
],
"helpers": [
"node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js",
"node_loader.js",
"deps.js"
]
}
......@@ -2,13 +2,15 @@
"name": "google-protobuf",
"version": "3.0.0-alpha.5",
"description": "Protocol Buffers for JavaScript",
"main": "debug.js",
"main": "google-protobuf.js",
"dependencies": {
"google-closure-library": "~20160125.0.0",
"gulp": "~3.9.0",
"jasmine": "~2.4.1"
},
"devDependencies": {},
"devDependencies": {
"google-closure-compiler": "~20151216.2.0"
},
"scripts": {
"test": "./node_modules/gulp/bin/gulp.js test"
},
......
......@@ -67,6 +67,13 @@ struct GeneratorOptions {
bool error_on_name_conflict;
// Enable binary-format support?
bool binary;
// What style of imports should be used.
enum ImportStyle {
IMPORT_CLOSURE, // goog.require()
IMPORT_COMMONJS, // require()
IMPORT_BROWSER, // no import statements
IMPORT_ES6, // import { member } from ''
} import_style;
GeneratorOptions()
: add_require_for_enums(false),
......@@ -75,7 +82,8 @@ struct GeneratorOptions {
namespace_prefix(""),
library(""),
error_on_name_conflict(false),
binary(false) {}
binary(false),
import_style(IMPORT_CLOSURE) {}
bool ParseFromOptions(
const vector< pair< string, string > >& options,
......@@ -111,6 +119,10 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
io::Printer* printer,
const vector<const FileDescriptor*>& file,
std::set<string>* provided) const;
void FindProvidesForFile(const GeneratorOptions& options,
io::Printer* printer,
const FileDescriptor* file,
std::set<string>* provided) const;
void FindProvidesForMessage(const GeneratorOptions& options,
io::Printer* printer,
const Descriptor* desc,
......@@ -168,6 +180,10 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
std::set<string>* required,
std::set<string>* forwards) const;
void GenerateFile(const GeneratorOptions& options,
io::Printer* printer,
const FileDescriptor* file) const;
// Generate definitions for all message classes and enums in all files,
// processing the files in dependence order.
void GenerateFilesInDepOrder(const GeneratorOptions& options,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment