Ajoute un outil de gestion interactive des liens morts
This commit is contained in:
@@ -92,6 +92,77 @@ async function resolveMarkdownTargets(inputs, { rootDir = process.cwd(), skipInd
|
||||
return Array.from(targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collecte tous les fichiers correspondant a une liste d'extensions.
|
||||
* @param {string} rootDir Racine a parcourir.
|
||||
* @param {string[]} extensions Extensions attendues, avec le point.
|
||||
* @param {{ skipDirs?: string[] }} options Options de parcours.
|
||||
* @returns {Promise<string[]>} Fichiers trouves, tries par chemin.
|
||||
*/
|
||||
async function collectFilesByExtensions(rootDir, extensions, options = {}) {
|
||||
const normalizedExtensions = new Set();
|
||||
for (const extension of extensions) {
|
||||
if (typeof extension !== "string") {
|
||||
continue;
|
||||
}
|
||||
const candidate = extension.trim().toLowerCase();
|
||||
if (!candidate) {
|
||||
continue;
|
||||
}
|
||||
normalizedExtensions.add(candidate);
|
||||
}
|
||||
|
||||
if (normalizedExtensions.size === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const skipDirs = new Set([".git", "node_modules"]);
|
||||
if (Array.isArray(options.skipDirs)) {
|
||||
for (const directoryName of options.skipDirs) {
|
||||
if (typeof directoryName !== "string") {
|
||||
continue;
|
||||
}
|
||||
const candidate = directoryName.trim();
|
||||
if (!candidate) {
|
||||
continue;
|
||||
}
|
||||
skipDirs.add(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
const files = [];
|
||||
await walk(rootDir);
|
||||
files.sort((a, b) => a.localeCompare(b));
|
||||
return files;
|
||||
|
||||
async function walk(currentDir) {
|
||||
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(currentDir, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
if (skipDirs.has(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
await walk(fullPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entry.isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const extension = path.extname(entry.name).toLowerCase();
|
||||
if (!normalizedExtensions.has(extension)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
files.push(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function collectBundles(rootDir) {
|
||||
const bundles = [];
|
||||
await walk(rootDir, rootDir, bundles);
|
||||
@@ -140,5 +211,6 @@ module.exports = {
|
||||
collectMarkdownFiles,
|
||||
collectSectionIndexDirs,
|
||||
resolveMarkdownTargets,
|
||||
collectFilesByExtensions,
|
||||
collectBundles,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user