basic run implementation with start invocations
parent
775f16ab62
commit
860c550904
23
core/aqua.js
23
core/aqua.js
|
|
@ -3,7 +3,6 @@ const {Signale} = require('signale');
|
|||
const log = new Signale({
|
||||
scope: 'CLI'
|
||||
});
|
||||
const interactive = new Signale({interactive: true});
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
|
|
@ -24,19 +23,35 @@ require('yargs')
|
|||
})
|
||||
}, cliCompile)
|
||||
|
||||
.command('run [paramaters]', 'executes a cache', (yargs) => {
|
||||
yargs.option('cache', {
|
||||
type: 'string',
|
||||
default: '.cache',
|
||||
describe: 'path of the cache'
|
||||
})
|
||||
}, cliRun)
|
||||
|
||||
.help()
|
||||
.argv;
|
||||
|
||||
return;
|
||||
|
||||
|
||||
async function cliRun(args) {
|
||||
const {Cache} = require('./cache.js');
|
||||
const {System} = require('./system.js')
|
||||
if(!path.isAbsolute(args.cache)) args.cache = path.join(process.cwd(), args.cache);
|
||||
const cache = new Cache(args.cache);
|
||||
new System(cache);
|
||||
}
|
||||
|
||||
|
||||
/// this is the base compile function, that the CLI directly calls.
|
||||
async function cliCompile(args) {
|
||||
const {compile} = require('./compiler.js');
|
||||
log.debug(path.isAbsolute(args.index));
|
||||
log.debug(args.index);
|
||||
log.debug(process.cwd());
|
||||
// log.debug(path.isAbsolute(args.index));
|
||||
// log.debug(args.index);
|
||||
// log.debug(process.cwd());
|
||||
if(!path.isAbsolute(args.index)) args.index = path.join(process.cwd(), args.index);
|
||||
if(!path.isAbsolute(args.cache)) args.cache = path.join(process.cwd(), args.cache);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ module.exports.Cache = class Cache {
|
|||
}
|
||||
|
||||
loadCache() {
|
||||
log.info(this.paths)
|
||||
// log.debug(this.paths)
|
||||
// if(fs.existsSync(this.paths.code))
|
||||
for(let file of fs.readdirSync(this.paths.code)) {
|
||||
// TODO like... do this
|
||||
|
|
@ -37,4 +37,20 @@ module.exports.Cache = class Cache {
|
|||
addInstance(instance) {
|
||||
fs.writeFileSync(path.join(this.paths.instances, `${instance._id}.json`), JSON.stringify(instance, null, 2));
|
||||
}
|
||||
|
||||
getInstances() {
|
||||
return fs.readdirSync(this.paths.instances).map((val) => {
|
||||
return val.split('.')[0];
|
||||
});
|
||||
}
|
||||
|
||||
getEntityCodePathFromUuid(uuid) {
|
||||
let instancePath = path.join(this.paths.instances, `${uuid}.json`);
|
||||
let codePath = path.join(this.paths.code, `${require(instancePath).Name}.js`);
|
||||
return codePath;
|
||||
}
|
||||
getDataFromUuid(uuid) {
|
||||
let instancePath = path.join(this.paths.instances, `${uuid}.json`);
|
||||
return require(instancePath).Data;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ const log = new Signale({
|
|||
module.exports.compile = compile;
|
||||
|
||||
|
||||
function compile({cache: cachePath, index}) {
|
||||
async function compile({cache: cachePath, index}) {
|
||||
index = compileParameters(index);
|
||||
log.info('parameters injected');
|
||||
|
||||
|
|
@ -18,10 +18,12 @@ function compile({cache: cachePath, index}) {
|
|||
log.info('entity links created')
|
||||
|
||||
|
||||
createCache({
|
||||
await createCache({
|
||||
index: index,
|
||||
cache: cachePath
|
||||
})
|
||||
});
|
||||
|
||||
log.info('cache created')
|
||||
}
|
||||
|
||||
/// cache is the (likely path) string to describe where the cache is store
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
const {Signale} = require('signale');
|
||||
const log = new Signale({
|
||||
scope: 'EXEC'
|
||||
});
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const uuid = require('uuid');
|
||||
|
||||
const timeout = 3000;
|
||||
const root = (typeof window === 'undefined' ? global : window)
|
||||
|
||||
module.exports.System = class System {
|
||||
constructor(cache) {
|
||||
this.cache = cache;
|
||||
this.entities = {};
|
||||
for(const uuid of cache.getInstances()) {
|
||||
this.send('Start', uuid)
|
||||
}
|
||||
}
|
||||
|
||||
async send(name, destination, options) {
|
||||
// log.debug(`sending ${name}`);
|
||||
|
||||
if(!(destination in this.entities))
|
||||
this.loadEntity(destination);
|
||||
|
||||
let a = require('./../tests/modules/module.js').entity
|
||||
let b = new a({});
|
||||
|
||||
if(name in this.entities[destination])
|
||||
this.entities[destination][name](options);
|
||||
|
||||
else if('*' in this.entities[destination])
|
||||
this.entities[destination]['*'](options);
|
||||
|
||||
else log.warn(`method ${name} does not exist for ${destination}`);
|
||||
}
|
||||
|
||||
loadEntity(uuid) {
|
||||
// log.debug(`spinning up ${uuid}`);
|
||||
if(typeof require === 'function') {
|
||||
let codePath = this.cache.getEntityCodePathFromUuid(uuid);
|
||||
// log.debug(codePath)
|
||||
let data = this.cache.getDataFromUuid(uuid);
|
||||
let entityProto = require(codePath).entity;
|
||||
this.entities[uuid] = new entityProto(data);
|
||||
} else {
|
||||
//TODO COMPLICATED EVAL SHIT, MIRRORING REQUIRE FUNCTIONALITY
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
module.exports.entity = class module {
|
||||
async OnStart() {
|
||||
async Start() {
|
||||
console.log('starting...');
|
||||
await new Promise(res => {
|
||||
setTimeout(_ => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue