Permalink
Browse files

CLI: Added --strict-long option to pbjs to always emit 'Long' instead…

… of 'number|Long' (only relevant with long.js), see #718
  • Loading branch information...
dcodeIO committed Mar 23, 2017
1 parent e1dd1bc commit c3f0a2124c661bb9ba35f92c21a98a4405d30b47
Showing with 19 additions and 15 deletions.
  1. +15 −12 cli/pbjs.js
  2. +2 −2 cli/targets/static.js
  3. +2 −1 package.json
@@ -31,19 +31,21 @@ exports.main = function main(args, callback) {
lint : "l"
},
string: [ "target", "out", "path", "wrap", "root", "lint" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "strict-long" ],
default: {
target : "json",
create : true,
encode : true,
decode : true,
verify : true,
convert : true,
delimited : true,
beautify : true,
comments : true,
es6 : null,
lint : lintDefault
target : "json",
create : true,
encode : true,
decode : true,
verify : true,
convert : true,
delimited : true,
beautify : true,
comments : true,
es6 : null,
lint : lintDefault,
"keep-case" : false,
"strict-long": false
}
});
@@ -107,6 +109,7 @@ exports.main = function main(args, callback) {
" --no-delimited Does not generate delimited encode/decode functions.",
" --no-beautify Does not beautify generated code.",
" --no-comments Does not output any JSDoc comments.",
" --strict-long Forces s-/u-/int64 and s-/fixed64 types to 'Long' only (no numbers).",
"",
"usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..." + chalk.gray(" (or) ") + "other | " + chalk.bold.green("pbjs") + " [options] -",
""
@@ -250,7 +250,7 @@ function buildFunction(type, functionName, gen, scope) {
push("};");
}
function toJsType(field, isReturn) {
function toJsType(field) {
switch (field.type) {
case "double":
case "float":
@@ -265,7 +265,7 @@ function toJsType(field, isReturn) {
case "sint64":
case "fixed64":
case "sfixed64":
return isReturn ? "Long" : "number|Long";
return config["strict-long"] ? "Long" : "number|Long";
case "bool":
return "boolean";
case "string":
@@ -36,7 +36,8 @@
"postinstall": "node scripts/postinstall",
"prof": "node bench/prof",
"test": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js | tap-spec",
"types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js && tsc tests/comp_typescript.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/test.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
"test-types": "tsc tests/comp_typescript.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/test.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
"types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js && npm run test-types",
"zuul": "zuul --ui tape --no-coverage --concurrency 4 -- tests/*.js",
"zuul-local": "zuul --ui tape --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js",
"make": "npm run test && npm run types && npm run build && npm run lint",

0 comments on commit c3f0a21

Please sign in to comment.