Skip to content

[RFC] Allow tyson config #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions devbox.tson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import otherConfig from './devbox.json'

otherConfig.shell.scripts["tyson-script"] = "echo hello TySON world"

export default {
...otherConfig
}
5 changes: 4 additions & 1 deletion internal/devconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"go.jetpack.io/devbox/internal/impl/shellcmd"
)

const DefaultName = "devbox.json"
const (
DefaultName = "devbox.json"
DefaultTySONName = "devbox.tson"
)

// Config defines a devbox environment as JSON.
type Config struct {
Expand Down
28 changes: 28 additions & 0 deletions internal/devconfig/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
package devconfig

import (
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/fatih/color"

"go.jetpack.io/devbox/internal/devpkg/pkgtype"
"go.jetpack.io/devbox/internal/initrec"
)

Expand Down Expand Up @@ -62,3 +65,28 @@ func initConfigFile(path string) (created bool, err error) {
}
return true, nil
}

func Open(projectDir string) (*Config, error) {
cfgPath := filepath.Join(projectDir, DefaultName)

if _, err := os.Stat(filepath.Join(projectDir, DefaultTySONName)); err == nil {
paths, err := pkgtype.RunXClient().Install(context.TODO(), "jetpack-io/tyson")
if err != nil {
return nil, err
}
binPath := filepath.Join(paths[0], "tyson")
tmpFile, err := os.CreateTemp("", "*.json")
if err != nil {
return nil, err
}
cmd := exec.Command(binPath, "eval", filepath.Join(projectDir, DefaultTySONName))
cmd.Stderr = os.Stderr
cmd.Stdout = tmpFile
if err = cmd.Run(); err != nil {
return nil, err
}
cfgPath = tmpFile.Name()
}

return Load(cfgPath)
}
3 changes: 1 addition & 2 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ func Open(opts *devopt.Opts) (*Devbox, error) {
if err != nil {
return nil, err
}
cfgPath := filepath.Join(projectDir, devconfig.DefaultName)

cfg, err := devconfig.Load(cfgPath)
cfg, err := devconfig.Open(projectDir)
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down