wv-gotcha
Version:
 wv-local-service-bus # Purpose To accumulate your walkthroughs to accomplish your common tasks with less effort.
146 lines • 7.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dialog = void 0;
const decova_terminal_1 = require("decova-terminal");
const Mcq_Walkthroughs_1 = require("./Mcq_Walkthroughs");
const Mcq_YesNo_1 = require("./Mcq_YesNo");
const chalk_1 = __importDefault(require("chalk"));
const inquirer_1 = __importDefault(require("inquirer"));
const cp = __importStar(require("child_process"));
class Dialog {
static yesOrNoAsync(question) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Mcq_YesNo_1.Mcq_YesNo().selectAsync(question);
});
}
static pickWalkghrough() {
return __awaiter(this, void 0, void 0, function* () {
const walkthrough = yield new Mcq_Walkthroughs_1.Mcq_Walkthroughs().selectAsync(`Pick a walkthrough:`);
yield walkthrough.execAsync();
});
}
static log(text, foreground = decova_terminal_1.Foreground.inverse, background = decova_terminal_1.Background.bgBlack, tabs = 0, isBold = false, isItalic = false, isStrikedOut = false, isUnderlined = false, isDimmed = false) {
let custom = chalk_1.default[foreground][background];
if (isBold)
custom = custom.bold;
if (isItalic)
custom = custom.italic;
if (isStrikedOut)
custom = custom.strikethrough;
if (isUnderlined)
custom = custom.underline;
if (isDimmed)
custom = custom.dim;
for (let x = 0; x++; x < tabs)
text = ` ${text}`;
// text = new XString(text).ReplaceAll("\"", "\\\"").Value;
console.log(custom(text));
}
static exec(cmd, currentDir = null) {
console.log(chalk_1.default.bgBlack.blackBright(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"));
console.log(chalk_1.default.green.bold(`>> ${cmd}`));
const child = cp.spawnSync(cmd, [], { stdio: 'inherit', shell: true });
console.log(chalk_1.default.bgBlack.blackBright("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"));
}
static confirmThenExecAsync(cmd, explanation = undefined) {
return __awaiter(this, void 0, void 0, function* () {
Dialog.hintWillExec(cmd);
if (explanation) {
Dialog.info(explanation);
}
const confirmed = yield Dialog.yesOrNoAsync("Continue?");
if (confirmed) {
Dialog.exec(cmd);
}
else {
Dialog.error("Execution terminated by user!");
throw "Execution terminated by user!";
}
});
}
static ShowCompletion() {
console.log(chalk_1.default.greenBright("██████████████████████████████ Completed ██████████████████████████████"));
}
static instructAsync(instruction, ackMessage = null) {
return __awaiter(this, void 0, void 0, function* () {
console.log(chalk_1.default.yellowBright.bold(`♣ ${instruction}`));
if (ackMessage !== null) {
yield inquirer_1.default.prompt([{ name: "foo", message: ackMessage }]);
}
});
}
static error(error) {
this.log(`! ${error}`, decova_terminal_1.Foreground.redBright, decova_terminal_1.Background.bgBlack, 1, true, true, false, true);
}
static warning(message) {
this.log(`! ${message}`, decova_terminal_1.Foreground.magentaBright, decova_terminal_1.Background.bgBlack, 1, true, true, false, true);
}
static info(info) {
console.log(chalk_1.default.bgYellowBright.green(` ${info} `));
}
static success(message) {
console.log(chalk_1.default.bgGreen.white(` ☺ ${message} `));
}
static _showQuestion(question) {
this.log(question, decova_terminal_1.Foreground.magentaBright, decova_terminal_1.Background.bgBlack, 1, true, true, false, true);
}
static askForTextAsync(question) {
return __awaiter(this, void 0, void 0, function* () {
// this._showQuestion(question);
let x = yield inquirer_1.default.prompt([{ name: "foo", message: question }]).then();
return x.foo;
});
}
static openExplorerAsync(dirPath) {
return __awaiter(this, void 0, void 0, function* () {
this.exec(`explorer \"${dirPath}\"`);
});
}
static hintWillExec(hint) {
console.log(chalk_1.default.bgRgb(110, 0, 0).white(`>>> ${hint}`));
// let x = await inquirer.prompt([{name:"foo", message:ch.bgYellow.black(`>>> ${hint}`)}]).then();
// return x.foo;
}
static promptContinueAsync() {
return __awaiter(this, void 0, void 0, function* () {
yield inquirer_1.default.prompt([{ name: "foo", message: chalk_1.default.bgMagenta.white(`>>> Press "ENTER" to continue`) }]).then();
});
}
}
exports.Dialog = Dialog;
//# sourceMappingURL=Dialog.js.map