Skip to content

Commit aa9f515

Browse files
authored
[cleanup] plugin framework: rename rootDir to projectDir (#448)
## Summary For the plugin framework, this renames rootDir to projectDir. This change makes it consistent with the rest of the devbox codebase. did not change this one, because it may break users. Or are we early enough that we can change it? ``` docs/app/docs/devbox_examples/servers/apache.md:HTTPD_DEVBOX_CONFIG_DIR={PROJECT_DIR} ``` ## How was it tested? automated tests
1 parent 09b7200 commit aa9f515

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

internal/plugin/files.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"go.jetpack.io/devbox/plugins"
99
)
1010

11-
func getConfigIfAny(pkg, rootDir string) (*config, error) {
11+
func getConfigIfAny(pkg, projectDir string) (*config, error) {
1212
configFiles, err := plugins.BuiltIn.ReadDir(".")
1313
if err != nil {
1414
return nil, errors.WithStack(err)
@@ -24,7 +24,7 @@ func getConfigIfAny(pkg, rootDir string) (*config, error) {
2424
return nil, errors.WithStack(err)
2525
}
2626

27-
cfg, err := buildConfig(pkg, rootDir, string(content))
27+
cfg, err := buildConfig(pkg, projectDir, string(content))
2828
if err != nil {
2929
return nil, errors.WithStack(err)
3030
}

internal/plugin/hooks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package plugin
22

3-
func InitHooks(pkgs []string, rootDir string) ([]string, error) {
3+
func InitHooks(pkgs []string, projectDir string) ([]string, error) {
44
hooks := []string{}
55
for _, pkg := range pkgs {
6-
c, err := getConfigIfAny(pkg, rootDir)
6+
c, err := getConfigIfAny(pkg, projectDir)
77
if err != nil {
88
return nil, err
99
}

internal/plugin/info.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
func PrintReadme(
12-
pkg, rootDir string,
12+
pkg, projectDir string,
1313
w io.Writer,
1414
showSourceEnv, markdown bool,
1515
) error {
16-
cfg, err := getConfigIfAny(pkg, rootDir)
16+
cfg, err := getConfigIfAny(pkg, projectDir)
1717

1818
if err != nil {
1919
return err
@@ -46,7 +46,7 @@ func PrintReadme(
4646
}
4747

4848
if showSourceEnv {
49-
err = printSourceEnvMessage(pkg, rootDir, w)
49+
err = printSourceEnvMessage(pkg, projectDir, w)
5050
}
5151
return err
5252
}
@@ -132,8 +132,8 @@ func printInfoInstructions(pkg string, w io.Writer) error {
132132
return errors.WithStack(err)
133133
}
134134

135-
func printSourceEnvMessage(pkg, rootDir string, w io.Writer) error {
136-
env, err := Env([]string{pkg}, rootDir)
135+
func printSourceEnvMessage(pkg, projectDir string, w io.Writer) error {
136+
env, err := Env([]string{pkg}, projectDir)
137137
if err != nil {
138138
return err
139139
}

internal/plugin/pkgcfg.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type config struct {
3838
} `json:"shell,omitempty"`
3939
}
4040

41-
func (m *Manager) CreateFilesAndShowReadme(pkg, rootDir string) error {
42-
cfg, err := getConfigIfAny(pkg, rootDir)
41+
func (m *Manager) CreateFilesAndShowReadme(pkg, projectDir string) error {
42+
cfg, err := getConfigIfAny(pkg, projectDir)
4343
if err != nil {
4444
return err
4545
}
@@ -77,11 +77,11 @@ func (m *Manager) CreateFilesAndShowReadme(pkg, rootDir string) error {
7777
}
7878
var buf bytes.Buffer
7979
if err = t.Execute(&buf, map[string]string{
80-
"DevboxConfigDir": rootDir,
81-
"DevboxDir": filepath.Join(rootDir, devboxDirName, pkg),
82-
"DevboxDirRoot": filepath.Join(rootDir, devboxDirName),
83-
"DevboxProfileDefault": filepath.Join(rootDir, nix.ProfilePath),
84-
"Virtenv": filepath.Join(rootDir, devboxHiddenDirName, "virtenv", pkg),
80+
"DevboxConfigDir": projectDir,
81+
"DevboxDir": filepath.Join(projectDir, devboxDirName, pkg),
82+
"DevboxDirRoot": filepath.Join(projectDir, devboxDirName),
83+
"DevboxProfileDefault": filepath.Join(projectDir, nix.ProfilePath),
84+
"Virtenv": filepath.Join(projectDir, devboxHiddenDirName, "virtenv", pkg),
8585
}); err != nil {
8686
return errors.WithStack(err)
8787
}
@@ -94,19 +94,19 @@ func (m *Manager) CreateFilesAndShowReadme(pkg, rootDir string) error {
9494
return errors.WithStack(err)
9595
}
9696
if fileMode == 0755 {
97-
if err := createSymlink(rootDir, filePath); err != nil {
97+
if err := createSymlink(projectDir, filePath); err != nil {
9898
return err
9999
}
100100
}
101101
}
102-
return createEnvFile(pkg, rootDir)
102+
return createEnvFile(pkg, projectDir)
103103

104104
}
105105

106-
func Env(pkgs []string, rootDir string) (map[string]string, error) {
106+
func Env(pkgs []string, projectDir string) (map[string]string, error) {
107107
env := map[string]string{}
108108
for _, pkg := range pkgs {
109-
cfg, err := getConfigIfAny(pkg, rootDir)
109+
cfg, err := getConfigIfAny(pkg, projectDir)
110110
if err != nil {
111111
return nil, err
112112
}
@@ -120,8 +120,8 @@ func Env(pkgs []string, rootDir string) (map[string]string, error) {
120120
return env, nil
121121
}
122122

123-
func createEnvFile(pkg, rootDir string) error {
124-
envVars, err := Env([]string{pkg}, rootDir)
123+
func createEnvFile(pkg, projectDir string) error {
124+
envVars, err := Env([]string{pkg}, projectDir)
125125
if err != nil {
126126
return err
127127
}
@@ -133,7 +133,7 @@ func createEnvFile(pkg, rootDir string) error {
133133
}
134134
env += fmt.Sprintf("export %s=%s\n", k, escaped)
135135
}
136-
filePath := filepath.Join(rootDir, VirtenvPath, pkg, "/env")
136+
filePath := filepath.Join(projectDir, VirtenvPath, pkg, "/env")
137137
if err = createDir(filepath.Dir(filePath)); err != nil {
138138
return err
139139
}
@@ -143,19 +143,19 @@ func createEnvFile(pkg, rootDir string) error {
143143
return nil
144144
}
145145

146-
func buildConfig(pkg, rootDir, content string) (*config, error) {
146+
func buildConfig(pkg, projectDir, content string) (*config, error) {
147147
cfg := &config{}
148148
t, err := template.New(pkg + "-template").Parse(content)
149149
if err != nil {
150150
return nil, errors.WithStack(err)
151151
}
152152
var buf bytes.Buffer
153153
if err = t.Execute(&buf, map[string]string{
154-
"DevboxConfigDir": rootDir,
155-
"DevboxDir": filepath.Join(rootDir, devboxDirName, pkg),
156-
"DevboxDirRoot": filepath.Join(rootDir, devboxDirName),
157-
"DevboxProfileDefault": filepath.Join(rootDir, nix.ProfilePath),
158-
"Virtenv": filepath.Join(rootDir, devboxHiddenDirName, "virtenv", pkg),
154+
"DevboxProjectDir": projectDir,
155+
"DevboxDir": filepath.Join(projectDir, devboxDirName, pkg),
156+
"DevboxDirRoot": filepath.Join(projectDir, devboxDirName),
157+
"DevboxProfileDefault": filepath.Join(projectDir, nix.ProfilePath),
158+
"Virtenv": filepath.Join(projectDir, devboxHiddenDirName, "virtenv", pkg),
159159
}); err != nil {
160160
return nil, errors.WithStack(err)
161161
}

internal/plugin/rm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
"github.com/pkg/errors"
88
)
99

10-
func Remove(rootDir string, pkgs []string) error {
10+
func Remove(projectDir string, pkgs []string) error {
1111
for _, pkg := range pkgs {
12-
if err := os.RemoveAll(filepath.Join(rootDir, VirtenvPath, pkg)); err != nil {
12+
if err := os.RemoveAll(filepath.Join(projectDir, VirtenvPath, pkg)); err != nil {
1313
return errors.WithStack(err)
1414
}
1515
}
1616
return nil
1717
}
1818

19-
func RemoveInvalidSymlinks(rootDir string) error {
20-
binPath := filepath.Join(rootDir, VirtenvBinPath)
19+
func RemoveInvalidSymlinks(projectDir string) error {
20+
binPath := filepath.Join(projectDir, VirtenvBinPath)
2121
if _, err := os.Stat(binPath); errors.Is(err, os.ErrNotExist) {
2222
return nil
2323
}
@@ -26,9 +26,9 @@ func RemoveInvalidSymlinks(rootDir string) error {
2626
return errors.WithStack(err)
2727
}
2828
for _, entry := range dirEntry {
29-
_, err := os.Stat(filepath.Join(rootDir, VirtenvPath, "bin", entry.Name()))
29+
_, err := os.Stat(filepath.Join(projectDir, VirtenvPath, "bin", entry.Name()))
3030
if errors.Is(err, os.ErrNotExist) {
31-
os.Remove(filepath.Join(rootDir, VirtenvPath, "bin", entry.Name()))
31+
os.Remove(filepath.Join(projectDir, VirtenvPath, "bin", entry.Name()))
3232
}
3333
}
3434
return nil

internal/plugin/services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type service struct {
1717
Stop string `json:"stop"`
1818
}
1919

20-
func GetServices(pkgs []string, rootDir string) (Services, error) {
20+
func GetServices(pkgs []string, projectDir string) (Services, error) {
2121
services := map[string]service{}
2222
for _, pkg := range pkgs {
23-
c, err := getConfigIfAny(pkg, rootDir)
23+
c, err := getConfigIfAny(pkg, projectDir)
2424
if err != nil {
2525
return nil, err
2626
}

plugins/apacheHttpd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"readme": "If you with to edit the config file, please copy it out of the .devbox directory.",
55
"env": {
6-
"HTTPD_DEVBOX_CONFIG_DIR": "{{ .DevboxConfigDir }}",
6+
"HTTPD_DEVBOX_CONFIG_DIR": "{{ .DevboxProjectDir }}",
77
"HTTPD_CONFDIR": "{{ .DevboxDir }}",
88
"HTTPD_ERROR_LOG_FILE": "{{ .Virtenv }}/error.log",
99
"HTTPD_PORT": "8080"

0 commit comments

Comments
 (0)