From c8df8917d94b99d88fb6e3e467ac5aa5dbb853db Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Wed, 20 Dec 2023 12:57:55 +0800 Subject: [PATCH] package workflows as submodule --- .gitmodules | 3 +++ package.json | 3 ++- src/contributes/commands.ts | 35 +++++++++++++++++++++++++++++++---- tools | 2 +- workflowsCommands | 1 + 5 files changed, 38 insertions(+), 6 deletions(-) create mode 160000 workflowsCommands diff --git a/.gitmodules b/.gitmodules index 8e16515..9a8013c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "gui"] path = gui url = https://github.com/devchat-ai/devchat-gui.git +[submodule "workflowsCommands"] + path = workflowsCommands + url = https://github.com/devchat-ai/workflows.git diff --git a/package.json b/package.json index a4a19f9..d725e38 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "assets/*", "tools/*", "workflows/*", + "workflowsCommands/*", "LICENSE", "README.md" ], @@ -797,7 +798,7 @@ } }, "scripts": { - "build:gui":"cd ./gui && yarn && yarn vscode", + "build:gui": "cd ./gui && yarn && yarn vscode", "vscode:uninstall": "node ./dist/uninstall", "vscode:prepublish": "npm run package", "compile": "webpack", diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index 0ed5dcb..5cd5af0 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -1,6 +1,8 @@ import * as vscode from 'vscode'; import * as fs from 'fs'; import * as os from 'os'; +import * as path from 'path'; +import * as util from 'util'; import { sendFileSelectMessage, sendCodeSelectMessage } from './util'; import { ExtensionContextHolder } from '../util/extensionContext'; import { TopicManager } from '../topic/topicManager'; @@ -12,14 +14,32 @@ import { isValidApiKey } from '../handler/historyMessagesBase'; import { logger } from '../util/logger'; -import path from 'path'; - import { sendCommandListByDevChatRun, updateChatModels } from '../handler/workflowCommandHandler'; import DevChat from "../toolwrapper/devchat"; import { createEnvByConda, createEnvByMamba } from '../util/python_installer/app_install'; import { installRequirements } from '../util/python_installer/package_install'; import { chatWithDevChat } from '../handler/chatHandler'; +const readdir = util.promisify(fs.readdir); +const stat = util.promisify(fs.stat); +const mkdir = util.promisify(fs.mkdir); +const copyFile = util.promisify(fs.copyFile); + +async function copyDirectory(src: string, dest: string): Promise { + await mkdir(dest, { recursive: true }); + const entries = await readdir(src, { withFileTypes: true }); + + for (let entry of entries) { + const srcPath = path.join(src, entry.name); + const destPath = path.join(dest, entry.name); + + if (entry.isDirectory()) { + await copyDirectory(srcPath, destPath); + } else { + await copyFile(srcPath, destPath); + } + } +} function registerOpenChatPanelCommand(context: vscode.ExtensionContext) { let disposable = vscode.commands.registerCommand('devchat.openChatPanel', async () => { @@ -251,8 +271,15 @@ export function regApplyDiffResultCommand(context: vscode.ExtensionContext) { export function registerInstallCommandsCommand(context: vscode.ExtensionContext) { let disposable = vscode.commands.registerCommand('DevChat.InstallCommands', async () => { - const sysDirPath = path.join(process.env.HOME || process.env.USERPROFILE || '', '.chat', 'workflows', 'sys'); - const devchat = new DevChat(); + const homePath = process.env.HOME || process.env.USERPROFILE || ''; + const sysDirPath = path.join(homePath, '.chat', 'workflows', 'sys'); + const pluginDirPath = path.join(UiUtilWrapper.extensionPath(), 'workflowsCommands'); // Adjust this path as needed + + const devchat = new DevChat(); + + if (!fs.existsSync(sysDirPath)) { + await copyDirectory(pluginDirPath, sysDirPath); + } // Check if ~/.chat/workflows/sys directory exists if (!fs.existsSync(sysDirPath)) { diff --git a/tools b/tools index 8ceeeea..0b5e2ad 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 8ceeeea147daee9ff0cd5b927d258710431d5ac0 +Subproject commit 0b5e2ad24f6186ac836f8d1850b54793769dedc5 diff --git a/workflowsCommands b/workflowsCommands new file mode 160000 index 0000000..94c73fe --- /dev/null +++ b/workflowsCommands @@ -0,0 +1 @@ +Subproject commit 94c73fe51809981cf5ba50763ec23964d50fdc60