forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiExtractorCommandLine.ts
57 lines (48 loc) · 2.03 KB
/
ApiExtractorCommandLine.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
54
55
56
57
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as os from 'os';
import { CommandLineParser, type CommandLineFlagParameter } from '@rushstack/ts-command-line';
import { InternalError } from '@rushstack/node-core-library';
import { Colorize } from '@rushstack/terminal';
import { RunAction } from './RunAction';
import { InitAction } from './InitAction';
export class ApiExtractorCommandLine extends CommandLineParser {
private readonly _debugParameter: CommandLineFlagParameter;
public constructor() {
super({
toolFilename: 'api-extractor',
toolDescription:
'API Extractor helps you build better TypeScript libraries. It analyzes the main entry' +
' point for your package, collects the inventory of exported declarations, and then generates three kinds' +
' of output: an API report file (.api.md) to facilitate reviews, a declaration rollup (.d.ts) to be' +
' published with your NPM package, and a doc model file (.api.json) to be used with a documentation' +
' tool such as api-documenter. For details, please visit the web site.'
});
this._populateActions();
this._debugParameter = this.defineFlagParameter({
parameterLongName: '--debug',
parameterShortName: '-d',
description: 'Show the full call stack if an error occurs while executing the tool'
});
}
protected override async onExecuteAsync(): Promise<void> {
if (this._debugParameter.value) {
InternalError.breakInDebugger = true;
}
process.exitCode = 1;
try {
await super.onExecuteAsync();
process.exitCode = 0;
} catch (error) {
if (this._debugParameter.value) {
console.error(os.EOL + error.stack);
} else {
console.error(os.EOL + Colorize.red('ERROR: ' + error.message.trim()));
}
}
}
private _populateActions(): void {
this.addAction(new InitAction(this));
this.addAction(new RunAction(this));
}
}