From d31590b82d8bafe6657bf877d403f01a034ab4ba Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Tue, 13 Dec 2016 15:05:25 +0100 Subject: [PATCH] Notes on descriptors vs static modules [ci skip] --- README.md | 8 +++++++- cli/pbts.js | 5 +++-- types/protobuf.js.d.ts | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f6d23918e..c41ec857e 100644 --- a/README.md +++ b/README.md @@ -336,7 +336,13 @@ protobuf.load("bundle.json", function(err, root) { }); ``` -#### Generating TypeScript definitions for static modules +### Descriptors vs. static modules + +While .proto and JSON files require the full library (about 20kb gzipped), pretty much all code but the relatively short descriptors is shared. + +Static code, on the other hand, requires just the runtime library (final size TBA), but generates relatively large code bases without any reflection features. + +### Generating TypeScript definitions from static modules Likewise, the `pbts` command line utility can be used to generate TypeScript definitions from `pbjs`-generated static modules. diff --git a/cli/pbts.js b/cli/pbts.js index 36f1c8f5c..b7b85a305 100644 --- a/cli/pbts.js +++ b/cli/pbts.js @@ -16,9 +16,10 @@ var protobuf = require(".."); exports.main = function(args) { var argv = minimist(args.slice(2), { alias: { + name: "n", out : "o" }, - string: [ "out" ] + string: [ "name", "out" ] }); var files = argv._; @@ -65,7 +66,7 @@ exports.main = function(args) { fs.unlinkSync(path.join(dir, "types.d.ts")); var header = [ - "// pbts " + process.argv.slice(2).join(' '), + "// $> pbts " + process.argv.slice(2).join(' '), "// Generated " + (new Date()).toUTCString().replace(/GMT/, "UTC"), "" ]; diff --git a/types/protobuf.js.d.ts b/types/protobuf.js.d.ts index 3bec9bdb8..ddce4cd8b 100644 --- a/types/protobuf.js.d.ts +++ b/types/protobuf.js.d.ts @@ -1,5 +1,5 @@ -// pbts --name protobufjs --out types/protobuf.js.d.ts ./src -// Generated Tue, 13 Dec 2016 12:42:40 UTC +// $> pbts --name protobufjs --out types/protobuf.js.d.ts ./src +// Generated Tue, 13 Dec 2016 12:45:34 UTC declare module "protobufjs" {