@microsoft/api-documenter
Version:
Read JSON files from api-extractor, generate documentation pages
45 lines • 2.22 kB
JavaScript
// 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 'node:path';
import { FileSystem } from '@rushstack/node-core-library';
import { BaseAction } from './BaseAction';
import { DocumenterConfig } from '../documenters/DocumenterConfig';
import { ExperimentalYamlDocumenter } from '../documenters/ExperimentalYamlDocumenter';
import { MarkdownDocumenter } from '../documenters/MarkdownDocumenter';
export class GenerateAction extends BaseAction {
constructor(parser) {
super({
actionName: 'generate',
summary: 'EXPERIMENTAL',
documentation: 'EXPERIMENTAL - This action is a prototype of a new config file driven mode of operation for' +
' API Documenter. It is not ready for general usage yet. Its design may change in the future.'
});
}
async onExecuteAsync() {
// Look for the config file under the current folder
let configFilePath = path.join(process.cwd(), DocumenterConfig.FILENAME);
// First try the current folder
if (!FileSystem.exists(configFilePath)) {
// Otherwise try the standard "config" subfolder
configFilePath = path.join(process.cwd(), 'config', DocumenterConfig.FILENAME);
if (!FileSystem.exists(configFilePath)) {
throw new Error(`Unable to find ${DocumenterConfig.FILENAME} in the current folder or in a "config" subfolder`);
}
}
const documenterConfig = DocumenterConfig.loadFile(configFilePath);
const { apiModel, outputFolder } = this.buildApiModel();
if (documenterConfig.configFile.outputTarget === 'markdown') {
const markdownDocumenter = new MarkdownDocumenter({
apiModel,
documenterConfig,
outputFolder
});
markdownDocumenter.generateFiles();
}
else {
const yamlDocumenter = new ExperimentalYamlDocumenter(apiModel, documenterConfig);
yamlDocumenter.generateFiles(outputFolder);
}
}
}
//# sourceMappingURL=GenerateAction.js.map