forked from bitnami/readme-generator-for-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (48 loc) · 1.95 KB
/
index.js
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
61
/*
* Copyright 2021-2021 VMware, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
const { createValuesObject, parseMetadataComments } = require('./lib/parser');
const { checkKeys } = require('./lib/checker');
const { combineMetadataAndValues, buildSectionsArrays, buildParamsToRenderList } = require('./lib/builder');
const { insertReadmeTable, renderOpenAPISchema } = require('./lib/render');
function getParameters(options) {
const valuesFilePath = options.values;
const configPath = options.config ? options.config : `${__dirname}/config.json`;
const CONFIG = require(configPath);
const valuesObject = createValuesObject(valuesFilePath);
const valuesMetadata = parseMetadataComments(valuesFilePath, CONFIG);
// Check the parsed keys are consistent with the real ones
checkKeys(valuesObject, valuesMetadata);
// Combine after the check
// valuesMetadata is modified and filled with more info
combineMetadataAndValues(valuesObject, valuesMetadata);
return valuesMetadata;
}
function runReadmeGenerator(options) {
const valuesFilePath = options.values;
const readmeFilePath = options.readme;
const schemaFilePath = options.schema;
if (!readmeFilePath && !schemaFilePath) {
throw new Error('Nothing to do. Please provide a README file or Schema file output.');
}
if (!valuesFilePath) {
throw new Error('Values file not provided');
}
const configPath = options.config ? options.config : `${__dirname}/config.json`;
const CONFIG = require(configPath);
const parametersList = getParameters(options);
if (readmeFilePath) {
const paramsToRender = buildParamsToRenderList(parametersList, CONFIG);
const sections = buildSectionsArrays(paramsToRender);
insertReadmeTable(readmeFilePath, sections, CONFIG);
}
if (schemaFilePath) {
renderOpenAPISchema(schemaFilePath, parametersList, CONFIG);
}
}
module.exports = {
runReadmeGenerator,
};