remove workspace workflows dir

This commit is contained in:
bobo.yang 2024-05-13 12:43:29 +08:00
parent 34da79b945
commit 0c41673afb
2 changed files with 15 additions and 61 deletions

View File

@ -11,52 +11,24 @@ function copyFileSync(source: string, target: string) {
if (!fs.existsSync(target)) {
fs.writeFileSync(target, data);
}
}
function copyDirSync(source: string, target: string) {
}
function copyDirSync(source: string, target: string) {
// 创建目标目录
fs.mkdirSync(target, { recursive: true });
// 遍历目录中的所有文件和子目录
const files = fs.readdirSync(source);
for (const file of files) {
const sourcePath = path.join(source, file);
const targetPath = path.join(target, file);
const stats = fs.statSync(sourcePath);
if (stats.isDirectory()) {
// 递归拷贝子目录
copyDirSync(sourcePath, targetPath);
} else {
// 拷贝文件
copyFileSync(sourcePath, targetPath);
}
const sourcePath = path.join(source, file);
const targetPath = path.join(target, file);
const stats = fs.statSync(sourcePath);
if (stats.isDirectory()) {
// 递归拷贝子目录
copyDirSync(sourcePath, targetPath);
} else {
// 拷贝文件
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();
}
}
}

View File

@ -1,13 +1,9 @@
import * as vscode from 'vscode';
import * as path from 'path';
import WebviewManager from './webviewManager';
import '../handler/handlerRegister';
import handleMessage from '../handler/messageHandler';
import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig';
import { ExtensionContextHolder } from '../util/extensionContext';
import { UiUtilWrapper } from '../util/uiUtil';
import { ChatContextManager } from '../context/contextManager';
export class DevChatViewProvider implements vscode.WebviewViewProvider {
@ -23,20 +19,7 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
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 {
// 创建 .chat 目录并复制 workflows
createChatDirectoryAndCopyInstructionsSync(ExtensionContextHolder.context?.extensionUri!);
this.reloadCustomDefines();
this._view = webviewView;
this._webviewManager = new WebviewManager(webviewView.webview, this._context.extensionUri);
@ -46,7 +29,6 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
public reloadWebview(): void {
if (this._webviewManager) {
this.reloadCustomDefines();
this._webviewManager.reloadWebviewContent();
}
}