From 4df43e8b008e72cc2498cdb92144d1d83b961d55 Mon Sep 17 00:00:00 2001 From: Sukairo-02 Date: Wed, 15 May 2024 17:22:27 +0300 Subject: [PATCH] Millionth attempt at getting prisma to run it from package --- package.json | 22 ++++------------------ scripts/build.ts | 37 ++++++++++++++++--------------------- src/index.ts | 6 ++++-- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 6425392..b03631b 100755 --- a/package.json +++ b/package.json @@ -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", @@ -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 diff --git a/scripts/build.ts b/scripts/build.ts index b25f645..039f980 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -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'); +})(); diff --git a/src/index.ts b/src/index.ts index 86991d2..485b219 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +#!/usr/bin/env node import { defaultPath, generatorName } from '@/globals'; import { GeneratorError, generatorHandler } from '@prisma/generator-helper'; import path from 'path'; @@ -5,7 +6,7 @@ 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, @@ -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.`, @@ -61,3 +61,5 @@ generatorHandler({ recursiveWrite(schemaPath, output); }, }); + +export default generator;