Skip to content

Commit

Permalink
Millionth attempt at getting prisma to run it from package
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukairo-02 committed May 15, 2024
1 parent 11722e3 commit 4df43e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
22 changes: 4 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"name": "drizzle-prisma-generator",
"type": "module",
"author": "Drizzle Team",
"version": "0.1.0",
"version": "0.1.1",
"description": "Generate Drizzle schema from Prisma schema",
"scripts": {
"run": "tsx src/index.ts",
"run": "pnpm run build && cd ../prisma-testbench && npx prisma generate dev && code ./src/db/schema.ts",
"build": "pnpm tsx scripts/build.ts",
"b": "pnpm build",
"pack": "(cd dist && npm pack --pack-destination ..) && rm -f package.tgz && mv *.tgz package.tgz",
"publish": "npm publish package.tgz",
"test": "vitest run",
"t": "pnpm run build && cd ../prisma-testbench && npx prisma generate dev && code ./src/db/schema.ts",
"lint": "dprint check --list-different"
},
"license": "Apache-2.0",
Expand Down Expand Up @@ -40,20 +38,8 @@
"ts",
"schema"
],
"exports": {
".": {
"import": {
"types": "./index.d.ts",
"default": "./index.js"
},
"require": {
"types": "./index.d.cjs",
"default": "./index.cjs"
},
"types": "./index.d.ts",
"default": "./index.js"
}
},
"bin": "./index.js",
"main": "./index.js",
"sideEffects": false,
"publishConfig": {
"provenance": true
Expand Down
37 changes: 16 additions & 21 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import 'zx/globals';

import { build } from 'tsup';
(async () => {
fs.removeSync('dist');

fs.removeSync('dist');

await build({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
dts: true,
format: ['cjs', 'esm'],
outExtension(ctx) {
if (ctx.format === 'cjs') {
await build({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
dts: true,
format: ['cjs'],
outExtension() {
return {
dts: '.d.cts',
js: '.cjs',
dts: '.d.ts',
js: '.js',
};
}
return {
dts: '.d.ts',
js: '.js',
};
},
});
},
});

fs.copyFileSync('package.json', 'dist/package.json');
fs.copyFileSync('README.md', 'dist/README.md');
fs.copyFileSync('package.json', 'dist/package.json');
fs.copyFileSync('README.md', 'dist/README.md');
})();
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node
import { defaultPath, generatorName } from '@/globals';
import { GeneratorError, generatorHandler } from '@prisma/generator-helper';
import path from 'path';
import { version } from '../package.json';
import { generateMySqlSchema, generatePgSchema, generateSQLiteSchema } from './util/generators';
import { recursiveWrite } from './util/recursive-write';

generatorHandler({
export const generator = generatorHandler({
onManifest() {
return {
version,
Expand Down Expand Up @@ -41,7 +42,6 @@ generatorHandler({
case undefined:
throw new GeneratorError('Unable to determine database type.\nMake sure datasource.provider is specified.');

case 'mongodb':
default:
throw new GeneratorError(
`Invalid database type for Drizzle schema generation: ${dbType}.\nSupported database types: PostgreSQL, MySQL, SQLite.`,
Expand All @@ -61,3 +61,5 @@ generatorHandler({
recursiveWrite(schemaPath, output);
},
});

export default generator;

0 comments on commit 4df43e8

Please sign in to comment.