flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
110 lines • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var FlagpoleOutput;
(function (FlagpoleOutput) {
FlagpoleOutput[FlagpoleOutput["console"] = 1] = "console";
FlagpoleOutput[FlagpoleOutput["text"] = 2] = "text";
FlagpoleOutput[FlagpoleOutput["json"] = 3] = "json";
FlagpoleOutput[FlagpoleOutput["html"] = 4] = "html";
FlagpoleOutput[FlagpoleOutput["csv"] = 5] = "csv";
FlagpoleOutput[FlagpoleOutput["tsv"] = 6] = "tsv";
FlagpoleOutput[FlagpoleOutput["psv"] = 7] = "psv";
FlagpoleOutput[FlagpoleOutput["browser"] = 8] = "browser";
})(FlagpoleOutput = exports.FlagpoleOutput || (exports.FlagpoleOutput = {}));
class FlagpoleExecutionOptions {
constructor() {
this.environment = 'dev';
this.quietMode = false;
this.automaticallyPrintToConsole = false;
this.exitOnDone = false;
this.output = FlagpoleOutput.console;
}
static create() {
return new FlagpoleExecutionOptions();
}
static createFromString(args) {
return FlagpoleExecutionOptions.createWithArgs(args.split(' '));
}
static createWithArgs(args) {
const opts = new FlagpoleExecutionOptions();
let lastArg = null;
let env = null;
args.forEach(function (arg) {
if (lastArg == '-e') {
env = arg;
opts.environment = env;
}
else if (lastArg == '-o') {
opts.setOutputFromString(arg);
opts.automaticallyPrintToConsole = true;
}
else if (arg == '-q') {
opts.quietMode = true;
lastArg = null;
return;
}
else if (arg == '-x') {
opts.exitOnDone = true;
lastArg = null;
return;
}
lastArg = arg;
});
return opts;
}
setOutputFromString(value) {
if (typeof value == 'string') {
if (Object.keys(FlagpoleOutput).includes(value)) {
if (parseInt(value) > 0) {
this.output = parseInt(value);
}
else {
this.output = FlagpoleOutput[value];
}
}
}
}
getOutputAsString() {
let out = 'console';
Object.keys(FlagpoleOutput).some(key => {
if (FlagpoleOutput[key] == this.output) {
out = key;
return true;
}
return false;
});
return out;
}
toString() {
let opts = '';
if (this.environment !== null) {
opts += ' -e ' + this.environment;
}
if (this.quietMode) {
opts += ' -q';
}
if (this.exitOnDone) {
opts += ' -x';
}
if (this.output !== null) {
opts += ' -o ' + this.getOutputAsString();
}
return opts;
}
toArgs() {
const str = this.toString().trim();
return str.split(' ');
}
}
exports.FlagpoleExecutionOptions = FlagpoleExecutionOptions;
class FlagpoleExecution {
static get opts() {
return this._opts;
}
static set opts(value) {
this._opts = value;
}
}
FlagpoleExecution._opts = FlagpoleExecutionOptions.createWithArgs(process.argv);
exports.FlagpoleExecution = FlagpoleExecution;
//# sourceMappingURL=flagpoleexecutionoptions.js.map