Skip to content

Commit 8563195

Browse files
authored
[gen-readme] For generated readme scripts, replace absolute paths (#1949)
## Summary Plugins v2 allow scripts that may have `Virtenv` or `DevboxDir` in them. This causes the commands to show up as absolute paths in the readme. This fixes that issue. An alternative is to read the raw scripts from the plugin (including the un-templatized string). This may be a better solution long term, but is more work and would require specially plugin parsing only for the readme generation so I punted on that approach for now. ## How was it tested? Tested with new go monorepo plugin jetify-com/devbox-plugins#7
1 parent 46ea79e commit 8563195

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

internal/devbox/docgen/docgen.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ func GenerateReadme(
5353
return tmpl.Execute(f, map[string]any{
5454
"Name": devbox.Config().Root.Name,
5555
"Description": devbox.Config().Root.Description,
56-
"Scripts": devbox.Config().Scripts(),
57-
"EnvVars": devbox.Config().Env(),
58-
"InitHook": devbox.Config().InitHook(),
59-
"Packages": devbox.TopLevelPackages(),
56+
"Scripts": devbox.Config().Scripts().
57+
WithRelativePaths(devbox.ProjectDir()),
58+
"EnvVars": devbox.Config().Env(),
59+
"InitHook": devbox.Config().InitHook(),
60+
"Packages": devbox.TopLevelPackages(),
6061
// TODO add includes
6162
})
6263
}

internal/devconfig/configfile/scripts.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package configfile
22

3-
import "go.jetpack.io/devbox/internal/devbox/shellcmd"
3+
import (
4+
"strings"
5+
6+
"go.jetpack.io/devbox/internal/devbox/shellcmd"
7+
)
48

59
type script struct {
610
shellcmd.Commands
@@ -27,3 +31,21 @@ func (c *ConfigFile) Scripts() Scripts {
2731

2832
return result
2933
}
34+
35+
func (s Scripts) WithRelativePaths(projectDir string) Scripts {
36+
result := make(Scripts, len(s))
37+
for name, s := range s {
38+
commandsWithRelativePaths := shellcmd.Commands{}
39+
for _, c := range s.Commands.Cmds {
40+
commandsWithRelativePaths.Cmds = append(
41+
commandsWithRelativePaths.Cmds,
42+
strings.ReplaceAll(c, projectDir, "."),
43+
)
44+
}
45+
result[name] = &script{
46+
Commands: commandsWithRelativePaths,
47+
Comments: s.Comments,
48+
}
49+
}
50+
return result
51+
}

0 commit comments

Comments
 (0)