UNPKG

create-prisma-generator

Version:
56 lines 2.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.replacePlaceholders = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const replacePlaceholders = (answers, pkgName) => { let filesContainingPkgName = [ './README.md', './packages/generator/package.json', './packages/generator/README.md', './packages/generator/src/constants.js', './packages/generator/src/constants.ts', './packages/usage/package.json', './packages/usage/prisma/schema.prisma', './package.json', './README.md', './src/constants.ts', './src/constants.js', ]; filesContainingPkgName.forEach((filePath) => { const fullPath = path_1.default.join(process.cwd(), pkgName, filePath); if (!fs_1.default.existsSync(fullPath)) { filesContainingPkgName = filesContainingPkgName.filter((e) => e != fullPath); return; } const file = fs_1.default.readFileSync(fullPath, { encoding: 'utf-8' }); fs_1.default.writeFileSync(fullPath, file.replace(/\$PACKAGE_NAME/g, pkgName.toLowerCase())); }); const packageJSONPath = path_1.default.join(process.cwd(), pkgName, './packages/usage/package.json'); const packageJSONFileExists = fs_1.default.existsSync(packageJSONPath); if (packageJSONFileExists) { const packageJSONFile = fs_1.default.readFileSync(packageJSONPath, { encoding: 'utf-8', }); const packageVersion = answers.packageManager === 'yarn' || answers.packageManager === 'npm' ? '1.0.0' : 'workspace:*'; fs_1.default.writeFileSync(packageJSONPath, packageJSONFile.replace(/\$PACKAGE_VERSION/g, packageVersion)); } const prismaSchemaPath = path_1.default.join(process.cwd(), pkgName, './packages/usage/prisma/schema.prisma'); const prismaSchemaFileExists = fs_1.default.existsSync(prismaSchemaPath); if (prismaSchemaFileExists) { const prismaSchemaFile = fs_1.default.readFileSync(prismaSchemaPath, { encoding: 'utf-8', }); const prismaProvider = answers.packageManager === 'yarn' || answers.packageManager === 'npm' ? `node ../../node_modules/${pkgName}` : `npx ${pkgName}`; fs_1.default.writeFileSync(prismaSchemaPath, prismaSchemaFile.replace(/\$CUSTOM_GENERATOR_PROVIDER/g, prismaProvider)); } }; exports.replacePlaceholders = replacePlaceholders; //# sourceMappingURL=replacePlaceholders.js.map