func lessFromConfig(c *config.Config, mode string) ([]*lessFile, error) { var from string if mode == "dev" { from = "app" } else if mode == "prod" { from = "temp" } files := []*lessFile{} size := c.CountRequired("recess") for i := 0; i < size; i++ { src := filepath.Join(from, "styles", c.GetRequired("recess[%d].source", i)) dest := filepath.Join("temp", "styles", c.GetRequired("recess[%d].dest", i)) files = append(files, &lessFile{src, dest}) } return files, 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 sassFromConfig(c *config.Config, mode string) ([]*sassFile, error) { var from string if len(c.GetDefault("closure.library", "")) == 0 { if mode == "dev" { from = filepath.Join("app") } else if mode == "prod" { from = filepath.Join("temp") } } files := []*sassFile{} size := c.CountRequired("sass") for i := 0; i < size; i++ { src := filepath.Join(from, "styles", c.GetRequired("sass[%d].source", i)) dest := filepath.Join("temp", "styles", c.GetRequired("sass[%d].dest", i)) files = append(files, &sassFile{src, dest}) } return files, nil }
func watch(c *config.Config, q *registry.Queue) error { size := c.CountRequired("watch") for i := 0; i < size; i++ { // Extract the task name task := c.GetRequired("watch[%d].task", i) // Extract the paths paths := []string{} pathsSize := c.CountDefault("watch[%d].paths", i) for j := 0; j < pathsSize; j++ { paths = append(paths, c.GetRequired("watch[%d].paths[%d]", i, j)) } // Init the watcher if err := watcher.Dirs(paths, task); err != nil { return fmt.Errorf("watch dirs failed: %s", err) } } return nil }
func parseFields(data *config.Config, spec string) []*field { fields := []*field{} size := data.CountRequired("%s", spec) for i := 0; i < size; i++ { field := &field{ Key: data.GetDefault("%s[%d].key", "", spec, i), Kind: data.GetRequired("%s[%d].kind", spec, i), Store: data.GetDefault("%s[%d].store", "", spec, i), Condition: data.GetDefault("%s[%d].condition", "", spec, i), Validators: make([]*validator, 0), } if field.Kind == "Array" || field.Kind == "Object" || field.Kind == "Conditional" { newSpec := fmt.Sprintf("%s[%d].fields", spec, i) field.Fields = parseFields(data, newSpec) } validatorsSize := data.CountDefault("%s[%d].validators", spec, i) for j := 0; j < validatorsSize; j++ { v := &validator{ Name: data.GetRequired("%s[%d].validators[%d].name", spec, i, j), Value: data.GetDefault("%s[%d].validators[%d].value", "", spec, i, j), } usesSize := data.CountDefault("%s[%d].validators[%d].use", spec, i, j) for k := 0; k < usesSize; k++ { value := data.GetDefault("%s[%d].validators[%d].use[%d]", "", spec, i, j, k) v.Uses = append(v.Uses, value) } field.Validators = append(field.Validators, v) } fields = append(fields, field) } return fields }