Skip to content

Commit

Permalink
Post-merge, accept custom targets in pbjs, see #512
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 2, 2016
1 parent a613a63 commit 926905b
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 18 deletions.
6 changes: 5 additions & 1 deletion cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ exports.main = function(args) {
files = argv._,
paths = typeof argv.path === 'string' ? [ argv.path ] : argv.path || [];

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

if (!target)
target = require(path.resolve(process.cwd(), argv.target));

// Resolve glob expressions
for (var i = 0; i < files.length;) {
if (glob.hasMagic(files[i])) {
Expand Down
4 changes: 3 additions & 1 deletion cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module.exports = static_target;

static_target.private = true;

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

// TBD:
// - Generate a single file or scaffold an entire project directory? Both?
Expand Down
4 changes: 2 additions & 2 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
"build": "gulp",
"docs": "jsdoc -c jsdoc.docs.json -R README.md",
"pages": "node scripts/pages",
"types": "jsdoc -c jsdoc.types.json && node scripts/types.js && tsc types/protobuf.js-test.ts --lib es2015 --noEmit",
"types": "jsdoc -c jsdoc.types.json && node scripts/types.js && tsc types/test.ts --lib es2015 --noEmit",
"lint": "eslint src",
"test": "tape tests/*.js | tap-spec",
"zuul": "zuul --ui tape --no-coverage --concurrency 1 -- tests/*.js",
"zuul-local": "zuul --ui tape --no-coverage --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js",
"bench": "node bench",
"all": "npm run lint && npm run test && npm run build && npm run types && npm run docs && npm run bench",
"prepublish": "node scripts/prepublish.js"
"prepublish": "node scripts/prepublish"
},
"optionalDependencies": {
"long": "^3.2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/inherits.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _TypeError = util._TypeError;
/**
* Inherits a custom class from the message prototype of the specified message type.
* @param {Function} clazz Inheriting class
* @param {Type|ReflectionObject} type Inherited message type
* @param {Type} type Inherited message type
* @param {InheritanceOptions} [options] Inheritance options
* @returns {Prototype} Created prototype
*/
Expand Down
6 changes: 3 additions & 3 deletions types/protobuf.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*
* protobuf.js v6.0.1 TypeScript definitions
* Generated Fri, 02 Dec 2016 15:01:02 UTC
* Generated Fri, 02 Dec 2016 16:05:19 UTC
*/
declare module "protobufjs" {

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

/**
* 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.
Expand Down
11 changes: 6 additions & 5 deletions types/protobuf.js-test.ts → types/test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
///<reference path="./protobuf.js.d.ts" />
/// <reference path="./protobuf.js.d.ts" />

import * as protobuf from "protobufjs";

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

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

export class Hello {
constructor (properties: any) {
protobuf.Prototype.call(this, properties);
}
constructor (properties: any) {
protobuf.Prototype.call(this, properties);
}
}

protobuf.inherits(Hello, root.lookup("Hello"));
protobuf.inherits(Hello, root.lookup("Hello") as protobuf.Type);

0 comments on commit 926905b

Please sign in to comment.