-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule.go
60 lines (50 loc) · 1.44 KB
/
module.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"github.com/golang/protobuf/proto"
pgs "github.com/lyft/protoc-gen-star"
pgsgo "github.com/lyft/protoc-gen-star/lang/go"
pbt "go.appointy.com/protoc-gen-jaal/schema"
)
type jaalModule struct {
*pgs.ModuleBase
pgsgo.Context
}
func (m *jaalModule) InitContext(c pgs.BuildContext) {
m.ModuleBase.InitContext(c)
m.Context = pgsgo.InitContext(c.Parameters())
}
func (m *jaalModule) Name() string { return "jaal" }
func (m *jaalModule) CheckSkipFile(target pgs.File) (bool, error) {
// checks file_skip option
opt := target.Descriptor().GetOptions()
if opt != nil {
x, err := proto.GetExtension(opt, pbt.E_FileSkip)
if err != nil && proto.ErrMissingExtension != err {
return false, err
}
if x != nil && *x.(*bool) == true { // skips only when file_skip is explicitly true
return true, nil
}
}
return false, nil
}
func (m *jaalModule) Execute(targets map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact {
for _, target := range targets { // loop over files
if ok, err := m.CheckSkipFile(target); err != nil { // checks file_skip option
fmt.Println("Error :", err)
continue
} else if ok == true {
continue
}
fname := target.Name().String()
fname = fname[:len(fname)-6]
name := m.BuildContext.OutputPath() + "/" + fname + ".pb.gq.go"
str, err := m.generateFileData(target)
if err != nil {
m.Log("Error : ", err)
}
m.AddGeneratorFile(name, str)
}
return m.Artifacts()
}