Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database URL option #60

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export default {
.default(false)
.describe("Should this invocation be recorded with Prisma's analytics?"),
"v vscode": z.boolean().default(false).describe("Are you using VSCode?"),
"d database-url": z.string().default("").describe("Provide a database URL to the template if desired."),
};
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env node
import fs from "node:fs"

import CLI from "./cli";
import download from "./helpers/download";
import installPackages from "./helpers/installPackages";
Expand Down Expand Up @@ -58,6 +60,16 @@ const main = async () => {
}
}

if (input.databaseUrl) {
fs.writeFileSync(`${input.path}/${input.name}/.env`, `DATABASE_URL="${input.databaseUrl}"\n`, { flag: "a" })
if (input.databaseUrl.startsWith("prisma://")) {
const queryParams = input.databaseUrl.split("?")[1]
const urlParams = new URLSearchParams(queryParams)
const apiKey = urlParams.get("api_key")
fs.writeFileSync(`${input.path}/${input.name}/.env`, `PULSE_API_KEY="${apiKey}"\n`, { flag: "a" })
}
}

if (input.vscode) {
await vscodeExtensionSuggestion(input);
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export type CliInput = {
vscode: boolean;
path: string;
folder: string;
databaseUrl: string;
};
Loading