mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add neondb support (#308)
This commit is contained in:
5
.changeset/poor-loops-tan.md
Normal file
5
.changeset/poor-loops-tan.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
add neondb cli support
|
||||
@@ -114,6 +114,36 @@ async function writeEnvFile(projectDir: string, config?: NeonConfig) {
|
||||
return true;
|
||||
}
|
||||
|
||||
async function setupWithNeonDb(
|
||||
projectDir: string,
|
||||
packageManager: PackageManager,
|
||||
) {
|
||||
try {
|
||||
const s = spinner();
|
||||
s.start("Creating Neon database using neondb...");
|
||||
|
||||
const serverDir = path.join(projectDir, "apps/server");
|
||||
await fs.ensureDir(serverDir);
|
||||
|
||||
const packageCmd = getPackageExecutionCommand(
|
||||
packageManager,
|
||||
"neondb --yes",
|
||||
);
|
||||
|
||||
await execa(packageCmd, {
|
||||
shell: true,
|
||||
cwd: serverDir,
|
||||
});
|
||||
|
||||
s.stop(pc.green("Neon database created successfully!"));
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
consola.error(pc.red("Failed to create database with neondb"));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function displayManualSetupInstructions() {
|
||||
log.info(`Manual Neon PostgreSQL Setup Instructions:
|
||||
|
||||
@@ -129,43 +159,69 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
|
||||
const { packageManager, projectDir } = config;
|
||||
|
||||
try {
|
||||
const suggestedProjectName = path.basename(projectDir);
|
||||
const projectName = await text({
|
||||
message: "Enter a name for your Neon project:",
|
||||
defaultValue: suggestedProjectName,
|
||||
initialValue: suggestedProjectName,
|
||||
const setupMethod = await select({
|
||||
message: "Choose your Neon setup method:",
|
||||
options: [
|
||||
{
|
||||
label: "Quick setup with neondb",
|
||||
value: "neondb",
|
||||
hint: "fastest, no auth required",
|
||||
},
|
||||
{
|
||||
label: "Custom setup with neonctl",
|
||||
value: "neonctl",
|
||||
hint: "More control - choose project name and region",
|
||||
},
|
||||
],
|
||||
initialValue: "neondb",
|
||||
});
|
||||
|
||||
const regionId = await select({
|
||||
message: "Select a region for your Neon project:",
|
||||
options: NEON_REGIONS,
|
||||
initialValue: NEON_REGIONS[0].value,
|
||||
});
|
||||
|
||||
if (isCancel(projectName) || isCancel(regionId)) {
|
||||
if (isCancel(setupMethod)) {
|
||||
cancel(pc.red("Operation cancelled"));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const config = await createNeonProject(
|
||||
projectName as string,
|
||||
regionId,
|
||||
packageManager,
|
||||
);
|
||||
if (setupMethod === "neondb") {
|
||||
await setupWithNeonDb(projectDir, packageManager);
|
||||
} else {
|
||||
const suggestedProjectName = path.basename(projectDir);
|
||||
const projectName = await text({
|
||||
message: "Enter a name for your Neon project:",
|
||||
defaultValue: suggestedProjectName,
|
||||
initialValue: suggestedProjectName,
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
throw new Error(
|
||||
"Failed to create project - couldn't get connection information",
|
||||
const regionId = await select({
|
||||
message: "Select a region for your Neon project:",
|
||||
options: NEON_REGIONS,
|
||||
initialValue: NEON_REGIONS[0].value,
|
||||
});
|
||||
|
||||
if (isCancel(projectName) || isCancel(regionId)) {
|
||||
cancel(pc.red("Operation cancelled"));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const neonConfig = await createNeonProject(
|
||||
projectName as string,
|
||||
regionId,
|
||||
packageManager,
|
||||
);
|
||||
|
||||
if (!neonConfig) {
|
||||
throw new Error(
|
||||
"Failed to create project - couldn't get connection information",
|
||||
);
|
||||
}
|
||||
|
||||
const finalSpinner = spinner();
|
||||
finalSpinner.start("Configuring database connection");
|
||||
|
||||
await fs.ensureDir(path.join(projectDir, "apps/server"));
|
||||
await writeEnvFile(projectDir, neonConfig);
|
||||
|
||||
finalSpinner.stop("Neon database configured!");
|
||||
}
|
||||
|
||||
const finalSpinner = spinner();
|
||||
finalSpinner.start("Configuring database connection");
|
||||
|
||||
await fs.ensureDir(path.join(projectDir, "apps/server"));
|
||||
await writeEnvFile(projectDir, config);
|
||||
|
||||
finalSpinner.stop("Neon database configured!");
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
consola.error(pc.red(error.message));
|
||||
|
||||
Reference in New Issue
Block a user