Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions cortex-js/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@ const os = require('os');
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const constants = require('./dist/src/infrastructure/constants/cortex.js')

const uninstall = async () => {
const cortexConfigPath = path.join(os.homedir(), '.cortexrc');
if (fs.existsSync(cortexConfigPath)) {
const content = await promises.readFile(cortexConfigPath, 'utf8');
const config = yaml.load(content);
if(!config) {
return;
}
const { dataFolderPath } = config;
const modelsFolderPath = path.join(dataFolderPath, 'models');
// remove all data in data folder path except models
const files = fs.readdirSync(dataFolderPath);
for (const file of files) {
const fileStat = fs.statSync(path.join(dataFolderPath, file));
if (file !== 'models') {
if (fileStat.isDirectory()) {
fs.rmSync(path.join(dataFolderPath, file), { recursive: true });
} else {
fs.unlinkSync(path.join(dataFolderPath, file));
}
}
const cortexConfigPath = path.join(os.homedir(), '.cortexrc');
if (fs.existsSync(cortexConfigPath)) {
const content = await promises.readFile(cortexConfigPath, 'utf8');
const config = yaml.load(content);
if(!config) {
return;
}
const { dataFolderPath, cortexCppHost, cortexCppPort, apiServerHost, apiServerPort } = config;

await fetch(constants.CORTEX_CPP_PROCESS_DESTROY_URL(cortexCppHost, cortexCppPort),
{ method: 'DELETE' })
.catch(() => {})
await fetch(constants.CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort),
{ method: 'DELETE' })
.catch(() => {})
// remove all data in data folder path except models
const modelsFolderPath = path.join(dataFolderPath, 'models');
const files = fs.readdirSync(dataFolderPath);
for (const file of files) {
const fileStat = fs.statSync(path.join(dataFolderPath, file));
if (file !== 'models') {
if (fileStat.isDirectory()) {
fs.rmSync(path.join(dataFolderPath, file), { recursive: true });
} else {
fs.unlinkSync(path.join(dataFolderPath, file));
}
}
}
}
};

uninstall();
uninstall();