forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiExtractorRunner.ts
More file actions
141 lines (127 loc) · 4.74 KB
/
ApiExtractorRunner.ts
File metadata and controls
141 lines (127 loc) · 4.74 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { ITerminalProvider } from '@rushstack/node-core-library';
import {
Extractor,
ExtractorConfig,
IExtractorInvokeOptions
} from '@microsoft/api-extractor';
import * as ApiExtractor from '@microsoft/api-extractor';
import {
RushStackCompilerBase,
IRushStackCompilerBaseOptions
} from './RushStackCompilerBase';
import { ToolPaths } from './ToolPaths';
import { LoggingUtilities } from './LoggingUtilities';
/**
* The ApiExtractorTask uses the api-extractor tool to analyze a project for public APIs. api-extractor will detect
* common problems and generate a report of the exported public API. The task uses the entry point of a project to
* find the aliased exports of the project. An api-extractor.ts file is generated for the project in the temp folder.
* @beta
*/
export class ApiExtractorRunner extends RushStackCompilerBase {
public static apiExtractor: typeof ApiExtractor = ApiExtractor;
private _extractorConfig: ExtractorConfig;
private _extractorOptions: IExtractorInvokeOptions;
public constructor(
extractorConfig: ExtractorConfig,
extractorOptions: IExtractorInvokeOptions,
rootPath: string,
terminalProvider: ITerminalProvider
) // Remove in the next major version
public constructor(
options: IRushStackCompilerBaseOptions,
extractorConfig: ExtractorConfig,
extractorOptions: IExtractorInvokeOptions,
rootPath: string,
terminalProvider: ITerminalProvider
)
public constructor(
arg1: IRushStackCompilerBaseOptions| ExtractorConfig,
arg2: ExtractorConfig| IExtractorInvokeOptions,
arg3: IExtractorInvokeOptions| string,
arg4: string | ITerminalProvider,
arg5?: ITerminalProvider
) {
let options: IRushStackCompilerBaseOptions;
let extractorConfig: ExtractorConfig;
let extractorOptions: IExtractorInvokeOptions;
let rootPath: string;
let terminalProvider: ITerminalProvider;
if (arg1 instanceof ExtractorConfig) {
extractorConfig = arg1;
extractorOptions = arg2 as IExtractorInvokeOptions;
rootPath = arg3 as string;
terminalProvider = arg4 as ITerminalProvider;
const loggingUtilities: LoggingUtilities = new LoggingUtilities(terminalProvider);
options = loggingUtilities.getDefaultRushStackCompilerBaseOptions();
} else {
options = arg1;
extractorConfig = arg2 as ExtractorConfig;
extractorOptions = arg3 as IExtractorInvokeOptions;
rootPath = arg4 as string;
terminalProvider = arg5 as ITerminalProvider;
}
super(options, rootPath, terminalProvider);
this._extractorConfig = extractorConfig;
this._extractorOptions = extractorOptions;
}
public invoke(): Promise<void> {
try {
const extractorOptions: IExtractorInvokeOptions = {
...this._extractorOptions,
messageCallback: (message: ApiExtractor.ExtractorMessage) => {
switch (message.logLevel) {
case ApiExtractor.ExtractorLogLevel.Error: {
if (message.sourceFilePath) {
this._fileError(
message.sourceFilePath,
message.sourceFileLine!,
message.sourceFileColumn!,
message.category,
message.text
);
} else {
this._terminal.writeErrorLine(message.text);
}
break;
}
case ApiExtractor.ExtractorLogLevel.Warning: {
if (message.sourceFilePath) {
this._fileWarning(
message.sourceFilePath,
message.sourceFileLine!,
message.sourceFileColumn!,
message.category,
message.text
);
} else {
this._terminal.writeWarningLine(message.text);
}
break;
}
case ApiExtractor.ExtractorLogLevel.Info: {
this._terminal.writeLine(message.text);
break;
}
case ApiExtractor.ExtractorLogLevel.Verbose: {
this._terminal.writeVerboseLine(message.text);
break;
}
default: {
return;
}
}
message.handled = true;
},
typescriptCompilerFolder: ToolPaths.typescriptPackagePath
};
// NOTE: ExtractorResult.succeeded indicates whether errors or warnings occurred, however we
// already handle this above via our customLogger
Extractor.invoke(this._extractorConfig, extractorOptions);
return Promise.resolve();
} catch (e) {
return Promise.reject(e);
}
}
}