Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fluffynuts/exec-step
https://github.com/fluffynuts/exec-step
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/fluffynuts/exec-step
- Owner: fluffynuts
- License: bsd-3-clause
- Created: 2020-09-10T09:57:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-09T10:50:22.000Z (3 months ago)
- Last Synced: 2024-10-12T07:07:34.762Z (3 months ago)
- Language: TypeScript
- Size: 522 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
exec-step
---
executes a step in a series with console feedback![demo](demo.gif)
usage
---
```typescript
import { ExecStepContext } from "exec-step";function takesAWhile() {
return new Promise(resolve => setTimeout(resolve, 5000));
}function isQuick() {
// does nothing!
}(async () => {
const ctx = new ExecStepContext();
ctx.exec("please wait", takesAWhile);
ctx.exec("done quickly!", isQuick);
})();
```options
----construct with optional options of the shape:
```typescript
export interface ExecStepConfiguration {
asciiPrefixes?: boolean;
prefixes?: PartialStepConfig;
colors?: PartialStepConfig;
throwErrors?: boolean;
dumpErrorStacks?: boolean;
}
```defaults are:
```typescript
const defaultConfig: ExecStepConfiguration = {
colors: {
wait: "yellowBright",
ok: "greenBright",
fail: "redBright"
},
throwErrors: true,
dumpErrorStacks: false
};
```by default, exec-step reports wait/ok/fail status with utf-8 characters:
```typescript
const utf8Prefixes: PartialStepConfig = {
wait: "⌛",
ok: "✔",
fail: "✖"
};
```but can use ascii -- either via the `prefixes` part of the config, or by
observing the environment variable `ASCII_STEP_MARKERS` for a truthy value
like `1` or `true` -- useful at CI. If that's set, you get the following prefixes:```typescript
const asciiPrefixes: PartialStepConfig = {
wait: "[ WAIT ]",
ok: "[ OK ]",
fail: "[ FAIL ]"
}
```error handling
---by default, exec-step will print out the task label with the failure marker
of your choosing and re-throw the error, however, you can take complete control
by handling errors within your task and throwing an ExecStepOverrideMessage error,
eg:```typescript
await ctx.exec("do the thing", async () => {
try {
await attemptToDoTheThing();
} catch (e) {
throw new ExecStepOverrideMessage(
// overrides the error label
`Error whilst attempting to do the thing: ${e.message}`,
// original error, rethrown if allowed
e,
// suppress the error being thrown with false, or
// set this true to rethrow the original error
// if the context's default behavior is to throw
false
);
}
});