commit eeb2775981b74f574aaf2e251825f0903ce971ad Author: Marcus Date: Sun May 26 02:29:08 2019 -0400 commit before 230 am marcus touches the code diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file diff --git a/core/aqua.js b/core/aqua.js new file mode 100644 index 0000000..761c4c9 --- /dev/null +++ b/core/aqua.js @@ -0,0 +1,69 @@ +#!/usr/bin/env node +const args = require('yargs').argv +const path = require('path'); +args.index = args.index || path.join(process.cwd(), 'index.js'); +args.cache = args.cache || path.join(process.cwd(), '.cache'); + +let index = platformPrecompile(); +index = compileParameters(index); + +/// Do all platform related things to the index file, like substituting +/// CLI arguments, and converting from a filepath to an actual index object. +// TODO make this also do dependencies +function platformPrecompile() { + // if its a path, require the file and create the object. + if(typeof args.index === 'string') { + args.index = require(args.index); + } + + const index = args.index; + + for(const key in args) { + if(key in index.Parameters) { + index.Parameters[key] = args[key]; + } + } + + 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 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 new file mode 100644 index 0000000..e69de29 diff --git a/core/system.js b/core/system.js new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json new file mode 100644 index 0000000..20fe466 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "aquatin", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/marcus13345/AquaTin.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/marcus13345/AquaTin/issues" + }, + "bin": { + "aqua": "core/aqua.js" + }, + "homepage": "https://github.com/marcus13345/AquaTin#readme", + "dependencies": { + "uuid": "^3.3.2", + "yargs": "^13.2.4" + } +} diff --git a/tests/modules/module.js b/tests/modules/module.js new file mode 100644 index 0000000..a639630 --- /dev/null +++ b/tests/modules/module.js @@ -0,0 +1,14 @@ + + +module.exports.entity = class module { + async OnStart() { + console.log('starting...'); + await new Promise(res => { + setTimeout(_ => { + console.log('done'); + res(); + }, 1000); + }) + } +} + diff --git a/tests/system/index.js b/tests/system/index.js new file mode 100644 index 0000000..e144721 --- /dev/null +++ b/tests/system/index.js @@ -0,0 +1,14 @@ +module.exports = { + Parameters: { + Source: './../modules/' + }, + Entities: { + Tester: { + Name: 'module', + From: '$Source', + Data: { + Thing: 5 + } + } + } +} \ No newline at end of file