@quenty/cli-output-helpers
Version:
Helpers to generate Nevermore package and game templates
55 lines • 1.76 kB
JavaScript
import { LiveStateTracker } from './state/live-state-tracker.js';
/**
* Owns a LiveStateTracker and fans out every lifecycle hook
* to an array of reporters created by a factory callback.
*
* State is always updated first, so reporters see current data.
*/
export class CompositeReporter {
_state;
_reporters;
constructor(packageNames, factory) {
this._state = new LiveStateTracker(packageNames);
this._reporters = factory(this._state);
}
get state() {
return this._state;
}
async startAsync() {
await this._state.startAsync();
for (const r of this._reporters) {
await r.startAsync();
}
}
onPackageStart(packageName) {
this._state.onPackageStart(packageName);
for (const r of this._reporters) {
r.onPackageStart(packageName);
}
}
onPackagePhaseChange(packageName, phase) {
this._state.onPackagePhaseChange(packageName, phase);
for (const r of this._reporters) {
r.onPackagePhaseChange(packageName, phase);
}
}
onPackageProgressUpdate(packageName, progress) {
this._state.onPackageProgressUpdate(packageName, progress);
for (const r of this._reporters) {
r.onPackageProgressUpdate(packageName, progress);
}
}
onPackageResult(result, bufferedOutput) {
this._state.onPackageResult(result, bufferedOutput);
for (const r of this._reporters) {
r.onPackageResult(result, bufferedOutput);
}
}
async stopAsync() {
for (const r of this._reporters) {
await r.stopAsync();
}
await this._state.stopAsync();
}
}
//# sourceMappingURL=composite-reporter.js.map