MCPcopy
hub / github.com/apache/answer / copyUIFiles

Function copyUIFiles

internal/cli/build.go:322–379  ·  view source on GitHub ↗

copyUIFiles copy ui files from answer module to tmp dir

(b *buildingMaterial)

Source from the content-addressed store, hash-verified

320
321// copyUIFiles copy ui files from answer module to tmp dir
322func copyUIFiles(b *buildingMaterial) (err error) {
323 goListCmd := b.newExecCmd("go", "list", "-mod=mod", "-m", "-f", "{{.Dir}}", "github.com/apache/answer")
324 buf := new(bytes.Buffer)
325 goListCmd.Stdout = buf
326 if err = goListCmd.Run(); err != nil {
327 return fmt.Errorf("failed to run go list: %w", err)
328 }
329
330 answerDir := strings.TrimSpace(buf.String())
331 goModUIDir := filepath.Join(answerDir, "ui")
332 localUIBuildDir := filepath.Join(b.tmpDir, "vendor/github.com/apache/answer/ui/")
333 // The node_modules folder generated during development will interfere packaging, so it needs to be ignored.
334 if err = copyDirEntries(os.DirFS(goModUIDir), ".", localUIBuildDir, "node_modules"); err != nil {
335 return fmt.Errorf("failed to copy ui files: %w", err)
336 }
337
338 pluginsDir := filepath.Join(b.tmpDir, "vendor/github.com/apache/answer-plugins/")
339 localUIPluginDir := filepath.Join(localUIBuildDir, "src/plugins/")
340
341 // copy plugins dir
342 fmt.Printf("try to copy dir from %s to %s\n", pluginsDir, localUIPluginDir)
343
344 // if plugins dir not exist means no plugins
345 if !dir.CheckDirExist(pluginsDir) {
346 return nil
347 }
348
349 pluginsDirEntries, err := os.ReadDir(pluginsDir)
350 if err != nil {
351 return fmt.Errorf("failed to read plugins dir: %w", err)
352 }
353 for _, entry := range pluginsDirEntries {
354 if !entry.IsDir() {
355 continue
356 }
357 sourcePluginDir := filepath.Join(pluginsDir, entry.Name())
358 // check if plugin is a ui plugin
359 packageJsonPath := filepath.Join(sourcePluginDir, "package.json")
360 fmt.Printf("check if %s is a ui plugin\n", packageJsonPath)
361 if !dir.CheckFileExist(packageJsonPath) {
362 continue
363 }
364
365 pnpmInstallCmd := b.newExecCmd("pnpm", "install")
366 pnpmInstallCmd.Dir = sourcePluginDir
367 if err = pnpmInstallCmd.Run(); err != nil {
368 return fmt.Errorf("failed to install plugin dependencies: %w", err)
369 }
370
371 localPluginDir := filepath.Join(localUIPluginDir, entry.Name())
372 fmt.Printf("try to copy dir from %s to %s\n", sourcePluginDir, localPluginDir)
373 if err = copyDirEntries(os.DirFS(sourcePluginDir), ".", localPluginDir, "node_modules"); err != nil {
374 return fmt.Errorf("failed to copy ui files: %w", err)
375 }
376 }
377 formatUIPluginsDirName(localUIPluginDir)
378 return nil
379}

Callers

nothing calls this directly

Calls 6

CheckDirExistFunction · 0.92
CheckFileExistFunction · 0.92
copyDirEntriesFunction · 0.85
formatUIPluginsDirNameFunction · 0.85
newExecCmdMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected