remove workspace workflows dir
This commit is contained in:
parent
34da79b945
commit
0c41673afb
@ -11,52 +11,24 @@ function copyFileSync(source: string, target: string) {
|
|||||||
if (!fs.existsSync(target)) {
|
if (!fs.existsSync(target)) {
|
||||||
fs.writeFileSync(target, data);
|
fs.writeFileSync(target, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyDirSync(source: string, target: string) {
|
function copyDirSync(source: string, target: string) {
|
||||||
// 创建目标目录
|
// 创建目标目录
|
||||||
fs.mkdirSync(target, { recursive: true });
|
fs.mkdirSync(target, { recursive: true });
|
||||||
|
|
||||||
// 遍历目录中的所有文件和子目录
|
// 遍历目录中的所有文件和子目录
|
||||||
const files = fs.readdirSync(source);
|
const files = fs.readdirSync(source);
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const sourcePath = path.join(source, file);
|
const sourcePath = path.join(source, file);
|
||||||
const targetPath = path.join(target, file);
|
const targetPath = path.join(target, file);
|
||||||
const stats = fs.statSync(sourcePath);
|
const stats = fs.statSync(sourcePath);
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
// 递归拷贝子目录
|
// 递归拷贝子目录
|
||||||
copyDirSync(sourcePath, targetPath);
|
copyDirSync(sourcePath, targetPath);
|
||||||
} else {
|
} else {
|
||||||
// 拷贝文件
|
// 拷贝文件
|
||||||
copyFileSync(sourcePath, targetPath);
|
copyFileSync(sourcePath, targetPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createChatDirectoryAndCopyInstructionsSync(extensionUri: vscode.Uri) {
|
|
||||||
const workspaceRoot = UiUtilWrapper.workspaceFoldersFirstPath();
|
|
||||||
if (!workspaceRoot) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatWorkflowsDirPath = path.join(workspaceRoot, '.chat', 'workflows');
|
|
||||||
const instructionsSrcPath = path.join(extensionUri.fsPath, 'workflows');
|
|
||||||
|
|
||||||
// if workflows directory exists, return
|
|
||||||
if (fs.existsSync(chatWorkflowsDirPath)) {
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!fs.existsSync(chatWorkflowsDirPath)) {
|
|
||||||
fs.mkdirSync(chatWorkflowsDirPath, {recursive: true});
|
|
||||||
} else {
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
|
|
||||||
copyDirSync(instructionsSrcPath, chatWorkflowsDirPath);
|
|
||||||
} catch (error) {
|
|
||||||
logger.channel()?.error('Error occurred while creating the .chat directory and copying workflows:', error);
|
|
||||||
logger.channel()?.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as path from 'path';
|
|
||||||
import WebviewManager from './webviewManager';
|
import WebviewManager from './webviewManager';
|
||||||
|
|
||||||
import '../handler/handlerRegister';
|
import '../handler/handlerRegister';
|
||||||
import handleMessage from '../handler/messageHandler';
|
import handleMessage from '../handler/messageHandler';
|
||||||
import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig';
|
|
||||||
import { ExtensionContextHolder } from '../util/extensionContext';
|
import { ExtensionContextHolder } from '../util/extensionContext';
|
||||||
import { UiUtilWrapper } from '../util/uiUtil';
|
|
||||||
import { ChatContextManager } from '../context/contextManager';
|
|
||||||
|
|
||||||
|
|
||||||
export class DevChatViewProvider implements vscode.WebviewViewProvider {
|
export class DevChatViewProvider implements vscode.WebviewViewProvider {
|
||||||
@ -23,20 +19,7 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
|
|||||||
return this._view;
|
return this._view;
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadCustomDefines() {
|
|
||||||
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
|
|
||||||
if (workspaceDir) {
|
|
||||||
const workflowsDir = path.join(workspaceDir!, '.chat', 'workflows');
|
|
||||||
ChatContextManager.getInstance().loadCustomContexts(workflowsDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): void {
|
resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): void {
|
||||||
// 创建 .chat 目录并复制 workflows
|
|
||||||
createChatDirectoryAndCopyInstructionsSync(ExtensionContextHolder.context?.extensionUri!);
|
|
||||||
|
|
||||||
this.reloadCustomDefines();
|
|
||||||
|
|
||||||
this._view = webviewView;
|
this._view = webviewView;
|
||||||
|
|
||||||
this._webviewManager = new WebviewManager(webviewView.webview, this._context.extensionUri);
|
this._webviewManager = new WebviewManager(webviewView.webview, this._context.extensionUri);
|
||||||
@ -46,7 +29,6 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
|
|||||||
|
|
||||||
public reloadWebview(): void {
|
public reloadWebview(): void {
|
||||||
if (this._webviewManager) {
|
if (this._webviewManager) {
|
||||||
this.reloadCustomDefines();
|
|
||||||
this._webviewManager.reloadWebviewContent();
|
this._webviewManager.reloadWebviewContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user