X Tutup
Skip to content

Commit 7da8025

Browse files
committed
Add cli-table to pretty print rush package lists. (Also ready for eventual NodeJs bump).
1 parent e7f1574 commit 7da8025

File tree

19 files changed

+413
-304
lines changed

19 files changed

+413
-304
lines changed

apps/api-documenter/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.2/includes/tsconfig-node.json",
33
"compilerOptions": {
44
"types": [
5-
"jest"
5+
"jest",
6+
"node"
67
]
78
}
89
}

apps/api-extractor/src/analyzer/test/PackageMetadataManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('PackageMetadataManager', () => {
3535
packageJson
3636
} = getPackageMetadata('package-inferred-from-tsdoc-metadata');
3737
expect(PackageMetadataManager.resolveTsdocMetadataPath(packageFolder, packageJson, tsdocMetadataPath))
38-
.toBe(path.resolve(packageFolder, packageJson.tsdocMetadata));
38+
.toBe(path.resolve(packageFolder, packageJson.tsdocMetadata as string));
3939
});
4040
});
4141
describe('given a package.json where the field "typings" is defined and "tsdocMetadata" is not defined', () => {

apps/rush-lib/package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
"@microsoft/ts-command-line": "4.2.6",
2828
"@pnpm/link-bins": "~1.0.1",
2929
"@pnpm/logger": "~1.0.1",
30+
"@types/inquirer": "0.0.43",
3031
"@yarnpkg/lockfile": "~1.0.2",
3132
"builtins": "~1.0.3",
33+
"cli-table": "~0.3.1",
3234
"colors": "~1.2.1",
3335
"git-repo-info": "~2.1.0",
3436
"glob": "~7.0.5",
3537
"glob-escape": "~0.0.1",
3638
"https-proxy-agent": "~2.2.1",
37-
"@types/inquirer": "0.0.43",
3839
"inquirer": "~6.2.0",
3940
"js-yaml": "~3.13.1",
4041
"lodash": "~4.17.5",
@@ -49,18 +50,18 @@
4950
"z-schema": "~3.18.3"
5051
},
5152
"devDependencies": {
52-
"@microsoft/rush-stack-compiler-3.2": "0.3.19",
5353
"@microsoft/node-library-build": "6.0.67",
54-
"@types/node": "8.5.8",
55-
"@types/node-fetch": "1.6.9",
56-
"@types/tar": "4.0.0",
57-
"@types/z-schema": "3.16.31",
58-
"gulp": "~3.9.1",
54+
"@microsoft/rush-stack-compiler-3.2": "0.3.19",
5955
"@types/glob": "5.0.30",
6056
"@types/jest": "23.3.11",
6157
"@types/js-yaml": "3.12.1",
6258
"@types/lodash": "4.14.116",
6359
"@types/minimatch": "2.0.29",
64-
"@types/semver": "5.3.33"
60+
"@types/node": "8.5.8",
61+
"@types/node-fetch": "1.6.9",
62+
"@types/semver": "5.3.33",
63+
"@types/tar": "4.0.0",
64+
"@types/z-schema": "3.16.31",
65+
"gulp": "~3.9.1"
6566
}
6667
}

apps/rush-lib/src/cli/RushCommandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { UpdateAction } from './actions/UpdateAction';
2222
import { InstallAction } from './actions/InstallAction';
2323
import { InitAction } from './actions/InitAction';
2424
import { LinkAction } from './actions/LinkAction';
25-
import { ProjectsAction } from './actions/ProjectsAction';
25+
import { ListAction } from './actions/ListAction';
2626
import { PublishAction } from './actions/PublishAction';
2727
import { PurgeAction } from './actions/PurgeAction';
2828
import { UnlinkAction } from './actions/UnlinkAction';
@@ -141,7 +141,7 @@ export class RushCommandLineParser extends CommandLineParser {
141141
this.addAction(new InstallAction(this));
142142
this.addAction(new InitAction(this));
143143
this.addAction(new LinkAction(this));
144-
this.addAction(new ProjectsAction(this));
144+
this.addAction(new ListAction(this));
145145
this.addAction(new PublishAction(this));
146146
this.addAction(new PurgeAction(this));
147147
this.addAction(new ScanAction(this));
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}

apps/rush-lib/src/cli/actions/ProjectsAction.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Positional arguments:
2626
according to the shrinkwrap file
2727
init Initializes a new repository to be managed by Rush
2828
link Create node_modules symlinks for all projects
29-
projects List package names for all projects in the repo
29+
list List package information for all projects in the repo
3030
publish Reads and processes package publishing change requests
3131
generated by \\"rush change\\".
3232
purge For diagnostic purposes, use this command to delete caches
@@ -319,13 +319,20 @@ Optional arguments:
319319
"
320320
`;
321321
322-
exports[`CommandLineHelp prints the help for each action: projects 1`] = `
323-
"usage: rush projects [-h]
322+
exports[`CommandLineHelp prints the help for each action: list 1`] = `
323+
"usage: rush list [-h] [-v] [-p] [-f]
324324
325-
This lists package name for projects from current rush configuration.
325+
List package names, and optionally version (--version) and path (--path) or
326+
full path (--full-path), for projects in the current rush config.
326327
327328
Optional arguments:
328-
-h, --help Show this help message and exit.
329+
-h, --help Show this help message and exit.
330+
-v, --version If this flag is specified, the project version will be
331+
displayed in a column along with the package name.
332+
-p, --path If this flag is specified, the project path will be
333+
displayed in a column along with the package name.
334+
-f, --full-path If this flag is specified, the project full path will be
335+
displayed in a column along with the package name.
329336
"
330337
`;
331338

apps/rush-lib/src/logic/taskRunner/ProjectTask.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@ export class ProjectTask implements ITaskDefinition {
164164
);
165165

166166
// Hook into events, in order to get live streaming of build log
167-
task.stdout.on('data', (data: string) => {
168-
writer.write(data);
169-
});
170-
171-
task.stderr.on('data', (data: string) => {
172-
writer.writeError(data);
173-
this._hasWarningOrError = true;
174-
});
167+
if (task.stdout !== null) {
168+
task.stdout.on('data', (data: string) => {
169+
writer.write(data);
170+
});
171+
}
172+
if (task.stderr !== null) {
173+
task.stderr.on('data', (data: string) => {
174+
writer.writeError(data);
175+
this._hasWarningOrError = true;
176+
});
177+
}
175178

176179
return new Promise((resolve: (status: TaskStatus) => void, reject: (error: TaskError) => void) => {
177180
task.on('close', (code: number) => {

apps/rush-lib/src/utilities/Utilities.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
FileConstants
1515
} from '@microsoft/node-core-library';
1616
import { RushConfiguration } from '../api/RushConfiguration';
17+
import { Stream } from 'stream';
1718

1819
export interface IEnvironment {
1920
// NOTE: the process.env doesn't actually support "undefined" as a value.
@@ -107,7 +108,7 @@ export class Utilities {
107108
const unresolvedUserFolder: string | undefined = process.env[
108109
(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'
109110
];
110-
const homeFolder: string = path.resolve(unresolvedUserFolder);
111+
const homeFolder: string = path.resolve(unresolvedUserFolder as string);
111112
if (!FileSystem.exists(homeFolder)) {
112113
throw new Error('Unable to determine the current user\'s home directory');
113114
}
@@ -680,7 +681,7 @@ export class Utilities {
680681
*/
681682
private static _executeCommandInternal(
682683
command: string, args: string[], workingDirectory: string,
683-
stdio: (string|number)[] | undefined,
684+
stdio: 'pipe'|'ignore'|'inherit'|(number|'pipe'|'ignore'|'inherit'|'ipc'|Stream|null|undefined)[]|undefined,
684685
environment?: IEnvironment,
685686
keepEnvironment: boolean = false
686687
): child_process.SpawnSyncReturns<Buffer> {

apps/rush-lib/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.2/includes/tsconfig-node.json",
33
"compilerOptions": {
44
"types": [
5-
"jest"
5+
"jest",
6+
"node"
67
]
78
},
89
"include": [

0 commit comments

Comments
 (0)
X Tutup