recursively readdir for module acquisition. Closes #17
parent
c089b279e2
commit
9aa7ac1cb8
42
run.js
42
run.js
|
|
@ -19,17 +19,51 @@ const standardLibrary = resolve(fileURLToPath(dirname(import.meta.url)), 'lib');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// TODO simplify this line gaddam
|
// TODO simplify this line gaddam
|
||||||
log('reading', systemLocation, '...');
|
const ignoreDeps = (path) => parse(path).name !== 'node_modules';
|
||||||
|
|
||||||
const files = [
|
const files = [
|
||||||
...readdirSync(systemLocation).map(v => resolve(systemLocation, v)),
|
...walkdirSync(systemLocation, ignoreDeps),
|
||||||
...readdirSync(standardLibrary).map(v => resolve(standardLibrary, v))
|
...walkdirSync(standardLibrary, ignoreDeps)
|
||||||
];
|
];
|
||||||
const fullpaths = files
|
const fullpaths = files
|
||||||
.filter(v => lstatSync(v).isFile())
|
.filter(v => lstatSync(v).isFile())
|
||||||
.filter(v => parse(v).ext === '.v');
|
.filter(v => parse(v).ext === '.v');
|
||||||
for(const path of fullpaths) log(path);
|
log('included modules');
|
||||||
|
log(files);
|
||||||
|
|
||||||
log('parsing modules...');
|
log('parsing modules...');
|
||||||
const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation)));
|
const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation)));
|
||||||
|
|
||||||
const sys = new System(modules, systemLocation);
|
const sys = new System(modules, systemLocation);
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
function walkdirSync(root, filter = () => true) {
|
||||||
|
log('reading', root, '...');
|
||||||
|
const paths = readdirSync(root).map(v => resolve(root, v));
|
||||||
|
const [ files, dirs ] = sift(paths.filter(filter), (v) => lstatSync(v).isFile());
|
||||||
|
log(`files: ${files.length} | dirs: ${dirs.length}`);
|
||||||
|
const rfiles = dirs.map(v => walkdirSync(v, filter)).reduce((a, v) => [...a, ...v], []);
|
||||||
|
|
||||||
|
return [
|
||||||
|
...files,
|
||||||
|
...rfiles
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {T[]} a
|
||||||
|
* @param {(v: T, i: number, a: T[]) => string} fn
|
||||||
|
*
|
||||||
|
* @returns {Object<string, T[]>}
|
||||||
|
*/
|
||||||
|
function sift(a, fn) {
|
||||||
|
let left = [], right = [];
|
||||||
|
for(let i = 0; i < a.length; i ++) {
|
||||||
|
const v = a[i]
|
||||||
|
const lr = !!fn(v, i, a);
|
||||||
|
if(lr) left = [...left, v];
|
||||||
|
else right = [...right, v];
|
||||||
|
}
|
||||||
|
return [left, right];
|
||||||
|
}
|
||||||
Reference in New Issue