clone commands by run --update-sys

This commit is contained in:
bobo.yang 2023-08-30 17:03:22 +08:00
parent 63fbb1289d
commit 9261a07589
2 changed files with 28 additions and 35 deletions

View File

@ -22,6 +22,7 @@ import { getPackageVersion } from '../util/python_installer/pip_package_version'
import { exec } from 'child_process';
import { sendCommandListByDevChatRun } from '../handler/regCommandList';
import DevChat from "../toolwrapper/devchat";
let indexProcess: CommandRun | null = null;
let summaryIndexProcess: CommandRun | null = null;
@ -506,42 +507,10 @@ export function registerAskCodeSummaryIndexStopCommand(context: vscode.Extension
export function registerInstallCommandsCommand(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('DevChat.InstallCommands', async () => {
// step 1: find User Home Dir
const homeDir = process.env.HOME || process.env.USERPROFILE;
if (!homeDir) {
logger.channel()?.error(`Error: No valid home directory found.`);
logger.channel()?.show();
return;
}
const devchat = new DevChat();
await devchat.updateSysCommand();
// step 2: create ensure {User Home Dir}/.chat/workflows/ exists
const targetDir = path.join(homeDir, '.chat', 'workflows');
fs.mkdirSync(targetDir, { recursive: true });
const sysDir = path.join(targetDir, 'sys');
if (fs.existsSync(sysDir)) {
// step 3: if sys exists, then git pull
logger.channel()?.info(`Git pull from sys...`);
exec('git pull', { cwd: sysDir }, (error, stdout, stderr) => {
if (error) {
logger.channel()?.error(`Error pulling git repo: ${error}`);
} else {
logger.channel()?.info(`Git pull successful: ${stdout}`);
sendCommandListByDevChatRun();
}
});
} else {
// step 4: if sys not exists, then git clone
logger.channel()?.info(`Git clone to sys...`);
exec('git clone https://github.com/devchat-ai/workflows.git sys', { cwd: targetDir }, (error, stdout, stderr) => {
if (error) {
logger.channel()?.error(`Error cloning git repo: ${error}`);
} else {
logger.channel()?.info(`Git clone successful: ${stdout}`);
sendCommandListByDevChatRun();
}
});
}
sendCommandListByDevChatRun();
});
context.subscriptions.push(disposable);

View File

@ -430,6 +430,30 @@ class DevChat {
return stdout;
}
async updateSysCommand(): Promise<string> {
const args = ["run", "--update-sys"];
const devChat = this.getDevChatPath();
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
logger.channel()?.info(`Running devchat with arguments: ${args.join(" ")}`);
const spawnOptions = {
maxBuffer: 10 * 1024 * 1024, // Set maxBuffer to 10 MB
cwd: workspaceDir,
env: {
...process.env
},
};
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(devChat, args, spawnOptions, undefined, undefined, undefined, undefined);
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
if (stderr) {
logger.channel()?.error(`Error: ${stderr}`);
logger.channel()?.show();
}
logger.channel()?.info(`${stdout}`);
return stdout;
}
async topics(): Promise<TopicEntry[]> {
const args = ["topic", "-l"];
const devChat = this.getDevChatPath();