@kentwynn/kgraph 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { rm } from 'node:fs/promises';
|
|
1
|
+
import { readdir, rm, rmdir } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { loadConfig } from '../../config/config.js';
|
|
4
4
|
import { removeIntegrations } from '../../integrations/integration-store.js';
|
|
5
5
|
import { pathExists, resolveWorkspace } from '../../storage/kgraph-paths.js';
|
|
6
6
|
import { runCommand } from '../errors.js';
|
|
7
7
|
const LEGACY_GENERATED_FILES = [
|
|
8
|
+
'.agents/generated/kgraph.md',
|
|
8
9
|
'.github/agents/kgraph.agent.md',
|
|
9
10
|
'.github/kgraph.agent.md',
|
|
10
11
|
];
|
|
@@ -44,7 +45,26 @@ export function registerUninstallCommand(program) {
|
|
|
44
45
|
}));
|
|
45
46
|
}
|
|
46
47
|
async function removeLegacyGeneratedFiles(rootPath) {
|
|
47
|
-
|
|
48
|
+
for (const filePath of LEGACY_GENERATED_FILES) {
|
|
49
|
+
const fullPath = path.join(rootPath, filePath);
|
|
50
|
+
await rm(fullPath, { force: true });
|
|
51
|
+
await pruneEmptyParents(rootPath, path.dirname(fullPath));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function pruneEmptyParents(rootPath, startDir) {
|
|
55
|
+
let dir = startDir;
|
|
56
|
+
while (dir !== rootPath && dir.startsWith(rootPath)) {
|
|
57
|
+
try {
|
|
58
|
+
const entries = await readdir(dir);
|
|
59
|
+
if (entries.length > 0)
|
|
60
|
+
break;
|
|
61
|
+
await rmdir(dir);
|
|
62
|
+
dir = path.dirname(dir);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
48
68
|
}
|
|
49
69
|
function printUninstallPreview(input) {
|
|
50
70
|
console.log('KGraph Uninstall Preview');
|
|
@@ -98,6 +98,7 @@ async function removeIntegrationInstructions(rootPath, targetPath, integrationNa
|
|
|
98
98
|
const next = removeManagedBlock(existing, integrationName);
|
|
99
99
|
if (next.trim().length === 0) {
|
|
100
100
|
await rm(fullPath, { force: true });
|
|
101
|
+
await pruneEmptyParents(rootPath, path.dirname(fullPath));
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
104
|
await writeFile(fullPath, next, 'utf8');
|
|
@@ -114,19 +115,21 @@ async function removeIntegrationCommandFiles(rootPath, files) {
|
|
|
114
115
|
const filePath = typeof file === 'string' ? file : file.path;
|
|
115
116
|
const fullPath = path.join(rootPath, filePath);
|
|
116
117
|
await rm(fullPath, { force: true, recursive: true });
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
118
|
+
await pruneEmptyParents(rootPath, path.dirname(fullPath));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function pruneEmptyParents(rootPath, startDir) {
|
|
122
|
+
let dir = startDir;
|
|
123
|
+
while (dir !== rootPath && dir.startsWith(rootPath)) {
|
|
124
|
+
try {
|
|
125
|
+
const entries = await readdir(dir);
|
|
126
|
+
if (entries.length > 0)
|
|
128
127
|
break;
|
|
129
|
-
|
|
128
|
+
await rmdir(dir);
|
|
129
|
+
dir = path.dirname(dir);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
break;
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
}
|