UNPKG

prisma-zod-generator

Version:

Prisma 2+ generator to emit Zod schemas from your Prisma schema

111 lines 4.12 kB
#! /usr/bin/env node "use strict"; /** * PZG Pro Generator * * A Prisma generator for PZG Pro features that works like the main prisma-zod-generator. * This generator: * 1. Uses Prisma's generatorHandler to receive DMMF data from Prisma * 2. Gets DMMF once and passes it to all pro features efficiently * 3. Supports all pro features: policies, server-actions, sdk, contracts, etc. * * Usage in schema.prisma: * generator pzgPro { * provider = "node ./node_modules/prisma-zod-generator/lib/cli/pzg-pro.js" * output = "./generated/pro" * config = "./zod-generator.config.json" * } */ Object.defineProperty(exports, "__esModule", { value: true }); const generator_helper_1 = require("@prisma/generator-helper"); const pzg_pro_generator_1 = require("./pzg-pro-generator"); const args = process.argv.slice(2); const firstArg = args[0]; const wantsGlobalHelp = firstArg === '--help' || firstArg === '-h'; const isCliInvocation = require.main === module && ((args.length > 0 && !(firstArg === null || firstArg === void 0 ? void 0 : firstArg.startsWith('--'))) || wantsGlobalHelp); if (isCliInvocation) { const [command, ...rest] = args; if (!command || command === '--help' || command === '-h') { printCliUsage(); process.exit(0); } if (command !== 'guard') { console.error(`Unknown command "${command}". Run "pzg-pro guard --help" for usage.`); process.exit(1); } try { const { runDriftGuardCLI } = loadProCliExports(); runDriftGuardCLI(rest) .then(() => process.exit(0)) .catch((error) => { const detail = error instanceof Error ? error.message : String(error); console.error(`❌ Drift Guard failed: ${detail}`); if (error instanceof Error && error.stack) { console.error(error.stack); } process.exit(1); }); } catch (error) { const detail = error instanceof Error ? error.message : String(error); console.error(detail); process.exit(1); } } else { (0, generator_helper_1.generatorHandler)({ onManifest: () => ({ defaultOutput: './generated/pro', prettyName: 'PZG Pro Generator (requires Pro license)', }), onGenerate: pzg_pro_generator_1.generateProFeatures, }); } function printCliUsage() { console.log([ 'PZG Pro CLI', '', 'Usage:', ' npx pzg-pro guard [options] Run Drift Guard without Prisma invoking the generator', '', 'Examples:', ' npx pzg-pro guard --help', ' npx pzg-pro guard --schema ./prisma/schema.prisma --format json', '', 'To use PZG Pro as a Prisma generator, add it to your schema:', ' generator pzgPro {', ' provider = "node ./node_modules/prisma-zod-generator/lib/cli/pzg-pro.js"', ' }', ].join('\n')); } function loadProCliExports() { const modulePath = ['..', 'pro'].join('/'); try { // eslint-disable-next-line @typescript-eslint/no-require-imports const mod = require(modulePath); if (typeof mod.runDriftGuardCLI !== 'function') { throw new Error(`Missing runDriftGuardCLI export in ${modulePath}`); } return mod; } catch (error) { if (isMissingProModuleError(error, modulePath)) { throw new Error(pzg_pro_generator_1.PRO_HELP_MESSAGE); } throw error; } } function isMissingProModuleError(error, modulePath) { var _a; if (!(error instanceof Error)) { return false; } const nodeError = error; if (nodeError.code !== 'MODULE_NOT_FOUND') { return false; } const normalized = modulePath.replace(/\\/g, '/'); const message = (_a = nodeError.message) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, '/'); return (message === null || message === void 0 ? void 0 : message.includes('/pro/')) || (message === null || message === void 0 ? void 0 : message.includes(normalized)) || false; } //# sourceMappingURL=pzg-pro.js.map