|
| 1 | +import { BaseRushAction } from './BaseRushAction'; |
| 2 | +import { RushCommandLineParser } from '../RushCommandLineParser'; |
| 3 | +import { CommandLineFlagParameter } from '@microsoft/ts-command-line'; |
| 4 | +import { RushConfigurationProject } from '../../api/RushConfigurationProject'; |
| 5 | +import * as Table from 'cli-table'; |
| 6 | + |
| 7 | +export class ListAction extends BaseRushAction { |
| 8 | + private _version: CommandLineFlagParameter; |
| 9 | + private _path: CommandLineFlagParameter; |
| 10 | + private _fullPath: CommandLineFlagParameter; |
| 11 | + |
| 12 | + constructor(parser: RushCommandLineParser) { |
| 13 | + super({ |
| 14 | + actionName: 'list', |
| 15 | + summary: 'List package information for all projects in the repo', |
| 16 | + documentation: |
| 17 | + 'List package names, and optionally version (--version) and ' + |
| 18 | + 'path (--path) or full path (--full-path), for projects in the ' + |
| 19 | + 'current rush config.', |
| 20 | + parser |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + protected onDefineParameters(): void { |
| 25 | + this._version = this.defineFlagParameter({ |
| 26 | + parameterLongName: '--version', |
| 27 | + parameterShortName: '-v', |
| 28 | + description: 'If this flag is specified, the project version will be ' + |
| 29 | + 'displayed in a column along with the package name.' |
| 30 | + }); |
| 31 | + |
| 32 | + this._path = this.defineFlagParameter({ |
| 33 | + parameterLongName: '--path', |
| 34 | + parameterShortName: '-p', |
| 35 | + description: 'If this flag is specified, the project path will be ' + |
| 36 | + 'displayed in a column along with the package name.' |
| 37 | + }); |
| 38 | + |
| 39 | + this._fullPath = this.defineFlagParameter({ |
| 40 | + parameterLongName: '--full-path', |
| 41 | + parameterShortName: '-f', |
| 42 | + description: 'If this flag is specified, the project full path will ' + |
| 43 | + 'be displayed in a column along with the package name.' |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + protected run(): Promise<void> { |
| 48 | + return Promise.resolve().then(() => { |
| 49 | + const allPackages: Map<string, RushConfigurationProject> = this.rushConfiguration.projectsByName; |
| 50 | + const tableHeader: string[] = ['Project']; |
| 51 | + if (this._version.value) { |
| 52 | + tableHeader.push('Version'); |
| 53 | + } |
| 54 | + if (this._path.value) { |
| 55 | + tableHeader.push('Path'); |
| 56 | + } |
| 57 | + if (this._fullPath.value) { |
| 58 | + tableHeader.push('Full Path'); |
| 59 | + } |
| 60 | + const table: typeof Table = new Table({ |
| 61 | + head: tableHeader |
| 62 | + }); |
| 63 | + |
| 64 | + allPackages.forEach((config: RushConfigurationProject, name: string) => { |
| 65 | + const packageRow: string[] = [name]; |
| 66 | + if (this._version.value) { |
| 67 | + packageRow.push(config.packageJson.version); |
| 68 | + } |
| 69 | + if (this._path.value) { |
| 70 | + packageRow.push(config.projectRelativeFolder); |
| 71 | + } |
| 72 | + if (this._fullPath.value) { |
| 73 | + packageRow.push(config.projectFolder); |
| 74 | + } |
| 75 | + table.push(packageRow); |
| 76 | + }); |
| 77 | + console.log(table.toString()); |
| 78 | + }); |
| 79 | + } |
| 80 | +} |
0 commit comments