-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
run.ts
53 lines (46 loc) · 1.26 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable no-console */
/* This is one rare place where we're fine to use process/console directly,
* but other code abstracts those to remain composable and testable. */
import Cli, { ICliRunResult } from './'
import VError from 'verror'
import publishBanner from './publish_banner'
import { validateNodeEngineVersion } from './validate_node_engine_version'
function logErrorMessageAndExit(message: string): void {
console.error(message)
process.exit(1)
}
function displayPublishAdvertisementBanner(): void {
console.error(publishBanner)
}
export default async function run(): Promise<void> {
validateNodeEngineVersion(
process.version,
(error) => {
console.error(error)
process.exit(1)
},
console.warn
)
const cli = new Cli({
argv: process.argv,
cwd: process.cwd(),
stdout: process.stdout,
stderr: process.stderr,
env: process.env,
})
let result: ICliRunResult
try {
result = await cli.run()
} catch (error) {
logErrorMessageAndExit(VError.fullStack(error))
}
if (result.shouldAdvertisePublish) {
displayPublishAdvertisementBanner()
}
const exitCode = result.success ? 0 : 1
if (result.shouldExitImmediately) {
process.exit(exitCode)
} else {
process.exitCode = exitCode
}
}