Skip to content

Commit

Permalink
Read config file from absolute and relative references (#111)
Browse files Browse the repository at this point in the history
* Read file from absolute and relative references

Signed-off-by: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com>

* Add tests

Signed-off-by: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com>

* Bump versions

Signed-off-by: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com>

* Fix lint

Signed-off-by: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com>

---------

Signed-off-by: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com>
  • Loading branch information
wcmjunior authored Sep 6, 2024
1 parent f59f07b commit 721a46e
Show file tree
Hide file tree
Showing 7 changed files with 654 additions and 8 deletions.
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.

0 comments on commit 721a46e

Please sign in to comment.