Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import path from 'node:path';
const plugin: CliPlugin = {
name: 'Prisma Schema Generator',
statusText: 'Generating Prisma schema',
async generate({ model, schemaFile, defaultOutputPath, pluginOptions }) {
async generate({ model, defaultOutputPath, pluginOptions }) {
let outFile = path.join(defaultOutputPath, 'schema.prisma');
if (typeof pluginOptions['output'] === 'string') {
outFile = path.resolve(path.dirname(schemaFile), pluginOptions['output']);
outFile = path.resolve(defaultOutputPath, pluginOptions['output']);
if (!fs.existsSync(path.dirname(outFile))) {
fs.mkdirSync(path.dirname(outFile), { recursive: true });
}
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/test/plugins/prisma-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,25 @@ model User {
runCli('generate', workDir);
expect(fs.existsSync(path.join(workDir, 'prisma/schema.prisma'))).toBe(true);
});

it('can generate a Prisma schema with custom output relative to zenstack.output', () => {
const workDir = createProject(`
plugin prisma {
provider = '@core/prisma'
output = './schema.prisma'
}

model User {
id String @id @default(cuid())
}
`);

const pkgJson = JSON.parse(fs.readFileSync(path.join(workDir, 'package.json'), 'utf8'));
pkgJson.zenstack = {
output: './relative',
};
fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
runCli('generate', workDir);
expect(fs.existsSync(path.join(workDir, 'relative/schema.prisma'))).toBe(true);
});
});
Loading