MCPcopy Index your code
hub / github.com/livebud/bud / Create

Method Create

internal/cli/create.go:53–144  ·  view source on GitHub ↗
(ctx context.Context, in *Create)

Source from the content-addressed store, hash-verified

51}
52
53func (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")

Callers 3

ParseMethod · 0.95
installFunction · 0.45
RunMethod · 0.45

Calls 14

loadLogMethod · 0.95
createGoModMethod · 0.95
createPackageJsonMethod · 0.95
commandMethod · 0.95
findBudModuleMethod · 0.95
GenerateMethod · 0.95
GitignoreFunction · 0.92
FaviconFunction · 0.92
DirMethod · 0.80
MkdirAllMethod · 0.65
WriteFileMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected