@@ -21,9 +21,23 @@ async function ensurePrismaClient() {
2121 if ( ! existsSync ( prismaClientPath ) ) {
2222 console . log ( '🔧 Prisma client not found. Generating...' ) ;
2323 try {
24- execSync ( 'npx prisma generate --schema=./src/core/infrastructure/db/schema.prisma' , {
24+ // 使用项目本地的 prisma CLI
25+ const prismaBin = process . platform === 'win32' ? 'prisma.cmd' : 'prisma' ;
26+ const prismaPath = join ( projectRoot , 'node_modules' , '.bin' , prismaBin ) ;
27+ const prismaCmd = existsSync ( prismaPath )
28+ ? `"${ prismaPath } "`
29+ : 'npx prisma' ;
30+
31+ // 设置临时的 DATABASE_URL,prisma generate 需要此变量存在
32+ // 实际的数据库路径在运行时由 db/index.ts 动态决定
33+ execSync ( `${ prismaCmd } generate --schema=./src/core/infrastructure/db/schema.prisma` , {
2534 cwd : projectRoot ,
26- stdio : 'inherit'
35+ stdio : 'inherit' ,
36+ shell : true ,
37+ env : {
38+ ...process . env ,
39+ DATABASE_URL : 'file:./placeholder.db'
40+ }
2741 } ) ;
2842 console . log ( '✅ Prisma client generated successfully.' ) ;
2943 } catch ( error ) {
@@ -33,14 +47,26 @@ async function ensurePrismaClient() {
3347 }
3448}
3549
50+ // 获取 Electron 可执行文件路径
51+ function getElectronPath ( ) {
52+ const require = createRequire ( import . meta. url ) ;
53+ try {
54+ // 使用 electron 包导出的路径(最可靠的方式)
55+ return require ( 'electron' ) ;
56+ } catch ( e ) {
57+ console . error ( '❌ Electron not found. Please ensure the package is installed correctly.' ) ;
58+ process . exit ( 1 ) ;
59+ }
60+ }
61+
3662// 启动 Electron
3763function launchElectron ( args ) {
38- const electronBin = process . platform === 'win32' ? 'electron.cmd' : 'electron' ;
39- const electronPath = join ( projectRoot , 'node_modules' , '.bin' , electronBin ) ;
64+ const electronPath = getElectronPath ( ) ;
4065 const mainPath = join ( projectRoot , 'dist' , 'main' , 'index.js' ) ;
4166
4267 if ( ! existsSync ( mainPath ) ) {
43- console . error ( '❌ Application not built. Please run: npm run build' ) ;
68+ console . error ( '❌ Application not built. Main file not found at:' , mainPath ) ;
69+ console . error ( ' Please run: npm run build' ) ;
4470 process . exit ( 1 ) ;
4571 }
4672
0 commit comments