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;
|
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() {
|
function displayManualSetupInstructions() {
|
||||||
log.info(`Manual Neon PostgreSQL Setup Instructions:
|
log.info(`Manual Neon PostgreSQL Setup Instructions:
|
||||||
|
|
||||||
@@ -129,6 +159,31 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
|
|||||||
const { packageManager, projectDir } = config;
|
const { packageManager, projectDir } = config;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isCancel(setupMethod)) {
|
||||||
|
cancel(pc.red("Operation cancelled"));
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setupMethod === "neondb") {
|
||||||
|
await setupWithNeonDb(projectDir, packageManager);
|
||||||
|
} else {
|
||||||
const suggestedProjectName = path.basename(projectDir);
|
const suggestedProjectName = path.basename(projectDir);
|
||||||
const projectName = await text({
|
const projectName = await text({
|
||||||
message: "Enter a name for your Neon project:",
|
message: "Enter a name for your Neon project:",
|
||||||
@@ -147,13 +202,13 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = await createNeonProject(
|
const neonConfig = await createNeonProject(
|
||||||
projectName as string,
|
projectName as string,
|
||||||
regionId,
|
regionId,
|
||||||
packageManager,
|
packageManager,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!config) {
|
if (!neonConfig) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Failed to create project - couldn't get connection information",
|
"Failed to create project - couldn't get connection information",
|
||||||
);
|
);
|
||||||
@@ -163,9 +218,10 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
|
|||||||
finalSpinner.start("Configuring database connection");
|
finalSpinner.start("Configuring database connection");
|
||||||
|
|
||||||
await fs.ensureDir(path.join(projectDir, "apps/server"));
|
await fs.ensureDir(path.join(projectDir, "apps/server"));
|
||||||
await writeEnvFile(projectDir, config);
|
await writeEnvFile(projectDir, neonConfig);
|
||||||
|
|
||||||
finalSpinner.stop("Neon database configured!");
|
finalSpinner.stop("Neon database configured!");
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
consola.error(pc.red(error.message));
|
consola.error(pc.red(error.message));
|
||||||
|
|||||||
Reference in New Issue
Block a user