MCPcopy Index your code
hub / github.com/jetify-com/devbox / createFile

Method createFile

internal/plugin/plugin.go:123–175  ·  view source on GitHub ↗
(
	pkg Includable,
	filePath, contentPath, virtenvPath string,
)

Source from the content-addressed store, hash-verified

121}
122
123func (m *Manager) createFile(
124 pkg Includable,
125 filePath, contentPath, virtenvPath string,
126) error {
127 name := pkg.CanonicalName()
128 slog.Debug("Creating file %q from contentPath: %q", filePath, contentPath)
129 content, err := pkg.FileContent(contentPath)
130 if err != nil {
131 return errors.WithStack(err)
132 }
133 tmpl, err := template.New(filePath + "-template").Parse(string(content))
134 if err != nil {
135 return errors.WithStack(err)
136 }
137
138 var urlForInput, attributePath string
139
140 if pkg, ok := pkg.(*devpkg.Package); ok {
141 attributePath, err = pkg.PackageAttributePath()
142 if err != nil {
143 return err
144 }
145 urlForInput = pkg.URLForFlakeInput()
146 }
147
148 var buf bytes.Buffer
149 if err = tmpl.Execute(&buf, map[string]any{
150 "DevboxDir": filepath.Join(m.ProjectDir(), devboxDirName, name),
151 "DevboxDirRoot": filepath.Join(m.ProjectDir(), devboxDirName),
152 "DevboxProfileDefault": filepath.Join(m.ProjectDir(), nix.ProfilePath),
153 "PackageAttributePath": attributePath,
154 "Packages": m.AllPackageNamesIncludingRemovedTriggerPackages(),
155 "System": nix.System(),
156 "URLForInput": urlForInput,
157 "Virtenv": filepath.Join(virtenvPath, name),
158 }); err != nil {
159 return errors.WithStack(err)
160 }
161 var fileMode fs.FileMode = 0o644
162 if strings.Contains(filePath, "bin/") {
163 fileMode = 0o755
164 }
165
166 if err := os.WriteFile(filePath, buf.Bytes(), fileMode); err != nil {
167 return errors.WithStack(err)
168 }
169 if fileMode == 0o755 {
170 if err := createSymlink(m.ProjectDir(), filePath); err != nil {
171 return err
172 }
173 }
174 return nil
175}
176
177// buildConfig returns a plugin.Config
178func buildConfig(pkg Includable, projectDir, content string) (*Config, error) {

Callers 1

CreateFilesForConfigMethod · 0.95

Calls 10

SystemFunction · 0.92
createSymlinkFunction · 0.85
PackageAttributePathMethod · 0.80
URLForFlakeInputMethod · 0.80
BytesMethod · 0.80
CanonicalNameMethod · 0.65
FileContentMethod · 0.65
ExecuteMethod · 0.65
ProjectDirMethod · 0.65

Tested by

no test coverage detected