Skip to content
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

Improve-updater #397

Closed
wants to merge 14 commits into from
7 changes: 7 additions & 0 deletions cli/cmd/turbo/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"context"
"fmt"
"log"
"os"
"runtime/debug"
"strings"
Expand All @@ -12,6 +14,7 @@ import (
prune "turbo/internal/prune"
"turbo/internal/run"
uiPkg "turbo/internal/ui"
"turbo/internal/update"
"turbo/internal/util"

"github.com/fatih/color"
Expand Down Expand Up @@ -63,6 +66,7 @@ func main() {
ui.Error(fmt.Sprintf("%s %s", uiPkg.ERROR_PREFIX, color.RedString(err.Error())))
os.Exit(1)
}

c.HiddenCommands = []string{"graph"}
c.Commands = map[string]cli.CommandFactory{
"run": func() (cli.Command, error) {
Expand Down Expand Up @@ -164,5 +168,8 @@ func main() {
}
}
}()
if err := update.CheckVersion(context.Background(), cf, turboVersion); err != nil {
log.Fatal(err)
}
os.Exit(exitCode)
}
2 changes: 2 additions & 0 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ require (
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-hclog v0.16.2
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/hashicorp/go-version v1.3.0
github.com/karrick/godirwalk v1.16.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/text v0.2.0 // indirect
Expand Down
5 changes: 4 additions & 1 deletion cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs=
github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
Expand All @@ -51,6 +52,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs=
github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
Expand Down
4 changes: 4 additions & 0 deletions cli/internal/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ type LanguageBackend struct {
GetWorkspaceGlobs func() ([]string, error)
// Returns run command
GetRunCommand func() []string
// GetInstallCommand returns the install command
GetInstallCommand func() []string
// GetTurboInstallCommand returns the turbo install command
GetTurboInstallCommand func() []string
}
12 changes: 12 additions & 0 deletions cli/internal/backends/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var NodejsYarnBackend = api.LanguageBackend{
GetRunCommand: func() []string {
return []string{"yarn", "run"}
},
GetTurboInstallCommand: func() []string {
return []string{"yarn", "add", "turbo", "--dev", "-w"}
},
}

// PnpmWorkspaces is a representation of workspace package globs found
Expand Down Expand Up @@ -61,6 +64,12 @@ var NodejsPnpmBackend = api.LanguageBackend{
GetRunCommand: func() []string {
return []string{"pnpm", "run"}
},
GetInstallCommand: func() []string {
return []string{"pnpm", "install"}
},
GetTurboInstallCommand: func() []string {
return []string{"pnpm", "install", "turbo", "-D", "-w"}
},
}

var NodejsNpmBackend = api.LanguageBackend{
Expand All @@ -81,4 +90,7 @@ var NodejsNpmBackend = api.LanguageBackend{
GetRunCommand: func() []string {
return []string{"npm", "run"}
},
GetTurboInstallCommand: func() []string {
return []string{"npm", "install", "turbo", "-D", "-w"}
},
}
2 changes: 1 addition & 1 deletion cli/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config,
if err != nil {
// not logged in
}
partialConfig, err := ReadConfigFile(filepath.Join(".turbo", "config.json"))
partialConfig, err := ReadTurboConfigFile(filepath.Join(".turbo", "config.json"))
if err != nil {
// not linked
}
Expand Down
25 changes: 18 additions & 7 deletions cli/internal/config/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"

Expand All @@ -23,7 +24,7 @@ type TurborepoConfig struct {
}

// WriteUserConfigFile writes config file at a oath
func WriteConfigFile(path string, config *TurborepoConfig) error {
func WriteTurboConfigFile(path string, config *TurborepoConfig) error {
jsonBytes, marhsallError := json.Marshal(config)
if marhsallError != nil {
return marhsallError
Expand All @@ -37,15 +38,15 @@ func WriteConfigFile(path string, config *TurborepoConfig) error {

// WriteUserConfigFile writes a user config file
func WriteUserConfigFile(config *TurborepoConfig) error {
path, err := xdg.ConfigFile(filepath.Join("turborepo", "config.json"))
path, err := GetConfigFilePath("config.json")
if err != nil {
return err
}
return WriteConfigFile(path, config)
return WriteTurboConfigFile(path, config)
}

// ReadConfigFile reads a config file at a path
func ReadConfigFile(path string) (*TurborepoConfig, error) {
// ReadTurboConfigFile reads a config file at a path
func ReadTurboConfigFile(path string) (*TurborepoConfig, error) {
var config = &TurborepoConfig{
Token: "",
TeamId: "",
Expand All @@ -66,7 +67,7 @@ func ReadConfigFile(path string) (*TurborepoConfig, error) {

// ReadUserConfigFile reads a user config file
func ReadUserConfigFile() (*TurborepoConfig, error) {
path, err := xdg.ConfigFile(filepath.Join("turborepo", "config.json"))
path, err := GetConfigFilePath("config.json")
if err != nil {
return &TurborepoConfig{
Token: "",
Expand All @@ -76,10 +77,20 @@ func ReadUserConfigFile() (*TurborepoConfig, error) {
TeamSlug: "",
}, err
}
return ReadConfigFile(path)
return ReadTurboConfigFile(path)
}

// DeleteUserConfigFile deletes a user config file
func DeleteUserConfigFile() error {
return WriteUserConfigFile(&TurborepoConfig{})
}

// GetConfigFilePath is the path to the config file on the machine
func GetConfigFilePath(name string) (string, error) {
file, err := xdg.ConfigFile(filepath.Join("turborepo", name))
if err != nil {
return "", fmt.Errorf("cannot get configuration file %q: %s", name, err)
}

return file, nil
}
2 changes: 1 addition & 1 deletion cli/internal/login/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (c *LinkCommand) Run(args []string) int {
}
}
fs.EnsureDir(filepath.Join(".turbo", "config.json"))
fsErr := config.WriteConfigFile(filepath.Join(".turbo", "config.json"), &config.TurborepoConfig{
fsErr := config.WriteTurboConfigFile(filepath.Join(".turbo", "config.json"), &config.TurborepoConfig{
TeamId: chosenTeam.ID,
ApiUrl: c.Config.ApiUrl,
})
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/login/unlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Usage: turbo unlink

// Run executes tasks in the monorepo
func (c *UnlinkCommand) Run(args []string) int {
if err := config.WriteConfigFile(filepath.Join(".turbo", "config.json"), &config.TurborepoConfig{}); err != nil {
if err := config.WriteTurboConfigFile(filepath.Join(".turbo", "config.json"), &config.TurborepoConfig{}); err != nil {
c.logError(c.Config.Logger, "", fmt.Errorf("Could not unlink. Something went wrong: %w", err))
return 1
}
Expand Down
Loading