UNPKG

wv-gotcha

Version:

![](https://raw.githubusercontent.com/wV-software/icons/main/Wv/Product%20Icon/wv_128x128.png) wv-local-service-bus # Purpose To accumulate your walkthroughs to accomplish your common tasks with less effort.

203 lines 9.72 kB
"use strict"; 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.Shell = 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 Shell { static yesOrNoAsync(question) { return __awaiter(this, void 0, void 0, function* () { return yield new Mcq_YesNo_1.Mcq_YesNo().selectAsync(question); }); } static getTimeStamp() { const date = new Date(); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-indexed const day = String(date.getDate()).padStart(2, '0'); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0'); return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`; } 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 printList(header, items) { console.log("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"); console.log(chalk_1.default.bold.bgGray.white(`${header}`)); items.forEach(i => console.log(chalk_1.default.white(`\t${i}`))); console.log("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"); } static printDangerList(header, items) { console.log(chalk_1.default.red("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬")); console.log(chalk_1.default.bold.bgGray.red(`${header}`)); items.forEach(i => console.log(chalk_1.default.red(`\t${i}`))); console.log(chalk_1.default.red("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬")); } 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) { return __awaiter(this, void 0, void 0, function* () { Shell.hintWillExec(cmd); Shell.info(explanation); const confirmed = yield Shell.yesOrNoAsync("Continue?"); if (confirmed) { Shell.exec(cmd); } else { Shell.error("Execution terminated by user!"); throw "Execution terminated by user!"; } }); } static ShowCompletion() { console.log(chalk_1.default.greenBright("██████████████████████████████ Completed ██████████████████████████████")); } static instructAsync(instruction_1) { return __awaiter(this, arguments, void 0, function* (instruction, ackMessage = null) { 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 terminate(error) { Shell.error(error); process.exit(0); } static warning(message) { this.log(`! ${message}`, decova_terminal_1.Foreground.magentaBright, decova_terminal_1.Background.bgBlack, 1, true, true, false, true); } static assert(message) { return __awaiter(this, void 0, void 0, function* () { console.log(chalk_1.default.bgRedBright.yellow("You must be dead sure before answering the following:")); const dlg = new Mcq_YesNo_1.Mcq_AreYouDeadSure(); const confirmed = yield dlg.selectAsync(message); if (!confirmed) this.terminate("The execution terminated by the user!"); }); } 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(); }); } static RunForStdout(cmd) { let output = cp.execSync(cmd).toString(); return output; } static openInBrowser(url) { // Define the command based on the operating system let command; switch (process.platform) { case 'darwin': // macOS command = `open ${url}`; break; case 'win32': // Windows command = `start "" "${url}"`; break; case 'linux': // Linux command = `xdg-open ${url}`; break; default: console.error('Unsupported platform:', process.platform); return; } // Execute the command to open the URL cp.execSync(command); } } exports.Shell = Shell; //# sourceMappingURL=Shell.js.map