protoc 1.0.0 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  A wrapper in Node for the compiled protoc from https://github.com/google/protobuf.
3
3
 
4
4
  ## Version
5
- It's currently using Protocol Buffers `v3.2.0`.
5
+ It's currently using Protocol Buffers `v3.11.2`.
6
6
 
7
7
  ## Platforms
8
8
  Google only provides binary files for Windows, Linux and OSX in x86_64 and x86_32.
package/index.js CHANGED
@@ -7,13 +7,51 @@ var uuid = require("node-uuid");
7
7
  var mkdirp = require("mkdirp");
8
8
  var glob = require("glob");
9
9
 
10
+ exports.protoc = function(args, options, callback) {
11
+ cp.execFile(protoc, args, options, callback);
12
+ };
13
+
14
+ exports.closure = function(files, options, callback) {
15
+ if (!callback) {
16
+ callback = options;
17
+ options = null;
18
+ }
19
+
20
+ options.imports = options.imports || [];
21
+ options.outputPath = options.outputPath || "./";
22
+
23
+ var cwd = process.cwd();
24
+ var absoluteOutputPath = path.resolve(cwd, options.outputPath);
25
+ var relative = path.relative(absoluteOutputPath, cwd);
26
+
27
+ var args = [
28
+ "--js_out=one_output_file_per_input_file,binary:."
29
+ ];
30
+
31
+ for (var i = 0; i < options.imports.length; i++) {
32
+ args.push("-I", path.join(relative, options.imports[i]));
33
+ }
34
+
35
+ for (var i = 0; i < files.length; i++) {
36
+ args.push(path.join(relative, files[i]));
37
+ }
38
+
39
+ mkdirp(options.outputPath, function(err) {
40
+ if (err) return callback(err);
41
+
42
+ exports.protoc(args, {
43
+ "cwd": options.outputPath
44
+ }, callback);
45
+ });
46
+ };
47
+
10
48
  /**
11
49
  * Converts .proto files to .js files that can be used in Google Closure
12
50
  * Compiler.
13
51
  * The generated .js files require the files in
14
52
  * https://github.com/google/protobuf/tree/master/js.
15
53
  * @param {?Array<string>} files the proto files.
16
- * @param {?function(?Error, ?Array<Vinyl>)} callback the callback method.
54
+ * @param {?function(?Error, ?Array<Vinyl>)} callback the callback method.
17
55
  */
18
56
  exports.library = function(files, callback) {
19
57
  var dirpath = "tmp";
@@ -22,7 +60,7 @@ exports.library = function(files, callback) {
22
60
  mkdirp("tmp", function(err) {
23
61
  if (err) return callback(err);
24
62
 
25
- cp.execFile(protoc, ["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) {
63
+ exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) {
26
64
  if (err) return callback(err);
27
65
 
28
66
  if (fs.existsSync(jsFile + ".js")) {