func prepareDist(c *config.Config, q *registry.Queue) error { dirs := c.GetListRequired("dist.prepare") for _, from := range dirs { to := "temp" if strings.Contains(from, "->") { parts := strings.Split(from, "->") from = strings.TrimSpace(parts[0]) to = filepath.Join("temp", strings.TrimSpace(parts[1])) } if _, err := os.Stat(from); err != nil { if os.IsNotExist(err) { continue } return fmt.Errorf("stat failed: %s", err) } if err := os.MkdirAll(filepath.Dir(to), 0755); err != nil { return fmt.Errorf("prepare dir failed (%s): %s", to, err) } output, err := utils.Exec("cp", []string{"-r", from, to}) if err != nil { fmt.Println(output) return fmt.Errorf("copy error: %s", err) } } return nil }
func ngtemplates(c *config.Config, q *registry.Queue) error { count := c.CountRequired("ngtemplates") for i := 0; i < count; i++ { append := c.GetRequired("ngtemplates[%d].append", i) files := c.GetListRequired("ngtemplates[%d].files", i) templates, err := readTemplates(files) if err != nil { return fmt.Errorf("cannot read templates: %s", err) } if err = writeTemplates(append, templates); err != nil { return fmt.Errorf("cannot save template file: %s", err) } } return nil }
func cacherev(c *config.Config, q *registry.Queue) error { dirs := c.GetListRequired("cacherev.dirs") exclude := c.GetListRequired("cacherev.exclude") for _, dir := range dirs { dir = filepath.Join("temp", dir) if err := filepath.Walk(dir, changeName(exclude)); err != nil { return fmt.Errorf("change names walk failed (%s): %s", dir, err) } } rev := c.GetListDefault("cacherev.rev") for _, dir := range rev { dir = filepath.Join("temp", dir) if err := filepath.Walk(dir, changeReferences); err != nil { return fmt.Errorf("change references walk failed (%s): %s", dir, err) } } utils.SaveChanges(changes) return nil }
func copyDist(c *config.Config, q *registry.Queue) error { dirs := c.GetListRequired("dist.final") changes := utils.LoadChanges() for i, dir := range dirs { if name, ok := changes[dir]; ok { dir = name } dirs[i] = dir } for _, dir := range dirs { from := dir to := dir if strings.Contains(dir, "->") { parts := strings.Split(dir, "->") from = strings.TrimSpace(parts[0]) to = strings.TrimSpace(parts[1]) } origin := filepath.Join("temp", from) dest := filepath.Join("dist", to) if err := os.MkdirAll(filepath.Dir(dest), 0755); err != nil { return fmt.Errorf("prepare dir failed (%s): %s", dir, err) } if *config.Verbose { log.Printf("copy `%s`\n", origin) } output, err := utils.Exec("cp", []string{"-r", origin, dest}) if err != nil { fmt.Println(output) return fmt.Errorf("copy error: %s", err) } } return nil }