xweb-templating
Version:
A cli tool for converting 'tags' to regular html, php or some other format
48 lines (43 loc) • 1.54 kB
text/typescript
import chalk from "chalk";
import inquirer from "inquirer";
import { ArgumentsCamelCase } from "yargs";
export async function confirm(argv: ArgumentsCamelCase<{
y: boolean;
}>, message: string): Promise<boolean> {
if (argv.yes) return true;
const CONFIRM = await inquirer.prompt([{
name: "ok",
message,
type: "list",
choices: ["yes", "no"],
default: "yes"
}]);
return CONFIRM.ok == "yes";
}
export function info(executer: string, message: string) {
console.info(`[${chalk.green(executer)}] ${chalk.blue("info")}: ${message}`);
}
export function large_info(executer: string, title: string, message: string) {
let actual_text = `[${chalk.green(executer)}] ${chalk.blue("info")}: ${title}\n`;
actual_text += message
.replaceAll("\r", "")
.split("\n")
.map((line: string) => chalk.magenta("> ") + line).join("\n");
console.log(actual_text);
}
export function status(executer: string, message: string) {
console.info(`[${chalk.green(executer)}] ${chalk.cyan("status")}: ${message}`);
}
export async function warn(executer: string, message: string, no_confirm: boolean) {
console.info(`[${chalk.green(executer)}] ${chalk.yellow("warn")}: ${message}`);
if (no_confirm) return;
const STOP = !await confirm({
y: no_confirm,
_: [],
$0: ""
}, "Continue?");
if (STOP) process.exit(0);
}
export function error(executer: string, message: string) {
throw new Error(`[${executer}] error: ${message}`);
}