AquaTin/core/aqua.js

69 lines
1.5 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
2019-05-26 22:18:26 -04:00
const {Signale} = require('signale');
2019-05-27 01:32:55 -04:00
const log = new Signale({
scope: 'CLI'
});
2019-05-26 22:18:26 -04:00
const interactive = new Signale({interactive: true});
const path = require('path');
2019-05-26 22:18:26 -04:00
require('yargs')
.scriptName("aqua")
.usage('$0 <cmd> [args]')
2019-05-26 22:18:26 -04:00
.command('compile [paramaters]', 'compiles a system into a cache', (yargs) => {
yargs.option('cache', {
type: 'string',
default: '.cache',
describe: 'path of the cache'
})
yargs.option('index', {
type: 'string',
default: 'index.js',
describe: 'path to the system index'
})
}, cliCompile)
2019-05-26 04:14:53 -04:00
2019-05-26 22:18:26 -04:00
.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');
2019-05-27 01:32:55 -04:00
if(!path.isAbsolute(args.cache)) args.cache = path.join(process.cwd(), '.cache');
2019-05-26 22:18:26 -04:00
let index = platformPrecompile(args);
log.info('precompile completed');
compile({
index: index,
cache: args.cache
})
}
2019-05-26 04:14:53 -04:00
/// 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
2019-05-26 22:18:26 -04:00
function platformPrecompile(args) {
// 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;
}