(ctx context.Context, in *Create)
| 51 | } |
| 52 | |
| 53 | func (c *CLI) Create(ctx context.Context, in *Create) error { |
| 54 | var files []*virtual.File |
| 55 | |
| 56 | log, err := c.loadLog() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | // Get the absolute directory |
| 62 | absDir, err := filepath.Abs(c.Dir) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | // create go.mod |
| 68 | gomodFile, err := c.createGoMod(in, absDir) |
| 69 | if err != nil { |
| 70 | return err |
| 71 | } |
| 72 | files = append(files, gomodFile) |
| 73 | |
| 74 | pkgFile, err := c.createPackageJson(in, absDir) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | files = append(files, pkgFile) |
| 79 | |
| 80 | // Add the .gitignore |
| 81 | files = append(files, &virtual.File{ |
| 82 | Path: ".gitignore", |
| 83 | Data: embedded.Gitignore(), |
| 84 | }) |
| 85 | |
| 86 | // Add favicon.ico |
| 87 | files = append(files, &virtual.File{ |
| 88 | Path: "public/favicon.ico", |
| 89 | Data: embedded.Favicon(), |
| 90 | }) |
| 91 | |
| 92 | // Sync the files |
| 93 | for _, file := range files { |
| 94 | abspath := filepath.Join(absDir, file.Path) |
| 95 | if err := os.MkdirAll(filepath.Dir(abspath), 0755); err != nil { |
| 96 | return err |
| 97 | } |
| 98 | if err := os.WriteFile(abspath, file.Data, 0644); err != nil { |
| 99 | return err |
| 100 | } |
| 101 | log.Info("Created: %s", file.Path) |
| 102 | } |
| 103 | |
| 104 | // Download the dependencies in go.mod to GOMODCACHE |
| 105 | // Run `go mod download all` |
| 106 | // TODO: do we need `all`? |
| 107 | if err := c.command(absDir, "go", "mod", "download", "all").Run(); err != nil { |
| 108 | return err |
| 109 | } |
| 110 | log.Info("Installed: go modules") |
no test coverage detected