Merge pull request #599 from devchat-ai/optimize
Refactor and improve file path handling
This commit is contained in:
commit
6ac60e7b31
2
gui
2
gui
@ -1 +1 @@
|
||||
Subproject commit 66c9115f69ad90eea993cee16dcf93e280673201
|
||||
Subproject commit c8836777f0d09ce1328166abec5cebc480a2590a
|
34
prebuild.js
34
prebuild.js
@ -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();
|
@ -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 = {
|
||||
|
@ -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 = {
|
||||
|
@ -216,29 +216,36 @@ 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);
|
||||
|
||||
// Check if ~/.chat/scripts directory exists
|
||||
if (!fs.existsSync(sysMericoDirPath)) {
|
||||
// Directory does not exist, wait for updateWorkflows to finish
|
||||
logger.channel()?.debug("Update workflows...");
|
||||
await dcClient.updateWorkflows();
|
||||
await dcClient.updateCustomWorkflows();
|
||||
if (copiedDirectory) {
|
||||
logger.channel()?.debug("Directory copied successfully.");
|
||||
sendCommandListByDevChatRun();
|
||||
} else {
|
||||
// Directory exists, execute sendCommandListByDevChatRun immediately
|
||||
logger.channel()?.debug("Sending and updating workflows...");
|
||||
await sendCommandListByDevChatRun();
|
||||
// Check if ~/.chat/scripts directory exists
|
||||
if (!fs.existsSync(sysMericoDirPath)) {
|
||||
// Directory does not exist, wait for updateWorkflows to finish
|
||||
logger.channel()?.debug("Update workflows...");
|
||||
await dcClient.updateWorkflows();
|
||||
await dcClient.updateCustomWorkflows();
|
||||
sendCommandListByDevChatRun();
|
||||
} else {
|
||||
// Directory exists, execute sendCommandListByDevChatRun immediately
|
||||
logger.channel()?.debug("Sending and updating workflows...");
|
||||
await sendCommandListByDevChatRun();
|
||||
|
||||
// Then asynchronously execute updateWorkflows
|
||||
await dcClient.updateWorkflows();
|
||||
await dcClient.updateCustomWorkflows();
|
||||
// Then asynchronously execute updateWorkflows
|
||||
await dcClient.updateWorkflows();
|
||||
await dcClient.updateCustomWorkflows();
|
||||
|
||||
await sendCommandListByDevChatRun();
|
||||
await sendCommandListByDevChatRun();
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the panel is activated
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit ed9898d038e09732bbcaba0ef655efc1f89ef9a8
|
||||
Subproject commit f4a4dbc529e4fc80f67a0492674854c6fb8a29d3
|
Loading…
x
Reference in New Issue
Block a user