-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdependencies.go
More file actions
106 lines (88 loc) · 3.01 KB
/
Copy pathdependencies.go
File metadata and controls
106 lines (88 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package create
import (
"fmt"
"os/exec"
"github.com/pterm/pterm"
)
// InstallDependencies sets up project dependencies based on language
func InstallDependencies(appPath string, ci CreateInput) (string, error) {
language := ci.Language
template := ci.Template
appName := ci.Name
installCommand, ok := InstallCommands[language]
if !ok {
return "", fmt.Errorf("unsupported language: %s", language)
}
requiredTool := RequiredTools[language]
if requiredTool != "" && !RequiredTools.CheckToolAvailable(language) {
return getNextStepsWithToolInstall(appName, language, requiredTool, template), nil
}
spinner, _ := pterm.DefaultSpinner.Start(pterm.Sprintf("Setting up %s environment...", language))
cmd := exec.Command("sh", "-c", installCommand)
cmd.Dir = appPath
if err := cmd.Run(); err != nil {
spinner.Stop()
pterm.Warning.Println("Failed to install dependencies. Please install them manually:")
switch language {
case LanguageTypeScript:
pterm.Printfln(" cd %s", appName)
pterm.Printfln(" pnpm install")
case LanguagePython:
pterm.Printfln(" cd %s", appName)
pterm.Println(" uv venv && source .venv/bin/activate && uv sync")
}
pterm.Println()
return getNextStepsStandard(appName, language, template), nil
}
spinner.Success(pterm.Sprintf("✔ %s environment set up successfully", language))
return getNextStepsStandard(appName, language, template), nil
}
// getNextStepsWithToolInstall returns next steps message including tool installation
func getNextStepsWithToolInstall(appName string, language string, requiredTool string, template string) string {
deployCommand := GetDeployCommand(language, template)
invokeCommand := GetInvokeSample(language, template)
pterm.Warning.Printfln(" %s is not installed or not in PATH", requiredTool)
switch language {
case LanguageTypeScript:
return pterm.FgYellow.Sprintf(`Next steps:
# Install pnpm (choose one):
npm install -g pnpm
# or: brew install pnpm
# or: curl -fsSL https://get.pnpm.io/install.sh | sh -
# Then install dependencies:
cd %s
pnpm install
# Deploy your app:
kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY>
%s
%s
`, appName, deployCommand, invokeCommand)
case LanguagePython:
return pterm.FgYellow.Sprintf(`Next steps:
# Install uv (choose one):
curl -LsSf https://astral.sh/uv/install.sh | sh
# or: brew install uv
# or: pipx install uv
# Then set up your environment:
cd %s
uv venv && source .venv/bin/activate && uv sync
# Deploy your app:
kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY>
%s
%s
`, appName, deployCommand, invokeCommand)
default:
return ""
}
}
// getNextStepsStandard returns standard next steps message
func getNextStepsStandard(appName string, language string, template string) string {
deployCommand := GetDeployCommand(language, template)
invokeCommand := GetInvokeSample(language, template)
return pterm.FgYellow.Sprintf(`Next steps:
cd %s
kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY>
%s
%s
`, appName, deployCommand, invokeCommand)
}