@@ -114,6 +114,36 @@ async function writeEnvFile(projectDir: string, config?: NeonConfig) {
114
114
return true ;
115
115
}
116
116
117
+ async function setupWithNeonDb (
118
+ projectDir : string ,
119
+ packageManager : PackageManager ,
120
+ ) {
121
+ try {
122
+ const s = spinner ( ) ;
123
+ s . start ( "Creating Neon database using neondb..." ) ;
124
+
125
+ const serverDir = path . join ( projectDir , "apps/server" ) ;
126
+ await fs . ensureDir ( serverDir ) ;
127
+
128
+ const packageCmd = getPackageExecutionCommand (
129
+ packageManager ,
130
+ "neondb --yes" ,
131
+ ) ;
132
+
133
+ await execa ( packageCmd , {
134
+ shell : true ,
135
+ cwd : serverDir ,
136
+ } ) ;
137
+
138
+ s . stop ( pc . green ( "Neon database created successfully!" ) ) ;
139
+
140
+ return true ;
141
+ } catch ( error ) {
142
+ consola . error ( pc . red ( "Failed to create database with neondb" ) ) ;
143
+ throw error ;
144
+ }
145
+ }
146
+
117
147
function displayManualSetupInstructions ( ) {
118
148
log . info ( `Manual Neon PostgreSQL Setup Instructions:
119
149
@@ -129,43 +159,69 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
129
159
const { packageManager, projectDir } = config ;
130
160
131
161
try {
132
- const suggestedProjectName = path . basename ( projectDir ) ;
133
- const projectName = await text ( {
134
- message : "Enter a name for your Neon project:" ,
135
- defaultValue : suggestedProjectName ,
136
- initialValue : suggestedProjectName ,
137
- } ) ;
138
-
139
- const regionId = await select ( {
140
- message : "Select a region for your Neon project:" ,
141
- options : NEON_REGIONS ,
142
- initialValue : NEON_REGIONS [ 0 ] . value ,
162
+ const setupMethod = await select ( {
163
+ message : "Choose your Neon setup method:" ,
164
+ options : [
165
+ {
166
+ label : "Quick setup with neondb" ,
167
+ value : "neondb" ,
168
+ hint : "fastest, no auth required" ,
169
+ } ,
170
+ {
171
+ label : "Custom setup with neonctl" ,
172
+ value : "neonctl" ,
173
+ hint : "More control - choose project name and region" ,
174
+ } ,
175
+ ] ,
176
+ initialValue : "neondb" ,
143
177
} ) ;
144
178
145
- if ( isCancel ( projectName ) || isCancel ( regionId ) ) {
179
+ if ( isCancel ( setupMethod ) ) {
146
180
cancel ( pc . red ( "Operation cancelled" ) ) ;
147
181
process . exit ( 0 ) ;
148
182
}
149
183
150
- const config = await createNeonProject (
151
- projectName as string ,
152
- regionId ,
153
- packageManager ,
154
- ) ;
155
-
156
- if ( ! config ) {
157
- throw new Error (
158
- "Failed to create project - couldn't get connection information" ,
184
+ if ( setupMethod === "neondb" ) {
185
+ await setupWithNeonDb ( projectDir , packageManager ) ;
186
+ } else {
187
+ const suggestedProjectName = path . basename ( projectDir ) ;
188
+ const projectName = await text ( {
189
+ message : "Enter a name for your Neon project:" ,
190
+ defaultValue : suggestedProjectName ,
191
+ initialValue : suggestedProjectName ,
192
+ } ) ;
193
+
194
+ const regionId = await select ( {
195
+ message : "Select a region for your Neon project:" ,
196
+ options : NEON_REGIONS ,
197
+ initialValue : NEON_REGIONS [ 0 ] . value ,
198
+ } ) ;
199
+
200
+ if ( isCancel ( projectName ) || isCancel ( regionId ) ) {
201
+ cancel ( pc . red ( "Operation cancelled" ) ) ;
202
+ process . exit ( 0 ) ;
203
+ }
204
+
205
+ const neonConfig = await createNeonProject (
206
+ projectName as string ,
207
+ regionId ,
208
+ packageManager ,
159
209
) ;
160
- }
161
210
162
- const finalSpinner = spinner ( ) ;
163
- finalSpinner . start ( "Configuring database connection" ) ;
211
+ if ( ! neonConfig ) {
212
+ throw new Error (
213
+ "Failed to create project - couldn't get connection information" ,
214
+ ) ;
215
+ }
216
+
217
+ const finalSpinner = spinner ( ) ;
218
+ finalSpinner . start ( "Configuring database connection" ) ;
164
219
165
- await fs . ensureDir ( path . join ( projectDir , "apps/server" ) ) ;
166
- await writeEnvFile ( projectDir , config ) ;
220
+ await fs . ensureDir ( path . join ( projectDir , "apps/server" ) ) ;
221
+ await writeEnvFile ( projectDir , neonConfig ) ;
167
222
168
- finalSpinner . stop ( "Neon database configured!" ) ;
223
+ finalSpinner . stop ( "Neon database configured!" ) ;
224
+ }
169
225
} catch ( error ) {
170
226
if ( error instanceof Error ) {
171
227
consola . error ( pc . red ( error . message ) ) ;
0 commit comments