Skip to content

Commit 24f2c03

Browse files
committed
Docs: Added notes on how to use pbjs and pbts programmatically
1 parent 3544576 commit 24f2c03

File tree

16 files changed

+42
-37
lines changed

16 files changed

+42
-37
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Documentation
313313

314314
* [Google's Developer Guide](https://developers.google.com/protocol-buffers/docs/overview)
315315

316-
* [protobuf.js API Documentation](http://dcode.io/protobuf.js/)
316+
* [protobuf.js API Documentation](http://dcode.io/protobuf.js/) and [CHANGELOG](https://github.com/dcodeIO/protobuf.js/blob/master/CHANGELOG.md)
317317

318318
* [Questions and answers on StackOverflow](http://stackoverflow.com/questions/tagged/protobuf.js)
319319

@@ -396,6 +396,20 @@ Generates TypeScript definitions from annotated JavaScript files.
396396
usage: pbts [options] file1.js file2.js ...
397397
```
398398

399+
### Using pbjs and pbts programmatically
400+
401+
Both utilities can be used programmatically by providing command line arguments and a callback to their respective `main` functions:
402+
403+
```js
404+
var pbjs = require("protobufjs/cli/pbjs");
405+
406+
pbjs.main([ "--target", "json-module", "path/to/myproto.proto" ], function(err, output) {
407+
if (err)
408+
throw err;
409+
// do something with output
410+
});
411+
```
412+
399413
### Descriptors vs. static modules
400414

401415
While .proto and JSON files require the full library (about 17.5kb gzipped), pretty much all code but the relatively short descriptors is shared and all features including reflection and the parser are available.

dist/protobuf.js

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

-5 Bytes
Binary file not shown.

dist/protobuf.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.min.js.gz

0 Bytes
Binary file not shown.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"types": "node bin/pbts --name protobufjs --out types/protobuf.js.d.ts src && tsc types/test.ts --lib es2015 --noEmit",
3838
"zuul": "zuul --ui tape --no-coverage --concurrency 4 -- tests/*.js",
3939
"zuul-local": "zuul --ui tape --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js",
40-
"make": "npm run lint && npm run test && npm run types && npm run build && npm run changelog"
40+
"make": "npm run lint && npm run test && npm run types && npm run build",
41+
"release": "npm run make && npm run changelog"
4142
},
4243
"dependencies": {
4344
"@protobufjs/aspromise": "^1.0.3",

0 commit comments

Comments
 (0)