Skip to content

Commit bd20392

Browse files
committed
[Fix] the supabase CLI init stucking issue
Signed-off-by: HSIU-CHI LIU (Tomlord) <aa123593465@gmail.com>
1 parent 1ce9885 commit bd20392

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

cmd/template/supabase/supabase.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,21 @@ func NewSupabaseManager(projectPath string, mode flags.SupabaseMode) *SupabaseMa
3838
func (sm *SupabaseManager) Init() error {
3939
cmd := exec.Command("supabase", "init")
4040
cmd.Dir = sm.ProjectPath
41-
cmd.Stdout = os.Stdout
42-
cmd.Stderr = os.Stderr
4341

4442
// Create a pipe to handle stdin for interactive prompts
4543
stdin, err := cmd.StdinPipe()
4644
if err != nil {
4745
return fmt.Errorf("failed to create stdin pipe: %w", err)
4846
}
47+
defer stdin.Close()
48+
49+
// Capture stdout to monitor for prompts
50+
stdout, err := cmd.StdoutPipe()
51+
if err != nil {
52+
return fmt.Errorf("failed to create stdout pipe: %w", err)
53+
}
54+
55+
cmd.Stderr = os.Stderr
4956

5057
fmt.Println("Initializing Supabase project...")
5158

@@ -54,14 +61,27 @@ func (sm *SupabaseManager) Init() error {
5461
return fmt.Errorf("failed to start Supabase init: %w", err)
5562
}
5663

57-
// Handle interactive prompts by sending 'N' (No) to both questions
58-
// This avoids generating IDE-specific settings that may not be needed
64+
// Handle interactive prompts by monitoring output and responding appropriately
5965
go func() {
60-
defer stdin.Close()
61-
// Send 'N' for "Generate VS Code settings for Deno? [y/N]"
62-
io.WriteString(stdin, "N\n")
63-
// Send 'N' for "Generate IntelliJ Settings for Deno? [y/N]"
64-
io.WriteString(stdin, "N\n")
66+
buffer := make([]byte, 1024)
67+
for {
68+
n, err := stdout.Read(buffer)
69+
if err != nil {
70+
break
71+
}
72+
73+
output := string(buffer[:n])
74+
fmt.Print(output) // Still show output to user
75+
76+
// Check for VS Code Deno prompt
77+
if strings.Contains(output, "Generate VS Code settings for Deno") {
78+
io.WriteString(stdin, "N\n")
79+
}
80+
// Check for IntelliJ Deno prompt
81+
if strings.Contains(output, "Generate IntelliJ Settings for Deno") {
82+
io.WriteString(stdin, "N\n")
83+
}
84+
}
6585
}()
6686

6787
// Wait for the command to complete

0 commit comments

Comments
 (0)