mirror of
https://github.com/civitai/civitai.git
synced 2026-09-20 22:08:18 +08:00
15c1408d3d
`pnpm run db:check-generated` has been failing for anyone who ran it, with no change of their own. `scripts/prisma-enum-generator.mjs` wrote each type alias on one line and never formatted the result, while the committed `enums.ts` is prettier-wrapped at the repo's printWidth of 100. Generator output could therefore never equal the committed file, and `postinstall` runs `db:generate` — so every `pnpm install` left the file dirty and every run of the check gate went red. CI does not run that gate, which is why this survived; the only person who hits it is someone following "Before Committing" step 5. The generator now formats with the resolved prettier config before writing. That is scoped to the one file this generator owns rather than a prettier pass over `packages/civitai-db-schema/src`, because the neighbouring generated files are NOT prettier-clean — `models.ts` is emitted with double quotes against a `singleQuote: true` config and passes the check exactly as it is. Formatting the directory would reformat it wholesale for no reason. With the generator fixed, the ~90 lines of churn collapse to one real staleness: `CollectionItemRejectionReason` was committed as raw generator output in `1ad8ae3443` while every other alias in the file was wrapped. That line is now regenerated, and `db:check-generated` passes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
// @see https://gist.github.com/juliusmarminge/b06a3e421117a56ba1fea54e2a4c0fcb
|
|
|
|
import PrismaGenHelper from '@prisma/generator-helper';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import prettier from 'prettier';
|
|
|
|
const header = `// This file was generated by a custom prisma generator, do not edit manually.\n`;
|
|
|
|
PrismaGenHelper.generatorHandler({
|
|
onManifest() {
|
|
return {
|
|
defaultOutput: './enums/index.ts',
|
|
prettyName: 'Enum Objects',
|
|
};
|
|
},
|
|
async onGenerate(options) {
|
|
const enums = options.dmmf.datamodel.enums;
|
|
|
|
const output = enums.map((e) => {
|
|
let enumString = `export const ${e.name} = {\n`;
|
|
e.values.forEach(({ name: value }) => {
|
|
enumString += ` ${value}: '${value}',\n`;
|
|
});
|
|
enumString += `} as const;\n\n`;
|
|
enumString += `export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];\n`;
|
|
|
|
return enumString;
|
|
});
|
|
|
|
const outputFile = options.generator.output;
|
|
if (!outputFile || !outputFile.value) {
|
|
throw new Error('No output file specified');
|
|
}
|
|
|
|
const outputPath = path.resolve(outputFile.value);
|
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
|
|
// Formatted here, not left raw: the committed copy is prettier-wrapped, so a generator emitting
|
|
// unwrapped type aliases makes `db:check-generated` fail on a clean checkout and leaves the file
|
|
// dirty after every `pnpm install` (postinstall runs db:generate).
|
|
const prettierConfig = await prettier.resolveConfig(outputPath);
|
|
const source = prettier.format(header + output.join('\n'), {
|
|
...prettierConfig,
|
|
parser: 'typescript',
|
|
});
|
|
|
|
await fs.writeFile(outputPath, source, 'utf-8');
|
|
},
|
|
});
|