protoc 1.0.3 → 1.1.0

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
@@ -1,26 +1,34 @@
1
- # Protocol Buffers for Node
2
- A wrapper in Node for the compiled protoc from https://github.com/google/protobuf.
3
-
4
- ## Version
5
- It's currently using Protocol Buffers `v3.2.0`.
6
-
7
- ## Platforms
8
- Google only provides binary files for Windows, Linux and OSX in x86_64 and x86_32.
9
-
10
- ## Examples
11
- There's currently no documentation. Hopefully this example will help.
12
-
13
- ```JavaScript
14
- var protoc = require("protoc");
15
-
16
- protoc.library(["path/to/file.proto", "path/to/file2.proto"], function(err, files) {
17
- if (err) return console.error(err);
18
-
19
- // Handle the JavaScript Vinyl files.
20
- // These files can be used in Google Closure Compiler,
21
- // but they require the files in
22
- // https://github.com/google/protobuf/tree/master/js
23
-
24
- // ...
25
- });
26
- ```
1
+ # Protocol Buffers for Node
2
+ A wrapper in Node for the compiled protoc from https://github.com/protocolbuffers/protobuf.
3
+
4
+ ## Version
5
+ It's currently using Protocol Buffers `v3.20.3`.
6
+
7
+ ## Platforms
8
+ Google only provides binary files for Windows, Linux and OSX in x86_64 and x86_32.
9
+
10
+ ## Examples
11
+ There's currently no documentation. Hopefully this example will help.
12
+
13
+ ```JavaScript
14
+ var protoc = require("protoc");
15
+
16
+ protoc.library(["path/to/file.proto", "path/to/file2.proto"], function(err, files) {
17
+ if (err) {
18
+ console.error(err);
19
+ return;
20
+ }
21
+
22
+ // Handle the JavaScript Vinyl files.
23
+ // These files can be used in Google Closure Compiler,
24
+ // but they require the files in
25
+ // https://github.com/google/protobuf/tree/master/js
26
+
27
+ // ...
28
+ });
29
+ ```
30
+
31
+ It's also possible to directly call the protoc binary file:
32
+ ```
33
+ npx protoc --help
34
+ ```
package/bin/protoc.js ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { protoc } = require("../");
4
+
5
+ protoc(process.argv.slice(2), {}, (err, stdout, stderr) => {
6
+ if (err) {
7
+ console.error(err);
8
+ process.exit(1);
9
+ return;
10
+ }
11
+
12
+ if (stdout) {
13
+ console.info(stdout);
14
+ }
15
+
16
+ if (stderr) {
17
+ console.error(stderr);
18
+ }
19
+ })
package/index.js CHANGED
@@ -1,109 +1,130 @@
1
- var path = require("path");
2
- var cp = require("child_process");
3
- var fs = require("fs");
4
- var protoc = require("./protoc.js");
5
- var Vinyl = require("vinyl");
6
- var uuid = require("node-uuid");
7
- var mkdirp = require("mkdirp");
8
- var glob = require("glob");
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
-
48
- /**
49
- * Converts .proto files to .js files that can be used in Google Closure
50
- * Compiler.
51
- * The generated .js files require the files in
52
- * https://github.com/google/protobuf/tree/master/js.
53
- * @param {?Array<string>} files the proto files.
54
- * @param {?function(?Error, ?Array<Vinyl>)} callback the callback method.
55
- */
56
- exports.library = function(files, callback) {
57
- var dirpath = "tmp";
58
- var filename = uuid.v4();
59
- var jsFile = path.join(dirpath, filename);
60
- mkdirp("tmp", function(err) {
61
- if (err) return callback(err);
62
-
63
- exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) {
64
- if (err) return callback(err);
65
-
66
- if (fs.existsSync(jsFile + ".js")) {
67
- fs.readFile(jsFile + ".js", function(err, contents) {
68
- if (err) return callback(err);
69
-
70
- fs.unlink(jsFile + ".js", function(err) {
71
- if (err) return callback(err);
72
-
73
- fs.rmdir(dirpath, function() {
74
- callback(null, [new Vinyl({
75
- "cwd": "/",
76
- "base": "/",
77
- "path": filename + ".js",
78
- "contents": contents
79
- })]);
80
- });
81
- });
82
- });
83
- } else {
84
- glob("**/*.js", {
85
- "cwd": jsFile
86
- }, function(err, matches) {
87
- if (err) return callback(err, null);
88
-
89
- var files = matches.map(function(match) {
90
- return new Vinyl({
91
- "cwd": "/",
92
- "base": "/",
93
- "path": match,
94
- "contents": fs.readFileSync(path.join(jsFile, match))
95
- });
96
- });
97
-
98
- rimraf(jsFile, function(err) {
99
- if (err) return callback(err);
100
-
101
- fs.rmdir(dirpath, function() {
102
- callback(null, files);
103
- });
104
- });
105
- });
106
- }
107
- });
108
- });
109
- };
1
+ const path = require("path");
2
+ const cp = require("child_process");
3
+ const fs = require("fs");
4
+ const protoc = require("./protoc.js");
5
+ const Vinyl = require("vinyl");
6
+ const uuid = require("uuid");
7
+ const mkdirp = require("mkdirp");
8
+ const glob = require("glob");
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
+ const cwd = process.cwd();
24
+ const absoluteOutputPath = path.resolve(cwd, options.outputPath);
25
+ const relative = path.relative(absoluteOutputPath, cwd);
26
+
27
+ const 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) {
41
+ callback(err);
42
+ return;
43
+ }
44
+
45
+ exports.protoc(args, {
46
+ "cwd": options.outputPath
47
+ }, callback);
48
+ });
49
+ };
50
+
51
+ /**
52
+ * Converts .proto files to .js files that can be used in Google Closure
53
+ * Compiler.
54
+ * The generated .js files require the files in
55
+ * https://github.com/protocolbuffers/protobuf/tree/v3.20.3/js.
56
+ * @param {?Array<string>} files the proto files.
57
+ * @param {?function(?Error, ?Array<Vinyl>)} callback the callback method.
58
+ */
59
+ exports.library = function(files, callback) {
60
+ var dirpath = "tmp";
61
+ var filename = uuid.v4();
62
+ var jsFile = path.join(dirpath, filename);
63
+ mkdirp("tmp", function(err) {
64
+ if (err) {
65
+ callback(err);
66
+ return;
67
+ }
68
+
69
+ exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) {
70
+ if (err) {
71
+ callback(err);
72
+ return;
73
+ }
74
+
75
+ if (fs.existsSync(jsFile + ".js")) {
76
+ fs.readFile(jsFile + ".js", function(err, contents) {
77
+ if (err) {
78
+ callback(err);
79
+ return;
80
+ }
81
+
82
+ fs.unlink(jsFile + ".js", function(err) {
83
+ if (err) {
84
+ callback(err);
85
+ return;
86
+ }
87
+
88
+ fs.rmdir(dirpath, function() {
89
+ callback(null, [new Vinyl({
90
+ "cwd": "/",
91
+ "base": "/",
92
+ "path": filename + ".js",
93
+ "contents": contents
94
+ })]);
95
+ });
96
+ });
97
+ });
98
+ } else {
99
+ glob("**/*.js", {
100
+ "cwd": jsFile
101
+ }, function(err, matches) {
102
+ if (err) {
103
+ callback(err, null);
104
+ return;
105
+ }
106
+
107
+ var files = matches.map(function(match) {
108
+ return new Vinyl({
109
+ "cwd": "/",
110
+ "base": "/",
111
+ "path": match,
112
+ "contents": fs.readFileSync(path.join(jsFile, match))
113
+ });
114
+ });
115
+
116
+ rimraf(jsFile, function(err) {
117
+ if (err) {
118
+ callback(err);
119
+ return;
120
+ }
121
+
122
+ fs.rmdir(dirpath, function() {
123
+ callback(null, files);
124
+ });
125
+ });
126
+ });
127
+ }
128
+ });
129
+ });
130
+ };
package/package.json CHANGED
@@ -1,21 +1,29 @@
1
1
  {
2
2
  "name": "protoc",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "A tool for converting proto buffers (.proto) files into javascript files usable in Closure Compiler with Closure Library.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "postinstall": "node scripts/postinstall.js",
8
8
  "test": "node scripts/test.js"
9
9
  },
10
+ "bin": {
11
+ "protoc": "./bin/protoc.sh"
12
+ },
10
13
  "author": "Jeppe Rune Mortensen <jepperm@gmail.com>",
11
14
  "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/YePpHa/node-protoc.git"
18
+ },
12
19
  "dependencies": {
13
- "glob": "^7.1.1",
14
- "mkdirp": "^0.5.1",
15
- "node-uuid": "^1.4.7",
16
- "request": "^2.79.0",
17
- "rimraf": "^2.5.4",
18
- "unzip": "^0.1.11",
19
- "vinyl": "^2.0.1"
20
+ "glob": "^7.2.3",
21
+ "mkdirp": "^0.5.6",
22
+ "node-fetch": "^3.2.10",
23
+ "request": "^2.88.2",
24
+ "rimraf": "^3.0.2",
25
+ "unzipper": "^0.10.11",
26
+ "uuid": "^9.0.0",
27
+ "vinyl": "^2.2.1"
20
28
  }
21
29
  }
package/protoc.js CHANGED
@@ -1,5 +1,5 @@
1
- var path = require("path");
2
-
3
- var protoc_bin = path.join(__dirname, "protoc", "bin");
4
-
5
- module.exports = path.join(protoc_bin, "protoc" + (process.platform === "win32" ? ".exe" : ""));
1
+ const path = require("path");
2
+
3
+ const protoc_bin = path.join(__dirname, "protoc", "bin");
4
+
5
+ module.exports = path.join(protoc_bin, "protoc" + (process.platform === "win32" ? ".exe" : ""));
@@ -1,46 +1,58 @@
1
- var request = require('request');
2
- var fs = require("fs");
3
- var path = require("path");
4
- var unzip = require("unzip");
5
- var mkdirp = require("mkdirp");
6
- var protoc = require("../protoc.js");
7
-
8
- var releases = {
9
- "win32_x86_32": "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-win32.zip",
10
- "win32_x86_64": "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-win32.zip",
11
- "linux_x86_32": "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_32.zip",
12
- "linux_x86_64": "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip",
13
- "darwin_x86_32": "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-osx-x86_32.zip",
14
- "darwin_x86_64": "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-osx-x86_64.zip"
15
- };
16
-
17
- var platform = process.platform;
18
- var arch = process.arch === "x64" ? "x86_64" : "x86_32";
19
- var release = platform + "_" + arch;
20
-
21
- if (releases[release]) {
22
- request(releases[release])
23
- .pipe(unzip.Parse())
24
- .on("entry", function(entry) {
25
- var isFile = "File" === entry.type;
26
- var isDir = "Directory" === entry.type;
27
- var fullpath = path.join(__dirname, "..", "protoc", entry.path);
28
- var directory = isDir ? fullpath : path.dirname(fullpath);
29
-
30
- mkdirp(directory, function(err) {
31
- if (err) throw err;
32
- if (isFile) {
33
- entry.pipe(fs.createWriteStream(fullpath))
34
- .on("finish", function() {
35
- if (protoc === fullpath) {
36
- fs.chmod(fullpath, 0755, function(err) {
37
- if (err) throw err;
38
- });
39
- }
40
- });
41
- }
42
- });
43
- });
44
- } else {
45
- throw new Error("Unsupported platform. Was not able to find a proper protoc version.");
46
- }
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const unzip = require("unzipper");
4
+ const mkdirp = require("mkdirp");
5
+ const protoc = require("../protoc.js");
6
+
7
+ const protoVersion = "3.20.3";
8
+
9
+ const releases = {
10
+ "win32_x86_32": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-win32.zip`,
11
+ "win32_x86_64": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-win32.zip`,
12
+ "linux_x86_32": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-linux-x86_32.zip`,
13
+ "linux_x86_64": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-linux-x86_64.zip`,
14
+ "darwin_x86_64": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-osx-x86_64.zip`
15
+ };
16
+
17
+ const platform = process.platform;
18
+ const arch = process.arch === "x64" ? "x86_64" : "x86_32";
19
+ const release = platform + "_" + arch;
20
+ const protocDirectory = path.join(__dirname, "..", "protoc");
21
+
22
+ (async () => {
23
+ if (!releases[release]) {
24
+ throw new Error(`Unsupported platform: ${release}. Was not able to find a proper protoc version.`);
25
+ }
26
+
27
+ fs.rmSync(protocDirectory, { recursive: true, force: true });
28
+
29
+ const fetch = await import("node-fetch");
30
+ const response = await fetch.default(releases[release]);
31
+ response
32
+ .body
33
+ .pipe(unzip.Parse())
34
+ .on("entry", entry => {
35
+ const isFile = "File" === entry.type;
36
+ const isDir = "Directory" === entry.type;
37
+ const fullpath = path.join(protocDirectory, entry.path);
38
+ const directory = isDir ? fullpath : path.dirname(fullpath);
39
+
40
+ mkdirp(directory, err => {
41
+ if (err) {
42
+ throw err;
43
+ }
44
+ if (isFile) {
45
+ entry.pipe(fs.createWriteStream(fullpath))
46
+ .on("finish", function() {
47
+ if (protoc === fullpath) {
48
+ fs.chmod(fullpath, 0o755, function(err) {
49
+ if (err) {
50
+ throw err;
51
+ }
52
+ });
53
+ }
54
+ });
55
+ }
56
+ });
57
+ });
58
+ })();
package/scripts/test.js CHANGED
@@ -1,6 +1,7 @@
1
- var protoc = require("../index.js");
2
- protoc.library(["protoc/include/google/protobuf/timestamp.proto"], function(err, files) {
3
- if (err) return console.error(err);
4
-
5
-
6
- });
1
+ const protoc = require("../index.js");
2
+ protoc.library(["protoc/include/google/protobuf/timestamp.proto"], function(err, files) {
3
+ if (err) {
4
+ console.error(err);
5
+ return;
6
+ }
7
+ });
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- protoc