import * as path from 'path' ; import { ApiDocumenterCommandLine } from './ApiDocumenterCommandLine' ; import { BaseAction } from './BaseAction' ; import { DocumenterConfig } from '../documenters/DocumenterConfig' ; import { ExperimentalYamlDocumenter } from '../documenters/ExperimentalYamlDocumenter' ; import { FileSystem } from '@rushstack/node-core-library' ; import { MarkdownDocumenter } from '../documenters/MarkdownDocumenter' ; export class GenerateAction extends BaseAction { public 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.' } ) ; } protected async onExecute ( ) { let configFilePath = path . join ( process . cwd ( ) , DocumenterConfig . FILENAME ) ; if ( ! FileSystem . exists ( configFilePath ) ) { 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 ) ; } } }