UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

100 lines 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("./config"); const clortho_lite_1 = require("clortho-lite"); const cli_helper_1 = require("./cli-helper"); const fs = require('fs'); const exec = require('child_process').exec; const path = require('path'); const ansiAlign = require('ansi-align'); class Cli { static log(message) { if (typeof message !== 'undefined') { Cli.consoleLog.push(message.replace(/\n$/, '')); } } static list(list) { list.forEach(function (message) { Cli.log(' » ' + message); }); } static exit(exitCode) { if (!Cli.hideBanner) { cli_helper_1.printHeader(); } Cli.consoleLog.forEach(function (message) { console.log(message); }); process.exit(exitCode); } ; static normalizePath(path) { if (path) { path = (path.match(/\/$/) ? path : path + '/'); } return path; } static parseConfigFile(configPath) { let config = new config_1.FlagpoleConfig(); if (configPath && fs.existsSync(configPath)) { let configContent = fs.readFileSync(configPath); let configDir = Cli.normalizePath(path.dirname(configPath)); let configData; try { configData = JSON.parse(configContent); } catch (_a) { configData = {}; } configData.configPath = configPath; configData.configDir = configDir; config = new config_1.FlagpoleConfig(configData); } return config; } static getCredentials() { const serviceName = 'Flagpole JS'; const service = new clortho_lite_1.ClorthoService(serviceName); let token; let email; return new Promise((resolve, reject) => { Promise.all([ new Promise((resolve, reject) => { service.get('token') .then(function (credentials) { token = credentials.password; resolve(); }).catch(function () { reject('No saved token.'); }); }), new Promise((resolve, reject) => { service.get('email') .then(function (credentials) { email = credentials.password; resolve(); }).catch(function () { reject('No saved email.'); }); }) ]).then(function () { resolve({ email: email, token: token }); }).catch(function (err) { reject('Not logged in. ' + err); }); }); } } Cli.consoleLog = []; Cli.hideBanner = false; Cli.rootPath = __dirname; Cli.configPath = __dirname + '/flagpole.json'; Cli.command = null; Cli.commandArg = null; Cli.commandArg2 = null; Cli.apiDomain = 'https://us-central1-flagpolejs-5ea61.cloudfunctions.net'; exports.Cli = Cli; //# sourceMappingURL=cli.js.map