Skip to content

Commit 8e64f2e

Browse files
CoderSerioxiejay97
authored andcommitted
fix(utils): adapte Windows-style and POSIX-style path separator
1 parent 7b05dad commit 8e64f2e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/base64-data.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let project = process.argv.find((arg) => arg.includes('--project'));
77
if (project) {
88
project = project.slice('--project='.length);
99
}
10-
const ROOT_PATH = path.join(__dirname, '..', project ? `packages/${project}` : '.');
10+
const ROOT_PATH = path.join(__dirname, '..', project ? `packages${path.sep}${project}` : '.');
1111
const OUT_FILE = 'base64.out.ts';
1212

1313
const table = createStream({
@@ -24,9 +24,12 @@ const reduceDir = (dirPath: string, paths: string[] = []) => {
2424
if (statSync(filePath).isDirectory()) {
2525
reduceDir(filePath, [...paths, file]);
2626
} else if (/^base64\.[\s\S]+\.[\s\S]+$/.test(file) && file !== OUT_FILE) {
27-
table.write([(filePath.match(/(?<=packages\/)[\s\S]+?(?=\/)/) as string[])?.[0], file]);
27+
const filePathReg = new RegExp(`(?<=packages\\${path.sep})[\\s\\S]+?(?=\\${path.sep})`);
28+
const targetPath = filePath.match(filePathReg) as string[];
29+
table.write([targetPath?.[0], file]);
2830
const bitmap = readFileSync(filePath, { encoding: 'base64' });
29-
output += String.raw` '${file.match(/(?<=\.)[\s\S]+(?=\.)/)![0]}': '${bitmap}',
31+
const fileMiddleName = file.match(/(?<=\.)[\s\S]+(?=\.)/) as string[];
32+
output += String.raw` '${fileMiddleName?.[0]}': '${bitmap}',
3033
`;
3134
}
3235
}

0 commit comments

Comments
 (0)