optc
Version:
An easy way to write TypeScript cli script application.
80 lines (73 loc) • 2.33 kB
TypeScript
import { EncodingOption } from 'node:fs';
interface ProcessOption {
cwd?: string;
verbose?: boolean;
shell?: boolean | string;
}
declare function Process(pieces: TemplateStringsArray | string[], args: any[], { cwd, verbose, shell }?: ProcessOption): Promise<ProcessResult>;
declare class ProcessResult {
readonly code: number | null;
readonly signal: string | null;
readonly stdout: string;
readonly stderr: string;
readonly combined: string;
constructor({ code, signal, stdout, stderr, combined }: {
code: number | null;
signal: string | null;
stdout: string;
stderr: string;
combined: string;
});
}
declare function $(pieces: TemplateStringsArray, ...args: any[]): Promise<ProcessResult>;
declare namespace $ {
var prompt: string;
var shell: boolean;
var verbose: boolean;
}
declare function cd(dir: string): void;
declare function pwd(): string;
declare function ls(dir?: string): string[];
declare function readTextFile(filename: string, encode?: EncodingOption): string | Buffer;
declare function writeTextFile(filename: string, content: string, encode?: EncodingOption): void;
declare function sleep(ms: number): Promise<void>;
declare enum ValueType {
String = "string",
Number = "number",
Boolean = "boolean",
Array = "string[]"
}
interface Parameter {
name: string;
type: ValueType;
required: boolean;
}
interface Option {
name: string;
type: ValueType;
required: boolean;
description: string;
}
interface Command {
name: string;
default: boolean;
options: Option[];
parameters: Parameter[];
description: string;
}
declare class Optc {
private readonly scriptPath;
private readonly breadc;
private commands;
constructor(scriptPath: string, option: {
name: string;
version: string;
description?: string;
});
getRawCommands(): Command[];
setupCommands(module: Record<string, any>, commands: Command[]): void;
run<T = any>(args: string[]): Promise<T>;
}
declare function makeOptc(script: string): Promise<Optc>;
declare function bootstrap<T = any>(script: string, ...args: string[]): Promise<T>;
export { $, Process, ProcessResult, bootstrap, cd, ls, makeOptc, pwd, readTextFile, sleep, writeTextFile };