Skip to content

Commit c48caba

Browse files
authored
Move to the directory of the created project (#75)
1 parent a61c547 commit c48caba

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

cmd/app/start.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ func runStart(cobraCmd *cobra.Command) error {
3030
return RunStartInDir(cobraCmd, "")
3131
}
3232

33-
// RunStartInDir runs pnpm install and pnpm dev in the specified directory.
33+
// RunStartInDir changes to the specified directory and runs pnpm install and pnpm dev.
3434
// If dir is empty, it uses the current directory.
3535
func RunStartInDir(cmd *cobra.Command, dir string) error {
36-
var absDir string
37-
var err error
36+
// Change to the target directory if specified
37+
if dir != "" {
38+
absDir, err := filepath.Abs(dir)
39+
if err != nil {
40+
return errors.WrapError("failed to get directory path", err)
41+
}
3842

39-
if dir == "" {
40-
absDir, err = os.Getwd()
41-
} else {
42-
absDir, err = filepath.Abs(dir)
43-
}
44-
if err != nil {
45-
return errors.WrapError("failed to get directory path", err)
43+
if err := os.Chdir(absDir); err != nil {
44+
return errors.WrapError("failed to change directory", err)
45+
}
46+
cmd.Printf("Changed to directory: %s\n", absDir)
4647
}
4748

4849
// Run pnpm install
4950
cmd.Println("Running pnpm install...")
5051
installCmd := exec.Command("pnpm", "install")
51-
installCmd.Dir = absDir
5252
installCmd.Stdout = os.Stdout
5353
installCmd.Stderr = os.Stderr
5454
installCmd.Stdin = os.Stdin
@@ -62,7 +62,6 @@ func RunStartInDir(cmd *cobra.Command, dir string) error {
6262
// Run pnpm dev
6363
cmd.Println("\nStarting development server...")
6464
devCmd := exec.Command("pnpm", "dev")
65-
devCmd.Dir = absDir
6665
devCmd.Stdout = os.Stdout
6766
devCmd.Stderr = os.Stderr
6867
devCmd.Stdin = os.Stdin

0 commit comments

Comments
 (0)