From e0e2a3033799b3c517d1deed6fb1383124c2d375 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 15 Apr 2024 18:05:04 +0200 Subject: [PATCH] fix: handle relative paths in convert plugin (#34) * fix: handle relative paths in convert plugin * fix: update dist --- dist/index.js | 13 +++++++------ src/plugins/convert-chinese.ts | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 44c481d..24bfaa6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40287,15 +40287,16 @@ const getFiles = (directory, fileList = []) => __awaiter(void 0, void 0, void 0, /** * Module to convert Simplified Chinese files to Traditional Chinese. * - * @param {string[]} directories The directory to convert. + * @param {string[]} paths The directories and file paths to convert. */ -const convertChinese = (directories) => __awaiter(void 0, void 0, void 0, function* () { +const convertChinese = (paths) => __awaiter(void 0, void 0, void 0, function* () { console.info("Getting file list..."); - for (const directory of directories) { - const status = yield (0, promises_1.stat)(directory); + for (const relativePath of paths) { + const absolutePath = (0, path_1.join)(process.cwd(), relativePath); + const status = yield (0, promises_1.stat)(absolutePath); const files = status.isDirectory() - ? yield getFiles((0, path_1.join)(process.cwd(), directory)) - : [directory]; + ? yield getFiles(absolutePath) + : [absolutePath]; for (const file of files) { console.info(`Converting ${file}...`); const fileText = yield (0, promises_1.readFile)(file, "utf-8"); diff --git a/src/plugins/convert-chinese.ts b/src/plugins/convert-chinese.ts index 4405cf3..7b5ae52 100644 --- a/src/plugins/convert-chinese.ts +++ b/src/plugins/convert-chinese.ts @@ -21,15 +21,16 @@ const getFiles = async (directory: string, fileList: string[] = []) => { /** * Module to convert Simplified Chinese files to Traditional Chinese. * - * @param {string[]} directories The directory to convert. + * @param {string[]} paths The directories and file paths to convert. */ -export const convertChinese = async (directories: string[]) => { +export const convertChinese = async (paths: string[]) => { console.info("Getting file list..."); - for (const directory of directories) { - const status = await stat(directory); + for (const relativePath of paths) { + const absolutePath = join(process.cwd(), relativePath); + const status = await stat(absolutePath); const files = status.isDirectory() - ? await getFiles(join(process.cwd(), directory)) - : [directory]; + ? await getFiles(absolutePath) + : [absolutePath]; for (const file of files) { console.info(`Converting ${file}...`); const fileText = await readFile(file, "utf-8");