@arianaprojects/prisma-nestjs-crud-generator
Version:
code generator from Prisma schema
88 lines • 3.85 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrismaGenerator = exports.GENERATOR_NAME = void 0;
const sdk_1 = require("@prisma/sdk");
const path = __importStar(require("path"));
const error_handler_1 = require("./error-handler");
const Model_1 = __importDefault(require("./components/Model"));
const templates_1 = require("./templates");
const util_1 = require("./util");
exports.GENERATOR_NAME = 'Prisma Code Generator';
class PrismaGenerator {
constructor(options) {
this.run = async () => {
let o = {
fullPath: this.options.generator.output.value || './gen',
configPath: this.options.generator.config['config'] || undefined,
};
let impFile = ["import { Module } from '@nestjs/common';"];
let impModule = [];
this.options.dmmf.datamodel.models.map((m) => {
const M = new Model_1.default(m, o);
M.postGenerate();
impFile.push((0, templates_1.importGenerator)('{' + M.namePascal + 'Module}', '"./' + M.nameCamel + '/' + M.nameCamel + '.module"'));
impModule.push(M.namePascal + 'Module');
});
(0, util_1.writeTSFile)(o.fullPath + `/GeneralModel.module.ts`, `
${impFile.join('\n')}
${(0, templates_1.moduleGenerator)('GeneralModelModule', impModule.join(','), '', '', '')}
`, false);
return;
};
if (options) {
this.options = options;
}
const output = (0, sdk_1.parseEnvValue)(options.generator.output);
}
get options() {
return this._options;
}
set options(value) {
this._options = value;
}
static getInstance(options) {
if (PrismaGenerator.instance) {
return PrismaGenerator.instance;
}
PrismaGenerator.instance = new PrismaGenerator(options);
return PrismaGenerator.instance;
}
getClientImportPath() {
if (!this.rootPath || !this.clientPath) {
throw new error_handler_1.GeneratorPathNotExists();
}
return path.relative(this.rootPath, this.clientPath).replace('node_modules/', '');
}
setPrismaClientPath() {
var _a;
const { otherGenerators, schemaPath } = this.options;
this.rootPath = schemaPath.replace('/prisma/schema.prisma', '');
const defaultPath = path.resolve(this.rootPath, 'node_modules/@prisma/client');
const clientGenerator = otherGenerators.find((g) => g.provider.value === 'prisma-client-js');
this.clientPath = (_a = clientGenerator === null || clientGenerator === void 0 ? void 0 : clientGenerator.output.value) !== null && _a !== void 0 ? _a : defaultPath;
}
}
exports.PrismaGenerator = PrismaGenerator;
//# sourceMappingURL=generator.js.map