checkscripts
Version:
Inspired by Dan Slimmon's concept of "Do Nothing scripts", this project facilitates incremental automation of repetitive tasks.
72 lines • 2.14 kB
JavaScript
import logUpdate from "log-update";
import { withLoadingSpinner, withWaitForSpacebarPressed } from "./output.js";
var CheckscriptStepType;
(function (CheckscriptStepType) {
CheckscriptStepType[CheckscriptStepType["MANUAL"] = 0] = "MANUAL";
CheckscriptStepType[CheckscriptStepType["AUTOMATED"] = 1] = "AUTOMATED";
})(CheckscriptStepType || (CheckscriptStepType = {}));
export function step(initial, ...args) {
if (typeof initial !== "string") {
return {
name: null,
type: CheckscriptStepType.MANUAL,
action: initial[0],
};
}
const [action] = args;
const type = getStepType(action);
return {
name: initial,
type,
action,
};
}
export function getDocumentStepHandler(action) {
switch (typeof action) {
case "string":
return async (_context, stepTitle) => {
console.log(`\n## ${stepTitle}`);
console.log(action);
};
case "function":
return async (_context, stepTitle) => {
console.log(`\n## ${stepTitle}`);
console.log("*[THIS IS AN AUTOMATED STEP]*");
};
}
}
export function getRunStepHandler(action) {
switch (typeof action) {
case "string":
return (_context, stepTitle) => manualStep(stepTitle, action);
case "function":
return (context, stepTitle) => automatedStep(context, stepTitle, action);
}
}
function getStepType(action) {
switch (typeof action) {
case "string":
return CheckscriptStepType.MANUAL;
case "function":
return CheckscriptStepType.AUTOMATED;
}
}
async function automatedStep(context, stepTitle, action) {
const text = await withLoadingSpinner(stepTitle, () => action(context));
logUpdate(`
✓ ${stepTitle}
${text ?? ""}
`);
logUpdate.done();
}
async function manualStep(stepTitle, action) {
await withWaitForSpacebarPressed(`
➤ ${stepTitle}
${action}`);
logUpdate(`
✓ ${stepTitle}
${action}
`);
logUpdate.done();
}
//# sourceMappingURL=step.js.map