markpdfdown 0.1.3-t → 0.1.3-tfour

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +46 -2
  2. package/package.json +11 -3
package/bin/cli.js CHANGED
@@ -14,6 +14,40 @@ const __filename = fileURLToPath(import.meta.url);
14
14
  const __dirname = dirname(__filename);
15
15
  const projectRoot = join(__dirname, '..');
16
16
 
17
+ // 从 package.json 读取 electron 版本要求
18
+ function getElectronVersion() {
19
+ const require = createRequire(import.meta.url);
20
+ const pkg = require('../package.json');
21
+ // 优先从 dependencies 读取,其次从 devDependencies,最后使用默认值
22
+ return pkg.dependencies?.electron
23
+ || pkg.devDependencies?.electron
24
+ || pkg.peerDependencies?.electron
25
+ || '^35.0.0';
26
+ }
27
+
28
+ // 确保 Electron 已安装
29
+ async function ensureElectron() {
30
+ const electronBin = process.platform === 'win32' ? 'electron.cmd' : 'electron';
31
+ const electronPath = join(projectRoot, 'node_modules', '.bin', electronBin);
32
+
33
+ if (!existsSync(electronPath)) {
34
+ const electronVersion = getElectronVersion();
35
+ console.log(`📦 Electron not found. Installing electron@${electronVersion}...`);
36
+ try {
37
+ execSync(`npm install electron@"${electronVersion}" --no-save`, {
38
+ cwd: projectRoot,
39
+ stdio: 'inherit',
40
+ shell: true
41
+ });
42
+ console.log('✅ Electron installed successfully.');
43
+ } catch (error) {
44
+ console.error('❌ Failed to install Electron:', error.message);
45
+ console.error(' Please try manually: npm install electron');
46
+ process.exit(1);
47
+ }
48
+ }
49
+ }
50
+
17
51
  // 确保 Prisma client 存在
18
52
  async function ensurePrismaClient() {
19
53
  const prismaClientPath = join(projectRoot, 'node_modules', '.prisma', 'client', 'index.js');
@@ -21,11 +55,19 @@ async function ensurePrismaClient() {
21
55
  if (!existsSync(prismaClientPath)) {
22
56
  console.log('🔧 Prisma client not found. Generating...');
23
57
  try {
58
+ // 使用项目本地的 prisma CLI,避免使用用户系统上可能不兼容的全局版本
59
+ const prismaBin = process.platform === 'win32' ? 'prisma.cmd' : 'prisma';
60
+ const prismaPath = join(projectRoot, 'node_modules', '.bin', prismaBin);
61
+ const prismaCmd = existsSync(prismaPath)
62
+ ? `"${prismaPath}"`
63
+ : 'npx prisma'; // 回退到 npx
64
+
24
65
  // 设置临时的 DATABASE_URL,prisma generate 需要此变量存在
25
66
  // 实际的数据库路径在运行时由 db/index.ts 动态决定
26
- execSync('npx prisma generate --schema=./src/core/infrastructure/db/schema.prisma', {
67
+ execSync(`${prismaCmd} generate --schema=./src/core/infrastructure/db/schema.prisma`, {
27
68
  cwd: projectRoot,
28
69
  stdio: 'inherit',
70
+ shell: true,
29
71
  env: {
30
72
  ...process.env,
31
73
  DATABASE_URL: 'file:./placeholder.db'
@@ -46,7 +88,8 @@ function launchElectron(args) {
46
88
  const mainPath = join(projectRoot, 'dist', 'main', 'index.js');
47
89
 
48
90
  if (!existsSync(mainPath)) {
49
- console.error('❌ Application not built. Please run: npm run build');
91
+ console.error('❌ Application not built. Main file not found at:', mainPath);
92
+ console.error(' Please run: npm run build');
50
93
  process.exit(1);
51
94
  }
52
95
 
@@ -107,6 +150,7 @@ async function main() {
107
150
  switch (command) {
108
151
  case 'gui':
109
152
  case 'start':
153
+ await ensureElectron();
110
154
  await ensurePrismaClient();
111
155
  launchElectron(args.slice(1));
112
156
  break;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "markpdfdown",
3
- "version": "0.1.3-t",
3
+ "version": "0.1.3-tfour",
4
4
  "description": "A high-quality PDF to Markdown tool based on large language model visual recognition.",
5
5
  "author": "MarkPDFdown",
6
6
  "main": "dist/main/index.js",
7
7
  "bin": {
8
- "markpdfdown": "./bin/cli.js"
8
+ "markpdfdown": "bin/cli.js"
9
9
  },
10
10
  "type": "module",
11
11
  "engines": {
@@ -106,6 +106,7 @@
106
106
  "dependencies": {
107
107
  "@ant-design/icons": "^5.6.1",
108
108
  "@prisma/client": "^6.5.0",
109
+ "prisma": "^6.5.0",
109
110
  "@types/sharp": "^0.31.1",
110
111
  "antd": "^5.24.4",
111
112
  "electron-is-dev": "^3.0.1",
@@ -125,6 +126,14 @@
125
126
  "sharp": "^0.34.1",
126
127
  "uuid": "^11.1.0"
127
128
  },
129
+ "peerDependencies": {
130
+ "electron": "^35.0.0"
131
+ },
132
+ "peerDependenciesMeta": {
133
+ "electron": {
134
+ "optional": true
135
+ }
136
+ },
128
137
  "devDependencies": {
129
138
  "@eslint/js": "^9.21.0",
130
139
  "@testing-library/jest-dom": "^6.1.5",
@@ -146,7 +155,6 @@
146
155
  "husky": "^9.1.7",
147
156
  "jsdom": "^25.0.1",
148
157
  "nodemon": "^3.1.9",
149
- "prisma": "^6.5.0",
150
158
  "typescript": "~5.7.2",
151
159
  "typescript-eslint": "^8.24.1",
152
160
  "vite": "^6.2.0",