build(gen-parser-map): Replace glob with built-in readdirSync (#1065)

This commit is contained in:
absidue
2025-10-12 18:02:47 +02:00
committed by GitHub
parent a9f19151b6
commit 44a5423ae7
3 changed files with 19 additions and 93 deletions

View File

@@ -1,4 +1,3 @@
import glob from 'glob';
import path from 'path';
import fs from 'fs';
import url from 'url';
@@ -8,18 +7,26 @@ const misc_imports = [];
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname })
.forEach((file) => {
// Trim path
const is_misc = file.includes('/misc/');
file = file.replace('../src/parser/classes/', '').replace('.js', '').replace('.ts', '');
const import_name = file.split('/').pop();
// Use case-insensitive sorting, to ensure the order stays consistent between runs
const collator = new Intl.Collator('en', { sensitivity: 'base' });
if (is_misc) {
const class_name = file.split('/').pop().replace('.js', '').replace('.ts', '');
misc_imports.push(`export { default as ${class_name} } from './classes/${file}.js';`);
} else {
import_list.push(`export { default as ${import_name} } from './classes/${file}.js';`);
fs.readdirSync(path.join(__dirname, '../src/parser/classes'), { recursive: true })
.sort((a, b) => collator.compare(a, b))
.forEach((file) => {
if (file.endsWith('.ts') || file.endsWith('.js')) {
// Convert Windows paths to posix ones
file = file.replaceAll('\\', '/')
// Trim path
const is_misc = file.startsWith('misc/');
file = file.replace('.js', '').replace('.ts', '');
const import_name = file.split('/').pop();
if (is_misc) {
misc_imports.push(`export { default as ${import_name} } from './classes/${file}.js';`);
} else {
import_list.push(`export { default as ${import_name} } from './classes/${file}.js';`);
}
}
});