checkscripts
Version:
Inspired by Dan Slimmon's concept of "Do Nothing scripts", this project facilitates incremental automation of repetitive tasks.
47 lines • 1.99 kB
JavaScript
import { useFormat } from "./output.js";
import { getDocumentStepHandler, getRunStepHandler } from "./step.js";
export var CheckscriptMode;
(function (CheckscriptMode) {
CheckscriptMode[CheckscriptMode["RUN"] = 0] = "RUN";
CheckscriptMode[CheckscriptMode["DOCUMENT"] = 1] = "DOCUMENT";
})(CheckscriptMode || (CheckscriptMode = {}));
export function checkscript(name, description, context = {}) {
return new Checkscript(name, description, context);
}
export { step } from "./step.js";
class Checkscript {
constructor(name, description, context) {
this.steps = function (...steps) {
this._steps = [...this._steps, ...steps];
return this;
};
this.run = async function () {
this._runCheckscript(CheckscriptMode.RUN, true);
};
this.document = async function (options = { includeFooter: true }) {
this._runCheckscript(CheckscriptMode.DOCUMENT, options.includeFooter);
};
this._runCheckscript = async function (mode, includeFooter) {
const { name, description, stepTitle, footer } = useFormat(mode);
console.log(name(this.name));
console.log(description(this.description));
for (let stepNumber = 1; stepNumber <= this._steps.length; stepNumber++) {
const step = this._steps[stepNumber - 1];
const getStepHandler = mode === CheckscriptMode.DOCUMENT
? getDocumentStepHandler
: getRunStepHandler;
const stepHandler = getStepHandler(step.action);
await stepHandler(this.context, stepTitle(stepNumber, step.name));
}
if (includeFooter) {
console.log(footer(this.name));
}
process.exit();
};
this._steps = [];
this.name = name;
this.description = description;
this.context = context;
}
}
//# sourceMappingURL=checkscript.js.map