UNPKG

@kwaeri/wizard

Version:

The @kwaeri/wizard component module of the @kwaeri/node-kit platform.

90 lines (89 loc) 3.87 kB
/// <reference types="node" /> import * as rl from 'readline'; import * as Event from 'events'; import { FilesystemDescriptor } from '@kwaeri/filesystem'; import { BaseServiceProvider, ServiceProviderSubscriptions, ServiceProviderHelpText, ServiceEventBits } from '@kwaeri/service'; export declare type WizardResponsePromise = { answers: Array<string>; }; /** * BaseWizard defines the interface for any service provider which will * implement a wizard-type service * * @since 0.1.0 */ export interface BaseWizardService { run<T extends WizardResponsePromise>(options: FilesystemDescriptor): Promise<T>; question1(instance: rl.ReadLine, answers: Array<any>, options?: FilesystemDescriptor): Promise<any>; setServiceEventMetadata(data: ServiceEventBits): void; } /** * WizardService Class * * The { WizardService } is the class from which all wizard services should inherit * from. A wizard service is one that prompts users for information, and will [or should] * always need the readline class, and have at least a pair of methods 'run' and `question1`. * * This class helps to sensibly build a derived service provider, it should not be * used directly. Instead, developers should extend from the WizardServiceProvider class. */ export declare abstract class WizardService extends Event.EventEmitter implements BaseWizardService { constructor(); abstract run<T extends WizardResponsePromise>(options: FilesystemDescriptor): Promise<T>; abstract question1(instance: rl.ReadLine, answers: Array<any>, options: FilesystemDescriptor): Promise<any>; setServiceEventMetadata(data: ServiceEventBits): void; } /** * WizardServiceProvider Class * * The { WizardServiceProvider } class implements a facility for presenting * a series of user promopts via CLI, in order to gather information * for a task, much in the same fashion as that of a wizard. */ export declare abstract class WizardServiceProvider extends WizardService implements BaseServiceProvider { /** * An array of user prompt functions * * @var { Array<Function>} */ prompts: Array<Function>; /** * Class constructor * * @param { void } * * @since 0.1.10 */ constructor(); abstract getServiceProviderSubscriptions(options: any): ServiceProviderSubscriptions; abstract getServiceProviderSubscriptionHelpText<T extends ServiceProviderHelpText>(options: any): T; /** * A method which runs a sequence of user prompts through a CLI * * @param { FilesystemDescriptor } options Any options that might have been provided preemptively * * @return { Promise<WizardResponsePromise> } An array of answers * * @since 0.1.10 */ run<T extends WizardResponsePromise>(options: FilesystemDescriptor): Promise<T>; /** * A method which implements the first user prompt for a setup wizard that is * run for assisting the automaton with generating file contents. * * @param { rl.ReadLine } instance An instance of readline.createInterface() * @param { Array<string> } answers An array filled with answers from the automaton project generator wizard. * @param { Array<Function> } prompts An array of user prompt functions * @param { FilesystemDescriptor } options An object with options for specifying * * @return { Promise<any> } Returns a promise for allowing asynchronous chaining * * @since 0.1.10 */ question1(instance: rl.ReadLine, answers: Array<any>, options?: FilesystemDescriptor): Promise<any>; } export declare class ExampleWizard extends WizardServiceProvider { getServiceProviderSubscriptions(options?: any): ServiceProviderSubscriptions; getServiceProviderSubscriptionHelpText<T extends ServiceProviderHelpText>(options?: any): T; testEvents(handler: any): void; }