protobufjs 6.8.8 → 6.9.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/CHANGELOG.md +941 -921
- package/LICENSE +39 -39
- package/README.md +901 -879
- package/cli/LICENSE +33 -33
- package/cli/README.md +11 -11
- package/cli/index.d.ts +3 -3
- package/cli/index.js +3 -3
- package/cli/lib/tsd-jsdoc/LICENSE +20 -20
- package/cli/lib/tsd-jsdoc/README.md +23 -23
- package/cli/lib/tsd-jsdoc/plugin.js +21 -21
- package/cli/lib/tsd-jsdoc/publish.js +705 -693
- package/cli/lib/tsd-jsdoc.json +18 -18
- package/cli/package.json +1 -1
- package/cli/package.standalone.json +32 -32
- package/cli/pbjs.d.ts +9 -9
- package/cli/pbjs.js +329 -329
- package/cli/pbts.d.ts +9 -9
- package/cli/pbts.js +197 -197
- package/cli/targets/json-module.js +38 -38
- package/cli/targets/json.js +8 -8
- package/cli/targets/proto.js +326 -326
- package/cli/targets/proto2.js +10 -10
- package/cli/targets/proto3.js +10 -10
- package/cli/targets/static-module.js +29 -29
- package/cli/targets/static.js +702 -702
- package/cli/util.js +183 -183
- package/cli/wrappers/amd.js +7 -7
- package/cli/wrappers/closure.js +7 -7
- package/cli/wrappers/commonjs.js +7 -7
- package/cli/wrappers/default.js +15 -15
- package/cli/wrappers/es6.js +5 -5
- package/dist/README.md +31 -31
- package/dist/light/README.md +31 -31
- package/dist/light/protobuf.js +6058 -6032
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/README.md +31 -31
- package/dist/minimal/protobuf.js +1900 -1877
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +7625 -7596
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/debug/README.md +4 -4
- package/ext/debug/index.js +71 -71
- package/ext/descriptor/README.md +72 -72
- package/ext/descriptor/index.js +1052 -1052
- package/ext/descriptor/test.js +54 -54
- package/google/LICENSE +27 -27
- package/google/README.md +1 -1
- package/google/api/annotations.proto +10 -10
- package/google/protobuf/descriptor.proto +286 -286
- package/google/protobuf/source_context.proto +7 -7
- package/index.d.ts +6 -6
- package/index.js +4 -4
- package/light.d.ts +2 -2
- package/light.js +3 -3
- package/minimal.d.ts +2 -2
- package/minimal.js +4 -4
- package/package-lock.json +4223 -3171
- package/package.json +122 -122
- package/scripts/changelog.js +150 -150
- package/scripts/postinstall.js +35 -35
- package/src/common.js +399 -399
- package/src/converter.js +293 -293
- package/src/decoder.js +106 -106
- package/src/encoder.js +100 -100
- package/src/enum.js +181 -181
- package/src/field.js +371 -371
- package/src/index-light.js +104 -104
- package/src/index-minimal.js +36 -36
- package/src/index.js +12 -12
- package/src/mapfield.js +126 -126
- package/src/message.js +138 -138
- package/src/method.js +151 -151
- package/src/namespace.js +433 -433
- package/src/object.js +200 -200
- package/src/oneof.js +203 -203
- package/src/parse.js +761 -758
- package/src/reader.js +411 -405
- package/src/reader_buffer.js +51 -44
- package/src/root.js +353 -351
- package/src/roots.js +18 -18
- package/src/rpc/service.js +142 -142
- package/src/rpc.js +36 -36
- package/src/service.js +167 -167
- package/src/tokenize.js +397 -397
- package/src/type.js +589 -589
- package/src/types.js +196 -196
- package/src/typescript.jsdoc +15 -15
- package/src/util/longbits.js +200 -200
- package/src/util/minimal.js +414 -414
- package/src/util.js +178 -178
- package/src/verifier.js +176 -176
- package/src/wrappers.js +83 -83
- package/src/writer.js +465 -459
- package/src/writer_buffer.js +85 -81
- package/tsconfig.json +6 -6
- package/cli/node_modules/os-tmpdir/index.js +0 -25
- package/cli/node_modules/os-tmpdir/license +0 -21
- package/cli/node_modules/os-tmpdir/readme.md +0 -32
- package/cli/node_modules/tmp/LICENSE +0 -21
- package/cli/node_modules/tmp/README.md +0 -314
- package/cli/node_modules/tmp/lib/tmp.js +0 -611
- package/cli/package-lock.json +0 -20
package/cli/pbts.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
type pbtsCallback = (err: Error|null, output?: string) => void;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Runs pbts programmatically.
|
|
5
|
-
* @param {string[]} args Command line arguments
|
|
6
|
-
* @param {function(?Error, string=)} [callback] Optional completion callback
|
|
7
|
-
* @returns {number|undefined} Exit code, if known
|
|
8
|
-
*/
|
|
9
|
-
export function main(args: string[], callback?: pbtsCallback): number|undefined;
|
|
1
|
+
type pbtsCallback = (err: Error|null, output?: string) => void;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs pbts programmatically.
|
|
5
|
+
* @param {string[]} args Command line arguments
|
|
6
|
+
* @param {function(?Error, string=)} [callback] Optional completion callback
|
|
7
|
+
* @returns {number|undefined} Exit code, if known
|
|
8
|
+
*/
|
|
9
|
+
export function main(args: string[], callback?: pbtsCallback): number|undefined;
|
package/cli/pbts.js
CHANGED
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var child_process = require("child_process"),
|
|
3
|
-
path = require("path"),
|
|
4
|
-
fs = require("fs"),
|
|
5
|
-
pkg = require("./package.json"),
|
|
6
|
-
util = require("./util");
|
|
7
|
-
|
|
8
|
-
util.setup();
|
|
9
|
-
|
|
10
|
-
var minimist = require("minimist"),
|
|
11
|
-
chalk = require("chalk"),
|
|
12
|
-
glob = require("glob"),
|
|
13
|
-
tmp = require("tmp");
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Runs pbts programmatically.
|
|
17
|
-
* @param {string[]} args Command line arguments
|
|
18
|
-
* @param {function(?Error, string=)} [callback] Optional completion callback
|
|
19
|
-
* @returns {number|undefined} Exit code, if known
|
|
20
|
-
*/
|
|
21
|
-
exports.main = function(args, callback) {
|
|
22
|
-
var argv = minimist(args, {
|
|
23
|
-
alias: {
|
|
24
|
-
name: "n",
|
|
25
|
-
out : "o",
|
|
26
|
-
main: "m",
|
|
27
|
-
global: "g",
|
|
28
|
-
import: "i"
|
|
29
|
-
},
|
|
30
|
-
string: [ "name", "out", "global", "import" ],
|
|
31
|
-
boolean: [ "comments", "main" ],
|
|
32
|
-
default: {
|
|
33
|
-
comments: true,
|
|
34
|
-
main: false
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
var files = argv._;
|
|
39
|
-
|
|
40
|
-
if (!files.length) {
|
|
41
|
-
if (callback)
|
|
42
|
-
callback(Error("usage")); // eslint-disable-line callback-return
|
|
43
|
-
else
|
|
44
|
-
process.stderr.write([
|
|
45
|
-
"protobuf.js v" + pkg.version + " CLI for TypeScript",
|
|
46
|
-
"",
|
|
47
|
-
chalk.bold.white("Generates TypeScript definitions from annotated JavaScript files."),
|
|
48
|
-
"",
|
|
49
|
-
" -o, --out Saves to a file instead of writing to stdout.",
|
|
50
|
-
"",
|
|
51
|
-
" -g, --global Name of the global object in browser environments, if any.",
|
|
52
|
-
"",
|
|
53
|
-
" -i, --import Comma delimited list of imports. Local names will equal camelCase of the basename.",
|
|
54
|
-
"",
|
|
55
|
-
" --no-comments Does not output any JSDoc comments.",
|
|
56
|
-
"",
|
|
57
|
-
chalk.bold.gray(" Internal flags:"),
|
|
58
|
-
"",
|
|
59
|
-
" -n, --name Wraps everything in a module of the specified name.",
|
|
60
|
-
"",
|
|
61
|
-
" -m, --main Whether building the main library without any imports.",
|
|
62
|
-
"",
|
|
63
|
-
"usage: " + chalk.bold.green("pbts") + " [options] file1.js file2.js ..." + chalk.bold.gray(" (or) ") + "other | " + chalk.bold.green("pbts") + " [options] -",
|
|
64
|
-
""
|
|
65
|
-
].join("\n"));
|
|
66
|
-
return 1;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Resolve glob expressions
|
|
70
|
-
for (var i = 0; i < files.length;) {
|
|
71
|
-
if (glob.hasMagic(files[i])) {
|
|
72
|
-
var matches = glob.sync(files[i]);
|
|
73
|
-
Array.prototype.splice.apply(files, [i, 1].concat(matches));
|
|
74
|
-
i += matches.length;
|
|
75
|
-
} else
|
|
76
|
-
++i;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var cleanup = [];
|
|
80
|
-
|
|
81
|
-
// Read from stdin (to a temporary file)
|
|
82
|
-
if (files.length === 1 && files[0] === "-") {
|
|
83
|
-
var data = [];
|
|
84
|
-
process.stdin.on("data", function(chunk) {
|
|
85
|
-
data.push(chunk);
|
|
86
|
-
});
|
|
87
|
-
process.stdin.on("end", function() {
|
|
88
|
-
files[0] = tmp.tmpNameSync() + ".js";
|
|
89
|
-
fs.writeFileSync(files[0], Buffer.concat(data));
|
|
90
|
-
cleanup.push(files[0]);
|
|
91
|
-
callJsdoc();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Load from disk
|
|
95
|
-
} else {
|
|
96
|
-
callJsdoc();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function callJsdoc() {
|
|
100
|
-
|
|
101
|
-
// There is no proper API for jsdoc, so this executes the CLI and pipes the output
|
|
102
|
-
var basedir = path.join(__dirname, ".");
|
|
103
|
-
var moduleName = argv.name || "null";
|
|
104
|
-
var nodePath = process.execPath;
|
|
105
|
-
var cmd = "\"" + nodePath + "\" \"" + require.resolve("jsdoc/jsdoc.js") + "\" -c \"" + path.join(basedir, "lib", "tsd-jsdoc.json") + "\" -q \"module=" + encodeURIComponent(moduleName) + "&comments=" + Boolean(argv.comments) + "\" " + files.map(function(file) { return "\"" + file + "\""; }).join(" ");
|
|
106
|
-
var child = child_process.exec(cmd, {
|
|
107
|
-
cwd: process.cwd(),
|
|
108
|
-
argv0: "node",
|
|
109
|
-
stdio: "pipe",
|
|
110
|
-
maxBuffer: 1 << 24 // 16mb
|
|
111
|
-
});
|
|
112
|
-
var out = [];
|
|
113
|
-
var ended = false;
|
|
114
|
-
var closed = false;
|
|
115
|
-
child.stdout.on("data", function(data) {
|
|
116
|
-
out.push(data);
|
|
117
|
-
});
|
|
118
|
-
child.stdout.on("end", function() {
|
|
119
|
-
if (closed) finish();
|
|
120
|
-
else ended = true;
|
|
121
|
-
});
|
|
122
|
-
child.stderr.pipe(process.stderr);
|
|
123
|
-
child.on("close", function(code) {
|
|
124
|
-
// clean up temporary files, no matter what
|
|
125
|
-
try { cleanup.forEach(fs.unlinkSync); } catch(e) {/**/} cleanup = [];
|
|
126
|
-
|
|
127
|
-
if (code) {
|
|
128
|
-
out = out.join("").replace(/\s*JSDoc \d+\.\d+\.\d+ [^$]+/, "");
|
|
129
|
-
process.stderr.write(out);
|
|
130
|
-
var err = Error("code " + code);
|
|
131
|
-
if (callback)
|
|
132
|
-
return callback(err);
|
|
133
|
-
throw err;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (ended) return finish();
|
|
137
|
-
closed = true;
|
|
138
|
-
return undefined;
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
function getImportName(importItem) {
|
|
142
|
-
return path.basename(importItem, ".js").replace(/([-_~.+]\w)/g, function(match) {
|
|
143
|
-
return match[1].toUpperCase();
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function finish() {
|
|
148
|
-
var output = [];
|
|
149
|
-
if (argv.main)
|
|
150
|
-
output.push(
|
|
151
|
-
"// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.",
|
|
152
|
-
""
|
|
153
|
-
);
|
|
154
|
-
if (argv.global)
|
|
155
|
-
output.push(
|
|
156
|
-
"export as namespace " + argv.global + ";",
|
|
157
|
-
""
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
if (!argv.main) {
|
|
161
|
-
// Ensure we have a usable array of imports
|
|
162
|
-
var importArray = typeof argv.import === "string" ? argv.import.split(",") : argv.import || [];
|
|
163
|
-
|
|
164
|
-
// Build an object of imports and paths
|
|
165
|
-
var imports = {
|
|
166
|
-
$protobuf: "protobufjs"
|
|
167
|
-
};
|
|
168
|
-
importArray.forEach(function(importItem) {
|
|
169
|
-
imports[getImportName(importItem)] = importItem;
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// Write out the imports
|
|
173
|
-
Object.keys(imports).forEach(function(key) {
|
|
174
|
-
output.push("import * as " + key + " from \"" + imports[key] + "\";");
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
output = output.join("\n") + "\n" + out.join("");
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
if (argv.out)
|
|
182
|
-
fs.writeFileSync(argv.out, output, { encoding: "utf8" });
|
|
183
|
-
else if (!callback)
|
|
184
|
-
process.stdout.write(output, "utf8");
|
|
185
|
-
return callback
|
|
186
|
-
? callback(null, output)
|
|
187
|
-
: undefined;
|
|
188
|
-
} catch (err) {
|
|
189
|
-
if (callback)
|
|
190
|
-
return callback(err);
|
|
191
|
-
throw err;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return undefined;
|
|
197
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var child_process = require("child_process"),
|
|
3
|
+
path = require("path"),
|
|
4
|
+
fs = require("fs"),
|
|
5
|
+
pkg = require("./package.json"),
|
|
6
|
+
util = require("./util");
|
|
7
|
+
|
|
8
|
+
util.setup();
|
|
9
|
+
|
|
10
|
+
var minimist = require("minimist"),
|
|
11
|
+
chalk = require("chalk"),
|
|
12
|
+
glob = require("glob"),
|
|
13
|
+
tmp = require("tmp");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Runs pbts programmatically.
|
|
17
|
+
* @param {string[]} args Command line arguments
|
|
18
|
+
* @param {function(?Error, string=)} [callback] Optional completion callback
|
|
19
|
+
* @returns {number|undefined} Exit code, if known
|
|
20
|
+
*/
|
|
21
|
+
exports.main = function(args, callback) {
|
|
22
|
+
var argv = minimist(args, {
|
|
23
|
+
alias: {
|
|
24
|
+
name: "n",
|
|
25
|
+
out : "o",
|
|
26
|
+
main: "m",
|
|
27
|
+
global: "g",
|
|
28
|
+
import: "i"
|
|
29
|
+
},
|
|
30
|
+
string: [ "name", "out", "global", "import" ],
|
|
31
|
+
boolean: [ "comments", "main" ],
|
|
32
|
+
default: {
|
|
33
|
+
comments: true,
|
|
34
|
+
main: false
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
var files = argv._;
|
|
39
|
+
|
|
40
|
+
if (!files.length) {
|
|
41
|
+
if (callback)
|
|
42
|
+
callback(Error("usage")); // eslint-disable-line callback-return
|
|
43
|
+
else
|
|
44
|
+
process.stderr.write([
|
|
45
|
+
"protobuf.js v" + pkg.version + " CLI for TypeScript",
|
|
46
|
+
"",
|
|
47
|
+
chalk.bold.white("Generates TypeScript definitions from annotated JavaScript files."),
|
|
48
|
+
"",
|
|
49
|
+
" -o, --out Saves to a file instead of writing to stdout.",
|
|
50
|
+
"",
|
|
51
|
+
" -g, --global Name of the global object in browser environments, if any.",
|
|
52
|
+
"",
|
|
53
|
+
" -i, --import Comma delimited list of imports. Local names will equal camelCase of the basename.",
|
|
54
|
+
"",
|
|
55
|
+
" --no-comments Does not output any JSDoc comments.",
|
|
56
|
+
"",
|
|
57
|
+
chalk.bold.gray(" Internal flags:"),
|
|
58
|
+
"",
|
|
59
|
+
" -n, --name Wraps everything in a module of the specified name.",
|
|
60
|
+
"",
|
|
61
|
+
" -m, --main Whether building the main library without any imports.",
|
|
62
|
+
"",
|
|
63
|
+
"usage: " + chalk.bold.green("pbts") + " [options] file1.js file2.js ..." + chalk.bold.gray(" (or) ") + "other | " + chalk.bold.green("pbts") + " [options] -",
|
|
64
|
+
""
|
|
65
|
+
].join("\n"));
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Resolve glob expressions
|
|
70
|
+
for (var i = 0; i < files.length;) {
|
|
71
|
+
if (glob.hasMagic(files[i])) {
|
|
72
|
+
var matches = glob.sync(files[i]);
|
|
73
|
+
Array.prototype.splice.apply(files, [i, 1].concat(matches));
|
|
74
|
+
i += matches.length;
|
|
75
|
+
} else
|
|
76
|
+
++i;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var cleanup = [];
|
|
80
|
+
|
|
81
|
+
// Read from stdin (to a temporary file)
|
|
82
|
+
if (files.length === 1 && files[0] === "-") {
|
|
83
|
+
var data = [];
|
|
84
|
+
process.stdin.on("data", function(chunk) {
|
|
85
|
+
data.push(chunk);
|
|
86
|
+
});
|
|
87
|
+
process.stdin.on("end", function() {
|
|
88
|
+
files[0] = tmp.tmpNameSync() + ".js";
|
|
89
|
+
fs.writeFileSync(files[0], Buffer.concat(data));
|
|
90
|
+
cleanup.push(files[0]);
|
|
91
|
+
callJsdoc();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Load from disk
|
|
95
|
+
} else {
|
|
96
|
+
callJsdoc();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function callJsdoc() {
|
|
100
|
+
|
|
101
|
+
// There is no proper API for jsdoc, so this executes the CLI and pipes the output
|
|
102
|
+
var basedir = path.join(__dirname, ".");
|
|
103
|
+
var moduleName = argv.name || "null";
|
|
104
|
+
var nodePath = process.execPath;
|
|
105
|
+
var cmd = "\"" + nodePath + "\" \"" + require.resolve("jsdoc/jsdoc.js") + "\" -c \"" + path.join(basedir, "lib", "tsd-jsdoc.json") + "\" -q \"module=" + encodeURIComponent(moduleName) + "&comments=" + Boolean(argv.comments) + "\" " + files.map(function(file) { return "\"" + file + "\""; }).join(" ");
|
|
106
|
+
var child = child_process.exec(cmd, {
|
|
107
|
+
cwd: process.cwd(),
|
|
108
|
+
argv0: "node",
|
|
109
|
+
stdio: "pipe",
|
|
110
|
+
maxBuffer: 1 << 24 // 16mb
|
|
111
|
+
});
|
|
112
|
+
var out = [];
|
|
113
|
+
var ended = false;
|
|
114
|
+
var closed = false;
|
|
115
|
+
child.stdout.on("data", function(data) {
|
|
116
|
+
out.push(data);
|
|
117
|
+
});
|
|
118
|
+
child.stdout.on("end", function() {
|
|
119
|
+
if (closed) finish();
|
|
120
|
+
else ended = true;
|
|
121
|
+
});
|
|
122
|
+
child.stderr.pipe(process.stderr);
|
|
123
|
+
child.on("close", function(code) {
|
|
124
|
+
// clean up temporary files, no matter what
|
|
125
|
+
try { cleanup.forEach(fs.unlinkSync); } catch(e) {/**/} cleanup = [];
|
|
126
|
+
|
|
127
|
+
if (code) {
|
|
128
|
+
out = out.join("").replace(/\s*JSDoc \d+\.\d+\.\d+ [^$]+/, "");
|
|
129
|
+
process.stderr.write(out);
|
|
130
|
+
var err = Error("code " + code);
|
|
131
|
+
if (callback)
|
|
132
|
+
return callback(err);
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (ended) return finish();
|
|
137
|
+
closed = true;
|
|
138
|
+
return undefined;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
function getImportName(importItem) {
|
|
142
|
+
return path.basename(importItem, ".js").replace(/([-_~.+]\w)/g, function(match) {
|
|
143
|
+
return match[1].toUpperCase();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function finish() {
|
|
148
|
+
var output = [];
|
|
149
|
+
if (argv.main)
|
|
150
|
+
output.push(
|
|
151
|
+
"// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.",
|
|
152
|
+
""
|
|
153
|
+
);
|
|
154
|
+
if (argv.global)
|
|
155
|
+
output.push(
|
|
156
|
+
"export as namespace " + argv.global + ";",
|
|
157
|
+
""
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
if (!argv.main) {
|
|
161
|
+
// Ensure we have a usable array of imports
|
|
162
|
+
var importArray = typeof argv.import === "string" ? argv.import.split(",") : argv.import || [];
|
|
163
|
+
|
|
164
|
+
// Build an object of imports and paths
|
|
165
|
+
var imports = {
|
|
166
|
+
$protobuf: "protobufjs"
|
|
167
|
+
};
|
|
168
|
+
importArray.forEach(function(importItem) {
|
|
169
|
+
imports[getImportName(importItem)] = importItem;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Write out the imports
|
|
173
|
+
Object.keys(imports).forEach(function(key) {
|
|
174
|
+
output.push("import * as " + key + " from \"" + imports[key] + "\";");
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
output = output.join("\n") + "\n" + out.join("");
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
if (argv.out)
|
|
182
|
+
fs.writeFileSync(argv.out, output, { encoding: "utf8" });
|
|
183
|
+
else if (!callback)
|
|
184
|
+
process.stdout.write(output, "utf8");
|
|
185
|
+
return callback
|
|
186
|
+
? callback(null, output)
|
|
187
|
+
: undefined;
|
|
188
|
+
} catch (err) {
|
|
189
|
+
if (callback)
|
|
190
|
+
return callback(err);
|
|
191
|
+
throw err;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return undefined;
|
|
197
|
+
};
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = json_module;
|
|
3
|
-
|
|
4
|
-
var util = require("../util");
|
|
5
|
-
|
|
6
|
-
var protobuf = require("../..");
|
|
7
|
-
|
|
8
|
-
json_module.description = "JSON representation as a module";
|
|
9
|
-
|
|
10
|
-
function jsonSafeProp(json) {
|
|
11
|
-
return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
|
|
12
|
-
return protobuf.util.safeProp($2).charAt(0) === "."
|
|
13
|
-
? $1 + $2 + ":"
|
|
14
|
-
: $0;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function json_module(root, options, callback) {
|
|
19
|
-
try {
|
|
20
|
-
var rootProp = protobuf.util.safeProp(options.root || "default");
|
|
21
|
-
var output = [
|
|
22
|
-
(options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
|
|
23
|
-
];
|
|
24
|
-
if (root.options) {
|
|
25
|
-
var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
|
|
26
|
-
output.push(".setOptions(" + optionsJson + ")\n");
|
|
27
|
-
}
|
|
28
|
-
var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
|
|
29
|
-
output.push(".addJSON(" + json + ");");
|
|
30
|
-
output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options));
|
|
31
|
-
process.nextTick(function() {
|
|
32
|
-
callback(null, output);
|
|
33
|
-
});
|
|
34
|
-
} catch (e) {
|
|
35
|
-
return callback(e);
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = json_module;
|
|
3
|
+
|
|
4
|
+
var util = require("../util");
|
|
5
|
+
|
|
6
|
+
var protobuf = require("../..");
|
|
7
|
+
|
|
8
|
+
json_module.description = "JSON representation as a module";
|
|
9
|
+
|
|
10
|
+
function jsonSafeProp(json) {
|
|
11
|
+
return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
|
|
12
|
+
return protobuf.util.safeProp($2).charAt(0) === "."
|
|
13
|
+
? $1 + $2 + ":"
|
|
14
|
+
: $0;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function json_module(root, options, callback) {
|
|
19
|
+
try {
|
|
20
|
+
var rootProp = protobuf.util.safeProp(options.root || "default");
|
|
21
|
+
var output = [
|
|
22
|
+
(options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
|
|
23
|
+
];
|
|
24
|
+
if (root.options) {
|
|
25
|
+
var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
|
|
26
|
+
output.push(".setOptions(" + optionsJson + ")\n");
|
|
27
|
+
}
|
|
28
|
+
var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
|
|
29
|
+
output.push(".addJSON(" + json + ");");
|
|
30
|
+
output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options));
|
|
31
|
+
process.nextTick(function() {
|
|
32
|
+
callback(null, output);
|
|
33
|
+
});
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return callback(e);
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
package/cli/targets/json.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = json_target;
|
|
3
|
-
|
|
4
|
-
json_target.description = "JSON representation";
|
|
5
|
-
|
|
6
|
-
function json_target(root, options, callback) {
|
|
7
|
-
callback(null, JSON.stringify(root, null, 2));
|
|
8
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = json_target;
|
|
3
|
+
|
|
4
|
+
json_target.description = "JSON representation";
|
|
5
|
+
|
|
6
|
+
function json_target(root, options, callback) {
|
|
7
|
+
callback(null, JSON.stringify(root, null, 2));
|
|
8
|
+
}
|