UNPKG

checkscripts

Version:

Inspired by Dan Slimmon's concept of "Do Nothing scripts", this project facilitates incremental automation of repetitive tasks.

45 lines 1.69 kB
import chalk from "chalk"; import logUpdate from "log-update"; import { CheckscriptMode } from "./checkscript.js"; import { waitForInput } from "./input.js"; const LOADING_FRAMES = ["-", "\\", "|", "/"]; export function useFormat(mode) { return mode === CheckscriptMode.DOCUMENT ? { name: (name) => `# ${name}`, description: (description) => `*${description}*`, stepTitle: (stepNumber, name) => `${stepNumber}. ${name ?? `Step ${stepNumber}`}`, footer: () => ` --- *This document is a [checkscript](https://github.com/gbannerman/checkscripts). It can be run using JavaScript.* `, } : { name: (name) => { const dividerLength = name.length + 6; return `${"-".repeat(dividerLength)}\n ${chalk.bold(name)}\n${"-".repeat(dividerLength)}`; }, description: (description) => `${chalk.italic(description)}\n`, stepTitle: (stepNumber, name) => chalk.bold(`${stepNumber}. ${name ?? `Step ${stepNumber}`}`), footer: (name) => `\n✅ Complete: ${chalk.bold(name)}`, }; } export async function withLoadingSpinner(text, operation) { let index = 0; const interval = setInterval(() => { const frame = LOADING_FRAMES[(index = ++index % LOADING_FRAMES.length)]; logUpdate(` ${frame} ${text} `); }, 80); const result = await operation(); clearInterval(interval); return result; } export async function withWaitForSpacebarPressed(text) { logUpdate(`${text} ${chalk.dim("PRESS SPACEBAR TO CONTINUE")} `); await waitForInput(); } //# sourceMappingURL=output.js.map