|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. |
2 | 2 | // See LICENSE in the project root for license information. |
3 | 3 |
|
| 4 | +import * as colors from 'colors'; |
4 | 5 | import * as fsx from 'fs-extra'; |
5 | 6 | import * as os from 'os'; |
6 | 7 |
|
7 | 8 | import { BaseScriptAction, IBaseScriptActionOptions } from './BaseScriptAction'; |
| 9 | +import { Utilities } from '../../utilities/Utilities'; |
| 10 | +import { AlreadyReportedError } from '../../../lib/utilities/AlreadyReportedError'; |
8 | 11 |
|
9 | 12 | /** |
10 | 13 | * Constructor parameters for GlobalScriptAction. |
@@ -34,19 +37,40 @@ export class GlobalScriptAction extends BaseScriptAction { |
34 | 37 | } |
35 | 38 |
|
36 | 39 | public run(): Promise<void> { |
37 | | - if (!fsx.existsSync(this.rushConfiguration.rushLinkJsonFilename)) { |
38 | | - throw new Error(`File not found: ${this.rushConfiguration.rushLinkJsonFilename}` + |
39 | | - `${os.EOL}Did you run "rush link"?`); |
40 | | - } |
| 40 | + return Promise.resolve().then(() => { |
| 41 | + if (!fsx.existsSync(this.rushConfiguration.rushLinkJsonFilename)) { |
| 42 | + throw new Error(`File not found: ${this.rushConfiguration.rushLinkJsonFilename}` + |
| 43 | + `${os.EOL}Did you run "rush link"?`); |
| 44 | + } |
41 | 45 |
|
42 | | - // Collect all custom parameter values |
43 | | - const customParameterValues: string[] = []; |
| 46 | + // Collect all custom parameter values |
| 47 | + const customParameterValues: string[] = []; |
44 | 48 |
|
45 | | - for (const customParameter of this.customParameters) { |
46 | | - customParameter.appendToArgList(customParameterValues); |
47 | | - } |
| 49 | + for (const customParameter of this.customParameters) { |
| 50 | + customParameter.appendToArgList(customParameterValues); |
| 51 | + } |
48 | 52 |
|
49 | | - return Promise.resolve(); |
| 53 | + let shellCommand: string = this._scriptPath; |
| 54 | + if (customParameterValues.length > 0) { |
| 55 | + shellCommand += ' ' + customParameterValues.join(' '); |
| 56 | + } |
| 57 | + |
| 58 | + const exitCode: number = Utilities.executeLifecycleCommand(shellCommand, |
| 59 | + { |
| 60 | + workingDirectory: this.rushConfiguration.rushJsonFolder, |
| 61 | + initCwd: this.rushConfiguration.commonTempFolder, |
| 62 | + handleOutput: false |
| 63 | + } |
| 64 | + ); |
| 65 | + |
| 66 | + if (exitCode > 0) { |
| 67 | + console.log(os.EOL + colors.red(`The script failed with exit code ${exitCode}`)); |
| 68 | + } |
| 69 | + |
| 70 | + process.exitCode = exitCode; |
| 71 | + |
| 72 | + throw new AlreadyReportedError(); |
| 73 | + }); |
50 | 74 | } |
51 | 75 |
|
52 | 76 | protected onDefineParameters(): void { |
|
0 commit comments