Permalink
Browse files

Other: Also lint cli utilities

  • Loading branch information...
dcodeIO committed Mar 6, 2017
1 parent 26d9fad commit 6e81fcb05f25386e3997399e6596e9d9414f0286
@@ -4,6 +4,7 @@ engines:
ratings:
paths:
- "src/**.js"
- "cli/**.js"
- "lib/aspromise/**.js"
- "lib/base64/**.js"
- "lib/eventemitter/**.js"
@@ -14,3 +15,4 @@ ratings:
- "lib/utf8/**.js"
exclude_paths:
- "**/tests/**"
- "cli/wrappers/**"
@@ -1,6 +1,6 @@
bench/*
bin/*
cli/*
cli/wrappers/*
coverage/*
dist/*
docs/*
@@ -10,6 +10,7 @@ lib/prelude.js
lib/polyfill.js
lib/tape-adapter.js
lib/tsd-jsdoc/*
lib/*/tests/*
sandbox/*
scripts/*
**/tests/*
tests/*
@@ -19,7 +19,7 @@ var targets = util.requireAll("./targets");
* @param {function(?Error)} [callback] Optional completion callback
* @returns {number|undefined} Exit code, if known
*/
exports.main = function(args, callback) {
exports.main = function main(args, callback) {
var lintDefault = "eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins";
var argv = minimist(args, {
alias: {
@@ -59,16 +59,16 @@ exports.main = function(args, callback) {
return " " + util.pad(key, 14, true) + targets[key].description;
});
if (callback)
callback(Error("usage"));
callback(Error("usage")); // eslint-disable-line callback-return
else
console.error([
process.stderr.write([
"protobuf.js v" + pkg.version + " CLI for JavaScript",
"",
chalk.bold.white("Consolidates imports and converts between file formats."),
"",
" -t, --target Specifies the target format. Also accepts a path to require a custom target.",
"",
descs.join('\n'),
descs.join("\n"),
"",
" -p, --path Adds a directory to the include path.",
"",
@@ -184,8 +184,10 @@ exports.main = function(args, callback) {
}
callTarget();
} catch (err) {
if (callback)
return callback(err);
if (callback) {
callback(err);
return;
}
throw err;
}
});
@@ -280,4 +282,6 @@ exports.main = function(args, callback) {
: undefined;
});
}
return undefined;
};
@@ -38,9 +38,9 @@ exports.main = function(args, callback) {
if (!files.length) {
if (callback)
callback(Error("usage"));
callback(Error("usage")); // eslint-disable-line callback-return
else
console.error([
process.stderr.write([
"protobuf.js v" + pkg.version + " CLI for TypeScript",
"",
chalk.bold.white("Generates TypeScript definitions from annotated JavaScript files."),
@@ -59,8 +59,6 @@ exports.main = function(args, callback) {
"",
"usage: " + chalk.bold.green("pbts") + " [options] file1.js file2.js ..." + chalk.bold.gray(" (or) ") + "other | " + chalk.bold.green("pbts") + " [options] -"
].join("\n"));
if (callback)
callback(Error("usage"));
return 1;
}
@@ -113,17 +111,17 @@ exports.main = function(args, callback) {
child.stderr.pipe(process.stderr);
child.on("close", function(code) {
// clean up temporary files, no matter what
try { cleanup.forEach(fs.unlinkSync); } catch(e) {} cleanup = [];
try { cleanup.forEach(fs.unlinkSync); } catch(e) {/**/} cleanup = [];
if (code) {
out = out.join('').replace(/\s*JSDoc \d+\.\d+\.\d+ [^$]+/, "");
out = out.join("").replace(/\s*JSDoc \d+\.\d+\.\d+ [^$]+/, "");
process.stderr.write(out);
var err = Error("code " + code);
if (callback)
if (callback) {
callback(err);
else
throw err;
return;
return;
}
throw err;
}
var output = [];
@@ -137,20 +135,21 @@ exports.main = function(args, callback) {
"import * as $protobuf from \"protobufjs\";",
""
);
output = output.join('\n') + "\n" + out.join('');
output = output.join("\n") + "\n" + out.join("");
try {
if (argv.out)
fs.writeFileSync(argv.out, output);
else
process.stdout.write(output, "utf8");
if (callback)
callback(null);
callback(null); // eslint-disable-line callback-return
} catch (err) {
if (callback)
if (callback) {
callback(err);
else
throw err;
return;
}
throw err;
}
});
}
@@ -1,7 +1,7 @@
"use strict";
module.exports = json_target;
json_target.description = "JSON representation"
json_target.description = "JSON representation";
function json_target(root, options, callback) {
callback(null, JSON.stringify(root, null, 2));
@@ -46,9 +46,9 @@ function proto_target(root, options, callback) {
first = false;
try {
buildRoot(root);
callback(null, out.join('\n'));
return callback(null, out.join("\n"));
} catch (err) {
callback(err);
return callback(err);
} finally {
out = [];
syntax = 3;
@@ -67,18 +67,18 @@ function push(line) {
}
function escape(str) {
return str.replace(/[\\"']/g, '\\$&')
.replace(/\u0000/g, '\\0');
return str.replace(/[\\"']/g, "\\$&")
.replace(/\u0000/g, "\\0");
}
function value(v) {
switch (typeof v) {
case 'boolean':
return v ? 'true' : 'false';
case 'number':
case "boolean":
return v ? "true" : "false";
case "number":
return v.toString();
default:
return '"' + escape(v + '') + '"';
return "\"" + escape(String(v)) + "\"";
}
}
@@ -178,10 +178,12 @@ function buildType(type) {
}
function buildField(field, passExtend) {
if (field.partOf || field.declaringField || (field.extend !== undefined && !passExtend))
if (field.partOf || field.declaringField || !(field.extend === undefined || passExtend))
return;
if (first)
first = false, push("");
if (first) {
first = false;
push("");
}
if (field.resolvedType && field.resolvedType.group) {
buildGroup(field);
return;
@@ -277,8 +279,10 @@ function buildOneOf(oneof) {
++indent; first = true;
oneof.oneof.forEach(function(fieldName) {
var field = oneof.parent.get(fieldName);
if (first)
push(""), first = false;
if (first) {
first = false;
push("");
}
var opts = buildFieldOptions(field);
push(field.type + " " + underScore(field.name) + " = " + field.id + (opts ? " " + opts : "") + ";");
});
@@ -301,11 +305,13 @@ function buildMethod(method) {
function buildOptions(object) {
if (!object.options)
return
return;
first = true;
Object.keys(object.options).forEach(function(key) {
if (first)
push(""), first = false;
if (first) {
first = false;
push("");
}
var val = object.options[key];
push("option " + key + " = " + JSON.stringify(val) + ";");
});
@@ -14,8 +14,10 @@ static_module_target.description = "Static code without reflection as a module";
function static_module_target(root, options, callback) {
require("./static")(root, options, function(err, output) {
if (err)
return callback(err);
if (err) {
callback(err);
return;
}
try {
output = util.wrap(output, protobuf.util.merge({ dependency: "protobufjs/minimal" }, options));
} catch (e) {
@@ -1,8 +1,9 @@
"use strict";
var fs = require("fs"),
path = require("path"),
child_process = require("child_process"),
semver;
child_process = require("child_process");
var semver;
var protobuf = require("..");
@@ -18,7 +19,7 @@ function basenameCompare(a, b) {
return 1;
}
return a.length < b.length ? -1 : 0;
};
}
exports.requireAll = function requireAll(dirname) {
dirname = path.join(__dirname, dirname);
@@ -110,7 +111,7 @@ function modExists(name, version) {
return semver
? semver.satisfies(pkg.version, version)
: parseInt(pkg.version, 10) === parseInt(version.replace(/^[\^~]/, ""), 10); // used for semver only
} catch (e) {}
} catch (e) {/**/}
}
return false;
}
@@ -156,8 +157,8 @@ exports.wrap = function(OUTPUT, options) {
// otherwise fetch the custom one
wrap = fs.readFileSync(path.resolve(process.cwd(), name)).toString("utf8");
}
wrap = wrap.replace(/%DEPENDENCY%/g, JSON.stringify(options.dependency || "protobufjs"));
wrap = wrap.replace(/( *)%OUTPUT%/, function($0, $1) {
wrap = wrap.replace(/\$DEPENDENCY/g, JSON.stringify(options.dependency || "protobufjs"));
wrap = wrap.replace(/( *)\$OUTPUT;/, function($0, $1) {
return $1.length ? OUTPUT.replace(/^/mg, $1) : OUTPUT;
});
if (options.lint !== "")
@@ -183,7 +184,7 @@ exports.safeProp = protobuf.util.safeProp = (function(safeProp) {
return !/^[$\w]+$/.test(name) || exports.reserved(name)
? safeProp(name)
: "." + name;
}
};
})(protobuf.util.safeProp);
exports.jsonSafeProp = function(json) {
@@ -1,7 +1,7 @@
define(["protobuf"], function($protobuf) {
"use strict";
%OUTPUT%
$OUTPUT;
return $root;
});
@@ -1,7 +1,7 @@
"use strict";
var $protobuf = require(%DEPENDENCY%);
var $protobuf = require($DEPENDENCY);
%OUTPUT%
$OUTPUT;
module.exports = $root;
@@ -4,12 +4,12 @@
define(["protobuf"], factory);
/* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports)
module.exports = factory(require(%DEPENDENCY%));
module.exports = factory(require($DEPENDENCY));
})(this, function($protobuf) {
"use strict";
%OUTPUT%
$OUTPUT;
return $root;
});
@@ -1,5 +1,5 @@
import * as $protobuf from "protobufjs";
%OUTPUT%
$OUTPUT;
export { $root as default };

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN -14 Bytes (100%) dist/light/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 6e81fcb

Please sign in to comment.