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

View File

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

19
run.js
View File

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