UNPKG

3.62 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3// See LICENSE in the project root for license information.
4var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5 if (k2 === undefined) k2 = k;
6 var desc = Object.getOwnPropertyDescriptor(m, k);
7 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8 desc = { enumerable: true, get: function() { return m[k]; } };
9 }
10 Object.defineProperty(o, k2, desc);
11}) : (function(o, m, k, k2) {
12 if (k2 === undefined) k2 = k;
13 o[k2] = m[k];
14}));
15var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16 Object.defineProperty(o, "default", { enumerable: true, value: v });
17}) : function(o, v) {
18 o["default"] = v;
19});
20var __importStar = (this && this.__importStar) || function (mod) {
21 if (mod && mod.__esModule) return mod;
22 var result = {};
23 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24 __setModuleDefault(result, mod);
25 return result;
26};
27Object.defineProperty(exports, "__esModule", { value: true });
28exports.GenerateAction = void 0;
29const path = __importStar(require("path"));
30const BaseAction_1 = require("./BaseAction");
31const DocumenterConfig_1 = require("../documenters/DocumenterConfig");
32const ExperimentalYamlDocumenter_1 = require("../documenters/ExperimentalYamlDocumenter");
33const node_core_library_1 = require("@rushstack/node-core-library");
34const MarkdownDocumenter_1 = require("../documenters/MarkdownDocumenter");
35class GenerateAction extends BaseAction_1.BaseAction {
36 constructor(parser) {
37 super({
38 actionName: 'generate',
39 summary: 'EXPERIMENTAL',
40 documentation: 'EXPERIMENTAL - This action is a prototype of a new config file driven mode of operation for' +
41 ' API Documenter. It is not ready for general usage yet. Its design may change in the future.'
42 });
43 }
44 async onExecute() {
45 // override
46 // Look for the config file under the current folder
47 let configFilePath = path.join(process.cwd(), DocumenterConfig_1.DocumenterConfig.FILENAME);
48 // First try the current folder
49 if (!node_core_library_1.FileSystem.exists(configFilePath)) {
50 // Otherwise try the standard "config" subfolder
51 configFilePath = path.join(process.cwd(), 'config', DocumenterConfig_1.DocumenterConfig.FILENAME);
52 if (!node_core_library_1.FileSystem.exists(configFilePath)) {
53 throw new Error(`Unable to find ${DocumenterConfig_1.DocumenterConfig.FILENAME} in the current folder or in a "config" subfolder`);
54 }
55 }
56 const documenterConfig = DocumenterConfig_1.DocumenterConfig.loadFile(configFilePath);
57 const { apiModel, outputFolder } = this.buildApiModel();
58 if (documenterConfig.configFile.outputTarget === 'markdown') {
59 const markdownDocumenter = new MarkdownDocumenter_1.MarkdownDocumenter({
60 apiModel,
61 documenterConfig,
62 outputFolder
63 });
64 markdownDocumenter.generateFiles();
65 }
66 else {
67 const yamlDocumenter = new ExperimentalYamlDocumenter_1.ExperimentalYamlDocumenter(apiModel, documenterConfig);
68 yamlDocumenter.generateFiles(outputFolder);
69 }
70 }
71}
72exports.GenerateAction = GenerateAction;
73//# sourceMappingURL=GenerateAction.js.map
\No newline at end of file