forked from bitnami/readme-generator-for-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (48 loc) · 1.92 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
/*
* Copyright 2021-2021 VMware, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
const { createValuesObject, parseMetadataComments, generateMetadataObject } = require('./lib/parser');
const { checkKeys } = require('./lib/checker');
const { buildSections } = require('./lib/builder');
const { insertReadmeTable, exportMetadata } = require('./lib/render');
function getValuesSections(options) {
const valuesFilePath = options.values;
const configPath = options.config ? options.config : `${__dirname}/config.json`;
const CONFIG = require(configPath);
const valuesObject = createValuesObject(valuesFilePath);
let valuesMetadata = parseMetadataComments(valuesFilePath, CONFIG);
// Check the parsed keys are consistent with the real ones
checkKeys(valuesObject, valuesMetadata);
// We don't need the skip objects anymore so filter them
valuesMetadata = valuesMetadata.filter((el) => (!el.skip));
// Return sections array combining metadata and real values
return buildSections(valuesObject, valuesMetadata);
}
function runReadmeGenerator(options) {
const valuesFilePath = options.values;
const readmeFilePath = options.readme;
const metadataFilePath = options.metadata;
if (!readmeFilePath && !metadataFilePath) {
throw new Error('Nothing to do. Please provide a README file or Metadata output.');
}
if (!valuesFilePath) {
throw new Error('Values file not provided');
}
const configPath = options.config ? options.config : `${__dirname}/config.json`;
const CONFIG = require(configPath);
const sections = getValuesSections(options);
if (readmeFilePath) {
insertReadmeTable(readmeFilePath, sections, CONFIG);
}
if (metadataFilePath) {
const metadata = generateMetadataObject(sections, valuesFilePath);
exportMetadata(metadataFilePath, metadata);
}
}
module.exports = {
getValuesSections,
runReadmeGenerator,
};