Skip to content

Commit 926905b

Browse files
committed
Post-merge, accept custom targets in pbjs, see #512
1 parent a613a63 commit 926905b

11 files changed

+25
-18
lines changed

cli/pbjs.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ exports.main = function(args) {
2727
files = argv._,
2828
paths = typeof argv.path === 'string' ? [ argv.path ] : argv.path || [];
2929

30-
if (!target || !files.length) {
30+
if (!files.length) {
3131
console.log([
3232
"protobuf.js v" + pkg.version + " cli",
3333
"",
3434
"Consolidates imports and converts between file formats.",
3535
"",
3636
" -t, --target Specifies the target format. [" + Object.keys(targets).filter(function(key) { return !targets[key].private; }).join(', ') + "]",
37+
" Also accepts a path to require a custom target.",
3738
" -p, --path Adds a directory to the include path.",
3839
" -o, --out Saves to a file instead of writing to stdout.",
3940
"",
@@ -42,6 +43,9 @@ exports.main = function(args) {
4243
return 1;
4344
}
4445

46+
if (!target)
47+
target = require(path.resolve(process.cwd(), argv.target));
48+
4549
// Resolve glob expressions
4650
for (var i = 0; i < files.length;) {
4751
if (glob.hasMagic(files[i])) {

cli/targets/static.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module.exports = static_target;
22

33
static_target.private = true;
44

5-
// Currently, this file contains initial static code for CommonJS modules.
5+
// Currently, this target builds single file CommonJS modules.
6+
// - There is no reflection and no message inheritance from Prototype.
7+
// - Generated code is tailored for browerify build processes (minimal runtime).
68

79
// TBD:
810
// - Generate a single file or scaffold an entire project directory? Both?

dist/protobuf.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

1 Byte
Binary file not shown.

dist/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
"build": "gulp",
2828
"docs": "jsdoc -c jsdoc.docs.json -R README.md",
2929
"pages": "node scripts/pages",
30-
"types": "jsdoc -c jsdoc.types.json && node scripts/types.js && tsc types/protobuf.js-test.ts --lib es2015 --noEmit",
30+
"types": "jsdoc -c jsdoc.types.json && node scripts/types.js && tsc types/test.ts --lib es2015 --noEmit",
3131
"lint": "eslint src",
3232
"test": "tape tests/*.js | tap-spec",
3333
"zuul": "zuul --ui tape --no-coverage --concurrency 1 -- tests/*.js",
3434
"zuul-local": "zuul --ui tape --no-coverage --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js",
3535
"bench": "node bench",
3636
"all": "npm run lint && npm run test && npm run build && npm run types && npm run docs && npm run bench",
37-
"prepublish": "node scripts/prepublish.js"
37+
"prepublish": "node scripts/prepublish"
3838
},
3939
"optionalDependencies": {
4040
"long": "^3.2.0"

src/inherits.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var _TypeError = util._TypeError;
1818
/**
1919
* Inherits a custom class from the message prototype of the specified message type.
2020
* @param {Function} clazz Inheriting class
21-
* @param {Type|ReflectionObject} type Inherited message type
21+
* @param {Type} type Inherited message type
2222
* @param {InheritanceOptions} [options] Inheritance options
2323
* @returns {Prototype} Created prototype
2424
*/

types/protobuf.js.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*
55
* protobuf.js v6.0.1 TypeScript definitions
6-
* Generated Fri, 02 Dec 2016 15:01:02 UTC
6+
* Generated Fri, 02 Dec 2016 16:05:19 UTC
77
*/
88
declare module "protobufjs" {
99

@@ -324,11 +324,11 @@ declare module "protobufjs" {
324324
/**
325325
* Inherits a custom class from the message prototype of the specified message type.
326326
* @param {Function} clazz Inheriting class
327-
* @param {Type|ReflectionObject} type Inherited message type
327+
* @param {Type} type Inherited message type
328328
* @param {InheritanceOptions} [options] Inheritance options
329329
* @returns {Prototype} Created prototype
330330
*/
331-
function inherits(clazz: any, type: (Type|ReflectionObject), options?: InheritanceOptions): Prototype;
331+
function inherits(clazz: any, type: Type, options?: InheritanceOptions): Prototype;
332332

333333
/**
334334
* This is not an actual type but stands as a reference for any constructor of a custom message class that you pass to the library.
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
///<reference path="./protobuf.js.d.ts" />
1+
/// <reference path="./protobuf.js.d.ts" />
2+
23
import * as protobuf from "protobufjs";
34

45
export const proto = {"nested":{"Hello":{"fields":{"value":{"rule":"required","type":"string","id":1}}}}};
56

67
const root = protobuf.Root.fromJSON(proto);
78

89
export class Hello {
9-
constructor (properties: any) {
10-
protobuf.Prototype.call(this, properties);
11-
}
10+
constructor (properties: any) {
11+
protobuf.Prototype.call(this, properties);
12+
}
1213
}
1314

14-
protobuf.inherits(Hello, root.lookup("Hello"));
15+
protobuf.inherits(Hello, root.lookup("Hello") as protobuf.Type);

0 commit comments

Comments
 (0)