forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRushCommandSelector.ts
More file actions
77 lines (69 loc) · 2.69 KB
/
RushCommandSelector.ts
File metadata and controls
77 lines (69 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as colors from 'colors';
import * as path from 'path';
import * as rushLib from '@microsoft/rush-lib';
type CommandName = 'rush' | 'rushx' | undefined;
/**
* Both "rush" and "rushx" share the same src/start.ts entry point. This makes it
* a little easier for them to share all the same startup checks and version selector
* logic. RushCommandSelector looks at argv to determine whether we're doing "rush"
* or "rushx" behavior, and then invokes the appropriate entry point in the selected
* @microsoft/rush-lib.
*/
export class RushCommandSelector {
public static failIfNotInvokedAsRush(version: string): void {
if (RushCommandSelector._getCommandName() === 'rushx') {
RushCommandSelector._failWithError(`This repository is using Rush version ${version}`
+ ` which does not support the "rushx" command`);
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static execute(launcherVersion: string, selectedRushLib: any, options: rushLib.ILaunchOptions): void {
const Rush: typeof rushLib.Rush = selectedRushLib.Rush;
if (!Rush) {
// This should be impossible unless we somehow loaded an unexpected version
RushCommandSelector._failWithError(`Unable to find the "Rush" entry point in @microsoft/rush-lib`);
}
if (RushCommandSelector._getCommandName() === 'rushx') {
if (!Rush.launchRushX) {
RushCommandSelector._failWithError(`This repository is using Rush version ${Rush.version}`
+ ` which does not support the "rushx" command`);
}
Rush.launchRushX(
launcherVersion,
{
isManaged: options.isManaged,
alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError
}
);
} else {
Rush.launch(
launcherVersion,
{
isManaged: options.isManaged,
alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError
}
);
}
}
private static _failWithError(message: string): never {
console.log(colors.red(message));
return process.exit(1);
}
private static _getCommandName(): CommandName {
if (process.argv.length >= 2) {
// Example:
// argv[0]: "C:\\Program Files\\nodejs\\node.exe"
// argv[1]: "C:\\Program Files\\nodejs\\node_modules\\@microsoft\\rush\\bin\\rushx"
const basename: string = path.basename(process.argv[1]).toUpperCase();
if (basename === 'RUSHX') {
return 'rushx';
}
if (basename === 'RUSH') {
return 'rush';
}
}
return undefined;
}
}