Skip to content

Commit 6423a41

Browse files
committed
CLI: Preparations for moving the CLI to its own package, see #716
1 parent 8401a47 commit 6423a41

File tree

11 files changed

+108
-10
lines changed

11 files changed

+108
-10
lines changed

cli/LICENSE

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Copyright (c) 2016, Daniel Wirtz All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of its author, nor the names of its contributors
13+
may be used to endorse or promote products derived from this software
14+
without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
---
29+
30+
Code generated by the command line utilities is owned by the owner
31+
of the input file used when generating it. This code is not
32+
standalone and requires a support library to be linked with it. This
33+
support library is itself covered by the above license.

cli/bin/pbjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
var path = require("path"),
3+
cli = require(path.join(__dirname, "..", "pbjs.js"));
4+
var ret = cli.main(process.argv.slice(2));
5+
if (typeof ret === 'number')
6+
process.exit(ret);

cli/bin/pbts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
var path = require("path"),
3+
cli = require(path.join(__dirname, "..", "pbts.js"));
4+
var ret = cli.main(process.argv.slice(2));
5+
if (typeof ret === 'number')
6+
process.exit(ret);

cli/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as pbjs from "./pbjs.js";
2+
import * as pbts from "./pbts.js";
3+
export { pbjs, pbts };

cli/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
exports.pbjs = require("./pbjs");
3+
exports.pbts = require("./pbts");

cli/package.json

+32-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
{}
1+
{
2+
"name": "protobufjs-cli",
3+
"description": "protobuf.js command line interface (CLI).",
4+
"version": "6.7.0",
5+
"author": "Daniel Wirtz <[email protected]>",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/dcodeIO/protobuf.js.git"
9+
},
10+
"license": "BSD-3-Clause",
11+
"main": "index.js",
12+
"types": "index.d.ts",
13+
"bin": {
14+
"pbjs": "bin/pbjs",
15+
"pbts": "bin/pbts"
16+
},
17+
"peerDependencies": {
18+
"protobufjs": "6.7.0"
19+
},
20+
"dependencies": {
21+
"chalk": "^1.1.3",
22+
"escodegen": "^1.8.1",
23+
"espree": "^3.1.3",
24+
"estraverse": "^4.2.0",
25+
"glob": "^7.1.1",
26+
"jsdoc": "^3.4.2",
27+
"minimist": "^1.2.0",
28+
"semver": "^5.3.0",
29+
"tmp": "0.0.31",
30+
"uglify-js": "^2.8.15"
31+
}
32+
}

cli/pbjs.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type pbjsCallback = (err: Error|null, output?: string) => {};
2+
3+
/**
4+
* Runs pbjs 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?: pbjsCallback): number|undefined;

cli/pbjs.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
var path = require("path"),
33
fs = require("fs"),
4-
pkg = require(path.join(__dirname, "..", "package.json")),
4+
pkg = require(path.join(__dirname, "package.json")),
55
util = require("./util");
66

77
util.setup();
@@ -16,7 +16,7 @@ var targets = util.requireAll("./targets");
1616
/**
1717
* Runs pbjs programmatically.
1818
* @param {string[]} args Command line arguments
19-
* @param {function(?Error)} [callback] Optional completion callback
19+
* @param {function(?Error, string=)} [callback] Optional completion callback
2020
* @returns {number|undefined} Exit code, if known
2121
*/
2222
exports.main = function main(args, callback) {
@@ -278,11 +278,11 @@ exports.main = function main(args, callback) {
278278
if (output !== "") {
279279
if (argv.out)
280280
fs.writeFileSync(argv.out, output, { encoding: "utf8" });
281-
else
281+
else if (!callback)
282282
process.stdout.write(output, "utf8");
283283
}
284284
return callback
285-
? callback(null)
285+
? callback(null, output)
286286
: undefined;
287287
});
288288
}

cli/pbts.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type pbtsCallback = (err: Error|null, output?: string) => {};
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;

cli/pbts.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var child_process = require("child_process"),
33
path = require("path"),
44
fs = require("fs"),
5-
pkg = require(path.join(__dirname, "..", "package.json")),
5+
pkg = require(path.join(__dirname, "./package.json")),
66
util = require("./util");
77

88
util.setup();
@@ -15,7 +15,7 @@ var minimist = require("minimist"),
1515
/**
1616
* Runs pbts programmatically.
1717
* @param {string[]} args Command line arguments
18-
* @param {function(?Error)} [callback] Optional completion callback
18+
* @param {function(?Error, string=)} [callback] Optional completion callback
1919
* @returns {number|undefined} Exit code, if known
2020
*/
2121
exports.main = function(args, callback) {

cli/targets/static.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ function buildType(ref, type) {
311311
pushComment(typeDef);
312312
}
313313

314+
// constructor
314315
push("");
315316
pushComment([
316317
"Constructs a new " + type.name + ".",
@@ -414,9 +415,7 @@ function buildType(ref, type) {
414415
push("return this.encode(message, writer).ldelim();");
415416
--indent;
416417
push("};");
417-
418418
}
419-
420419
}
421420

422421
if (config.decode) {
@@ -449,7 +448,6 @@ function buildType(ref, type) {
449448
push("return this.decode(reader, reader.uint32());");
450449
--indent;
451450
push("};");
452-
453451
}
454452
}
455453

0 commit comments

Comments
 (0)