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

# gato generate

> Regenerate the GatoJS module registry, the locales file and the wa:* regions from .wa/kit.json; when to run it, what it writes and its errors.

```bash theme={null}
gato generate
```

`gato generate` rewrites the files that connect modules to the core: the module registry, the list of locales and the `wa:*` regions in shared files such as the Prisma schema, `.env.example` and `docker-compose.yml`. It reads [`.wa/kit.json`](https://docs.gatojs.com/cli/kit-json) and the feature directories on disk. It takes no options; extra arguments are ignored. How the registry is used at runtime is explained in [Module registry](https://docs.gatojs.com/concepts/module-registry.md).

```bash theme={null}
npx gato generate
npm run wa -- generate
```

`gato create`, `gato add`, `gato remove` and `gato update` (without conflicts) run it themselves at the end.

## When to run it

Run it, and commit the result together with the change that triggered it, after you:

* change `.wa/kit.json`, including `locales` and entries in `projectModules`;
* add or remove `module.ts`, `env.ts`, `auth.ts`, `auth-client.ts`, `audit-sink.ts` or `i18n/<locale>.json` in a feature;
* add, remove or rename a feature directory;
* change the content of a file a manifest points to in `compose` or `ciSteps`;
* resolve the conflicts of a [`gato update`](https://docs.gatojs.com/cli/update);
* in the kit repository, run `gato kit sync`.

## Output

`Bez zmian` ("no changes"), or one line `zmieniono <file>` ("changed") per written file. A second run without changes prints `Bez zmian` and touches nothing, which is what the CI check relies on.

## What it writes

The generator computes every file first and writes only at the end, so an error at any stage stops it before any file changes. It writes only files whose content differs.

| File | Contents |
| - | - |
| `src/modules.generated.ts` | Server registry: `modules`, `moduleEnvSchemas`, `authPlugins`, `auditSinks`, `env`, `moduleMessages` |
| `src/modules.client.generated.ts` | Client registry: `clientModules`, `authClientPlugins` |
| `src/i18n/locales.generated.ts` | The locales from `.wa/kit.json` |
| `wa:relations` in `prisma/schema/auth.prisma` | Back-relations on `User` from `schemaRelations` |
| `wa:relations` in `prisma/schema/organizations.prisma` | Back-relations on `Organization` from `schemaRelations` |
| `wa:modules` in `.env.example` | A `# <module>` header and `NAME=example` lines for every module except `core` with `env` entries |
| `wa:services` in `docker-compose.yml` | The content of each module's `compose` file, indented under `services:` |
| `wa:ci-integration` in `.github/workflows/ci.yml` and `.github/workflows/mutation.yml` | The content of each module's `ciSteps` file, as steps before the integration tests |
| `wa:workspaces` in `Dockerfile` | A `COPY packages/<name>/package.json …` line for every `packages/<name>` directory with a `package.json` |

The three generated files start with a header telling you not to edit them by hand. Regions have no header: the generator replaces everything between the `wa:<marker>:start` and `wa:<marker>:end` lines and keeps the marker lines.

In `env` examples, `{{projectSlug}}` and `{{projectName}}` are replaced with the values from `project` in `.wa/kit.json`, so the `uploads` bucket becomes `S3_BUCKET=<slug>-uploads`.

## How features are found

The generator walks the modules in registry order (`core`, the other kit modules by name, then project modules alphabetically) and their `files` patterns. A pattern that starts with `src/features/<name>/`, where `<name>` contains no `/` or `*`, makes `<name>` a candidate. A candidate is registered when its directory contains at least one of `module.ts`, `env.ts`, `auth.ts`, `auth-client.ts`, `audit-sink.ts` or `i18n/<locale>.json` for a configured locale. Otherwise it is skipped silently.

| Pattern in `files` | Result |
| - | - |
| `src/features/<name>/**` | Feature `<name>` |
| `src/features/<name>/module.ts` | Feature `<name>`; only the start of the pattern matters |
| `src/features/{a,b}/**` | Skipped: braces are not supported, use one pattern per feature |
| `src/features/**`, `src/features/*/module.ts` | Skipped: a wildcard right after `src/features/` |
| A pattern outside `src/features/` | Does not affect the registry |

A feature that no pattern covers gets no menu entry, `requireModuleAccess` with its key returns 404 and its translations do not load.

## Region rules

* A file must contain exactly one start line and one end line for a marker, with the end below the start. A region's content must not contain its own marker. If the file uses CRLF line endings anywhere, the whole result uses CRLF.
* A target file that does not exist is skipped.
* A target file without markers is skipped when the region would be empty. When some module has content for it, the generator stops with `<file>: brak regionu wa:<marker>; …` ("no region; add the start and end marker lines") and nothing changes.
* A missing file referenced by `compose` or `ciSteps` stops the generator with `ENOENT`, as long as the region's target file exists.
* Relations to models other than `User` and `Organization`, unknown manifest fields and `env[].required` are ignored without a warning. Review the region diff after running it.

## Checking it in CI

The project's CI runs the generator and fails if tracked files changed:

```yaml theme={null}
- name: Regenerate wa files
  run: npm run wa -- generate

- name: Generated files are up to date
  run: git diff --exit-code
```

A hand edit of a generated file or region, or a feature change committed without regenerating, fails this step. Run `npx gato generate` and commit. See [CI](https://docs.gatojs.com/deployment/ci.md).

## Errors

| Message | Meaning and fix |
| - | - |
| `Brak .wa/kit.json w <dir> — to nie jest projekt wa-kit` | No `.wa/kit.json`: run it in the project root. |
| A JSON parser error | `.wa/kit.json` is not valid JSON. |
| A list of Zod issues | `.wa/kit.json` does not match the schema, for example `locales musi zawierać "pl"` ("must contain pl") or `locales nie może zawierać duplikatów` ("no duplicates"). |
| `projectModules.<key>: name "<name>" nie zgadza się z kluczem` | A project module's `name` differs from its key. |
| `Moduł <x> jest jednocześnie modułem kitu i modułem projektu` | The same name in `modules` and `projectModules`. |
| `Moduł projektu <x> wymaga niezainstalowanego modułu: <y>` | A project module requires a module the project does not have. |
| `Moduł projektu <x>: files musi obejmować src/features/<x>/**` | A project module's `files` has no pattern for its feature directory. |
| `<file>: brak regionu wa:<marker>; dodaj linie ze znacznikami …` | The file has no markers but a module has content for the region. Add the marker lines. |
| `<file>: uszkodzony region wa:<marker>` | A missing, duplicated or reversed marker ("broken region"). |
| `<file>: treść regionu wa:<marker> zawiera znacznik regionu` | The region's content contains its own marker. |
| `ENOENT: no such file or directory, open '<path>'` | The file named in `compose` or `ciSteps` is missing. |

All of them exit with `1`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.