microsoft/typespec

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4d92e0825d81d6432d29b0fade7b161a2e2aafb7

Branches

Tags

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

Clone

HTTPS

Download ZIP

common/scripts/install-run-rush.js

107lines · modecode

1"use strict";
2// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3// See the @microsoft/rush package's LICENSE file for license information.
4var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5 if (k2 === undefined) k2 = k;
6 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
7}) : (function(o, m, k, k2) {
8 if (k2 === undefined) k2 = k;
9 o[k2] = m[k];
10}));
11var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
12 Object.defineProperty(o, "default", { enumerable: true, value: v });
13}) : function(o, v) {
14 o["default"] = v;
15});
16var __importStar = (this && this.__importStar) || function (mod) {
17 if (mod && mod.__esModule) return mod;
18 var result = {};
19 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
20 __setModuleDefault(result, mod);
21 return result;
22};
23Object.defineProperty(exports, "__esModule", { value: true });
24// THIS FILE WAS GENERATED BY A TOOL. ANY MANUAL MODIFICATIONS WILL GET OVERWRITTEN WHENEVER RUSH IS UPGRADED.
25//
26// This script is intended for usage in an automated build environment where the Rush command may not have
27// been preinstalled, or may have an unpredictable version. This script will automatically install the version of Rush
28// specified in the rush.json configuration file (if not already installed), and then pass a command-line to it.
29// An example usage would be:
30//
31// node common/scripts/install-run-rush.js install
32//
33// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
34const path = __importStar(require("path"));
35const fs = __importStar(require("fs"));
36const install_run_1 = require("./install-run");
37const PACKAGE_NAME = '@microsoft/rush';
38const RUSH_PREVIEW_VERSION = 'RUSH_PREVIEW_VERSION';
39function _getRushVersion(logger) {
40 const rushPreviewVersion = process.env[RUSH_PREVIEW_VERSION];
41 if (rushPreviewVersion !== undefined) {
42 logger.info(`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION}=${rushPreviewVersion}`);
43 return rushPreviewVersion;
44 }
45 const rushJsonFolder = (0, install_run_1.findRushJsonFolder)();
46 const rushJsonPath = path.join(rushJsonFolder, install_run_1.RUSH_JSON_FILENAME);
47 try {
48 const rushJsonContents = fs.readFileSync(rushJsonPath, 'utf-8');
49 // Use a regular expression to parse out the rushVersion value because rush.json supports comments,
50 // but JSON.parse does not and we don't want to pull in more dependencies than we need to in this script.
51 const rushJsonMatches = rushJsonContents.match(/\"rushVersion\"\s*\:\s*\"([0-9a-zA-Z.+\-]+)\"/);
52 return rushJsonMatches[1];
53 }
54 catch (e) {
55 throw new Error(`Unable to determine the required version of Rush from rush.json (${rushJsonFolder}). ` +
56 "The 'rushVersion' field is either not assigned in rush.json or was specified " +
57 'using an unexpected syntax.');
58 }
59}
60function _run() {
61 const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
62 // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
63 // appropriate binary inside the rush package to run
64 const scriptName = path.basename(scriptPath);
65 const bin = scriptName.toLowerCase() === 'install-run-rushx.js' ? 'rushx' : 'rush';
66 if (!nodePath || !scriptPath) {
67 throw new Error('Unexpected exception: could not detect node path or script path');
68 }
69 let commandFound = false;
70 let logger = { info: console.log, error: console.error };
71 for (const arg of packageBinArgs) {
72 if (arg === '-q' || arg === '--quiet') {
73 // The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress
74 // any normal informational/diagnostic information printed during startup.
75 //
76 // To maintain the same user experience, the install-run* scripts pass along this
77 // flag but also use it to suppress any diagnostic information normally printed
78 // to stdout.
79 logger = {
80 info: () => { },
81 error: console.error
82 };
83 }
84 else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
85 // We either found something that looks like a command (i.e. - doesn't start with a "-"),
86 // or we found the -h/--help flag, which can be run without a command
87 commandFound = true;
88 }
89 }
90 if (!commandFound) {
91 console.log(`Usage: ${scriptName} <command> [args...]`);
92 if (scriptName === 'install-run-rush.js') {
93 console.log(`Example: ${scriptName} build --to myproject`);
94 }
95 else {
96 console.log(`Example: ${scriptName} custom-command`);
97 }
98 process.exit(1);
99 }
100 (0, install_run_1.runWithErrorAndStatusCode)(logger, () => {
101 const version = _getRushVersion(logger);
102 logger.info(`The rush.json configuration requests Rush version ${version}`);
103 return (0, install_run_1.installAndRun)(logger, PACKAGE_NAME, version, bin, packageBinArgs);
104 });
105}
106_run();
107//# sourceMappingURL=install-run-rush.js.map