Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (57 sloc) 2.38 KB
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'path';
import { IBuildConfig } from '@microsoft/gulp-core-build';
import {
JsonFile,
FileSystem
} from '@microsoft/node-core-library';
import { IExtractorConfig, IExtractorOptions } from '@microsoft/api-extractor';
import { ApiExtractorRunner as TApiExtractorRunner } from '@microsoft/rush-stack-compiler-3.2';
import { RSCTask, IRSCTaskConfig } from './RSCTask';
/** @public */
export interface IApiExtractorTaskConfig extends IRSCTaskConfig {
}
/**
* 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 ApiExtractorTask extends RSCTask<IApiExtractorTaskConfig> {
constructor() {
super(
'api-extractor',
{}
);
}
public loadSchema(): Object {
return JsonFile.load(path.resolve(__dirname, 'schemas', 'api-extractor.schema.json'));
}
public isEnabled(buildConfig: IBuildConfig): boolean {
return FileSystem.exists(this._getApiExtractorConfigFilePath(buildConfig.rootPath));
}
public executeTask(): Promise<void> {
this.initializeRushStackCompiler();
const extractorOptions: IExtractorOptions = {
localBuild: !this.buildConfig.production
};
const ApiExtractorRunner: typeof TApiExtractorRunner = this._rushStackCompiler.ApiExtractorRunner;
const extractorConfig: IExtractorConfig = ApiExtractorRunner.apiExtractor.Extractor.loadConfigObject(
this._getApiExtractorConfigFilePath(this.buildConfig.rootPath)
);
const apiExtractorRunner: TApiExtractorRunner = new ApiExtractorRunner(
extractorConfig,
extractorOptions,
this.buildFolder,
this._terminalProvider
);
return apiExtractorRunner.invoke();
}
protected _getConfigFilePath(): string {
return path.join('.', 'config', 'gcb-api-extractor.json'); // There aren't config options specific to this task
}
private _getApiExtractorConfigFilePath(rootPath: string): string {
return path.resolve(rootPath, 'config', 'api-extractor.json');
}
}