-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathGenerateAction.ts
More file actions
60 lines (50 loc) · 2.25 KB
/
GenerateAction.ts
File metadata and controls
60 lines (50 loc) · 2.25 KB
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
// 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 type { ApiDocumenterCommandLine } from './ApiDocumenterCommandLine.ts';
import { BaseAction } from './BaseAction.ts';
import { DocumenterConfig } from '../documenters/DocumenterConfig.ts';
import { ExperimentalYamlDocumenter } from '../documenters/ExperimentalYamlDocumenter.ts';
import { MarkdownDocumenter } from '../documenters/MarkdownDocumenter.ts';
export class GenerateAction extends BaseAction {
public constructor(parser: ApiDocumenterCommandLine) {
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 override async onExecuteAsync(): Promise<void> {
// Look for the config file under the current folder
let configFilePath: string = 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 = DocumenterConfig.loadFile(configFilePath);
const { apiModel, outputFolder } = this.buildApiModel();
if (documenterConfig.configFile.outputTarget === 'markdown') {
const markdownDocumenter: MarkdownDocumenter = new MarkdownDocumenter({
apiModel,
documenterConfig,
outputFolder
});
markdownDocumenter.generateFiles();
} else {
const yamlDocumenter: ExperimentalYamlDocumenter = new ExperimentalYamlDocumenter(
apiModel,
documenterConfig
);
yamlDocumenter.generateFiles(outputFolder);
}
}
}