Skip to content

Commit

Permalink
CLI: Preparations for moving the CLI to its own package, see #716
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 24, 2017
1 parent 8401a47 commit 6423a41
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 10 deletions.
33 changes: 33 additions & 0 deletions cli/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Copyright (c) 2016, Daniel Wirtz All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of its author, nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

---

Code generated by the command line utilities is owned by the owner
of the input file used when generating it. This code is not
standalone and requires a support library to be linked with it. This
support library is itself covered by the above license.
6 changes: 6 additions & 0 deletions cli/bin/pbjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
var path = require("path"),
cli = require(path.join(__dirname, "..", "pbjs.js"));
var ret = cli.main(process.argv.slice(2));
if (typeof ret === 'number')
process.exit(ret);
6 changes: 6 additions & 0 deletions cli/bin/pbts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
var path = require("path"),
cli = require(path.join(__dirname, "..", "pbts.js"));
var ret = cli.main(process.argv.slice(2));
if (typeof ret === 'number')
process.exit(ret);
3 changes: 3 additions & 0 deletions cli/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as pbjs from "./pbjs.js";
import * as pbts from "./pbts.js";
export { pbjs, pbts };
3 changes: 3 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
exports.pbjs = require("./pbjs");
exports.pbts = require("./pbts");
33 changes: 32 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
{}
{
"name": "protobufjs-cli",
"description": "protobuf.js command line interface (CLI).",
"version": "6.7.0",
"author": "Daniel Wirtz <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/dcodeIO/protobuf.js.git"
},
"license": "BSD-3-Clause",
"main": "index.js",
"types": "index.d.ts",
"bin": {
"pbjs": "bin/pbjs",
"pbts": "bin/pbts"
},
"peerDependencies": {
"protobufjs": "6.7.0"
},
"dependencies": {
"chalk": "^1.1.3",
"escodegen": "^1.8.1",
"espree": "^3.1.3",
"estraverse": "^4.2.0",
"glob": "^7.1.1",
"jsdoc": "^3.4.2",
"minimist": "^1.2.0",
"semver": "^5.3.0",
"tmp": "0.0.31",
"uglify-js": "^2.8.15"
}
}
9 changes: 9 additions & 0 deletions cli/pbjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type pbjsCallback = (err: Error|null, output?: string) => {};

/**
* Runs pbjs programmatically.
* @param {string[]} args Command line arguments
* @param {function(?Error, string=)} [callback] Optional completion callback
* @returns {number|undefined} Exit code, if known
*/
export function main(args: string[], callback?: pbjsCallback): number|undefined;
8 changes: 4 additions & 4 deletions cli/pbjs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
var path = require("path"),
fs = require("fs"),
pkg = require(path.join(__dirname, "..", "package.json")),
pkg = require(path.join(__dirname, "package.json")),
util = require("./util");

util.setup();
Expand All @@ -16,7 +16,7 @@ var targets = util.requireAll("./targets");
/**
* Runs pbjs programmatically.
* @param {string[]} args Command line arguments
* @param {function(?Error)} [callback] Optional completion callback
* @param {function(?Error, string=)} [callback] Optional completion callback
* @returns {number|undefined} Exit code, if known
*/
exports.main = function main(args, callback) {
Expand Down Expand Up @@ -278,11 +278,11 @@ exports.main = function main(args, callback) {
if (output !== "") {
if (argv.out)
fs.writeFileSync(argv.out, output, { encoding: "utf8" });
else
else if (!callback)
process.stdout.write(output, "utf8");
}
return callback
? callback(null)
? callback(null, output)
: undefined;
});
}
Expand Down
9 changes: 9 additions & 0 deletions cli/pbts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type pbtsCallback = (err: Error|null, output?: string) => {};

/**
* Runs pbts programmatically.
* @param {string[]} args Command line arguments
* @param {function(?Error, string=)} [callback] Optional completion callback
* @returns {number|undefined} Exit code, if known
*/
export function main(args: string[], callback?: pbtsCallback): number|undefined;
4 changes: 2 additions & 2 deletions cli/pbts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var child_process = require("child_process"),
path = require("path"),
fs = require("fs"),
pkg = require(path.join(__dirname, "..", "package.json")),
pkg = require(path.join(__dirname, "./package.json")),
util = require("./util");

util.setup();
Expand All @@ -15,7 +15,7 @@ var minimist = require("minimist"),
/**
* Runs pbts programmatically.
* @param {string[]} args Command line arguments
* @param {function(?Error)} [callback] Optional completion callback
* @param {function(?Error, string=)} [callback] Optional completion callback
* @returns {number|undefined} Exit code, if known
*/
exports.main = function(args, callback) {
Expand Down
4 changes: 1 addition & 3 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ function buildType(ref, type) {
pushComment(typeDef);
}

// constructor
push("");
pushComment([
"Constructs a new " + type.name + ".",
Expand Down Expand Up @@ -414,9 +415,7 @@ function buildType(ref, type) {
push("return this.encode(message, writer).ldelim();");
--indent;
push("};");

}

}

if (config.decode) {
Expand Down Expand Up @@ -449,7 +448,6 @@ function buildType(ref, type) {
push("return this.decode(reader, reader.uint32());");
--indent;
push("};");

}
}

Expand Down

0 comments on commit 6423a41

Please sign in to comment.