From d01394a1463062824c066b653aad53c449752202 Mon Sep 17 00:00:00 2001 From: Matthew Douglass <5410142+mdouglass@users.noreply.github.com> Date: Wed, 14 Apr 2021 10:33:42 -0700 Subject: [PATCH] feat: add --no-service option for pbjs static target (#1577) This option skips generation of service clients. Co-authored-by: Alexander Fenster --- cli/README.md | 1 + cli/pbjs.js | 4 +++- cli/targets/static.js | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/README.md b/cli/README.md index 25a0cbbb1..e7f189007 100644 --- a/cli/README.md +++ b/cli/README.md @@ -63,6 +63,7 @@ Translates between file formats and generates static code. --no-delimited Does not generate delimited encode/decode functions. --no-beautify Does not beautify generated code. --no-comments Does not output any JSDoc comments. + --no-service Does not output service classes. --force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields. --force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields. diff --git a/cli/pbjs.js b/cli/pbjs.js index 8766e4f43..6b69397f3 100644 --- a/cli/pbjs.js +++ b/cli/pbjs.js @@ -41,7 +41,7 @@ exports.main = function main(args, callback) { "force-message": "strict-message" }, string: [ "target", "out", "path", "wrap", "dependency", "root", "lint" ], - boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "keep-case", "force-long", "force-number", "force-enum-string", "force-message" ], + boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "service", "es6", "sparse", "keep-case", "force-long", "force-number", "force-enum-string", "force-message" ], default: { target: "json", create: true, @@ -52,6 +52,7 @@ exports.main = function main(args, callback) { delimited: true, beautify: true, comments: true, + service: true, es6: null, lint: lintDefault, "keep-case": false, @@ -132,6 +133,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.", + " --no-service Does not output service classes.", "", " --force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.", " --force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.", diff --git a/cli/targets/static.js b/cli/targets/static.js index 7d5c706a4..f72734a82 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -109,6 +109,10 @@ function aOrAn(name) { function buildNamespace(ref, ns) { if (!ns) return; + + if (ns instanceof Service && !config.service) + return; + if (ns.name !== "") { push(""); if (!ref && config.es6)