Checks if a file with the given path has to be generated, creates a directory structure, and a file with the given content.
(path string, content []byte)
| 40 | // Checks if a file with the given path has to be generated, creates |
| 41 | // a directory structure, and a file with the given content. |
| 42 | func (g generator) processFile(path string, content []byte) { |
| 43 | if !g.needed(path) { |
| 44 | return |
| 45 | } |
| 46 | for _, tech := range g.techStack { |
| 47 | path = strings.Replace(path, tech+".", "", 1) |
| 48 | } |
| 49 | pathElements := strings.Split(path, "/") |
| 50 | separator := string(os.PathSeparator) |
| 51 | pathElements = append([]string{g.projectName}, pathElements...) |
| 52 | _ = os.MkdirAll( |
| 53 | strings.Join(pathElements[:len(pathElements)-1], separator), |
| 54 | os.ModePerm, |
| 55 | ) |
| 56 | fmt.Println("creating: " + strings.Join(pathElements, separator)) |
| 57 | err := ioutil.WriteFile( |
| 58 | strings.Join(pathElements, separator), |
| 59 | content, |
| 60 | 0644, |
| 61 | ) |
| 62 | if err != nil { |
| 63 | log.Fatal(err) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func (g generator) initGitRepo() error { |
| 68 | fmt.Println("setting up Git repository") |