This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues/pull-requests.
vogue/src/run.ts

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-05-02 17:42:04 -04:00
#!/usr/bin/env node
2021-05-16 20:41:45 -04:00
import debug from 'debug';
const log = debug('vogue:cli');
const systemLocation = resolve(process.argv[2]);
2021-05-02 17:42:04 -04:00
import { parse, resolve, dirname } from 'path';
2021-05-16 20:41:45 -04:00
import { readdirSync, lstatSync } from 'fs';
2021-05-10 23:13:17 -04:00
2021-05-06 23:05:36 -04:00
import _ from 'lodash';
2021-05-20 00:19:25 -04:00
import Module from './Module';
import System from './System';
import './extensions.js';
import { fileURLToPath } from 'url';
2021-05-06 09:33:28 -04:00
// globals inside grammar context
2021-05-20 00:19:25 -04:00
import minify from './minify';
2021-05-02 17:42:04 -04:00
const { get, set } = _;
const standardLibrary = resolve(fileURLToPath(dirname(import.meta.url)), 'lib');
2021-05-02 17:42:04 -04:00
2021-05-06 23:05:36 -04:00
(async () => {
// TODO simplify this line gaddam
2021-05-20 00:19:25 -04:00
const ignoreDeps = (path: string) => parse(path).name !== 'node_modules';
const files = [
...walkdirSync(systemLocation, ignoreDeps),
...walkdirSync(standardLibrary, ignoreDeps)
];
2021-05-16 20:41:45 -04:00
const fullpaths = files
.filter(v => lstatSync(v).isFile())
.filter(v => parse(v).ext === '.v');
log('included modules');
log(files);
log('parsing modules...');
2021-05-16 20:41:45 -04:00
const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation)));
2021-05-16 20:41:45 -04:00
const sys = new System(modules, systemLocation);
2021-05-06 23:05:36 -04:00
})()
2021-05-20 00:19:25 -04:00
function walkdirSync(root: string, filter: ((path: string) => boolean) = () => true): string[] {
log('reading', root, '...');
const paths = readdirSync(root).map(v => resolve(root, v));
2021-05-20 00:19:25 -04:00
const [ files, dirs ] = sift(paths.filter(filter), (v: string) => 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
];
}
2021-05-20 00:19:25 -04:00
function sift<T>(a: T[], fn: (v: T, i: number, a: T[]) => boolean): [T[], T[]] {
let left: T[] = [], right: T[] = [];
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];
}