use vogue from outside repo

sdl
Bronwen 2021-05-16 20:41:45 -04:00
parent 502173e32b
commit c85ee41c21
3 changed files with 22 additions and 12 deletions

View File

@ -1,6 +1,8 @@
import createAst from './createAst.js'
import path from 'path';
import debug from 'debug';
import { createRequire } from 'module';
import { pathToFileURL } from 'url';
const log = debug('vogue:module');
export default class Module {
@ -55,7 +57,11 @@ export default class Module {
}
async import({importName, name}) {
const imported = await import(importName);
const nodePath = path.resolve(this.rootDir, 'node_module');
log('#'.repeat(80));
log(nodePath);
const __require__ = createRequire(nodePath);
const imported = __require__(importName);
if('default' in imported) this.imports[name] = imported.default;
else this.imports[name] = imported;
}
@ -64,15 +70,15 @@ export default class Module {
this.variables[persist ? 'cold' : 'warm'].push(name);
}
static async create(location) {
static async create(location, rootDir) {
const module = new Module();
const ast = createAst(location);
const name = path.parse(location).name;
module.name.last = name;
module.name.full = name;
module.rootDir = rootDir;
// move module whole loop ass bitch into module.
for (const item of ast) {
if ('name' in item) {
if(item.name in module.identifiers)

View File

@ -13,12 +13,13 @@ export default class System extends Serializable {
namespace = null;
staticInstances = {};
constructor(modules, location = '.running') {
constructor(modules, rootDir) {
super();
this.modules = modules;
this.createNamespace();
const bootModules = this.deriveBootModules();
this.createStaticInstances();
this.rootDir = rootDir;
log('instantiating boot modules...');
for(const name of bootModules) {

19
run.js
View File

@ -1,28 +1,31 @@
#!/usr/bin/env node
import debug from 'debug';
const log = debug('vogue:cli');
const systemLocation = resolve(process.argv[2]);
import { resolve } from 'path';
import { readdirSync } from 'fs';
import { parse, resolve } from 'path';
import { readdirSync, lstatSync } from 'fs';
import _ from 'lodash';
import Module from './Module.js';
import System from './System.js';
import debug from 'debug';
import './extensions.js';
// globals inside grammar context
import minify from './minify.js';
const { get, set } = _;
const log = debug('vogue:cli');
const systemLocation = resolve(process.argv[2]);
(async () => {
// TODO simplify this line gaddam
log('reading', systemLocation, '...');
const files = readdirSync(systemLocation);
const fullpaths = files.map(v => resolve(systemLocation, v));
const fullpaths = files
.map(v => resolve(systemLocation, v))
.filter(v => lstatSync(v).isFile())
.filter(v => parse(v).ext === '.v');
for(const path of fullpaths) log(path);
log('parsing modules...');
const modules = await Promise.all(fullpaths.map(loc => Module.create(loc)));
const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation)));
// const modules =
// (await Promise.all(
@ -35,5 +38,5 @@ const systemLocation = resolve(process.argv[2]);
// return acc;
// }, {});
const sys = new System(modules);
const sys = new System(modules, systemLocation);
})()