Skip to content

Commit

Permalink
Merge pull request #60 from prisma/database-url-option
Browse files Browse the repository at this point in the history
database URL option
  • Loading branch information
jharrell authored Oct 28, 2024
2 parents 44b9454 + bd19d12 commit ce01168
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
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
```
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
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

0 comments on commit ce01168

Please sign in to comment.