实现 tesseract 的核心部分打包
This commit is contained in:
parent
73a5b05a5d
commit
1c92b6fddd
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,9 +4,10 @@ node_modules
|
|||||||
.vscode-test/
|
.vscode-test/
|
||||||
*.vsix
|
*.vsix
|
||||||
.env
|
.env
|
||||||
resources
|
openmcp-sdk
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.exe
|
.exe
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
*.traineddata
|
resources/ocr/*.js
|
||||||
|
resources/ocr/*.wasm
|
@ -1,7 +1,7 @@
|
|||||||
# 创建并清理资源目录
|
# 创建并清理资源目录
|
||||||
New-Item -ItemType Directory -Path ./resources -Force
|
New-Item -ItemType Directory -Path ./openmcp-sdk -Force
|
||||||
Remove-Item -Recurse -Force ./resources/* -ErrorAction SilentlyContinue
|
Remove-Item -Recurse -Force ./openmcp-sdk/* -ErrorAction SilentlyContinue
|
||||||
New-Item -ItemType Directory -Path ./resources -Force
|
New-Item -ItemType Directory -Path ./openmcp-sdk -Force
|
||||||
|
|
||||||
# 获取当前工作目录的绝对路径
|
# 获取当前工作目录的绝对路径
|
||||||
$currentDir = (Get-Location).Path
|
$currentDir = (Get-Location).Path
|
||||||
@ -11,23 +11,23 @@ $rendererJob = Start-Job -ScriptBlock {
|
|||||||
param($workDir)
|
param($workDir)
|
||||||
Set-Location -Path "$workDir\renderer"
|
Set-Location -Path "$workDir\renderer"
|
||||||
npm run build
|
npm run build
|
||||||
Move-Item -Path "./dist" -Destination "$workDir\resources\renderer" -Force
|
Move-Item -Path "./dist" -Destination "$workDir\openmcp-sdk\renderer" -Force
|
||||||
} -ArgumentList $currentDir
|
} -ArgumentList $currentDir
|
||||||
|
|
||||||
$serviceJob = Start-Job -ScriptBlock {
|
$serviceJob = Start-Job -ScriptBlock {
|
||||||
param($workDir)
|
param($workDir)
|
||||||
Set-Location -Path "$workDir\service"
|
Set-Location -Path "$workDir\service"
|
||||||
npm run build
|
npm run build
|
||||||
Move-Item -Path "./dist" -Destination "$workDir\resources\service" -Force
|
Move-Item -Path "./dist" -Destination "$workDir\openmcp-sdk\service" -Force
|
||||||
} -ArgumentList $currentDir
|
} -ArgumentList $currentDir
|
||||||
|
|
||||||
# 等待任务完成
|
# 等待任务完成
|
||||||
$rendererJob | Wait-Job | Receive-Job
|
$rendererJob | Wait-Job | Receive-Job
|
||||||
$serviceJob | Wait-Job | Receive-Job
|
$serviceJob | Wait-Job | Receive-Job
|
||||||
|
|
||||||
# 将 resources 目录复制到 software/resources
|
# 将 openmcp-sdk 目录复制到 software/openmcp-sdk
|
||||||
New-Item -ItemType Directory -Path ./software/resources -Force
|
New-Item -ItemType Directory -Path ./software/openmcp-sdk -Force
|
||||||
Remove-Item -Recurse -Force ./software/resources/* -ErrorAction SilentlyContinue
|
Remove-Item -Recurse -Force ./software/openmcp-sdk/* -ErrorAction SilentlyContinue
|
||||||
Copy-Item -Recurse -Path ./resources -Destination ./software/ -Force
|
Copy-Item -Recurse -Path ./openmcp-sdk -Destination ./software/ -Force
|
||||||
|
|
||||||
Write-Output "finish building services in ./resources"
|
Write-Output "finish building services in ./openmcp-sdk"
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mkdir -p ./resources
|
mkdir -p ./openmcp-sdk
|
||||||
rm -rf ./resources/
|
rm -rf ./openmcp-sdk/
|
||||||
mkdir -p ./resources
|
mkdir -p ./openmcp-sdk
|
||||||
|
|
||||||
(cd ./renderer && npm run build && mv ./dist ../resources/renderer) &
|
(cd ./renderer && npm run build && mv ./dist ../openmcp-sdk/renderer) &
|
||||||
(cd ./service && npm run build && mv ./dist ../resources/service) &
|
(cd ./service && npm run build && mv ./dist ../openmcp-sdk/service) &
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
||||||
mkdir -p ./software/resources
|
mkdir -p ./software/openmcp-sdk
|
||||||
rm -rf ./software/resources
|
rm -rf ./software/openmcp-sdk
|
||||||
cp -r ./resources ./software/
|
cp -r ./openmcp-sdk ./software/
|
||||||
|
|
||||||
echo "finish building services in ./resources"
|
echo "finish building services in ./openmcp-sdk"
|
||||||
|
3
configure.sh
Normal file → Executable file
3
configure.sh
Normal file → Executable file
@ -1,4 +1,5 @@
|
|||||||
cd renderer && npm i && cd ..
|
cd renderer && npm i && cd ..
|
||||||
cd service && npm i && node patch-mcp-sdk.js && cd ..
|
cd service && npm i && cd ..
|
||||||
cd servers && uv sync
|
cd servers && uv sync
|
||||||
npm i
|
npm i
|
||||||
|
npm run prepare:ocr
|
116
package-lock.json
generated
116
package-lock.json
generated
@ -23,6 +23,7 @@
|
|||||||
"@types/pako": "^2.0.3",
|
"@types/pako": "^2.0.3",
|
||||||
"@types/showdown": "^2.0.0",
|
"@types/showdown": "^2.0.0",
|
||||||
"@types/vscode": "^1.72.0",
|
"@types/vscode": "^1.72.0",
|
||||||
|
"copy-webpack-plugin": "^13.0.0",
|
||||||
"ts-loader": "^9.5.1",
|
"ts-loader": "^9.5.1",
|
||||||
"typescript": "^5.4.2",
|
"typescript": "^5.4.2",
|
||||||
"webpack": "^5.99.5",
|
"webpack": "^5.99.5",
|
||||||
@ -850,6 +851,30 @@
|
|||||||
"node": ">=6.6.0"
|
"node": ">=6.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/copy-webpack-plugin": {
|
||||||
|
"version": "13.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-13.0.0.tgz",
|
||||||
|
"integrity": "sha512-FgR/h5a6hzJqATDGd9YG41SeDViH+0bkHn6WNXCi5zKAZkeESeSxLySSsFLHqLEVCh0E+rITmCf0dusXWYukeQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"glob-parent": "^6.0.1",
|
||||||
|
"normalize-path": "^3.0.0",
|
||||||
|
"schema-utils": "^4.2.0",
|
||||||
|
"serialize-javascript": "^6.0.2",
|
||||||
|
"tinyglobby": "^0.2.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 18.12.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/webpack"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"webpack": "^5.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cors": {
|
"node_modules/cors": {
|
||||||
"version": "2.8.5",
|
"version": "2.8.5",
|
||||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
@ -1450,6 +1475,19 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/glob-parent": {
|
||||||
|
"version": "6.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"is-glob": "^4.0.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.13.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/glob-to-regexp": {
|
"node_modules/glob-to-regexp": {
|
||||||
"version": "0.4.1",
|
"version": "0.4.1",
|
||||||
"resolved": "https://registry.npmmirror.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz",
|
"resolved": "https://registry.npmmirror.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz",
|
||||||
@ -1669,6 +1707,16 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-extglob": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/is-generator-function": {
|
"node_modules/is-generator-function": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.0.tgz",
|
||||||
@ -1687,6 +1735,19 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-glob": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"is-extglob": "^2.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/is-number": {
|
"node_modules/is-number": {
|
||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"resolved": "https://registry.npmmirror.com/is-number/-/is-number-7.0.0.tgz",
|
"resolved": "https://registry.npmmirror.com/is-number/-/is-number-7.0.0.tgz",
|
||||||
@ -1993,6 +2054,16 @@
|
|||||||
"integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==",
|
"integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/normalize-path": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/object-assign": {
|
"node_modules/object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
@ -2781,6 +2852,51 @@
|
|||||||
"integrity": "sha512-1Qncm/9oKM7xgrQXZXNB+NRh19qiXGhxlrR8EwFbK5SaUbPZnS5OMtP/ghtqfd23hsr1ZvZbZjeuAGcMxd/ooA==",
|
"integrity": "sha512-1Qncm/9oKM7xgrQXZXNB+NRh19qiXGhxlrR8EwFbK5SaUbPZnS5OMtP/ghtqfd23hsr1ZvZbZjeuAGcMxd/ooA==",
|
||||||
"license": "Apache-2.0"
|
"license": "Apache-2.0"
|
||||||
},
|
},
|
||||||
|
"node_modules/tinyglobby": {
|
||||||
|
"version": "0.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.13.tgz",
|
||||||
|
"integrity": "sha512-mEwzpUgrLySlveBwEVDMKk5B57bhLPYovRfPAXD5gA/98Opn0rCDj3GtLwFvCvH5RK9uPCExUROW5NjDwvqkxw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"fdir": "^6.4.4",
|
||||||
|
"picomatch": "^4.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tinyglobby/node_modules/fdir": {
|
||||||
|
"version": "6.4.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.4.tgz",
|
||||||
|
"integrity": "sha512-1NZP+GK4GfuAv3PqKvxQRDMjdSRZjnkq7KfhlNrCNNlZ0ygQFpebfrnfnq/W7fpUnAv9aGWmY1zKx7FYL3gwhg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"picomatch": "^3 || ^4"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"picomatch": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tinyglobby/node_modules/picomatch": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/jonschlinkert"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/to-regex-range": {
|
"node_modules/to-regex-range": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmmirror.com/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
"resolved": "https://registry.npmmirror.com/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||||
|
@ -218,7 +218,8 @@
|
|||||||
"watch": "tsc -watch -p ./",
|
"watch": "tsc -watch -p ./",
|
||||||
"pretest": "npm run compile && npm run lint",
|
"pretest": "npm run compile && npm run lint",
|
||||||
"lint": "eslint src --ext ts",
|
"lint": "eslint src --ext ts",
|
||||||
"test": "node ./out/test/runTest.js"
|
"test": "node ./out/test/runTest.js",
|
||||||
|
"prepare:ocr": "webpack --config webpack/webpack.tesseract.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.10.2",
|
"@modelcontextprotocol/sdk": "^1.10.2",
|
||||||
@ -236,6 +237,7 @@
|
|||||||
"@types/pako": "^2.0.3",
|
"@types/pako": "^2.0.3",
|
||||||
"@types/showdown": "^2.0.0",
|
"@types/showdown": "^2.0.0",
|
||||||
"@types/vscode": "^1.72.0",
|
"@types/vscode": "^1.72.0",
|
||||||
|
"copy-webpack-plugin": "^13.0.0",
|
||||||
"ts-loader": "^9.5.1",
|
"ts-loader": "^9.5.1",
|
||||||
"typescript": "^5.4.2",
|
"typescript": "^5.4.2",
|
||||||
"webpack": "^5.99.5",
|
"webpack": "^5.99.5",
|
||||||
|
BIN
resources/ocr/chi_sim.traineddata
Normal file
BIN
resources/ocr/chi_sim.traineddata
Normal file
Binary file not shown.
BIN
resources/ocr/eng.traineddata
Normal file
BIN
resources/ocr/eng.traineddata
Normal file
Binary file not shown.
2
software/.gitignore
vendored
2
software/.gitignore
vendored
@ -4,7 +4,7 @@ node_modules
|
|||||||
.vscode-test/
|
.vscode-test/
|
||||||
*.vsix
|
*.vsix
|
||||||
.env
|
.env
|
||||||
resources
|
openmcp-sdk
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.exe
|
.exe
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
|
"openmcp-sdk/**/*",
|
||||||
"resources/**/*",
|
"resources/**/*",
|
||||||
"icons/**/*"
|
"icons/**/*"
|
||||||
],
|
],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
import { app, BrowserWindow, ipcMain } from 'electron';
|
||||||
import * as OpenMCPService from '../resources/service';
|
import * as OpenMCPService from '../openmcp-sdk/service';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { ElectronIPCLike, getInitConnectionOption, ILaunchSigature, updateConnectionOption } from './util';
|
import { ElectronIPCLike, getInitConnectionOption, ILaunchSigature, updateConnectionOption } from './util';
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ function createWindow(): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const indexPath = path.join(__dirname, '..', 'resources/renderer/index.html');
|
const indexPath = path.join(__dirname, '..', 'openmcp-sdk/renderer/index.html');
|
||||||
mainWindow.loadFile(indexPath);
|
mainWindow.loadFile(indexPath);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as OpenMCPService from '../resources/service';
|
import * as OpenMCPService from '../openmcp-sdk/service';
|
||||||
import { launch } from './common/entry';
|
import { launch } from './common/entry';
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
@ -13,6 +13,12 @@ export class HookController {
|
|||||||
|
|
||||||
console.log('test ocr begin');
|
console.log('test ocr begin');
|
||||||
|
|
||||||
|
const cachePath = context.extensionPath;
|
||||||
|
const workerPath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.js');
|
||||||
|
const corePath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.wasm');
|
||||||
|
|
||||||
|
console.log('workerPath', workerPath);
|
||||||
|
console.log('corePath', corePath);
|
||||||
console.log('cachePath', context.extensionPath);
|
console.log('cachePath', context.extensionPath);
|
||||||
|
|
||||||
const { data: { text } } = await Tesseract.recognize(
|
const { data: { text } } = await Tesseract.recognize(
|
||||||
@ -23,7 +29,9 @@ export class HookController {
|
|||||||
langPath: './',
|
langPath: './',
|
||||||
gzip: false,
|
gzip: false,
|
||||||
cacheMethod: 'cache',
|
cacheMethod: 'cache',
|
||||||
cachePath: context.extensionPath
|
cachePath,
|
||||||
|
workerPath,
|
||||||
|
corePath
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@ import * as vscode from 'vscode';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as fspath from 'path';
|
import * as fspath from 'path';
|
||||||
import { IConnectionItem, ILaunchSigature, panels, updateInstalledConnectionConfig, updateWorkspaceConnectionConfig } from '../global';
|
import { IConnectionItem, ILaunchSigature, panels, updateInstalledConnectionConfig, updateWorkspaceConnectionConfig } from '../global';
|
||||||
import * as OpenMCPService from '../../resources/service';
|
import * as OpenMCPService from '../../openmcp-sdk/service';
|
||||||
|
|
||||||
export function getWebviewContent(context: vscode.ExtensionContext, panel: vscode.WebviewPanel): string | undefined {
|
export function getWebviewContent(context: vscode.ExtensionContext, panel: vscode.WebviewPanel): string | undefined {
|
||||||
const viewRoot = fspath.join(context.extensionPath, 'resources', 'renderer');
|
const viewRoot = fspath.join(context.extensionPath, 'openmcp-sdk', 'renderer');
|
||||||
const htmlIndexPath = fspath.join(viewRoot, 'index.html');
|
const htmlIndexPath = fspath.join(viewRoot, 'index.html');
|
||||||
const html = fs.readFileSync(htmlIndexPath, { encoding: 'utf-8' })?.replace(/(<link.+?href="|<script.+?src="|<img.+?src="|url\()(.+?)(\)|")/g, (m, $1, $2) => {
|
const html = fs.readFileSync(htmlIndexPath, { encoding: 'utf-8' })?.replace(/(<link.+?href="|<script.+?src="|<img.+?src="|url\()(.+?)(\)|")/g, (m, $1, $2) => {
|
||||||
const absLocalPath = fspath.resolve(viewRoot, $2);
|
const absLocalPath = fspath.resolve(viewRoot, $2);
|
||||||
@ -58,7 +58,7 @@ export function revealOpenMcpWebviewPanel(
|
|||||||
// 设置HTML内容
|
// 设置HTML内容
|
||||||
const html = getWebviewContent(context, panel);
|
const html = getWebviewContent(context, panel);
|
||||||
panel.webview.html = html || '';
|
panel.webview.html = html || '';
|
||||||
panel.iconPath = vscode.Uri.file(fspath.join(context.extensionPath, 'resources', 'renderer', 'images', 'openmcp.png'));
|
panel.iconPath = vscode.Uri.file(fspath.join(context.extensionPath, 'openmcp-sdk', 'renderer', 'images', 'openmcp.png'));
|
||||||
|
|
||||||
// 处理来自webview的消息
|
// 处理来自webview的消息
|
||||||
panel.webview.onDidReceiveMessage(message => {
|
panel.webview.onDidReceiveMessage(message => {
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
// 允许访问 resources 目录
|
// 允许访问 openmcp-sdk 目录
|
||||||
"paths": {
|
"paths": {
|
||||||
"@resources/*": ["./resources/*"]
|
"@openmcp-sdk/*": ["./openmcp-sdk/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
|
43
webpack/webpack.tesseract.js
Normal file
43
webpack/webpack.tesseract.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './node_modules/tesseract.js/src/worker-script/node/index.js',
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, '..', 'resources', 'ocr'),
|
||||||
|
filename: 'worker.js',
|
||||||
|
libraryTarget: 'commonjs2'
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
fallback: {
|
||||||
|
bufferutil: false,
|
||||||
|
'utf-8-validate': false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mode: 'production',
|
||||||
|
target: 'node',
|
||||||
|
plugins: [
|
||||||
|
new CopyWebpackPlugin({
|
||||||
|
patterns: [
|
||||||
|
{
|
||||||
|
from: path.resolve(__dirname, '..', 'node_modules', 'tesseract.js-core', 'tesseract*'),
|
||||||
|
to: path.resolve(__dirname, '..', 'resources', 'ocr', '[name][ext]'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: {
|
||||||
|
loader: 'babel-loader',
|
||||||
|
options: {
|
||||||
|
presets: ['@babel/preset-env'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user