Skip to content

Commit

Permalink
fix(utils): adapte Windows-style and POSIX-style path separator
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderSerio authored and xiejay97 committed Jun 2, 2024
1 parent 7b05dad commit 8e64f2e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/base64-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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}',
`;
}
}
Expand Down

0 comments on commit 8e64f2e

Please sign in to comment.