microsoft/typespec

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
c344444f7bc36557af928b028ea191224adcd46c

Branches

Tags

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

Clone

HTTPS

Download ZIP

common/scripts/install-run-rush.js

215lines · 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 LICENSE in the project root for license information.
117/* eslint-disable no-console */
118
119
120const { installAndRun, findRushJsonFolder, RUSH_JSON_FILENAME, runWithErrorAndStatusCode } = require('./install-run');
121const PACKAGE_NAME = '@microsoft/rush';
122const RUSH_PREVIEW_VERSION = 'RUSH_PREVIEW_VERSION';
123const INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE = 'INSTALL_RUN_RUSH_LOCKFILE_PATH';
124function _getRushVersion(logger) {
125 const rushPreviewVersion = process.env[RUSH_PREVIEW_VERSION];
126 if (rushPreviewVersion !== undefined) {
127 logger.info(`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION}=${rushPreviewVersion}`);
128 return rushPreviewVersion;
129 }
130 const rushJsonFolder = findRushJsonFolder();
131 const rushJsonPath = path__WEBPACK_IMPORTED_MODULE_0__.join(rushJsonFolder, RUSH_JSON_FILENAME);
132 try {
133 const rushJsonContents = fs__WEBPACK_IMPORTED_MODULE_1__.readFileSync(rushJsonPath, 'utf-8');
134 // Use a regular expression to parse out the rushVersion value because rush.json supports comments,
135 // but JSON.parse does not and we don't want to pull in more dependencies than we need to in this script.
136 const rushJsonMatches = rushJsonContents.match(/\"rushVersion\"\s*\:\s*\"([0-9a-zA-Z.+\-]+)\"/);
137 return rushJsonMatches[1];
138 }
139 catch (e) {
140 throw new Error(`Unable to determine the required version of Rush from rush.json (${rushJsonFolder}). ` +
141 "The 'rushVersion' field is either not assigned in rush.json or was specified " +
142 'using an unexpected syntax.');
143 }
144}
145function _getBin(scriptName) {
146 switch (scriptName.toLowerCase()) {
147 case 'install-run-rush-pnpm.js':
148 return 'rush-pnpm';
149 case 'install-run-rushx.js':
150 return 'rushx';
151 default:
152 return 'rush';
153 }
154}
155function _run() {
156 const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
157 // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
158 // appropriate binary inside the rush package to run
159 const scriptName = path__WEBPACK_IMPORTED_MODULE_0__.basename(scriptPath);
160 const bin = _getBin(scriptName);
161 if (!nodePath || !scriptPath) {
162 throw new Error('Unexpected exception: could not detect node path or script path');
163 }
164 let commandFound = false;
165 let logger = { info: console.log, error: console.error };
166 for (const arg of packageBinArgs) {
167 if (arg === '-q' || arg === '--quiet') {
168 // The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress
169 // any normal informational/diagnostic information printed during startup.
170 //
171 // To maintain the same user experience, the install-run* scripts pass along this
172 // flag but also use it to suppress any diagnostic information normally printed
173 // to stdout.
174 logger = {
175 info: () => { },
176 error: console.error
177 };
178 }
179 else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
180 // We either found something that looks like a command (i.e. - doesn't start with a "-"),
181 // or we found the -h/--help flag, which can be run without a command
182 commandFound = true;
183 }
184 }
185 if (!commandFound) {
186 console.log(`Usage: ${scriptName} <command> [args...]`);
187 if (scriptName === 'install-run-rush-pnpm.js') {
188 console.log(`Example: ${scriptName} pnpm-command`);
189 }
190 else if (scriptName === 'install-run-rush.js') {
191 console.log(`Example: ${scriptName} build --to myproject`);
192 }
193 else {
194 console.log(`Example: ${scriptName} custom-command`);
195 }
196 process.exit(1);
197 }
198 runWithErrorAndStatusCode(logger, () => {
199 const version = _getRushVersion(logger);
200 logger.info(`The rush.json configuration requests Rush version ${version}`);
201 const lockFilePath = process.env[INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE];
202 if (lockFilePath) {
203 logger.info(`Found ${INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE}="${lockFilePath}", installing with lockfile.`);
204 }
205 return installAndRun(logger, PACKAGE_NAME, version, bin, packageBinArgs, lockFilePath);
206 });
207}
208_run();
209//# sourceMappingURL=install-run-rush.js.map
210})();
211
212module.exports = __webpack_exports__;
213/******/ })()
214;
215//# sourceMappingURL=install-run-rush.js.map