@microsoft/rush
Version:
A professional solution for consolidating all your JavaScript projects in one Git repo
109 lines • 4.71 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.RushCommandSelector = void 0;
const path = __importStar(require("path"));
const terminal_1 = require("@rushstack/terminal");
/**
* 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.
*/
class RushCommandSelector {
static failIfNotInvokedAsRush(version) {
const commandName = RushCommandSelector._getCommandName();
if (commandName !== 'rush' && commandName !== undefined) {
RushCommandSelector._failWithError(`This repository is using Rush version ${version} which does not support the ${commandName} command`);
}
}
static execute(launcherVersion,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
selectedRushLib, options) {
const 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`);
}
const commandName = RushCommandSelector._getCommandName();
if (commandName === 'rush-pnpm') {
if (!Rush.launchRushPnpm) {
RushCommandSelector._failWithError(`This repository is using Rush version ${Rush.version}` +
` which does not support the "rush-pnpm" command`);
}
Rush.launchRushPnpm(launcherVersion, {
isManaged: options.isManaged,
alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError
});
}
else if (commandName === 'rushx') {
if (!Rush.launchRushX) {
RushCommandSelector._failWithError(`This repository is using Rush version ${Rush.version}` +
` which does not support the "rushx" command`);
}
Rush.launchRushX(launcherVersion, options);
}
else {
Rush.launch(launcherVersion, options);
}
}
static _failWithError(message) {
console.log(terminal_1.Colorize.red(message));
return process.exit(1);
}
static _getCommandName() {
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 = path.basename(process.argv[1]).toUpperCase();
if (basename === 'RUSH') {
return 'rush';
}
if (basename === 'RUSH-PNPM') {
return 'rush-pnpm';
}
if (basename === 'RUSHX') {
return 'rushx';
}
}
return undefined;
}
}
exports.RushCommandSelector = RushCommandSelector;
//# sourceMappingURL=RushCommandSelector.js.map
;