# Prisma

Generate the Prisma client of every package with a Prisma schema, cached until the schema changes.

The Prisma plugin gives every package with a Prisma schema a `generate` task, so the client is generated once, cached, and ready before the tasks that need it.

## Add it

```sh
axle add prisma
```

This writes it into the root `axle.toml`:

```toml
[plugins.prisma]
source = "npm:@axle-rs/plugin-prisma@0.1.0"
hash = "sha256-…"
```

## Tasks

A package or project with `prisma/schema.prisma`, `schema.prisma`, a `prisma/schema` folder of `.prisma` files, or the schema its `package.json` names under `"prisma": { "schema": … }`, gets:

| Task       | Command           | Settings                                                                               |
| ---------- | ----------------- | -------------------------------------------------------------------------------------- |
| `generate` | `prisma generate` | `outputs` each generator's `output`, or `node_modules/.prisma/client` when none is set |

Each command runs through the repository's package manager, such as `pnpm exec prisma generate`, so it uses the version the package installs.

Each `output` is read from the schema and counts from the schema's folder, as in Prisma. When one points outside the repository, the plugin leaves `outputs` out. A task that needs the client, such as `build`, waits for it with `dependsOn = ["generate"]` in the package's `axle.toml`.

## Scripts the repository already has

A package's own script wins. When its `package.json` has a script with a task's name that runs something else, such as `"generate": "prisma generate --no-engine"`, the plugin leaves that task alone and Axle runs the script. A script that runs the same command is replaced by the plugin's task, which runs it and adds its settings. The repository's `axle.toml` changes a task as it would any other, and wins over the plugin.

## Settings

| Setting    | Default      | Meaning                                          |
| ---------- | ------------ | ------------------------------------------------ |
| `generate` | `"generate"` | the name of the task, or `false` to leave it out |

The plugin's answers are kept until a `.prisma` file, a `package.json`, `pnpm-workspace.yaml` or a lockfile changes.
