microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4b0eb8ea94e5a39b8f80d1797aed02ae6c11a07b

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

common/scripts/install-run-rush.js

214lines · modecode

1// THIS FILE WAS GENERATED BY A TOOL. ANY MANUAL MODIFICATIONS WILL GET OVERWRITTEN WHENEVER RUSH IS UPGRADED.
2//
3// This script is intended for usage in an automated build environment where the Rush command may not have
4// been preinstalled, or may have an unpredictable version. This script will automatically install the version of Rush
5// specified in the rush.json configuration file (if not already installed), and then pass a command-line to it.
6// An example usage would be:
7//
8// node common/scripts/install-run-rush.js install
9//
10// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
11
12/******/ (() => { // webpackBootstrap
13/******/ "use strict";
14/******/ var __webpack_modules__ = ({
15
16/***/ 657147:
17/*!*********************!*\
18 !*** external "fs" ***!
19 \*********************/
20/***/ ((module) => {
21
22module.exports = require("fs");
23
24/***/ }),
25
26/***/ 371017:
27/*!***********************!*\
28 !*** external "path" ***!
29 \***********************/
30/***/ ((module) => {
31
32module.exports = require("path");
33
34/***/ })
35
36/******/ });
37/************************************************************************/
38/******/ // The module cache
39/******/ var __webpack_module_cache__ = {};
40/******/
41/******/ // The require function
42/******/ function __webpack_require__(moduleId) {
43/******/ // Check if module is in cache
44/******/ var cachedModule = __webpack_module_cache__[moduleId];
45/******/ if (cachedModule !== undefined) {
46/******/ return cachedModule.exports;
47/******/ }
48/******/ // Create a new module (and put it into the cache)
49/******/ var module = __webpack_module_cache__[moduleId] = {
50/******/ // no module.id needed
51/******/ // no module.loaded needed
52/******/ exports: {}
53/******/ };
54/******/
55/******/ // Execute the module function
56/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
57/******/
58/******/ // Return the exports of the module
59/******/ return module.exports;
60/******/ }
61/******/
62/************************************************************************/
63/******/ /* webpack/runtime/compat get default export */
64/******/ (() => {
65/******/ // getDefaultExport function for compatibility with non-harmony modules
66/******/ __webpack_require__.n = (module) => {
67/******/ var getter = module && module.__esModule ?
68/******/ () => (module['default']) :
69/******/ () => (module);
70/******/ __webpack_require__.d(getter, { a: getter });
71/******/ return getter;
72/******/ };
73/******/ })();
74/******/
75/******/ /* webpack/runtime/define property getters */
76/******/ (() => {
77/******/ // define getter functions for harmony exports
78/******/ __webpack_require__.d = (exports, definition) => {
79/******/ for(var key in definition) {
80/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
81/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
82/******/ }
83/******/ }
84/******/ };
85/******/ })();
86/******/
87/******/ /* webpack/runtime/hasOwnProperty shorthand */
88/******/ (() => {
89/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
90/******/ })();
91/******/
92/******/ /* webpack/runtime/make namespace object */
93/******/ (() => {
94/******/ // define __esModule on exports
95/******/ __webpack_require__.r = (exports) => {
96/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
97/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
98/******/ }
99/******/ Object.defineProperty(exports, '__esModule', { value: true });
100/******/ };
101/******/ })();
102/******/
103/************************************************************************/
104var __webpack_exports__ = {};
105// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
106(() => {
107/*!************************************************!*\
108 !*** ./lib-esnext/scripts/install-run-rush.js ***!
109 \************************************************/
110__webpack_require__.r(__webpack_exports__);
111/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! path */ 371017);
112/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
113/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! fs */ 657147);
114/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_1__);
115// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
116// See the @microsoft/rush package's LICENSE file for license information.
117
118
119const { installAndRun, findRushJsonFolder, RUSH_JSON_FILENAME, runWithErrorAndStatusCode } = require('./install-run');
120const PACKAGE_NAME = '@microsoft/rush';
121const RUSH_PREVIEW_VERSION = 'RUSH_PREVIEW_VERSION';
122const INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE = 'INSTALL_RUN_RUSH_LOCKFILE_PATH';
123function _getRushVersion(logger) {
124 const rushPreviewVersion = process.env[RUSH_PREVIEW_VERSION];
125 if (rushPreviewVersion !== undefined) {
126 logger.info(`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION}=${rushPreviewVersion}`);
127 return rushPreviewVersion;
128 }
129 const rushJsonFolder = findRushJsonFolder();
130 const rushJsonPath = path__WEBPACK_IMPORTED_MODULE_0__.join(rushJsonFolder, RUSH_JSON_FILENAME);
131 try {
132 const rushJsonContents = fs__WEBPACK_IMPORTED_MODULE_1__.readFileSync(rushJsonPath, 'utf-8');
133 // Use a regular expression to parse out the rushVersion value because rush.json supports comments,
134 // but JSON.parse does not and we don't want to pull in more dependencies than we need to in this script.
135 const rushJsonMatches = rushJsonContents.match(/\"rushVersion\"\s*\:\s*\"([0-9a-zA-Z.+\-]+)\"/);
136 return rushJsonMatches[1];
137 }
138 catch (e) {
139 throw new Error(`Unable to determine the required version of Rush from rush.json (${rushJsonFolder}). ` +
140 "The 'rushVersion' field is either not assigned in rush.json or was specified " +
141 'using an unexpected syntax.');
142 }
143}
144function _getBin(scriptName) {
145 switch (scriptName.toLowerCase()) {
146 case 'install-run-rush-pnpm.js':
147 return 'rush-pnpm';
148 case 'install-run-rushx.js':
149 return 'rushx';
150 default:
151 return 'rush';
152 }
153}
154function _run() {
155 const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
156 // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
157 // appropriate binary inside the rush package to run
158 const scriptName = path__WEBPACK_IMPORTED_MODULE_0__.basename(scriptPath);
159 const bin = _getBin(scriptName);
160 if (!nodePath || !scriptPath) {
161 throw new Error('Unexpected exception: could not detect node path or script path');
162 }
163 let commandFound = false;
164 let logger = { info: console.log, error: console.error };
165 for (const arg of packageBinArgs) {
166 if (arg === '-q' || arg === '--quiet') {
167 // The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress
168 // any normal informational/diagnostic information printed during startup.
169 //
170 // To maintain the same user experience, the install-run* scripts pass along this
171 // flag but also use it to suppress any diagnostic information normally printed
172 // to stdout.
173 logger = {
174 info: () => { },
175 error: console.error
176 };
177 }
178 else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
179 // We either found something that looks like a command (i.e. - doesn't start with a "-"),
180 // or we found the -h/--help flag, which can be run without a command
181 commandFound = true;
182 }
183 }
184 if (!commandFound) {
185 console.log(`Usage: ${scriptName} <command> [args...]`);
186 if (scriptName === 'install-run-rush-pnpm.js') {
187 console.log(`Example: ${scriptName} pnpm-command`);
188 }
189 else if (scriptName === 'install-run-rush.js') {
190 console.log(`Example: ${scriptName} build --to myproject`);
191 }
192 else {
193 console.log(`Example: ${scriptName} custom-command`);
194 }
195 process.exit(1);
196 }
197 runWithErrorAndStatusCode(logger, () => {
198 const version = _getRushVersion(logger);
199 logger.info(`The rush.json configuration requests Rush version ${version}`);
200 const lockFilePath = process.env[INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE];
201 if (lockFilePath) {
202 logger.info(`Found ${INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE}="${lockFilePath}", installing with lockfile.`);
203 }
204 return installAndRun(logger, PACKAGE_NAME, version, bin, packageBinArgs, lockFilePath);
205 });
206}
207_run();
208//# sourceMappingURL=install-run-rush.js.map
209})();
210
211module.exports = __webpack_exports__;
212/******/ })()
213;
214//# sourceMappingURL=install-run-rush.js.map