Skip to content

Commit 01238d5

Browse files
mylukinLinkinStars
authored andcommitted
feat(build): add plugin vendor directory management function
Implement movePluginToVendor to handle plugin directory organization during build process
1 parent d8582ec commit 01238d5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/cli/build.go

+19
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func BuildNewAnswer(buildDir, outputPath string, plugins []string, originalAnswe
125125
builder := newAnswerBuilder(buildDir, outputPath, plugins, originalAnswerInfo)
126126
builder.DoTask(createMainGoFile)
127127
builder.DoTask(downloadGoModFile)
128+
builder.DoTask(movePluginToVendor)
128129
builder.DoTask(copyUIFiles)
129130
builder.DoTask(buildUI)
130131
builder.DoTask(mergeI18nFiles)
@@ -221,6 +222,24 @@ func downloadGoModFile(b *buildingMaterial) (err error) {
221222
return
222223
}
223224

225+
// movePluginToVendor move plugin to vendor dir
226+
// Traverse the plugins, and if the plugin path is not github.com/apache/answer-plugins, move the contents of the current plugin to the vendor/github.com/apache/answer-plugins/ directory.
227+
func movePluginToVendor(b *buildingMaterial) (err error) {
228+
pluginsDir := filepath.Join(b.tmpDir, "vendor/github.com/apache/answer-plugins/")
229+
for _, p := range b.plugins {
230+
pluginDir := filepath.Join(b.tmpDir, "vendor/", p.Name)
231+
pluginName := filepath.Base(p.Name)
232+
if !strings.HasPrefix(p.Name, "github.com/apache/answer-plugins/") {
233+
fmt.Printf("try to copy dir from %s to %s\n", pluginDir, filepath.Join(pluginsDir, pluginName))
234+
err = copyDirEntries(os.DirFS(pluginDir), ".", filepath.Join(pluginsDir, pluginName), "node_modules")
235+
if err != nil {
236+
return err
237+
}
238+
}
239+
}
240+
return nil
241+
}
242+
224243
// copyUIFiles copy ui files from answer module to tmp dir
225244
func copyUIFiles(b *buildingMaterial) (err error) {
226245
goListCmd := b.newExecCmd("go", "list", "-mod=mod", "-m", "-f", "{{.Dir}}", "github.com/apache/answer")

0 commit comments

Comments
 (0)