diff --git a/cli/LICENSE b/cli/LICENSE new file mode 100644 index 000000000..e5f7a5c9a --- /dev/null +++ b/cli/LICENSE @@ -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. diff --git a/cli/bin/pbjs b/cli/bin/pbjs new file mode 100644 index 000000000..9bfedb310 --- /dev/null +++ b/cli/bin/pbjs @@ -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); diff --git a/cli/bin/pbts b/cli/bin/pbts new file mode 100644 index 000000000..48d392c39 --- /dev/null +++ b/cli/bin/pbts @@ -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); diff --git a/cli/index.d.ts b/cli/index.d.ts new file mode 100644 index 000000000..09c202691 --- /dev/null +++ b/cli/index.d.ts @@ -0,0 +1,3 @@ +import * as pbjs from "./pbjs.js"; +import * as pbts from "./pbts.js"; +export { pbjs, pbts }; diff --git a/cli/index.js b/cli/index.js new file mode 100644 index 000000000..c565aa6fa --- /dev/null +++ b/cli/index.js @@ -0,0 +1,3 @@ +"use strict"; +exports.pbjs = require("./pbjs"); +exports.pbts = require("./pbts"); diff --git a/cli/package.json b/cli/package.json index 9e26dfeeb..a21f4f2c8 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1 +1,32 @@ -{} \ No newline at end of file +{ + "name": "protobufjs-cli", + "description": "protobuf.js command line interface (CLI).", + "version": "6.7.0", + "author": "Daniel Wirtz ", + "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" + } +} \ No newline at end of file diff --git a/cli/pbjs.d.ts b/cli/pbjs.d.ts new file mode 100644 index 000000000..5fbe06a73 --- /dev/null +++ b/cli/pbjs.d.ts @@ -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; diff --git a/cli/pbjs.js b/cli/pbjs.js index 8210c0377..1af431364 100644 --- a/cli/pbjs.js +++ b/cli/pbjs.js @@ -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; }); } diff --git a/cli/pbts.d.ts b/cli/pbts.d.ts new file mode 100644 index 000000000..a2a5f7cb2 --- /dev/null +++ b/cli/pbts.d.ts @@ -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; diff --git a/cli/pbts.js b/cli/pbts.js index bcba91825..4d373bd2c 100644 --- a/cli/pbts.js +++ b/cli/pbts.js @@ -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) { diff --git a/cli/targets/static.js b/cli/targets/static.js index ef6990574..e8c2973bf 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -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("};"); - } }