(templates []*fileConfig, data interface{}, delimiters []string)
| 159 | } |
| 160 | |
| 161 | func executeTemplates(templates []*fileConfig, data interface{}, delimiters []string) { |
| 162 | var wg sync.WaitGroup |
| 163 | leftDelim := delimiters[0] |
| 164 | rightDelim := delimiters[1] |
| 165 | if leftDelim == "" { |
| 166 | leftDelim = "{{" |
| 167 | } |
| 168 | if rightDelim == "" { |
| 169 | rightDelim = "}}" |
| 170 | } |
| 171 | // flog.Infof("Templating params:") |
| 172 | // pp.Println(data) |
| 173 | |
| 174 | for _, tmpltConfig := range templates { |
| 175 | source := tmpltConfig.source |
| 176 | dest := tmpltConfig.destination |
| 177 | |
| 178 | outputDirPath, _ := path.Split(dest) |
| 179 | err := fs.CreateDirs(outputDirPath) |
| 180 | if err != nil { |
| 181 | flog.Errorf("Error creating directory '%s': %v", source, err) |
| 182 | } |
| 183 | f, err := os.Create(dest) |
| 184 | if err != nil { |
| 185 | flog.Errorf("Error initializing file '%s'", err) |
| 186 | } |
| 187 | |
| 188 | err = f.Chmod(tmpltConfig.modeBits) |
| 189 | if err != nil { |
| 190 | flog.Errorf("Error changing mode bits '%s'", err) |
| 191 | } |
| 192 | |
| 193 | // @TODO if strict mode then only copy file |
| 194 | name := path.Base(source) |
| 195 | template, err := template.New(name).Delims(leftDelim, rightDelim).Funcs(util.FuncMap).ParseFiles(source) |
| 196 | if err != nil { |
| 197 | flog.Errorf("Error in template '%s': %v", source, err) |
| 198 | } |
| 199 | err = template.Execute(f, data) |
| 200 | |
| 201 | if err != nil { |
| 202 | flog.Errorf("Error templating '%s': %v", source, err) |
| 203 | } else { |
| 204 | flog.Successf("Finished templating : %s", dest) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | wg.Wait() |
| 209 | } |
| 210 | |
| 211 | func copyBinFiles(binTypeFiles []*fileConfig) { |
| 212 | for _, binFile := range binTypeFiles { |
no test coverage detected