briareus
Version:
Briareus assists with Feature Branch deploys to ECS
89 lines (71 loc) • 2.49 kB
JavaScript
'use strict'
const fs = require('fs');
const bunyan = require('bunyan');
const _ = require('lodash');
const s = require('underscore.string');
const taskDefinitionValidator = require('../taskDefinitionValidator');
const Client = require('../client');
class CLI {
constructor(args, output) {
this.paths = {
briareus: {}
};
this.args = args;
this.params = _
.chain(this.args)
.mapKeys((value, key) => s.camelize(key))
.omit([
'',
'_',
'$0',
'authtoken',
'projectRootPath',
'logLevel'
])
.mapValues((param) => param + "") // force all params to be strings
.value()
this.output = output;
this.log = bunyan.createLogger({
name: 'Briareus CLI',
level: this.args['log-level'],
streams: [
{ stream: output }
]
});
this.paths.root = args.projectRootPath;
this.paths.briareus.dir = `${this.paths.root}/.briareus`;
this.paths.briareus.config = `${this.paths.briareus.dir}/config.json`;
this.paths.briareus.taskDefinition = `${this.paths.briareus.dir}/task-definition.json`;
this.config = this.getProjectConfigRaw(this.paths.briareus.config);
let endpoint = this.params.endpoint ? this.params.endpoint : this.config.briareus;
this.api = new Client({ endpoint, authtoken: args.authtoken, logger: this.log });
}
getProjectConfigRaw() {
if (!fs.existsSync(this.paths.briareus.config)) {
throw new Error(`config.json file not found in .briareus directory`);
}
try { var config = JSON.parse(fs.readFileSync(this.paths.briareus.config)); }
catch (e) {
throw new Error(`Error parsing json at ${this.paths.briareus.config}. ${e.message}`);
}
return config;
}
getProjectTaskDefinition() {
if (!fs.existsSync(this.paths.briareus.taskDefinition)) {
throw new Error(`task-definition.json file not found in .briareus directory`);
}
try { var taskDefinition = JSON.parse(fs.readFileSync(this.paths.briareus.taskDefinition, 'utf8')); }
catch (e) {
throw new Error(`Error parsing json at ${this.paths.briareus.taskDefinition}. ${e.message}`);
}
let result = taskDefinitionValidator(taskDefinition);
if (result) throw result;
return taskDefinition;
}
packageBriareusConfig() {
let config = this.getProjectConfigRaw();
config.taskDefinition = this.getProjectTaskDefinition();
return config;
}
}
module.exports = CLI;