| 12 | } |
| 13 | |
| 14 | export class TaskProgress extends EventEmitter implements ITaskProgress { |
| 15 | private readonly _stageCount: number; |
| 16 | private _stage: number; |
| 17 | private _stageTask: string; |
| 18 | private _stageProgressDone: number; |
| 19 | private _stageProgressTask: string; |
| 20 | private _done: boolean; |
| 21 | |
| 22 | constructor(stageCount?: number) { |
| 23 | super(); |
| 24 | if (stageCount) { |
| 25 | this._stageCount = stageCount; |
| 26 | } else { |
| 27 | this._stageCount = 1; |
| 28 | } |
| 29 | this._stage = 1; |
| 30 | this._stageProgressDone = 0; |
| 31 | this._stageTask = '...'; |
| 32 | this._stageProgressTask = '...'; |
| 33 | this._done = false; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Advance the stage ahead forcefully, setting progress of that stage to 0 |
| 38 | * @param stage Numbered stage to skip to |
| 39 | * @param task Task progress string to show user |
| 40 | */ |
| 41 | setStage(stage: number, task: string) { |
| 42 | if (!this._done) { |
| 43 | if (stage > this._stageCount) { |
| 44 | throw Error('Stage given exceeds Progress Stage Count'); |
| 45 | } else { |
| 46 | this._stage = stage; |
| 47 | this._stageTask = task; |
| 48 | this._stageProgressDone = 0; |
| 49 | this._stageProgressTask = '...'; |
| 50 | this._fireProgress(); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Set progress and task string for a stage |
| 57 | * @param done Demical progress (1 is done) |
| 58 | * @param task Task progress string to show user |
| 59 | */ |
| 60 | setStageProgress(done: number, task: string) { |
| 61 | if (!this._done) { |
| 62 | this._stageProgressDone = Math.min(done, 1); |
| 63 | this._stageProgressTask = task; |
| 64 | this._fireProgress(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | done(stageTask: string) { |
| 69 | if (!this._done) { |
| 70 | this._stageTask = stageTask; |
| 71 | this._done = true; |
nothing calls this directly
no outgoing calls
no test coverage detected