flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
138 lines • 4.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cli_1 = require("./cli/cli");
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.configPath = "";
this.baseDomain = "";
this.environment = "dev";
this.quietMode = false;
this.asyncExecution = false;
this.automaticallyPrintToConsole = false;
this.exitOnDone = false;
this.output = FlagpoleOutput.console;
this.isChildProcess = false;
}
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 (lastArg == "--base") {
opts.baseDomain = arg;
}
else if (lastArg == "--config") {
opts.configPath = arg;
}
else if (arg == "-q") {
opts.quietMode = true;
lastArg = null;
return;
}
else if (arg == "-x") {
opts.exitOnDone = true;
lastArg = null;
return;
}
else if (arg == "-z") {
opts.isChildProcess = true;
lastArg = null;
return;
}
lastArg = arg;
});
if (opts.configPath) {
opts.config = cli_1.parseConfigFile(opts.configPath);
}
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.baseDomain) {
opts += ` --base ${this.baseDomain}`;
}
if (this.configPath) {
opts += ` --config ${this.configPath}`;
}
if (this.environment !== null) {
opts += " -e " + this.environment;
}
if (this.quietMode) {
opts += " -q";
}
if (this.exitOnDone) {
opts += " -x";
}
if (this.isChildProcess) {
opts += " -z";
}
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;
}
}
exports.FlagpoleExecution = FlagpoleExecution;
FlagpoleExecution._opts = FlagpoleExecutionOptions.createWithArgs(process.argv);
//# sourceMappingURL=flagpoleexecutionoptions.js.map