Permalink
Browse files

CLI: Preparations for moving the CLI to its own package, see #716

  • Loading branch information...
dcodeIO committed Mar 24, 2017
1 parent 8401a47 commit 6423a419fe45e648593833bf535ba1736b31ef63
Showing with 108 additions and 10 deletions.
  1. +33 −0 cli/LICENSE
  2. +6 −0 cli/bin/pbjs
  3. +6 −0 cli/bin/pbts
  4. +3 −0 cli/index.d.ts
  5. +3 −0 cli/index.js
  6. +32 −1 cli/package.json
  7. +9 −0 cli/pbjs.d.ts
  8. +4 −4 cli/pbjs.js
  9. +9 −0 cli/pbts.d.ts
  10. +2 −2 cli/pbts.js
  11. +1 −3 cli/targets/static.js
@@ -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.
@@ -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);
@@ -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);
@@ -0,0 +1,3 @@
import * as pbjs from "./pbjs.js";
import * as pbts from "./pbts.js";
export { pbjs, pbts };
@@ -0,0 +1,3 @@
"use strict";
exports.pbjs = require("./pbjs");
exports.pbts = require("./pbts");
@@ -1 +1,32 @@
{}
{
"name": "protobufjs-cli",
"description": "protobuf.js command line interface (CLI).",
"version": "6.7.0",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"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"
}
}
@@ -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;
@@ -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();
@@ -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) {
@@ -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;
});
}
@@ -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;
@@ -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();
@@ -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) {
@@ -311,6 +311,7 @@ function buildType(ref, type) {
pushComment(typeDef);
}
// constructor
push("");
pushComment([
"Constructs a new " + type.name + ".",
@@ -414,9 +415,7 @@ function buildType(ref, type) {
push("return this.encode(message, writer).ldelim();");
--indent;
push("};");
}
}
if (config.decode) {
@@ -449,7 +448,6 @@ function buildType(ref, type) {
push("return this.decode(reader, reader.uint32());");
--indent;
push("};");
}
}

0 comments on commit 6423a41

Please sign in to comment.