mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-13 01:22:11 +00:00
build(gen-parser-map): Replace glob with built-in readdirSync (#1065)
This commit is contained in:
@@ -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';`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user