thinned cli entry point code
parent
c9c7157c65
commit
af55784d1a
69
core/aqua.js
69
core/aqua.js
|
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const {Signale} = require('signale');
|
const {Signale} = require('signale');
|
||||||
const log = new Signale();
|
const log = new Signale({
|
||||||
|
scope: 'CLI'
|
||||||
|
});
|
||||||
const interactive = new Signale({interactive: true});
|
const interactive = new Signale({interactive: true});
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
require('yargs')
|
require('yargs')
|
||||||
|
|
@ -32,21 +34,13 @@ async function cliCompile(args) {
|
||||||
console.log('things')
|
console.log('things')
|
||||||
const {compile} = require('./compiler.js');
|
const {compile} = require('./compiler.js');
|
||||||
if(!path.isAbsolute(args.index)) args.index = path.join(process.cwd(), 'index.js');
|
if(!path.isAbsolute(args.index)) args.index = path.join(process.cwd(), 'index.js');
|
||||||
if(!path.isAbsolute(args.cache)) args.cache = path.join(process.cwd(), 'index.js');
|
if(!path.isAbsolute(args.cache)) args.cache = path.join(process.cwd(), '.cache');
|
||||||
|
|
||||||
|
|
||||||
let index = platformPrecompile(args);
|
let index = platformPrecompile(args);
|
||||||
log.info('precompile completed');
|
log.info('precompile completed');
|
||||||
|
|
||||||
|
|
||||||
index = compileParameters(index);
|
|
||||||
log.info('parameters injected');
|
|
||||||
|
|
||||||
|
|
||||||
index = compileLinks(index);
|
|
||||||
log.info('entity links created')
|
|
||||||
|
|
||||||
|
|
||||||
compile({
|
compile({
|
||||||
index: index,
|
index: index,
|
||||||
cache: args.cache
|
cache: args.cache
|
||||||
|
|
@ -72,59 +66,4 @@ function platformPrecompile(args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function compileParameters (index) {
|
|
||||||
let entities = index.Entities;
|
|
||||||
|
|
||||||
for(const key in index.Parameters) {
|
|
||||||
entities = recursiveReplace(entities, `\$${key}`, index.Parameters[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
Entities: entities
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function compileLinks (index) {
|
|
||||||
// TODO implement links
|
|
||||||
|
|
||||||
let entities = index.Entities;
|
|
||||||
|
|
||||||
for(const key in index.Parameters) {
|
|
||||||
entities = recursiveReplace(entities, `\$${key}`, index.Parameters[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
Entities: entities
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function recursiveReplace(obj, find, replace) {
|
|
||||||
switch(typeof obj) {
|
|
||||||
case 'string': {
|
|
||||||
if(obj === find) return replace;
|
|
||||||
else return obj;
|
|
||||||
}
|
|
||||||
case 'object': {
|
|
||||||
if(Array.isArray(obj)) {
|
|
||||||
const newArr = [];
|
|
||||||
for(const value of obj) {
|
|
||||||
newArr.push(recursiveReplace(value, find, replace));
|
|
||||||
}
|
|
||||||
return newArr;
|
|
||||||
} else {
|
|
||||||
const newObj = {};
|
|
||||||
for (const key in obj) {
|
|
||||||
newObj[key] = recursiveReplace(obj[key], find, replace);
|
|
||||||
}
|
|
||||||
return newObj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const {Signale} = require('signale');
|
||||||
|
const log = new Signale({
|
||||||
|
scope: 'CACHE'
|
||||||
|
});
|
||||||
|
|
||||||
module.exports.Cache = class Cache {
|
module.exports.Cache = class Cache {
|
||||||
constructor (basePath) {
|
constructor (basePath) {
|
||||||
|
|
@ -19,6 +23,8 @@ module.exports.Cache = class Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCache() {
|
loadCache() {
|
||||||
|
log.info(this.paths)
|
||||||
|
// if(fs.existsSync(this.paths.code))
|
||||||
for(let file of fs.readdirSync(this.paths.code)) {
|
for(let file of fs.readdirSync(this.paths.code)) {
|
||||||
// TODO like... do this
|
// TODO like... do this
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,32 @@
|
||||||
const {Cache} = require('./cache.js');
|
const {Cache} = require('./cache.js');
|
||||||
const {retrieveModule} = require('./retrieveModule.js');
|
const {retrieveModule} = require('./retrieveModule.js');
|
||||||
|
const {Signale} = require('signale');
|
||||||
|
const log = new Signale({
|
||||||
|
scope: 'COMPILER'
|
||||||
|
});
|
||||||
|
|
||||||
module.exports.compile = compile;
|
module.exports.compile = compile;
|
||||||
|
|
||||||
|
|
||||||
|
function compile({cache: cachePath, index}) {
|
||||||
|
index = compileParameters(index);
|
||||||
|
log.info('parameters injected');
|
||||||
|
|
||||||
|
|
||||||
|
index = compileLinks(index);
|
||||||
|
log.info('entity links created')
|
||||||
|
|
||||||
|
|
||||||
|
createCache({
|
||||||
|
index: index,
|
||||||
|
cache: cachePath
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// cache is the (likely path) string to describe where the cache is store
|
/// cache is the (likely path) string to describe where the cache is store
|
||||||
/// on the web this might be a database name for example.
|
/// on the web this might be a database name for example.
|
||||||
/// index, is the post pre compiled index.
|
/// index, is the post pre compiled index.
|
||||||
async function compile({cache: cachePath, index}) {
|
async function createCache({cache: cachePath, index}) {
|
||||||
const cache = new Cache(cachePath);
|
const cache = new Cache(cachePath);
|
||||||
// const modules = {};
|
// const modules = {};
|
||||||
|
|
||||||
|
|
@ -22,4 +40,59 @@ async function compile({cache: cachePath, index}) {
|
||||||
for(const symbol in index.Entities) {
|
for(const symbol in index.Entities) {
|
||||||
cache.addInstance(index.Entities[symbol]);
|
cache.addInstance(index.Entities[symbol]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function compileParameters (index) {
|
||||||
|
let entities = index.Entities;
|
||||||
|
|
||||||
|
for(const key in index.Parameters) {
|
||||||
|
entities = recursiveReplace(entities, `\$${key}`, index.Parameters[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
Entities: entities
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function compileLinks (index) {
|
||||||
|
// TODO implement links
|
||||||
|
|
||||||
|
let entities = index.Entities;
|
||||||
|
|
||||||
|
for(const key in index.Parameters) {
|
||||||
|
entities = recursiveReplace(entities, `\$${key}`, index.Parameters[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
Entities: entities
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function recursiveReplace(obj, find, replace) {
|
||||||
|
switch(typeof obj) {
|
||||||
|
case 'string': {
|
||||||
|
if(obj === find) return replace;
|
||||||
|
else return obj;
|
||||||
|
}
|
||||||
|
case 'object': {
|
||||||
|
if(Array.isArray(obj)) {
|
||||||
|
const newArr = [];
|
||||||
|
for(const value of obj) {
|
||||||
|
newArr.push(recursiveReplace(value, find, replace));
|
||||||
|
}
|
||||||
|
return newArr;
|
||||||
|
} else {
|
||||||
|
const newObj = {};
|
||||||
|
for (const key in obj) {
|
||||||
|
newObj[key] = recursiveReplace(obj[key], find, replace);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue