diff --git a/dist/index.js b/dist/index.js index f74274b..ea4588d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40584,49 +40584,28 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.lowercaseDirectories = void 0; const promises_1 = __nccwpck_require__(3292); const path_1 = __nccwpck_require__(1017); -function readAllFiles(dir) { +// Recursive function to process directories and subdirectories +function lowerCaseSubDirectories(dir) { return __awaiter(this, void 0, void 0, function* () { const files = yield (0, promises_1.readdir)(dir, { withFileTypes: true }); - let allFiles = []; for (const file of files) { - const filePath = (0, path_1.join)(dir, file.name); if (file.isDirectory()) { - const subFiles = yield readAllFiles(filePath); - allFiles = allFiles.concat(subFiles); - } - else { - allFiles.push(filePath); + const filePath = (0, path_1.join)(dir, file.name); + const newFilePath = (0, path_1.join)(dir, file.name.toLowerCase()); + console.log(`Renaming directory ${filePath} to ${newFilePath}`); + yield (0, promises_1.rename)(filePath, newFilePath); + yield lowerCaseSubDirectories(newFilePath); } } - return allFiles; }); } -// Recursive function to process directories and subdirectories -const processDirectory = (dirPath) => __awaiter(void 0, void 0, void 0, function* () { - // Get all files recursively - const allFiles = yield readAllFiles(dirPath); - // Lowercase directory names - for (const filePath of allFiles) { - const dirPath = filePath.split("/").slice(0, -1).join("/"); - const dirName = filePath.split("/").pop(); - const lowercasedDirName = dirName === null || dirName === void 0 ? void 0 : dirName.toLowerCase(); - if (lowercasedDirName === undefined) { - throw new Error("Lowercased DirName Required"); - } - if (lowercasedDirName !== dirName) { - const newPath = (0, path_1.join)(dirPath, lowercasedDirName); - console.log(`Renaming directory ${filePath} to ${newPath}`); - yield (0, promises_1.rename)(filePath, newPath); - } - } -}); /** * * @param {string} directory The directory tree that must be sorted through. */ const lowercaseDirectories = (directory) => { console.info("Getting directory list..."); - processDirectory(directory); + lowerCaseSubDirectories(directory); }; exports.lowercaseDirectories = lowercaseDirectories; diff --git a/src/plugins/lowercase-directories.ts b/src/plugins/lowercase-directories.ts index 5a34150..ab0d3f8 100644 --- a/src/plugins/lowercase-directories.ts +++ b/src/plugins/lowercase-directories.ts @@ -2,42 +2,20 @@ import { Dirent } from "fs"; import { readdir, rename } from "fs/promises"; import { join } from "path"; -async function readAllFiles(dir: string): Promise { +// Recursive function to process directories and subdirectories +async function lowerCaseSubDirectories(dir: string): Promise { const files: Dirent[] = await readdir(dir, { withFileTypes: true }); - let allFiles: string[] = []; for (const file of files) { - const filePath = join(dir, file.name); if (file.isDirectory()) { - const subFiles = await readAllFiles(filePath); - allFiles = allFiles.concat(subFiles); - } else { - allFiles.push(filePath); - } - } - return allFiles; -} - -// Recursive function to process directories and subdirectories -const processDirectory = async (dirPath: string) => { - // Get all files recursively - const allFiles = await readAllFiles(dirPath); - - // Lowercase directory names - for (const filePath of allFiles) { - const dirPath = filePath.split("/").slice(0, -1).join("/"); - const dirName = filePath.split("/").pop(); - const lowercasedDirName = dirName?.toLowerCase(); - if (lowercasedDirName === undefined) { - throw new Error("Lowercased DirName Required"); - } + const filePath = join(dir, file.name); + const newFilePath = join(dir, file.name.toLowerCase()); - if (lowercasedDirName !== dirName) { - const newPath = join(dirPath, lowercasedDirName); - console.log(`Renaming directory ${filePath} to ${newPath}`); - await rename(filePath, newPath); + console.log(`Renaming directory ${filePath} to ${newFilePath}`); + await rename(filePath, newFilePath); + await lowerCaseSubDirectories(newFilePath); } } -}; +} /** * @@ -45,5 +23,5 @@ const processDirectory = async (dirPath: string) => { */ export const lowercaseDirectories = (directory: string) => { console.info("Getting directory list..."); - processDirectory(directory); + lowerCaseSubDirectories(directory); };