@@ -3,30 +3,38 @@ const os = require('os');
33const fs = require ( 'fs' ) ;
44const path = require ( 'path' ) ;
55const yaml = require ( 'js-yaml' ) ;
6+ const constants = require ( './dist/src/infrastructure/constants/cortex.js' )
67
78const uninstall = async ( ) => {
8- const cortexConfigPath = path . join ( os . homedir ( ) , '.cortexrc' ) ;
9- if ( fs . existsSync ( cortexConfigPath ) ) {
10- const content = await promises . readFile ( cortexConfigPath , 'utf8' ) ;
11- const config = yaml . load ( content ) ;
12- if ( ! config ) {
13- return ;
14- }
15- const { dataFolderPath } = config ;
16- const modelsFolderPath = path . join ( dataFolderPath , 'models' ) ;
17- // remove all data in data folder path except models
18- const files = fs . readdirSync ( dataFolderPath ) ;
19- for ( const file of files ) {
20- const fileStat = fs . statSync ( path . join ( dataFolderPath , file ) ) ;
21- if ( file !== 'models' ) {
22- if ( fileStat . isDirectory ( ) ) {
23- fs . rmSync ( path . join ( dataFolderPath , file ) , { recursive : true } ) ;
24- } else {
25- fs . unlinkSync ( path . join ( dataFolderPath , file ) ) ;
26- }
27- }
9+ const cortexConfigPath = path . join ( os . homedir ( ) , '.cortexrc' ) ;
10+ if ( fs . existsSync ( cortexConfigPath ) ) {
11+ const content = await promises . readFile ( cortexConfigPath , 'utf8' ) ;
12+ const config = yaml . load ( content ) ;
13+ if ( ! config ) {
14+ return ;
15+ }
16+ const { dataFolderPath, cortexCppHost, cortexCppPort, apiServerHost, apiServerPort } = config ;
17+
18+ await fetch ( constants . CORTEX_CPP_PROCESS_DESTROY_URL ( cortexCppHost , cortexCppPort ) ,
19+ { method : 'DELETE' } )
20+ . catch ( ( ) => { } )
21+ await fetch ( constants . CORTEX_JS_SYSTEM_URL ( apiServerHost , apiServerPort ) ,
22+ { method : 'DELETE' } )
23+ . catch ( ( ) => { } )
24+ // remove all data in data folder path except models
25+ const modelsFolderPath = path . join ( dataFolderPath , 'models' ) ;
26+ const files = fs . readdirSync ( dataFolderPath ) ;
27+ for ( const file of files ) {
28+ const fileStat = fs . statSync ( path . join ( dataFolderPath , file ) ) ;
29+ if ( file !== 'models' ) {
30+ if ( fileStat . isDirectory ( ) ) {
31+ fs . rmSync ( path . join ( dataFolderPath , file ) , { recursive : true } ) ;
32+ } else {
33+ fs . unlinkSync ( path . join ( dataFolderPath , file ) ) ;
2834 }
35+ }
2936 }
37+ }
3038} ;
3139
32- uninstall ( ) ;
40+ uninstall ( ) ;
0 commit comments