@ehmpathy/as-command
Version:
easily create commands within a pit-of-success
37 lines (36 loc) • 1.03 kB
TypeScript
/// <reference types="node" />
import * as fs from 'fs/promises';
import type { LogMethods } from 'simple-leveled-log-methods';
/**
* context provided by the command
*/
export interface CommandContext {
log: LogMethods;
out: {
write: (file: {
name: string;
data: Parameters<typeof fs.writeFile>[1];
}) => Promise<{
path: string;
}>;
};
}
/**
* converts any function into a pit-of-success command
*
* features
* - observability
* - logs inputs, outputs, and errors to console
* - persists inputs, outputs, and errors to file storage (locally and optionally to s3)
* - parallelism
* - supports parallel operations with progress reporting
* - experience
* - easily pass in inputs from the command line
*/
export declare const asCommand: <I, O>(options: {
name: string;
purpose?: string;
stage: string;
log: LogMethods;
dir: string;
}, logic: (input: I, context: CommandContext) => Promise<O>) => (input: I) => Promise<O>;