增加 ps1 脚本
This commit is contained in:
parent
ad11e4b5c7
commit
1b3130ad6c
23
build_service.ps1
Normal file
23
build_service.ps1
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Create resources directory if it doesn't exist
|
||||||
|
New-Item -ItemType Directory -Force -Path .\resources | Out-Null
|
||||||
|
|
||||||
|
# Start both build tasks in parallel
|
||||||
|
$jobs = @(
|
||||||
|
Start-Job -ScriptBlock {
|
||||||
|
Set-Location $using:PWD\renderer
|
||||||
|
npm run build
|
||||||
|
Move-Item -Force -Path .\dist -Destination ..\resources\renderer
|
||||||
|
}
|
||||||
|
Start-Job -ScriptBlock {
|
||||||
|
Set-Location $using:PWD\service
|
||||||
|
npm run build
|
||||||
|
Move-Item -Force -Path .\dist -Destination ..\resources\service
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Wait for all jobs to complete
|
||||||
|
Wait-Job -Job $jobs | Out-Null
|
||||||
|
Receive-Job -Job $jobs
|
||||||
|
Remove-Job -Job $jobs
|
||||||
|
|
||||||
|
Write-Host "构建完成,dist文件已移动到resources目录"
|
@ -3,7 +3,7 @@ import * as path from 'path';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as fspath from 'path';
|
import * as fspath from 'path';
|
||||||
|
|
||||||
import OpenMCPService from '../resources/service';
|
import * as OpenMCPService from '../resources/service';
|
||||||
|
|
||||||
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
|
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
|
||||||
const viewRoot = fspath.join(context.extensionPath, 'resources', 'renderer');
|
const viewRoot = fspath.join(context.extensionPath, 'resources', 'renderer');
|
||||||
@ -23,13 +23,6 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
// 注册 showOpenMCP 命令
|
// 注册 showOpenMCP 命令
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
vscode.commands.registerCommand('openmcp.showOpenMCP', async () => {
|
vscode.commands.registerCommand('openmcp.showOpenMCP', async () => {
|
||||||
const htmlPath = path.join(context.extensionPath, 'resources', 'renderer', 'index.html');
|
|
||||||
|
|
||||||
if (!fs.existsSync(htmlPath)) {
|
|
||||||
vscode.window.showErrorMessage('未找到 index.html 文件');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const panel = vscode.window.createWebviewPanel(
|
const panel = vscode.window.createWebviewPanel(
|
||||||
'openmcpView',
|
'openmcpView',
|
||||||
'OpenMCP',
|
'OpenMCP',
|
||||||
@ -40,8 +33,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const htmlContent = fs.readFileSync(htmlPath, 'utf8');
|
initaliseWebview(context, panel.webview);
|
||||||
panel.webview.html = htmlContent;
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -52,6 +44,23 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initaliseWebview(context: vscode.ExtensionContext, webview: vscode.Webview) {
|
||||||
|
webview.options = {
|
||||||
|
enableScripts: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置HTML内容
|
||||||
|
const html = getWebviewContent(context);
|
||||||
|
webview.html = html || '';
|
||||||
|
|
||||||
|
// 处理来自webview的消息
|
||||||
|
webview.onDidReceiveMessage(message => {
|
||||||
|
const { command, data } = message;
|
||||||
|
|
||||||
|
OpenMCPService.messageController(command, data, webview as any);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class WebviewViewProvider implements vscode.WebviewViewProvider {
|
class WebviewViewProvider implements vscode.WebviewViewProvider {
|
||||||
private _view?: vscode.WebviewView;
|
private _view?: vscode.WebviewView;
|
||||||
|
|
||||||
@ -63,30 +72,10 @@ class WebviewViewProvider implements vscode.WebviewViewProvider {
|
|||||||
_token: vscode.CancellationToken,
|
_token: vscode.CancellationToken,
|
||||||
) {
|
) {
|
||||||
this._view = webviewView;
|
this._view = webviewView;
|
||||||
webviewView.webview.options = {
|
initaliseWebview(this.context, webviewView.webview);
|
||||||
enableScripts: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
// 设置HTML内容
|
|
||||||
const html = getWebviewContent(this.context);
|
|
||||||
webviewView.webview.html = html || '';
|
|
||||||
|
|
||||||
// 处理来自webview的消息
|
|
||||||
webviewView.webview.onDidReceiveMessage(message => {
|
|
||||||
const { command, data } = message;
|
|
||||||
|
|
||||||
OpenMCPService.messageController(command, data, webviewView.webview as any);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 向webview发送消息的示例
|
|
||||||
this.sendMessageToWebview({ command: 'init', data: 'Hello from extension' });
|
|
||||||
}
|
|
||||||
|
|
||||||
private sendMessageToWebview(message: any) {
|
|
||||||
if (this._view) {
|
|
||||||
this._view.webview.postMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate() {}
|
export function deactivate() {
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
],
|
],
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
|
|
||||||
"strict": true, /* enable all strict type-checking options */
|
"strict": true, /* enable all strict type-checking options */
|
||||||
/* Additional Checks */
|
/* Additional Checks */
|
||||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user