copy workflows to .chat even .chat exist

This commit is contained in:
bobo.yang 2023-05-11 10:48:52 +08:00
parent eca629b4f3
commit 1bbe2a3e91
2 changed files with 29 additions and 23 deletions

View File

@ -28,26 +28,32 @@ class CustomCommands {
public parseCommands(workflowsDir: string): void {
this.commands = [];
const subDirs = fs.readdirSync(workflowsDir, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
try {
const subDirs = fs.readdirSync(workflowsDir, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
for (const dir of subDirs) {
const settingsPath = path.join(workflowsDir, dir, '_setting_.json');
if (fs.existsSync(settingsPath)) {
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
const command: Command = {
name: dir,
pattern: settings.pattern,
description: settings.description,
message: settings.message,
default: settings.default,
instructions: settings.instructions
};
this.commands.push(command);
}
}
}
for (const dir of subDirs) {
const settingsPath = path.join(workflowsDir, dir, '_setting_.json');
if (fs.existsSync(settingsPath)) {
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
const command: Command = {
name: dir,
pattern: settings.pattern,
description: settings.description,
message: settings.message,
default: settings.default,
instructions: settings.instructions
};
this.commands.push(command);
}
}
} catch (error) {
// 显示错误消息
logger.channel()?.error(`Failed to parse commands: ${error}`);
logger.channel()?.show();
}
}
public getCommands(): Command[] {
return this.commands;

View File

@ -39,19 +39,19 @@ export function createChatDirectoryAndCopyInstructionsSync(extensionUri: vscode.
}
const workspaceRoot = workspaceFolders[0].uri.fsPath;
const chatDirPath = path.join(workspaceRoot, '.chat');
const chatWorkflowsDirPath = path.join(workspaceRoot, '.chat', 'workflows');
const instructionsSrcPath = path.join(extensionUri.fsPath, 'workflows');
try {
// 检查 .chat 目录是否存在,如果不存在,则创建它
if (!fs.existsSync(chatDirPath)) {
fs.mkdirSync(chatDirPath);
if (!fs.existsSync(chatWorkflowsDirPath)) {
fs.mkdirSync(chatWorkflowsDirPath, {recursive: true});
} else {
return;
}
// 将 workflows 目录复制到 .chat 目录中
copyDirSync(instructionsSrcPath, path.join(chatDirPath, 'workflows'));
copyDirSync(instructionsSrcPath, chatWorkflowsDirPath);
} catch (error) {
logger.channel()?.error('Error creating .chat directory and copying workflows:', error);
logger.channel()?.show();