From a9ae19c71e2f252a1e6471b3c343e86059792b81 Mon Sep 17 00:00:00 2001
From: Jon Harrell <4829245+jharrell@users.noreply.github.com>
Date: Mon, 28 Oct 2024 08:44:24 -0500
Subject: [PATCH 1/4] add databaseUrl command line option
---
src/cli/parameters.ts | 1 +
src/index.ts | 12 ++++++++++++
src/types.ts | 1 +
3 files changed, 14 insertions(+)
diff --git a/src/cli/parameters.ts b/src/cli/parameters.ts
index 1834af3..59ba8c3 100644
--- a/src/cli/parameters.ts
+++ b/src/cli/parameters.ts
@@ -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."),
};
diff --git a/src/index.ts b/src/index.ts
index d871945..59ab831 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -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";
@@ -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);
}
diff --git a/src/types.ts b/src/types.ts
index 959202b..7149af7 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -7,4 +7,5 @@ export type CliInput = {
vscode: boolean;
path: string;
folder: string;
+ databaseUrl: string;
};
From f079e6a42b0d536969a91e90576b6b8c2e051518 Mon Sep 17 00:00:00 2001
From: Jon Harrell <4829245+jharrell@users.noreply.github.com>
Date: Mon, 28 Oct 2024 09:02:22 -0500
Subject: [PATCH 2/4] fix test
---
test/cli/input-collector.test.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/cli/input-collector.test.ts b/test/cli/input-collector.test.ts
index d6b1982..484c4d8 100644
--- a/test/cli/input-collector.test.ts
+++ b/test/cli/input-collector.test.ts
@@ -50,6 +50,7 @@ describe("Input Collector", () => {
folder: "orm",
path: ".",
anonymous: false,
+ databaseUrl: "",
vscode: false,
});
});
From 68ed616d1354600c7ed52799a1c567920f9a2090 Mon Sep 17 00:00:00 2001
From: Jon Harrell <4829245+jharrell@users.noreply.github.com>
Date: Mon, 28 Oct 2024 09:20:23 -0500
Subject: [PATCH 3/4] update readme
---
README.md | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index f47ad33..310507f 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
+
-
+![readme-try-prisma](https://user-images.githubusercontent.com/18456526/202004157-e7c97399-1669-4d80-899c-537e09758214.png)
+
+[![Tests](https://github.com/prisma/try-prisma/actions/workflows/test.yml/badge.svg)](https://github.com/prisma/try-prisma/actions/workflows/test.yml)
+[![Linting](https://github.com/prisma/try-prisma/actions/workflows/lint.yml/badge.svg)](https://github.com/prisma/try-prisma/actions/workflows/lint.yml)
- ![readme-try-prisma](https://user-images.githubusercontent.com/18456526/202004157-e7c97399-1669-4d80-899c-537e09758214.png)
-
- [![Tests](https://github.com/prisma/try-prisma/actions/workflows/test.yml/badge.svg)](https://github.com/prisma/try-prisma/actions/workflows/test.yml)
- [![Linting](https://github.com/prisma/try-prisma/actions/workflows/lint.yml/badge.svg)](https://github.com/prisma/try-prisma/actions/workflows/lint.yml)
`try-prisma` is a CLI tool that helps you easily get up and running with any project from the [`prisma/prisma-examples`](https://github.com/prisma/prisma-examples) repository.
@@ -29,12 +29,13 @@ You can _optionally_ provide arguments to the `npx try-prisma` command as an alt
The options are as follows:
-| Option | Alias | Arguments | Default | Description |
-| :----------: | :---: | :------------------: | :-------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `--install` | -i | Boolean | String _(optional)_ | `false` | Specifies if you would like to install npm packages automatically after creating the project. You can also specify which package manager to use: `npm`, `yarn`, or `pnpm` |
-| `--name` | -n | | Name of the selected template | Defines the name of the resulting directory. |
-| `--template` | -t | | n/a | Specifies which example project you would like to start off with. |
-| `--vscode` | -v | Boolean _(optional)_ | `false` | Adds a `.vscode` folder with an `extensions.json` file suggesting the [Prisma VS Code extension](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma). |
+| Option | Alias | Arguments | Default | Description |
+| :--------------: | :---: | :------------------: | :---------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `--install` | -i | Boolean | `false` | | Specifies if you would like to install npm packages automatically after creating the project. You can also specify which package manager to use: `npm`, `yarn`, or `pnpm` |
+| `--name` | -n | | Name of the selected template | Defines the name of the resulting directory. |
+| `--template` | -t | | n/a | Specifies which example project you would like to start off with. |
+| `--database-url` | -d | | n/a | Specifies the database URL you would like to use for the project. |
+| `--vscode` | -v | Boolean _(optional)_ | `false` | Adds a `.vscode` folder with an `extensions.json` file suggesting the [Prisma VS Code extension](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma). |
## Examples
@@ -70,4 +71,4 @@ Interactive terminal who?? Use all the options!
```npx
npx try-prisma -t orm/grpc -i pnpm -n my_project
-```
\ No newline at end of file
+```
From bd19d125dc80af1993c0ecba1d224a90ad2f1657 Mon Sep 17 00:00:00 2001
From: Jon Harrell <4829245+jharrell@users.noreply.github.com>
Date: Mon, 28 Oct 2024 09:23:04 -0500
Subject: [PATCH 4/4] don't forget version bump
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index f22a2cd..66a5a2d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "try-prisma",
- "version": "1.0.56",
+ "version": "1.0.57",
"description": "A CLI tool to help get you up and running with any Prisma example project.",
"type": "module",
"exports": "./dist/index.js",