diff --git a/core/aqua.js b/core/aqua.js index cc5c264..fee82b3 100644 --- a/core/aqua.js +++ b/core/aqua.js @@ -1,6 +1,8 @@ #!/usr/bin/env node const {Signale} = require('signale'); -const log = new Signale(); +const log = new Signale({ + scope: 'CLI' +}); const interactive = new Signale({interactive: true}); const path = require('path'); require('yargs') @@ -32,21 +34,13 @@ async function cliCompile(args) { console.log('things') const {compile} = require('./compiler.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); log.info('precompile completed'); - - index = compileParameters(index); - log.info('parameters injected'); - - index = compileLinks(index); - log.info('entity links created') - - compile({ index: index, cache: args.cache @@ -72,59 +66,4 @@ function platformPrecompile(args) { } 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; - } - } } \ No newline at end of file diff --git a/core/cache.js b/core/cache.js index c09c5ea..c84d329 100644 --- a/core/cache.js +++ b/core/cache.js @@ -1,5 +1,9 @@ const fs = require('fs'); const path = require('path'); +const {Signale} = require('signale'); +const log = new Signale({ + scope: 'CACHE' +}); module.exports.Cache = class Cache { constructor (basePath) { @@ -19,6 +23,8 @@ module.exports.Cache = class Cache { } loadCache() { + log.info(this.paths) + // if(fs.existsSync(this.paths.code)) for(let file of fs.readdirSync(this.paths.code)) { // TODO like... do this } diff --git a/core/compiler.js b/core/compiler.js index aaf14ac..a32f2fe 100644 --- a/core/compiler.js +++ b/core/compiler.js @@ -1,14 +1,32 @@ const {Cache} = require('./cache.js'); const {retrieveModule} = require('./retrieveModule.js'); - +const {Signale} = require('signale'); +const log = new Signale({ + scope: 'COMPILER' +}); 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 /// on the web this might be a database name for example. /// 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 modules = {}; @@ -22,4 +40,59 @@ async function compile({cache: cachePath, index}) { for(const symbol in index.Entities) { 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; + } + } } \ No newline at end of file