UNPKG

2.87 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3// See LICENSE in the project root for license information.
4Object.defineProperty(exports, "__esModule", { value: true });
5const colors = require("colors");
6const path = require("path");
7/**
8 * Both "rush" and "rushx" share the same src/start.ts entry point. This makes it
9 * a little easier for them to share all the same startup checks and version selector
10 * logic. RushCommandSelector looks at argv to determine whether we're doing "rush"
11 * or "rushx" behavior, and then invokes the appropriate entry point in the selected
12 * @microsoft/rush-lib.
13 */
14class RushCommandSelector {
15 static failIfNotInvokedAsRush(version) {
16 if (RushCommandSelector._getCommandName() === 'rushx') {
17 RushCommandSelector._failWithError(`This repository is using Rush version ${version}`
18 + ` which does not support the "rushx" command`);
19 }
20 }
21 // eslint-disable-next-line @typescript-eslint/no-explicit-any
22 static execute(launcherVersion, selectedRushLib, options) {
23 const Rush = selectedRushLib.Rush;
24 if (!Rush) {
25 // This should be impossible unless we somehow loaded an unexpected version
26 RushCommandSelector._failWithError(`Unable to find the "Rush" entry point in @microsoft/rush-lib`);
27 }
28 if (RushCommandSelector._getCommandName() === 'rushx') {
29 if (!Rush.launchRushX) {
30 RushCommandSelector._failWithError(`This repository is using Rush version ${Rush.version}`
31 + ` which does not support the "rushx" command`);
32 }
33 Rush.launchRushX(launcherVersion, {
34 isManaged: options.isManaged,
35 alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError
36 });
37 }
38 else {
39 Rush.launch(launcherVersion, {
40 isManaged: options.isManaged,
41 alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError
42 });
43 }
44 }
45 static _failWithError(message) {
46 console.log(colors.red(message));
47 return process.exit(1);
48 }
49 static _getCommandName() {
50 if (process.argv.length >= 2) {
51 // Example:
52 // argv[0]: "C:\\Program Files\\nodejs\\node.exe"
53 // argv[1]: "C:\\Program Files\\nodejs\\node_modules\\@microsoft\\rush\\bin\\rushx"
54 const basename = path.basename(process.argv[1]).toUpperCase();
55 if (basename === 'RUSHX') {
56 return 'rushx';
57 }
58 if (basename === 'RUSH') {
59 return 'rush';
60 }
61 }
62 return undefined;
63 }
64}
65exports.RushCommandSelector = RushCommandSelector;
66//# sourceMappingURL=RushCommandSelector.js.map
\No newline at end of file