Merge pull request #599 from devchat-ai/optimize

Refactor and improve file path handling
This commit is contained in:
boob.yang 2024-12-02 15:14:40 +08:00 committed by GitHub
commit 6ac60e7b31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 36 deletions

2
gui

@ -1 +1 @@
Subproject commit 66c9115f69ad90eea993cee16dcf93e280673201
Subproject commit c8836777f0d09ce1328166abec5cebc480a2590a

View File

@ -1,26 +1,26 @@
require('dotenv').config()
require('dotenv').config();
const fs = require('fs')
const path = require('path')
const fs = require('fs');
const path = require('path');
function copyIcon(src, dst) {
if (!src) {
console.warn(`Icon path for ${dst} is not defined in your environment variables`)
return
console.warn(`Icon path for ${dst} is not defined in your environment variables`);
return;
}
console.log(`Replacing icon ${dst} by ${src}`)
console.log(`Replacing icon ${dst} by ${src}`);
if (!fs.existsSync(src)) {
console.warn(`Icon file ${src} does not exist.`)
return
console.warn(`Icon file ${src} does not exist.`);
return;
}
const destPath = path.join(__dirname, 'assets', dst)
const destPath = path.join(__dirname, 'assets', dst);
try {
fs.copyFileSync(src, destPath)
fs.chmodSync(destPath, 0o644)
fs.copyFileSync(src, destPath);
fs.chmodSync(destPath, 0o644);
} catch(e) {
console.warn(`Failed to copy logo ${e}`)
console.warn(`Failed to copy logo ${e}`);
}
}
@ -31,7 +31,7 @@ function updatePackageJson() {
ASSISTANT_NAME_EN: process.env.ASSISTANT_NAME_EN || "DevChat",
ASSISTANT_NAME_ZH: process.env.ASSISTANT_NAME_ZH || "DevChat"
}
console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`)
console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`);
let packageJson = fs.readFileSync('package.json', 'utf8');
@ -44,8 +44,8 @@ function updatePackageJson() {
fs.writeFileSync('package.json', packageJson);
}
copyIcon(process.env.EXTENSION_ICON, 'devchat.png')
copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg')
copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg')
copyIcon(process.env.EXTENSION_ICON, 'devchat.png');
copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg');
copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg');
updatePackageJson()
updatePackageJson();

View File

@ -16,7 +16,9 @@ export async function handleCodeSelected(fileSelected: string, codeSelected: str
// get relative path of workspace
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
const relativePath = path.relative(workspaceDir!, fileSelected);
const relativePath = workspaceDir
? path.relative(workspaceDir, fileSelected)
: fileSelected;
// convert fileContent to markdown code block with languageId and file path
const data = {

View File

@ -19,7 +19,9 @@ export async function handleFileSelected(fileSelected: string) {
// get relative path of workspace
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
const relativePath = path.relative(workspaceDir!, fileSelected);
const relativePath = workspaceDir
? path.relative(workspaceDir, fileSelected)
: fileSelected;
// convert fileContent to markdown code block with languageId and file path
const data = {

View File

@ -216,12 +216,18 @@ export function registerInstallCommandsCommand(
const currentVersion = UiUtilWrapper.extensionPath();
const previousVersion = devchatConfig.get("last_devchat_version", "");
let copiedDirectory = false;
if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) {
logger.channel()?.debug("Creating directory: " + sysMericoDirPath);
await copyDirectory(pluginDirPath, sysDirPath);
copiedDirectory = true;
}
devchatConfig.set("last_devchat_version", currentVersion);
if (copiedDirectory) {
logger.channel()?.debug("Directory copied successfully.");
sendCommandListByDevChatRun();
} else {
// Check if ~/.chat/scripts directory exists
if (!fs.existsSync(sysMericoDirPath)) {
// Directory does not exist, wait for updateWorkflows to finish
@ -240,6 +246,7 @@ export function registerInstallCommandsCommand(
await sendCommandListByDevChatRun();
}
}
// Ensure the panel is activated
await ensureChatPanel(context);

@ -1 +1 @@
Subproject commit ed9898d038e09732bbcaba0ef655efc1f89ef9a8
Subproject commit f4a4dbc529e4fc80f67a0492674854c6fb8a29d3