better yargs implementation
parent
6a589ad991
commit
c9c7157c65
64
core/aqua.js
64
core/aqua.js
|
|
@ -1,29 +1,63 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const args = require('yargs').argv
|
const {Signale} = require('signale');
|
||||||
|
const log = new Signale();
|
||||||
|
const interactive = new Signale({interactive: true});
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {compile} = require('./compiler.js');
|
require('yargs')
|
||||||
args.index = args.index || path.join(process.cwd(), 'index.js');
|
.scriptName("aqua")
|
||||||
args.cache = args.cache || path.join(process.cwd(), '.cache');
|
.usage('$0 <cmd> [args]')
|
||||||
|
|
||||||
console.log('a')
|
.command('compile [paramaters]', 'compiles a system into a cache', (yargs) => {
|
||||||
let index = platformPrecompile();
|
yargs.option('cache', {
|
||||||
console.log('a')
|
type: 'string',
|
||||||
index = compileParameters(index);
|
default: '.cache',
|
||||||
console.log('a')
|
describe: 'path of the cache'
|
||||||
index = compileLinks(index);
|
})
|
||||||
console.log('a')
|
yargs.option('index', {
|
||||||
|
type: 'string',
|
||||||
|
default: 'index.js',
|
||||||
|
describe: 'path to the system index'
|
||||||
|
})
|
||||||
|
}, cliCompile)
|
||||||
|
|
||||||
compile({
|
.help()
|
||||||
|
.argv;
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// this is the base compile function, that the CLI directly calls.
|
||||||
|
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');
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
index: index,
|
||||||
cache: args.cache
|
cache: args.cache
|
||||||
})
|
})
|
||||||
console.log('a')
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Do all platform related things to the index file, like substituting
|
/// Do all platform related things to the index file, like substituting
|
||||||
/// CLI arguments, and converting from a filepath to an actual index object.
|
/// CLI arguments, and converting from a filepath to an actual index object.
|
||||||
// TODO make this also do dependencies
|
// TODO make this also do dependencies
|
||||||
function platformPrecompile() {
|
function platformPrecompile(args) {
|
||||||
// if its a path, require the file and create the object.
|
// if its a path, require the file and create the object.
|
||||||
if(typeof args.index === 'string') {
|
if(typeof args.index === 'string') {
|
||||||
args.index = require(args.index);
|
args.index = require(args.index);
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,10 @@ module.exports.Cache = class Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
addEntity(name, code) {
|
addEntity(name, code) {
|
||||||
console.log(`writing ${name}...`);
|
|
||||||
fs.writeFileSync(path.join(this.paths.code, `${name}.js`), code);
|
fs.writeFileSync(path.join(this.paths.code, `${name}.js`), code);
|
||||||
}
|
}
|
||||||
|
|
||||||
addInstance(instance) {
|
addInstance(instance) {
|
||||||
console.log(`writing ${instance}...`);
|
|
||||||
fs.writeFileSync(path.join(this.paths.instances, `${instance._id}.json`), JSON.stringify(instance, null, 2));
|
fs.writeFileSync(path.join(this.paths.instances, `${instance._id}.json`), JSON.stringify(instance, null, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,6 @@ async function compile({cache: cachePath, index}) {
|
||||||
// const modules = {};
|
// const modules = {};
|
||||||
|
|
||||||
for(const symbol in index.Entities) {
|
for(const symbol in index.Entities) {
|
||||||
console.log(symbol)
|
|
||||||
const module = index.Entities[symbol];
|
const module = index.Entities[symbol];
|
||||||
let code = await retrieveModule(module.From, module.Name);
|
let code = await retrieveModule(module.From, module.Name);
|
||||||
// modules[module.Name] = code;
|
// modules[module.Name] = code;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/marcus13345/AquaTin#readme",
|
"homepage": "https://github.com/marcus13345/AquaTin#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"signale": "^1.4.0",
|
||||||
"uuid": "^3.3.2",
|
"uuid": "^3.3.2",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue