@@ -19,7 +19,8 @@ import (
19
19
20
20
"github.com/pkg/errors"
21
21
"github.com/samber/lo"
22
- "go.jetpack.io/devbox/internal/filegen"
22
+ "go.jetpack.io/devbox/internal/impl/generate"
23
+ "go.jetpack.io/devbox/internal/shellgen"
23
24
"golang.org/x/exp/slices"
24
25
25
26
"go.jetpack.io/devbox/internal/boxcli/usererr"
@@ -141,7 +142,7 @@ func (d *Devbox) Generate(ctx context.Context) error {
141
142
ctx , task := trace .NewTask (ctx , "devboxGenerate" )
142
143
defer task .End ()
143
144
144
- return errors .WithStack (filegen .GenerateForPrintEnv (ctx , d ))
145
+ return errors .WithStack (shellgen .GenerateForPrintEnv (ctx , d ))
145
146
}
146
147
147
148
func (d * Devbox ) Shell (ctx context.Context ) error {
@@ -175,7 +176,7 @@ func (d *Devbox) Shell(ctx context.Context) error {
175
176
)
176
177
177
178
opts := []ShellOption {
178
- WithHooksFilePath (filegen .ScriptPath (d .ProjectDir (), filegen .HooksFilename )),
179
+ WithHooksFilePath (shellgen .ScriptPath (d .ProjectDir (), shellgen .HooksFilename )),
179
180
WithProfile (profileDir ),
180
181
WithHistoryFile (filepath .Join (d .projectDir , shellHistoryFile )),
181
182
WithProjectDir (d .projectDir ),
@@ -199,7 +200,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
199
200
return err
200
201
}
201
202
202
- if err := filegen .WriteScriptsToFiles (d ); err != nil {
203
+ if err := shellgen .WriteScriptsToFiles (d ); err != nil {
203
204
return err
204
205
}
205
206
@@ -224,18 +225,18 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
224
225
var cmdWithArgs []string
225
226
if _ , ok := d .cfg .Scripts ()[cmdName ]; ok {
226
227
// it's a script, so replace the command with the script file's path.
227
- cmdWithArgs = append ([]string {filegen .ScriptPath (d .ProjectDir (), cmdName )}, cmdArgs ... )
228
+ cmdWithArgs = append ([]string {shellgen .ScriptPath (d .ProjectDir (), cmdName )}, cmdArgs ... )
228
229
} else {
229
230
// Arbitrary commands should also run the hooks, so we write them to a file as well. However, if the
230
231
// command args include env variable evaluations, then they'll be evaluated _before_ the hooks run,
231
232
// which we don't want. So, one solution is to write the entire command and its arguments into the
232
233
// file itself, but that may not be great if the variables contain sensitive information. Instead,
233
234
// we save the entire command (with args) into the DEVBOX_RUN_CMD var, and then the script evals it.
234
- err := filegen .WriteScriptFile (d , arbitraryCmdFilename , filegen .ScriptBody (d , "eval $DEVBOX_RUN_CMD\n " ))
235
+ err := shellgen .WriteScriptFile (d , arbitraryCmdFilename , shellgen .ScriptBody (d , "eval $DEVBOX_RUN_CMD\n " ))
235
236
if err != nil {
236
237
return err
237
238
}
238
- cmdWithArgs = []string {filegen .ScriptPath (d .ProjectDir (), arbitraryCmdFilename )}
239
+ cmdWithArgs = []string {shellgen .ScriptPath (d .ProjectDir (), arbitraryCmdFilename )}
239
240
env ["DEVBOX_RUN_CMD" ] = strings .Join (append ([]string {cmdName }, cmdArgs ... ), " " )
240
241
}
241
242
@@ -282,7 +283,7 @@ func (d *Devbox) PrintEnv(ctx context.Context, includeHooks bool) (string, error
282
283
envStr := exportify (envs )
283
284
284
285
if includeHooks {
285
- hooksStr := ". " + filegen .ScriptPath (d .ProjectDir (), filegen .HooksFilename )
286
+ hooksStr := ". " + shellgen .ScriptPath (d .ProjectDir (), shellgen .HooksFilename )
286
287
envStr = fmt .Sprintf ("%s\n %s;\n " , envStr , hooksStr )
287
288
}
288
289
@@ -372,14 +373,14 @@ func (d *Devbox) GenerateDevcontainer(ctx context.Context, force bool) error {
372
373
redact .Safe (filepath .Base (devContainerPath )), err )
373
374
}
374
375
// generate dockerfile
375
- err = filegen .CreateDockerfile (ctx ,
376
+ err = generate .CreateDockerfile (ctx ,
376
377
devContainerPath , d .getLocalFlakesDirs (), true /* isDevcontainer */ )
377
378
if err != nil {
378
379
return redact .Errorf ("error generating dev container Dockerfile in <project>/%s: %w" ,
379
380
redact .Safe (filepath .Base (devContainerPath )), err )
380
381
}
381
382
// generate devcontainer.json
382
- err = filegen .CreateDevcontainer (ctx , devContainerPath , d .Packages ())
383
+ err = generate .CreateDevcontainer (ctx , devContainerPath , d .Packages ())
383
384
if err != nil {
384
385
return redact .Errorf ("error generating devcontainer.json in <project>/%s: %w" ,
385
386
redact .Safe (filepath .Base (devContainerPath )), err )
@@ -404,12 +405,12 @@ func (d *Devbox) GenerateDockerfile(ctx context.Context, force bool) error {
404
405
405
406
// generate dockerfile
406
407
return errors .WithStack (
407
- filegen .CreateDockerfile (ctx ,
408
+ generate .CreateDockerfile (ctx ,
408
409
d .projectDir , d .getLocalFlakesDirs (), false /* isDevcontainer */ ))
409
410
}
410
411
411
412
func PrintEnvrcContent (w io.Writer ) error {
412
- return filegen .EnvrcContent (w )
413
+ return generate .EnvrcContent (w )
413
414
}
414
415
415
416
// GenerateEnvrcFile generates a .envrc file that makes direnv integration convenient
@@ -438,7 +439,7 @@ func (d *Devbox) GenerateEnvrcFile(ctx context.Context, force bool) error {
438
439
}
439
440
440
441
// .envrc file creation
441
- err := filegen .CreateEnvrc (ctx , d .projectDir )
442
+ err := generate .CreateEnvrc (ctx , d .projectDir )
442
443
if err != nil {
443
444
return errors .WithStack (err )
444
445
}
0 commit comments