promptgraph-mcp 2.3.3 → 2.3.5
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.
- package/github-import.js +34 -2
- package/package.json +1 -1
package/github-import.js
CHANGED
|
@@ -54,7 +54,7 @@ async function detectSkillsDirFromAPI(ownerRepo) {
|
|
|
54
54
|
const sub = await httpsGet(`https://api.github.com/repos/${ownerRepo}/contents/${dir.name}`);
|
|
55
55
|
const subEntries = JSON.parse(sub);
|
|
56
56
|
const mdCount = subEntries.filter(e => e.type === 'file' && e.name.endsWith('.md')).length;
|
|
57
|
-
if (mdCount >=
|
|
57
|
+
if (mdCount >= 1 && mdCount > bestCount) { best = dir.name; bestCount = mdCount; }
|
|
58
58
|
} catch {}
|
|
59
59
|
}
|
|
60
60
|
if (best) return { subdir: best, label: best };
|
|
@@ -97,6 +97,37 @@ function sparseClone(url, dest, subdir) {
|
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
// After full-clone root: remove files that are not skills and dirs we don't need
|
|
101
|
+
function cleanupRepoRoot(repoRoot) {
|
|
102
|
+
const SKIP_RE = /^(readme|changelog|license|contributing|code.of.conduct|security|authors|credits|install|installation|usage|promotion|faq|glossary|index|overview|summary|roadmap|todo|notes|template|example|sample|demo|guide|tutorial|walkthrough|architecture|design|spec|requirements|privacy|terms|disclaimer|notice|copying|warranty|funding)/i;
|
|
103
|
+
const SKIP_DIRS_LOCAL = new Set(['.github', 'docs', 'doc', 'assets', 'images', 'img', 'screenshots', 'media', 'static', 'scripts', 'ci_scripts', 'node_modules', 'vendor', 'dist', 'build', 'tests', 'test']);
|
|
104
|
+
|
|
105
|
+
let removed = 0;
|
|
106
|
+
const entries = fs.readdirSync(repoRoot, { withFileTypes: true });
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
if (entry.name === '.git') continue;
|
|
109
|
+
const fullPath = path.join(repoRoot, entry.name);
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
if (SKIP_DIRS_LOCAL.has(entry.name.toLowerCase())) {
|
|
112
|
+
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
113
|
+
removed++;
|
|
114
|
+
}
|
|
115
|
+
} else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
116
|
+
const base = entry.name.replace(/\.md$/i, '').toLowerCase();
|
|
117
|
+
if (SKIP_RE.test(base)) {
|
|
118
|
+
fs.unlinkSync(fullPath);
|
|
119
|
+
removed++;
|
|
120
|
+
}
|
|
121
|
+
} else if (entry.isFile() && !entry.name.endsWith('.md')) {
|
|
122
|
+
// Remove non-md files (gitignore, LICENSE, Makefile, etc.) — keep only .md
|
|
123
|
+
if (entry.name !== '.gitignore') {
|
|
124
|
+
try { fs.unlinkSync(fullPath); removed++; } catch {}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (removed > 0) console.log(`Cleaned up ${removed} non-skill files/dirs from root`);
|
|
129
|
+
}
|
|
130
|
+
|
|
100
131
|
// Update sparse repo — fetch + reset
|
|
101
132
|
function sparseUpdate(dest, subdir) {
|
|
102
133
|
const fetch = git(['fetch', '--depth=1', 'origin'], dest);
|
|
@@ -132,7 +163,7 @@ function detectSkillsDirLocal(repoRoot) {
|
|
|
132
163
|
const candidate = path.join(repoRoot, dir);
|
|
133
164
|
if (fs.existsSync(candidate)) {
|
|
134
165
|
const files = globSync(`${candidate}/**/*.md`);
|
|
135
|
-
if (files.length >=
|
|
166
|
+
if (files.length >= 1) return { dir: candidate, label: dir, sparse: true };
|
|
136
167
|
}
|
|
137
168
|
}
|
|
138
169
|
return { dir: repoRoot, label: '(root)', sparse: false };
|
|
@@ -182,6 +213,7 @@ export async function importFromGitHub(repoUrl) {
|
|
|
182
213
|
} else {
|
|
183
214
|
console.log(`no subdir found, cloning root...`);
|
|
184
215
|
cloneOk = fullClone(url, dest);
|
|
216
|
+
if (cloneOk) cleanupRepoRoot(dest);
|
|
185
217
|
}
|
|
186
218
|
|
|
187
219
|
if (!cloneOk) throw new Error(`Clone failed for ${url}`);
|