From 26e30038e2aa7cc71cb4ca003d2b48bf6e607822 Mon Sep 17 00:00:00 2001 From: CoderSerio <2779066456@qq.com> Date: Fri, 31 May 2024 14:51:35 +0800 Subject: [PATCH 1/2] fix(utils): unable to start on Windows11 --- tools/base64-data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/base64-data.ts b/tools/base64-data.ts index 8a1419c3..0a1ad7d5 100644 --- a/tools/base64-data.ts +++ b/tools/base64-data.ts @@ -24,7 +24,7 @@ const reduceDir = (dirPath: string, paths: string[] = []) => { if (statSync(filePath).isDirectory()) { reduceDir(filePath, [...paths, file]); } else if (/^base64\.[\s\S]+\.[\s\S]+$/.test(file) && file !== OUT_FILE) { - table.write([filePath.match(/(?<=packages\/)[\s\S]+?(?=\/)/)![0], file]); + table.write([(filePath.match(/(?<=packages\/)[\s\S]+?(?=\/)/) as string[])?.[0], file]); const bitmap = readFileSync(filePath, { encoding: 'base64' }); output += String.raw` '${file.match(/(?<=\.)[\s\S]+(?=\.)/)![0]}': '${bitmap}', `; From ca94cec10c18f2ffce15a25e68e905ad30613c6f Mon Sep 17 00:00:00 2001 From: CoderSerio <2779066456@qq.com> Date: Sun, 2 Jun 2024 23:17:42 +0800 Subject: [PATCH 2/2] fix(utils): adapte Windows-style and POSIX-style path separator --- tools/base64-data.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/base64-data.ts b/tools/base64-data.ts index 0a1ad7d5..97e09082 100644 --- a/tools/base64-data.ts +++ b/tools/base64-data.ts @@ -7,7 +7,7 @@ let project = process.argv.find((arg) => arg.includes('--project')); if (project) { project = project.slice('--project='.length); } -const ROOT_PATH = path.join(__dirname, '..', project ? `packages/${project}` : '.'); +const ROOT_PATH = path.join(__dirname, '..', project ? `packages${path.sep}${project}` : '.'); const OUT_FILE = 'base64.out.ts'; const table = createStream({ @@ -24,9 +24,12 @@ const reduceDir = (dirPath: string, paths: string[] = []) => { if (statSync(filePath).isDirectory()) { reduceDir(filePath, [...paths, file]); } else if (/^base64\.[\s\S]+\.[\s\S]+$/.test(file) && file !== OUT_FILE) { - table.write([(filePath.match(/(?<=packages\/)[\s\S]+?(?=\/)/) as string[])?.[0], file]); + const filePathReg = new RegExp(`(?<=packages\\${path.sep})[\\s\\S]+?(?=\\${path.sep})`); + const targetPath = filePath.match(filePathReg) as string[]; + table.write([targetPath?.[0], file]); const bitmap = readFileSync(filePath, { encoding: 'base64' }); - output += String.raw` '${file.match(/(?<=\.)[\s\S]+(?=\.)/)![0]}': '${bitmap}', + const fileMiddleName = file.match(/(?<=\.)[\s\S]+(?=\.)/) as string[]; + output += String.raw` '${fileMiddleName?.[0]}': '${bitmap}', `; } }