forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRush.ts
More file actions
117 lines (102 loc) · 4.37 KB
/
Rush.ts
File metadata and controls
117 lines (102 loc) · 4.37 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { EOL } from 'os';
import * as colors from 'colors';
import { PackageJsonLookup } from '@rushstack/node-core-library';
import { RushCommandLineParser } from '../cli/RushCommandLineParser';
import { RushConstants } from '../logic/RushConstants';
import { RushXCommandLine } from '../cli/RushXCommandLine';
import { CommandLineMigrationAdvisor } from '../cli/CommandLineMigrationAdvisor';
import { NodeJsCompatibility } from '../logic/NodeJsCompatibility';
/**
* Options to pass to the rush "launch" functions.
*
* @public
*/
export interface ILaunchOptions {
/**
* True if the tool was invoked from within a project with a rush.json file, otherwise false. We
* consider a project without a rush.json to be "unmanaged" and we'll print that to the command line when
* the tool is executed. This is mainly used for debugging purposes.
*/
isManaged: boolean;
/**
* If true, the wrapper process already printed a warning that the version of Node.js hasn't been tested
* with this version of Rush, so we shouldn't print a similar error.
*/
alreadyReportedNodeTooNewError?: boolean;
}
/**
* General operations for the Rush engine.
*
* @public
*/
export class Rush {
/**
* This API is used by the `@microsoft/rush` front end to launch the "rush" command-line.
* Third-party tools should not use this API. Instead, they should execute the "rush" binary
* and start a new Node.js process.
*
* @param launcherVersion - The version of the `@microsoft/rush` wrapper used to call invoke the CLI.
*
* @remarks
* Earlier versions of the rush frontend used a different API contract. In the old contract,
* the second argument was the `isManaged` value of the {@link ILaunchOptions} object.
*
* Even though this API isn't documented, it is still supported for legacy compatibility.
*/
public static launch(launcherVersion: string, arg: ILaunchOptions): void {
const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg);
Rush._printStartupBanner(options.isManaged);
if (!CommandLineMigrationAdvisor.checkArgv(process.argv)) {
// The migration advisor recognized an obsolete command-line
process.exitCode = 1;
return;
}
const parser: RushCommandLineParser = new RushCommandLineParser({
alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError
});
parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise
}
/**
* This API is used by the `@microsoft/rush` front end to launch the "rushx" command-line.
* Third-party tools should not use this API. Instead, they should execute the "rushx" binary
* and start a new Node.js process.
*
* @param launcherVersion - The version of the `@microsoft/rush` wrapper used to call invoke the CLI.
*/
public static launchRushX(launcherVersion: string, options: ILaunchOptions): void {
options = Rush._normalizeLaunchOptions(options);
Rush._printStartupBanner(options.isManaged);
RushXCommandLine._launchRushXInternal(launcherVersion, { ...options });
}
/**
* The currently executing version of the "rush-lib" library.
* This is the same as the Rush tool version for that release.
*/
public static get version(): string {
return PackageJsonLookup.loadOwnPackageJson(__dirname).version;
}
/**
* This function normalizes legacy options to the current {@link ILaunchOptions} object.
*/
private static _normalizeLaunchOptions(arg: ILaunchOptions): ILaunchOptions {
return (typeof arg === 'boolean')
? { isManaged: arg } // In older versions of Rush, this the `launch` functions took a boolean arg for "isManaged"
: arg;
}
private static _printStartupBanner(isManaged: boolean): void {
const nodeVersion: string = process.versions.node;
const nodeReleaseLabel: string = (NodeJsCompatibility.isOddNumberedVersion)
? 'unstable'
: (NodeJsCompatibility.isLtsVersion ? 'LTS' : 'pre-LTS');
console.log(
EOL +
colors.bold(`Rush Multi-Project Build Tool ${Rush.version}` + colors.yellow(isManaged ? '' : ' (unmanaged)')) +
colors.cyan(` - ${RushConstants.rushWebSiteUrl}`) +
EOL +
`Node.js version is ${nodeVersion} (${nodeReleaseLabel})` +
EOL
);
}
}