UNPKG

@microsoft/api-extractor

Version:

Validate, document, and review the exported API for a TypeScript library

76 lines (74 loc) 3.42 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. Object.defineProperty(exports, "__esModule", { value: true }); const colors = require("colors"); const fsx = require("fs-extra"); const os = require("os"); const path = require("path"); const node_core_library_1 = require("@microsoft/node-core-library"); const ts_command_line_1 = require("@microsoft/ts-command-line"); const Extractor_1 = require("../extractor/Extractor"); const AE_CONFIG_FILENAME = 'api-extractor.json'; class RunAction extends ts_command_line_1.CommandLineAction { constructor(parser) { super({ actionVerb: 'run', summary: 'Invoke API Extractor on a project', documentation: 'Invoke API Extractor on a project' }); this._parser = parser; } onDefineParameters() { this._configFileParameter = this.defineStringParameter({ parameterLongName: '--config', parameterShortName: '-c', key: 'FILE', description: `Use the specified ${AE_CONFIG_FILENAME} file path, rather than guessing its location` }); this._localParameter = this.defineFlagParameter({ parameterLongName: '--local', parameterShortName: '-l', description: 'Indicates that API Extractor is running as part of a local build,' + ' e.g. on a developer\'s machine. This disables certain validation that would' + ' normally be performed for a ship/production build. For example, the *.api.ts' + ' review file is automatically copied in a local build.' }); } onExecute() { let configFilename; if (this._configFileParameter.value) { configFilename = path.normalize(this._configFileParameter.value); if (!fsx.existsSync(configFilename)) { throw new Error('Config file not found: ' + this._configFileParameter.value); } } else { // Otherwise, figure out which project we're in and look for the config file // at the project root const lookup = new node_core_library_1.PackageJsonLookup(); const packageFolder = lookup.tryGetPackageFolder('.'); if (packageFolder) { configFilename = path.join(packageFolder, AE_CONFIG_FILENAME); } else { // If there is no package, then try the current directory configFilename = path.join(process.cwd(), AE_CONFIG_FILENAME); } if (!fsx.existsSync(configFilename)) { throw new Error(`Unable to find an ${AE_CONFIG_FILENAME} file`); } console.log(`Using configuration from ${configFilename}` + os.EOL + os.EOL); } const config = node_core_library_1.JsonFile.loadAndValidate(configFilename, Extractor_1.Extractor.jsonSchema); const extractor = new Extractor_1.Extractor(config, { localBuild: this._localParameter.value }); if (!extractor.processProject()) { console.log(os.EOL + colors.yellow('API Extractor completed with errors or warnings')); process.exitCode = 1; } } } exports.RunAction = RunAction; //# sourceMappingURL=RunAction.js.map