import * as chalk from 'chalk'; import {command, help, namespace, optional, param} from 'oo-cli'; import * as semver from 'semver'; import * as table from 'text-table'; import {die} from '../../lib/die'; import {styledStringLength} from '../../lib/StringUtils'; import {Rivendell} from '../../lib/Rivendell'; import {formatReviewStatus} from '../../lib/formatReviewStatus'; import {formatError} from '../../lib/formatError'; import AppVersion = Rivendell.AppVersion; import AppVersionSearchCriteria = Rivendell.AppVersionSearchCriteria; import AppVersionState = Rivendell.AppVersionState; import ReviewStatus = Rivendell.ReviewStatus; @namespace('review') export class ListCommand { @param @optional @help('A specific App ID to filter down to (lists all apps by default)') private appId!: string; @command @help('List app versions currently under review') public async list(): Promise { try { const criteria: AppVersionSearchCriteria = { states: [AppVersionState.PUBLISHED], reviewStatuses: [ReviewStatus.IN_REVIEW, ReviewStatus.APPROVED] }; if (this.appId) { criteria.appId = this.appId; } this.render(await Rivendell.searchAppVersions(criteria, 'us')); } catch (e: any) { die(formatError(e)); } } private render(appVersions: AppVersion[]) { const header = ['App ID', 'Version', 'Review Status', 'Created At', 'Updated At'].map((item) => chalk.grey(item)); const rows = appVersions .sort((lhs, rhs) => { let result = lhs.id.appId.localeCompare(rhs.id.appId); if (result === 0) { const lhsVersion = lhs.id.version; const rhsVersion = rhs.id.version; if (lhsVersion !== rhsVersion) { result = semver.gt(lhsVersion, rhsVersion) ? -1 : 1; } } return result; }) .map((appVersion) => [ appVersion.id.appId, appVersion.id.version, formatReviewStatus( appVersion.reviewStatus as Rivendell.ReviewStatus ), appVersion.createdAt, appVersion.updatedAt ]); const t = table( [ header, ...rows ], { hsep: ' '.repeat(8), stringLength: styledStringLength } ); console.log(`\n${t}\n`); } }