feat(build): add ignore path for build

This commit is contained in:
LinkinStars 2023-07-29 11:02:09 +08:00
parent d3f1b5dbe1
commit aa606ed01a
1 changed files with 15 additions and 2 deletions

View File

@ -207,7 +207,8 @@ func copyUIFiles(b *buildingMaterial) (err error) {
goModUIDir := filepath.Join(strings.TrimSpace(buf.String()), "ui") goModUIDir := filepath.Join(strings.TrimSpace(buf.String()), "ui")
localUIBuildDir := filepath.Join(b.tmpDir, "vendor/github.com/answerdev/answer/ui/") localUIBuildDir := filepath.Join(b.tmpDir, "vendor/github.com/answerdev/answer/ui/")
if err = copyDirEntries(os.DirFS(goModUIDir), ".", localUIBuildDir); err != nil { // The node_modules folder generated during development will interfere packaging, so it needs to be ignored.
if err = copyDirEntries(os.DirFS(goModUIDir), ".", localUIBuildDir, "node_modules"); err != nil {
return fmt.Errorf("failed to copy ui files: %w", err) return fmt.Errorf("failed to copy ui files: %w", err)
} }
return nil return nil
@ -366,15 +367,27 @@ func mergeI18nFiles(b *buildingMaterial) (err error) {
return err return err
} }
func copyDirEntries(sourceFs fs.FS, sourceDir string, targetDir string) (err error) { func copyDirEntries(sourceFs fs.FS, sourceDir, targetDir string, ignoreDir ...string) (err error) {
err = dir.CreateDirIfNotExist(targetDir) err = dir.CreateDirIfNotExist(targetDir)
if err != nil { if err != nil {
return err return err
} }
ignoreThisDir := func(path string) bool {
for _, s := range ignoreDir {
if strings.HasPrefix(path, s) {
return true
}
}
return false
}
err = fs.WalkDir(sourceFs, sourceDir, func(path string, d fs.DirEntry, err error) error { err = fs.WalkDir(sourceFs, sourceDir, func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return err return err
} }
if ignoreThisDir(path) {
return nil
}
// Convert the path to use forward slashes, important because we use embedded FS which always uses forward slashes // Convert the path to use forward slashes, important because we use embedded FS which always uses forward slashes
path = filepath.ToSlash(path) path = filepath.ToSlash(path)