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 4 commits
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
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div align=center>

<div align=center>
![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)
</div>

`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.
Expand All @@ -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

Expand Down Expand Up @@ -70,4 +71,4 @@ Interactive terminal who?? Use all the options!

```npx
npx try-prisma -t orm/grpc -i pnpm -n my_project
```
```
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;
};
1 change: 1 addition & 0 deletions test/cli/input-collector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("Input Collector", () => {
folder: "orm",
path: ".",
anonymous: false,
databaseUrl: "",
vscode: false,
});
});
Expand Down
Loading