import { ActionType , TaskArguments , TaskDefinition , TasksMap } from '../../../types' ; import { OverriddenTaskDefinition , SimpleTaskDefinition } from './task-definitions' ; /**
 * This class defines the DSL used in Redspot config files
 * for creating and overriding tasks.
 */ export class TasksDSL { public readonly internalTask = this . subtask ; private readonly _tasks : TasksMap = { } ; remarks param name param description param action returns public task < ArgsT extends TaskArguments > ( name , description ? , action ? ) ; remarks param name param action returns public task < ArgsT extends TaskArguments > ( name , action ) ; public task < ArgsT extends TaskArguments > ( name , descriptionOrAction ? , action ? ) { return this . _addTask ( name , descriptionOrAction , action , false ) ; } remarks remarks param name param description param action returns public subtask < ArgsT extends TaskArguments > ( name , description ? , action ? ) ; remarks remarks param name param action returns public subtask < ArgsT extends TaskArguments > ( name , action ) ; public subtask < ArgsT extends TaskArguments > ( name , descriptionOrAction ? , action ? ) { return this . _addTask ( name , descriptionOrAction , action , true ) ; } returns public getTaskDefinitions ( ) { return this . _tasks ; } private _addTask < ArgT extends TaskArguments > ( name , descriptionOrAction ? , action ? , isSubtask ? ) { const parentTaskDefinition = this . _tasks [ name ] ; let taskDefinition ; if ( parentTaskDefinition !== undefined ) { taskDefinition = new OverriddenTaskDefinition ( parentTaskDefinition , isSubtask ) ; } else { taskDefinition = new SimpleTaskDefinition ( name , isSubtask ) ; } if ( descriptionOrAction instanceof Function ) { action = descriptionOrAction ; descriptionOrAction = undefined ; } if ( descriptionOrAction !== undefined ) { taskDefinition . setDescription ( descriptionOrAction as string ) ; } if ( action !== undefined ) { taskDefinition . setAction ( action ) ; } this . _tasks [ name ] = taskDefinition ; return taskDefinition ; } }