Skip to content

Commit

Permalink
Initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lgo committed Aug 10, 2017
1 parent 9cdc118 commit 48ffd0f
Show file tree
Hide file tree
Showing 13 changed files with 3,325 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# protobufjs-brunch 1.0.0 (Aug. 8 2017)
* Initial release
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# protobufjs-bruch
Adds ProtoBuf.JS support to Brunch
## protobufjs-brunch
Adds `.proto` compilation support to
[brunch](http://brunch.io) using [protobuf.js](https://github.com/dcodeIO/ProtoBuf.js/).

## Usage
Install the plugin via npm with `npm install --save-dev protobufjs-brunch`.

Or, do manual install:

* Add `"protobufjs-brunch": "x.y.z"` to `package.json` of your brunch app.
Pick a plugin version that corresponds to your minor (y) brunch version.
* If you want to use git version of plugin, add
`"protobufjs-brunch": "git+ssh://[email protected]:lego/protobufjs-brunch.git"`.

### Options
Set additional include paths:
```javascript
module.exports = {
plugins: {
proto: {
includePath: 'src/messages'
}
}
}
```
5 changes: 5 additions & 0 deletions fixtures/included/dependancy.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

message Dependancy {
string a = 0;
}
5 changes: 5 additions & 0 deletions fixtures/inner.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

message Inner {
string name = 0;
}
7 changes: 7 additions & 0 deletions fixtures/outer.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

import "inner.proto";

message Outer {
Inner inner = 0;
}
7 changes: 7 additions & 0 deletions fixtures/package.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package foo.bar.baz;

message Test {
string id = 1;
}
7 changes: 7 additions & 0 deletions fixtures/source/depender.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

import "dependancy.proto";

message Depender {
Dependancy dep = 0;
}
8 changes: 8 additions & 0 deletions fixtures/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

message Test {
string id = 1;
string name = 2;
int32 x = 3;
int32 y = 4;
}
58 changes: 58 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

const pbjs = require('protobufjs/cli/pbjs');
const progeny = require('progeny');

const formatError = (path, err) => {
const error = new Error(`${path}\n${err}`);
error.name = '';
return error;
};


class ProtoBufJSCompiler {
constructor(cfg) {
if (cfg == null) cfg = {};
this.config = cfg.plugins && cfg.plugins.proto || {};
if (this.config.includePath !== undefined) {
this.includePath = this.config.includePath;
}
}

get getDependencies() {
return progeny({
reverseArgs: true,
});
}

compile(file) {
let compiled;
let args = ['--target', 'static-module', '--wrap', 'es6', '--es6', file.path];
if (this.includePath) {
args = args.concat(['-p', this.includePath]);
}
try {
pbjs.main(args, (err, output) => {
if (err) {
throw err;
}
// do something with output
compiled = output;
});
} catch (err) {
return Promise.reject(formatError(err));
}

const result = {
data: compiled,
};

return Promise.resolve(result);
}
}

ProtoBufJSCompiler.prototype.brunchPlugin = true;
ProtoBufJSCompiler.prototype.type = 'javascript';
ProtoBufJSCompiler.prototype.pattern = /\.proto/;

module.exports = ProtoBufJSCompiler;
Loading

0 comments on commit 48ffd0f

Please sign in to comment.