Skip to content

Commit 3faa2cf

Browse files
authored
fix: output path handling for prisma plugin (#194)
1 parent 88e4381 commit 3faa2cf

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/cli/src/plugins/prisma.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import path from 'node:path';
55
const plugin: CliPlugin = {
66
name: 'Prisma Schema Generator',
77
statusText: 'Generating Prisma schema',
8-
async generate({ model, defaultOutputPath, pluginOptions }) {
9-
let outDir = defaultOutputPath;
8+
async generate({ model, schemaFile, defaultOutputPath, pluginOptions }) {
9+
let outFile = path.join(defaultOutputPath, 'schema.prisma');
1010
if (typeof pluginOptions['output'] === 'string') {
11-
outDir = path.resolve(defaultOutputPath, pluginOptions['output']);
12-
if (!fs.existsSync(outDir)) {
13-
fs.mkdirSync(outDir, { recursive: true });
11+
outFile = path.resolve(path.dirname(schemaFile), pluginOptions['output']);
12+
if (!fs.existsSync(path.dirname(outFile))) {
13+
fs.mkdirSync(path.dirname(outFile), { recursive: true });
1414
}
1515
}
1616
const prismaSchema = await new PrismaSchemaGenerator(model).generate();
17-
fs.writeFileSync(path.join(outDir, 'schema.prisma'), prismaSchema);
17+
fs.writeFileSync(outFile, prismaSchema);
1818
},
1919
};
2020

packages/cli/test/plugins/prisma-plugin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ model User {
4747
const workDir = createProject(`
4848
plugin prisma {
4949
provider = '@core/prisma'
50-
output = './prisma'
50+
output = '../prisma/schema.prisma'
5151
}
5252
5353
model User {
5454
id String @id @default(cuid())
5555
}
5656
`);
5757
runCli('generate', workDir);
58-
expect(fs.existsSync(path.join(workDir, 'zenstack/prisma/schema.prisma'))).toBe(true);
58+
expect(fs.existsSync(path.join(workDir, 'prisma/schema.prisma'))).toBe(true);
5959
});
6060
});

0 commit comments

Comments
 (0)