/
runScenarios.ts
112 lines (91 loc) · 3.65 KB
/
runScenarios.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
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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as fs from 'fs';
import * as path from 'path';
import { JsonFile } from '@microsoft/node-core-library';
import {
Extractor,
ExtractorConfig,
CompilerState,
ExtractorResult,
ExtractorMessage,
ConsoleMessageId,
ExtractorLogLevel
} from '@microsoft/api-extractor';
export function runScenarios(buildConfigPath: string): void {
const buildConfig = JsonFile.load(buildConfigPath);
const entryPoints: string[] = [];
// TODO: Eliminate this workaround
// See GitHub issue https://github.com/microsoft/rushstack/issues/1017
for (const scenarioFolderName of buildConfig.scenarioFolderNames) {
const entryPoint: string = path.resolve(`./lib/${scenarioFolderName}/index.d.ts`);
entryPoints.push(entryPoint);
const overridesPath = path.resolve(`./src/${scenarioFolderName}/config/api-extractor-overrides.json`);
const apiExtractorJsonOverrides = fs.existsSync(overridesPath) ? JsonFile.load(overridesPath) : {};
const apiExtractorJson = {
'$schema': 'https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json',
'mainEntryPointFilePath': entryPoint,
'apiReport': {
'enabled': true,
'reportFolder': `<projectFolder>/etc/test-outputs/${scenarioFolderName}`
},
'dtsRollup': {
'enabled': true,
'untrimmedFilePath': `<projectFolder>/etc/test-outputs/${scenarioFolderName}/rollup.d.ts`
},
'docModel': {
'enabled': true,
'apiJsonFilePath': `<projectFolder>/etc/test-outputs/${scenarioFolderName}/<unscopedPackageName>.api.json`
},
'messages': {
'extractorMessageReporting': {
// For test purposes, write these warnings into .api.md
// TODO: Capture the full list of warnings in the tracked test output file
'ae-cyclic-inherit-doc': {
'logLevel': 'warning',
'addToApiReportFile': true
},
'ae-unresolved-link': {
'logLevel': 'warning',
'addToApiReportFile': true
}
}
},
'testMode': true,
...apiExtractorJsonOverrides
};
const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;
JsonFile.save(apiExtractorJson, apiExtractorJsonPath, { ensureFolderExists: true });
}
let compilerState: CompilerState | undefined = undefined;
let anyErrors: boolean = false;
process.exitCode = 1;
for (const scenarioFolderName of buildConfig.scenarioFolderNames) {
const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;
console.log('Scenario: ' + scenarioFolderName);
// Run the API Extractor command-line
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath);
if (!compilerState) {
compilerState = CompilerState.create(extractorConfig, {
additionalEntryPoints: entryPoints
});
}
const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true,
messageCallback: (message: ExtractorMessage) => {
if (message.messageId === ConsoleMessageId.ApiReportCreated) {
// This script deletes the outputs for a clean build, so don't issue a warning if the file gets created
message.logLevel = ExtractorLogLevel.None;
}
},
compilerState
});
if (extractorResult.errorCount > 0) {
anyErrors = true;
}
}
if (!anyErrors) {
process.exitCode = 0;
}
}