Skip to content

Commit 2f29a1d

Browse files
authored
fix sub plugin (#14)
1 parent a11b2ac commit 2f29a1d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

cmd/protobuild/cmd.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,24 +148,12 @@ func Main() *cli.Command {
148148
continue
149149
}
150150

151-
assert.Must(filepath.Walk(globalCfg.Root[i], func(path string, info fs.FileInfo, err error) error {
151+
assert.Must(filepath.WalkDir(globalCfg.Root[i], func(path string, d fs.DirEntry, err error) error {
152152
if err != nil {
153153
return err
154154
}
155155

156-
// skip dir
157-
if !info.IsDir() {
158-
return nil
159-
}
160-
161-
// check contains proto file in dir
162-
hasProto := lo.ContainsBy(
163-
assert.Must1(os.ReadDir(path)),
164-
func(item os.DirEntry) bool {
165-
return !item.IsDir() && strings.HasSuffix(item.Name(), ".proto")
166-
},
167-
)
168-
if !hasProto {
156+
if !d.IsDir() {
169157
return nil
170158
}
171159

@@ -174,6 +162,13 @@ func Main() *cli.Command {
174162
pluginCfgPath := filepath.Join(path, protoPluginCfg)
175163
if pathutil.IsExist(pluginCfgPath) {
176164
pluginCfg = parsePluginConfig(pluginCfgPath)
165+
} else {
166+
for dir, v := range pluginMap {
167+
if strings.HasPrefix(path, dir) {
168+
pluginCfg = v
169+
break
170+
}
171+
}
177172
}
178173
pluginCfg = mergePluginConfig(&globalCfg, pluginCfg)
179174

@@ -189,6 +184,17 @@ func Main() *cli.Command {
189184
}
190185

191186
for protoSourcePath, pp := range pluginMap {
187+
// check contains proto file in dir
188+
hasProto := lo.ContainsBy(
189+
assert.Must1(os.ReadDir(protoSourcePath)),
190+
func(item os.DirEntry) bool {
191+
return !item.IsDir() && strings.HasSuffix(item.Name(), ".proto")
192+
},
193+
)
194+
if !hasProto {
195+
continue
196+
}
197+
192198
var doF = func(pluginCfg *Config, protoPath string) {
193199
data := ""
194200
base := fmt.Sprintf("protoc -I %s -I %s", pluginCfg.Vendor, pwd)

0 commit comments

Comments
 (0)