-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
3,325 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# protobufjs-brunch 1.0.0 (Aug. 8 2017) | ||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
syntax = "proto3"; | ||
|
||
message Dependancy { | ||
string a = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
syntax = "proto3"; | ||
|
||
message Inner { | ||
string name = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
import "inner.proto"; | ||
|
||
message Outer { | ||
Inner inner = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
import "dependancy.proto"; | ||
|
||
message Depender { | ||
Dependancy dep = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.