-
Notifications
You must be signed in to change notification settings - Fork 5
Add dependecies.go to install packages
#46
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d3d84a8
feat: initial setup for "create" cmd in cli
archandatta cb1dde5
feat: add ts sample-app template
archandatta 966ea89
feat: add cli prompts
archandatta f93d77c
feat: add file copying function into new directory
archandatta ee4ac92
feat: add types
archandatta 078e7e9
feat: add types_test.go
archandatta fd452dd
fix: remove old files
archandatta 628b530
feat: add testing for create_test.go
archandatta 39f13c7
hide `create` command
archandatta 89aa20b
self review
archandatta d1376a1
review: refactor prompting to use pterm
archandatta 4db2ecd
review: add app name validation with flag
archandatta f54d0d4
review: update copy text
archandatta 261ead0
refactor: fix test and refactor structure
archandatta 3a20a69
feat: add python and ts templates
archandatta b5091a1
feat: add fetch templates logic
archandatta bd95ae9
feat: add template validation
archandatta 9a78824
enable py templates
archandatta 5570832
remove test
archandatta 35220b4
fix: update ts template readme
archandatta ed1d016
fix: update ts package.json to new pkg versions
archandatta 7dc6f47
fix: update py package.json to new pkg versions
archandatta b8dced4
fix: adding sorting for UX consistency && tests
archandatta 412069a
feat: add dependecy pkg for installations
archandatta f9d23ca
feat: add dependency installation tests
archandatta 31a7eb2
review: add installation step && update error message
archandatta ea70fee
review: update installation step
archandatta 4337c65
refactor: update dependencies
archandatta 2b33946
Merge branch 'main' into archand/install-dependencies
archandatta 2cc2438
Merge branch 'main' into archand/install-dependencies
archandatta 66d4e7b
review
archandatta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/onkernel/cli/pkg/create" | ||
| "github.com/pterm/pterm" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type CreateInput struct { | ||
| Name string | ||
| Language string | ||
| Template string | ||
| } | ||
|
|
||
| // CreateCmd is a cobra-independent command handler for create operations | ||
| type CreateCmd struct{} | ||
|
|
||
| // Create executes the creating a new Kernel app logic | ||
| func (c CreateCmd) Create(ctx context.Context, ci CreateInput) error { | ||
| appPath, err := filepath.Abs(ci.Name) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to resolve app path: %w", err) | ||
| } | ||
|
|
||
| // TODO: handle overwrite gracefully (prompt user) | ||
| // Check if directory already exists | ||
| if _, err := os.Stat(appPath); err == nil { | ||
| return fmt.Errorf("directory %s already exists", ci.Name) | ||
| } | ||
|
|
||
| if err := os.MkdirAll(appPath, 0755); err != nil { | ||
| return fmt.Errorf("failed to create directory: %w", err) | ||
| } | ||
|
|
||
| pterm.Println(fmt.Sprintf("\nCreating a new %s %s\n", ci.Language, ci.Template)) | ||
|
|
||
| spinner, _ := pterm.DefaultSpinner.Start("Copying template files...") | ||
|
|
||
| if err := create.CopyTemplateFiles(appPath, ci.Language, ci.Template); err != nil { | ||
| spinner.Fail("Failed to copy template files") | ||
| return fmt.Errorf("failed to copy template files: %w", err) | ||
| } | ||
|
|
||
| ok, _ := create.InstallDependencies(appPath, ci.Language) | ||
| if !ok { | ||
| pterm.Warning.Println("Failed to install dependencies. Please install them manually:") | ||
| switch ci.Language { | ||
| case create.LanguageTypeScript: | ||
| pterm.Println(fmt.Sprintf(" cd %s", ci.Name)) | ||
| pterm.Println(" npm install") | ||
| case create.LanguagePython: | ||
| pterm.Println(fmt.Sprintf(" cd %s", ci.Name)) | ||
| pterm.Println(" uv venv && source .venv/bin/activate && uv sync") | ||
| } | ||
| pterm.Println() | ||
| } else { | ||
| spinner.Success(fmt.Sprintf("✔ %s environment set up successfully", ci.Language)) | ||
archandatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| pterm.Success.Println("🎉 Kernel app created successfully!") | ||
| pterm.Println() | ||
|
|
||
| nextSteps := fmt.Sprintf(`Next steps: | ||
| brew install onkernel/tap/kernel | ||
| cd %s | ||
| kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY> | ||
| kernel deploy index.ts | ||
| kernel invoke ts-basic get-page-title --payload '{"url": "https://www.google.com"}' | ||
| `, ci.Name) | ||
|
|
||
| pterm.FgYellow.Println(nextSteps) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| var createCmd = &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Create a new application", | ||
| Long: "Commands for creating new Kernel applications", | ||
| RunE: runCreateApp, | ||
| } | ||
|
|
||
| func init() { | ||
| createCmd.Flags().StringP("name", "n", "", "Name of the application") | ||
| createCmd.Flags().StringP("language", "l", "", "Language of the application") | ||
| createCmd.Flags().StringP("template", "t", "", "Template to use for the application") | ||
| } | ||
|
|
||
| func runCreateApp(cmd *cobra.Command, args []string) error { | ||
| appName, _ := cmd.Flags().GetString("name") | ||
| language, _ := cmd.Flags().GetString("language") | ||
| template, _ := cmd.Flags().GetString("template") | ||
|
|
||
| appName, err := create.PromptForAppName(appName) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get app name: %w", err) | ||
| } | ||
|
|
||
| language, err = create.PromptForLanguage(language) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get language: %w", err) | ||
| } | ||
|
|
||
| template, err = create.PromptForTemplate(template, language) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get template: %w", err) | ||
| } | ||
|
|
||
| c := CreateCmd{} | ||
| return c.Create(cmd.Context(), CreateInput{ | ||
| Name: appName, | ||
| Language: language, | ||
| Template: template, | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.