-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathjs_closure_plugin.go
41 lines (34 loc) · 1.12 KB
/
js_closure_plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// for some bizarre reason, naming this file 'protoc_js.go' makes it be ignored
// by the compiler?
package builtin
import (
"fmt"
"path"
"path/filepath"
"strings"
"github.com/bazelbuild/bazel-gazelle/label"
"github.com/stackb/rules_proto/pkg/protoc"
)
func init() {
protoc.Plugins().MustRegisterPlugin(&JsClosurePlugin{})
}
// JsClosurePlugin implements Plugin for the built-in protoc js/library plugin.
type JsClosurePlugin struct{}
// Name implements part of the Plugin interface.
func (p *JsClosurePlugin) Name() string {
return "builtin:js:closure"
}
// Configure implements part of the Plugin interface.
func (p *JsClosurePlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration {
basename := strings.ToLower(ctx.ProtoLibrary.BaseName())
library := path.Join(ctx.Rel, basename+"_closure.js")
return &protoc.PluginConfiguration{
Label: label.New("build_stack_rules_proto", "plugin/builtin", "closurejs"),
Outputs: []string{library},
Options: append(
ctx.PluginConfig.GetOptions(),
"import_style=closure",
fmt.Sprintf("library=%s", strings.TrimSuffix(library, filepath.Ext(library))),
),
}
}