nadle
Version:
A modern, type-safe task runner for Node.js inspired by the awesome Gradle build tool
223 lines (208 loc) • 7.37 kB
TypeScript
import { InputLogObject } from 'consola';
import { RimrafAsyncOptions } from 'rimraf';
declare const SupportLogLevels: ["error", "log", "info", "debug"];
type SupportLogLevel = (typeof SupportLogLevels)[number];
interface LoggerOptions {
readonly logLevel?: SupportLogLevel;
/** @internal */
readonly isWorkerThread?: boolean;
}
declare class Logger {
private _clearScreenPending;
private readonly consola;
readonly options: Required<LoggerOptions>;
readonly outputStream: NodeJS.WriteStream;
readonly errorStream: NodeJS.WriteStream;
constructor(options: LoggerOptions);
log(message: any, ...args: unknown[]): void;
error(message: any, ...args: unknown[]): void;
warn(message: any, ...args: unknown[]): void;
info(message: any, ...args: unknown[]): void;
debug(message: InputLogObject | string, ...args: unknown[]): void;
clearFullScreen(message?: string): void;
clearScreen(message: string, force?: boolean): void;
private _clearScreen;
getColumns(): number;
}
interface Reporter {
onInit?: () => void;
onExecutionStart?: () => Awaitable<void>;
onExecutionFinish?: () => Awaitable<void>;
onExecutionFailed?: (error: any) => Awaitable<void>;
onTasksScheduled?: (tasks: string[]) => Awaitable<void>;
onTaskFinish?: (task: RegisteredTask) => Awaitable<void>;
onTaskFailed?: (task: RegisteredTask) => Awaitable<void>;
onTaskStart?: (task: RegisteredTask, threadId: number) => Awaitable<void>;
}
declare class DefaultReporter implements Reporter {
readonly nadle: Nadle;
private readonly renderer;
private taskStat;
private threadIdPerWorker;
private startTime;
private currentTime;
private duration;
private durationInterval;
constructor(nadle: Nadle);
private printLabel;
private createSummary;
private printRunningTasks;
onInit(): void;
onTaskStart(task: RegisteredTask, threadId: number): Promise<void>;
onTaskFinish(task: RegisteredTask): Promise<void>;
onTaskFailed(task: RegisteredTask): Promise<void>;
onTasksScheduled(tasks: string[]): Promise<void>;
onExecutionStart(): Promise<void>;
onExecutionFinish(): Promise<void>;
onExecutionFailed(error: any): Promise<void>;
private startTimers;
}
declare class TaskRegistry {
private readonly registry;
register(name: string, task: RegisteredTask): void;
has(name: string): boolean;
getAll(): RegisteredTask[];
findByName(taskName: string): RegisteredTask | undefined;
getByName(taskName: string): RegisteredTask;
onTaskStart(name: string): void;
onTaskFinish(name: string): void;
onTaskFailed(name: string): void;
onTasksScheduled(names: string[]): void;
}
declare const taskRegistry: TaskRegistry;
interface NadleUserBaseOptions {
readonly parallel?: boolean;
readonly showSummary?: boolean;
readonly logLevel?: SupportLogLevel;
readonly minWorkers?: number | string;
readonly maxWorkers?: number | string;
/** @internal */
readonly isWorkerThread?: boolean;
}
interface NadleCLIOptions extends NadleUserBaseOptions {
readonly list: boolean;
readonly dryRun: boolean;
readonly configPath?: string;
readonly showConfig: boolean;
readonly stacktrace: boolean;
}
interface NadleConfigFileOptions extends NadleUserBaseOptions {
}
interface NadleResolvedOptions extends Required<Omit<NadleCLIOptions, "maxWorkers" | "minWorkers">> {
readonly minWorkers: number;
readonly maxWorkers: number;
}
declare function configure(options: Partial<NadleConfigFileOptions>): void;
declare class Nadle {
readonly version: string;
readonly logger: Logger;
readonly reporter: Reporter;
readonly registry: TaskRegistry;
private readonly optionsResolver;
constructor(options: NadleCLIOptions);
execute(tasks: string[]): Promise<void>;
get options(): NadleResolvedOptions;
private runTasks;
private dryRunTasks;
listTasks(): void;
showConfig(): void;
private resolveTasks;
computeTaskGroups(): [string, (RegisteredTask & {
description?: string;
})[]][];
printNoTasksFound(): void;
registerTask(): Promise<void>;
onTaskStart(task: RegisteredTask, threadId: number): Promise<void>;
onTaskFinish(task: RegisteredTask): Promise<void>;
onTaskFailed(task: RegisteredTask): Promise<void>;
onTasksScheduled(tasks: string[]): Promise<void>;
}
type Awaitable<T> = T | PromiseLike<T>;
interface Context {
readonly nadle: Nadle;
}
type Callback<T = unknown, P = {
context: Context;
}> = (params: P) => T;
type Resolver<T = unknown> = T | Callback<T>;
type TaskFn = Callback<Awaitable<void>, {
context: Context & {
workingDir: string;
};
}>;
interface Task<Options = unknown> {
run: Callback<Awaitable<void>, {
options: Options;
context: Context & {
workingDir: string;
};
}>;
}
type TaskEnv = Record<string, string | number | boolean>;
interface TaskConfiguration {
/**
* The group name to which this task belongs.
*/
group?: string;
/**
* The description of the task.
*/
description?: string;
/**
* A list of tasks that this task depends on.
*/
dependsOn?: string[];
/**
* Environment variables to set when running the task.
*/
env?: TaskEnv;
/**
* Changes the working directory for the task.
*/
workingDir?: string;
}
interface ConfigBuilder {
config(builder: Callback<TaskConfiguration> | TaskConfiguration): void;
}
declare enum TaskStatus {
Registered = "registered",
Scheduled = "scheduled",
Running = "running",
Finished = "finished",
Failed = "failed"
}
interface RegisteredTask extends Task {
name: string;
status: TaskStatus;
optionsResolver: Resolver | undefined;
configResolver: Callback<TaskConfiguration>;
result: {
duration: number | null;
startTime: number | null;
};
}
declare function registerTask(name: string): ConfigBuilder;
declare function registerTask(name: string, fnTask: TaskFn): ConfigBuilder;
declare function registerTask<Options>(name: string, optTask: Task<Options>, optionsResolver: Resolver<Options>): ConfigBuilder;
declare const tasks: {
register: typeof registerTask;
};
declare function resolveTask(input: string, allTasks: string[]): {
result: string;
} | {
result: undefined;
suggestions: string[];
};
declare function formatSuggestions(names: string[]): string;
declare const PnpmTask: Task<{
args: string[];
}>;
declare const ExecTask: Task<{
command: string;
args: string[] | string;
}>;
interface DeleteTaskOptions extends RimrafAsyncOptions {
readonly paths: string | string[];
}
declare const DeleteTask: Task<DeleteTaskOptions>;
export { type Awaitable, type Callback, type ConfigBuilder, type Context, DefaultReporter, DeleteTask, type DeleteTaskOptions, ExecTask, Logger, type LoggerOptions, Nadle, type NadleCLIOptions, type NadleConfigFileOptions, type NadleResolvedOptions, type NadleUserBaseOptions, PnpmTask, type RegisteredTask, type Reporter, type Resolver, type SupportLogLevel, SupportLogLevels, type Task, type TaskConfiguration, type TaskEnv, type TaskFn, TaskRegistry, TaskStatus, configure, formatSuggestions, resolveTask, taskRegistry, tasks };