Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read config file from absolute and relative references #111

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ const { checkKeys } = require('./lib/checker');
const { combineMetadataAndValues, buildParamsToRenderList } = require('./lib/builder');
const { insertReadmeTable, renderOpenAPISchema } = require('./lib/render');

function getParsedMetadata(options) {
const valuesFilePath = options.values;
const configPath = options.config ? options.config : `${__dirname}/config.json`;
const config = require(configPath);

function getParsedMetadata(valuesFilePath, config) {
const valuesObject = createValuesObject(valuesFilePath);
const valuesMetadata = parseMetadataComments(valuesFilePath, config);

Expand Down Expand Up @@ -49,7 +45,7 @@ function runReadmeGenerator(options) {
}
const configPath = options.config ? options.config : `${__dirname}/config.json`;
const config = JSON.parse(fs.readFileSync(configPath));
const parsedMetadata = getParsedMetadata(options);
const parsedMetadata = getParsedMetadata(options.values, config);

if (readmeFilePath) {
/* eslint no-param-reassign: ["error", { "props": false }] */
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitnami/readme-generator-for-helm",
"version": "2.6.1",
"version": "2.6.2",
"description": "Autogenerate READMEs tables and OpenAPI schemas for Helm Charts",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const testReadmeLastSectionWithTextBelowPath = `${__dirname}/test-readme.last-se
const expectedReadmeLastSectionWithTextBelowPath = `${__dirname}/expected-readme.last-section-text-below.md`; // File that must result from executing the tool providing the test README and values
const testSchemaPath = `${__dirname}/test-schema.json`; // File where the content will end after the tool is executed
const expectedSchemaPath = `${__dirname}/expected-schema.json`; // File that must result from executing the tool providing the test README and values
const testReadConfigFile = `${__dirname}/test-readme.config.md`; // Configuration file
const testConfigFile = `${__dirname}/test-config.json`; // Configuration file
const expectedReadmeConfig = `${__dirname}/expected-readme.config.md`; // File where the content will end after the tool is executed

const { runReadmeGenerator } = require('../index.js');

Expand Down Expand Up @@ -79,3 +82,16 @@ test('Check schema', () => {
// Check the output is the expected one
expect(fs.readFileSync(testSchemaPath)).toEqual(fs.readFileSync(expectedSchemaPath));
});

test('Check config file', () => {
// Run readme generator with the test files
const options = {
readme: testReadConfigFile,
values: testValuesPath,
config: testConfigFile,
};
runReadmeGenerator(options);

// Check the output is the expected one
expect(fs.readFileSync(testReadConfigFile)).toEqual(fs.readFileSync(expectedReadmeConfig));
});
305 changes: 305 additions & 0 deletions tests/expected-readme.config.md

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions tests/test-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"comments": {
"format": "##"
},
"tags": {
"param": "@param",
"section": "@section",
"descriptionStart": "@descriptionStart",
"descriptionEnd": "@descriptionEnd",
"skip": "@skip",
"extra": "@extra"
},
"modifiers": {
"array": "array",
"object": "object",
"string": "string",
"nullable": "nullable",
"default": "default"
},
"regexp": {
"paramsSectionTitle": "New Parameters Section"
}
}

305 changes: 305 additions & 0 deletions tests/test-readme.config.md

Large diffs are not rendered by default.

Loading