> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plato.ae/llms.txt
> Use this file to discover all available pages before exploring further.

# Build And Release

> Build, package, stress test, and release the PC printer driver.

# Build And Release

The current package is `@plato/pc-printer`.

## Scripts

| Script   | Command                                                                                        | Purpose                                                     |
| -------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| `clean`  | `node scripts/clean.js`                                                                        | Removes build artifacts, output, logs, zip, and `dump.rdb`. |
| `build`  | `esbuild src/index.ts src/scripts/*.ts --bundle --platform=node --target=node12 --outdir=dist` | Bundles runtime code.                                       |
| `start`  | `node dist/index.js`                                                                           | Starts the built driver.                                    |
| `pkg`    | `pkg dist/index.js -t node12-win-x64 -o output/plato-printer.exe --config package.json`        | Creates Windows executable.                                 |
| `bundle` | version bump, build, Redis prep, pkg, zip                                                      | Produces `plato-printer.zip`.                               |
| `stress` | `node scripts/stress-test.js`                                                                  | Runs mock-printer load test.                                |

## Build Locally

```sh theme={null}
pnpm --filter @plato/pc-printer clean
pnpm --filter @plato/pc-printer build
pnpm --filter @plato/pc-printer start
```

## Create Release Zip

```sh theme={null}
pnpm --filter @plato/pc-printer bundle
```

The bundle script:

1. Increments `src/version.ts`.
2. Builds the driver into `dist`.
3. Prepares the configured Windows Redis binary.
4. Builds `output/plato-printer.exe`.
5. Copies `config.json`.
6. Copies Caddy assets.
7. Copies certificates.
8. Copies `redis-binaries/<redis.version>`.
9. Creates `plato-printer.zip`.

## Release Contents

```txt theme={null}
plato-printer.exe
config.json
assets/
  caddy/
  certs/
redis-binaries/
```

## Versioning

`src/version.ts` contains:

```ts theme={null}
export const BUILD_VERSION = 66;
```

The build version is returned by `GET /health` and printed in the startup banner. Do not edit this file manually; `scripts/increment-version.js` updates it during `pnpm bundle`.

## Caddy Preparation

Caddy is pinned to `2.6.4`.

To download Caddy into `assets/caddy` before bundling:

```sh theme={null}
pnpm --filter @plato/pc-printer exec node scripts/download-caddy.js
```

If `assets/caddy/caddy.exe` exists, runtime setup can copy it instead of downloading Caddy on the customer machine.

## Redis Binary Preparation

`scripts/prepare-redis-binaries.js` reads `config.json` and downloads the configured Windows Redis release if missing.

The expected path is:

```txt theme={null}
redis-binaries/<version>/Redis-<version>-Windows-x64-msys2/redis-server.exe
```

## Stress Test

The stress test starts mock TCP printers and sends many `/print` requests.

```sh theme={null}
pnpm --filter @plato/pc-printer stress
```

Useful options:

```sh theme={null}
node scripts/stress-test.js \
  --host http://127.0.0.1:8080 \
  --printers 5 \
  --jobs 100 \
  --base-port 9200 \
  --poll-ms 500 \
  --timeout-ms 60000
```

The test passes when all target queues drain.

## Release Checklist

1. Confirm `config.json` is correct for the release.
2. Confirm Caddy assets exist if HTTPS should work offline.
3. Run `pnpm --filter @plato/pc-printer clean`.
4. Run `pnpm --filter @plato/pc-printer bundle`.
5. Run the executable from `output/`.
6. Check `GET /health`.
7. Run a real test print.
8. Verify `plato-printer.zip` contains the expected files.
