@@ -10,7 +10,23 @@ COLOR_PREFIX="\e[32m"
1010COLOR_ERROR=" \e[31m"
1111COLOR_RESET=" \e[0m"
1212
13- USAGE=" $( basename " ${0} " ) --scanner|--hook|--demo-target|--operator|--auto-discovery path/to/scanner/Chart.yaml path/to/.helm-docs"
13+ #
14+ # This script generates various HElm documentation from chart files
15+ #
16+ # This script was extracted from the main Makefile to make both easier maintainable.
17+ #
18+ # This script provides some switches to generate particular parts of the whole documentation. The documentation
19+ # Consists of three parts:
20+ #
21+ # 1. A main README file for the Chart. This is generated by the switch `--readme`. This is exceptional from the other
22+ # switches because it expects thebase directory with all chart files in sub directories. All the readmes for all
23+ # charts will be generated in one sigle run.
24+ # 2. Chart documentation for ArtifactHub. This file is generated as part of this script when invoked with any switch
25+ # except the`--readme` switch (see above). Not for all images (see below) a chart documentation wil be generated!
26+ # 3. Image documentation forDockerHub. . This file is generated as part of this script when invoked with any switch
27+ # except the`--readme` switch (see above). Not for all charts (see below) a DockerHub documentation will be generated!
28+
29+ USAGE=" $( basename " ${0} " ) --scanner|--hook|--demo-target|--operator|--auto-discovery|--readme path/to/Chart.yaml|dir/with/charts path/to/.helm-docs"
1430
1531DOC_TYPE=" ${1:- } "
1632CHART_FILE=" ${2:- } "
@@ -47,19 +63,19 @@ function validate_args() {
4763}
4864
4965function generate_docs() {
50- local chart_search_root output_file docs_template dockerhub_template
66+ local chart_search_root output_file docs_template readme_template
5167
5268 chart_search_root=" ${1} "
5369 output_file=" ${2} "
5470 docs_template=" ${3} "
55- dockerhub_template =" ${4} "
71+ readme_template =" ${4} "
5672
57- helm-docs --log-level debug \
73+ helm-docs \
5874 --chart-search-root=" ${chart_search_root} " \
5975 --output-file=" ${output_file} " \
6076 --template-files=" ${HELM_DOCS_DIR} /templates.gotmpl" \
6177 --template-files=" ${docs_template} " \
62- --template-files=" ${dockerhub_template } "
78+ --template-files=" ${readme_template } "
6379}
6480
6581function generate_scanner_docs() {
@@ -162,19 +178,40 @@ function generate_auto_discovery_docs() {
162178 " ${HELM_DOCS_DIR} /README.ArtifactHub.md.gotmpl"
163179}
164180
181+ function generate_readme() {
182+ local repo_base_dir
183+
184+ repo_base_dir=" ${1} "
185+
186+ generate_docs " ${repo_base_dir} " \
187+ " README.md" \
188+ " .helm-docs.gotmpl" \
189+ " ${HELM_DOCS_DIR} /README.md.gotmpl"
190+ }
191+
165192function main() {
166193 validate_args
167194
168195 log " Generating docs for ${CHART_FILE} ..."
169196
170197 local work_dir docs_dir
171198
172- work_dir=" $( dirname " ${CHART_FILE} " ) "
173- docs_dir=" ${work_dir} /${DOCS_DIR_NAME} "
199+ # There are two main cases this script is invoked:
200+ # 1. For one found chart file (e.g. of a scanner or hook): In this case we need
201+ # the parent directory of this chart file as working directory and we ned to ensure
202+ # that there is a ${DOCS_DIR_NAME} directory where we store the generated files.
203+ # 2. For generating the top level READMEs. Here we expect a base directory as working dir
204+ # from where helm-docs collect all Chart.yml by itself.
205+ if [[ -d " ${CHART_FILE} " ]]; then
206+ work_dir=" ${CHART_FILE} "
207+ else
208+ work_dir=" $( dirname " ${CHART_FILE} " ) "
209+ docs_dir=" ${work_dir} /${DOCS_DIR_NAME} "
174210
175- if [ ! -d " ${docs_dir} " ]; then
176- log " Ignoring docs creation process for '${CHART_FILE} ' because docs folder found at: '${docs_dir} '!"
177- exit 0
211+ if [ ! -d " ${docs_dir} " ]; then
212+ log " Ignoring docs creation process for '${CHART_FILE} ' because docs folder found at: '${docs_dir} '!"
213+ exit 0
214+ fi
178215 fi
179216
180217 case " ${DOC_TYPE} " in
@@ -193,6 +230,9 @@ function main() {
193230 " --auto-discovery" )
194231 generate_auto_discovery_docs " ${work_dir} "
195232 ;;
233+ " --readme" )
234+ generate_readme " ${work_dir} "
235+ ;;
196236 * )
197237 error " Unsupported doc type: ${DOC_TYPE} !"
198238 error " ${USAGE} "
0 commit comments