-
Notifications
You must be signed in to change notification settings - Fork 607
/
ApiExtractorRunner.ts
73 lines (65 loc) · 2.64 KB
/
ApiExtractorRunner.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { ITerminalProvider } from '@microsoft/node-core-library';
import {
Extractor,
ExtractorConfig,
IExtractorInvokeOptions
} from '@microsoft/api-extractor';
import * as ApiExtractor from '@microsoft/api-extractor';
import { RushStackCompilerBase } from './RushStackCompilerBase';
import { ToolPaths } from './ToolPaths';
/**
* 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;
constructor(
extractorConfig: ExtractorConfig,
extractorOptions: IExtractorInvokeOptions,
rootPath: string,
terminalProvider: ITerminalProvider
) {
super({}, 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:
this._terminal.writeErrorLine.bind(this._terminal);
break;
case ApiExtractor.ExtractorLogLevel.Warning:
this._terminal.writeWarningLine.bind(this._terminal);
break;
case ApiExtractor.ExtractorLogLevel.Info:
this._terminal.writeLine.bind(this._terminal);
break;
case ApiExtractor.ExtractorLogLevel.Verbose:
this._terminal.writeVerboseLine.bind(this._terminal);
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);
}
}
}