mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 06:51:11 +00:00
a462e4ec3b
* refactor(docs): don't use an `end` for autogenerated docs As part of #42910, we wanted to avoid needing a "begin" and "end" to each of our autogenerated docs replacements. While looking into it, we're not actually using the "end" for anything, so we can instead refactor this to be a single-line replacement. To simplify the code and docs, we can remove this. At the point we need this again, we can re-add the functionality. Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io> * fixup! Merge remote-tracking branch 'origin/HEAD' into chore/no-replaceStop --------- Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { getOptions } from '../../lib/config/options/index.ts';
|
|
import {
|
|
allowedFields,
|
|
exposedConfigOptions,
|
|
} from '../../lib/util/template/index.ts';
|
|
import { readFile, updateFile } from '../utils/index.ts';
|
|
import { replaceContent } from './utils.ts';
|
|
|
|
function getOptionLink(
|
|
name: string,
|
|
optionParentMap: Map<string, string>,
|
|
optionGlobalOnly: Set<string>,
|
|
): string {
|
|
const parent = optionParentMap.get(name);
|
|
const anchor = parent ? `${parent}${name}`.toLowerCase() : name.toLowerCase();
|
|
const page = optionGlobalOnly.has(name)
|
|
? 'self-hosted-configuration.md'
|
|
: 'configuration-options.md';
|
|
return ` - [\`${name}\`](${page}#${anchor})`;
|
|
}
|
|
|
|
export async function generateTemplates(dist: string): Promise<void> {
|
|
const options = getOptions();
|
|
const optionParentMap = new Map(
|
|
options
|
|
.filter((o) => o.parents?.length)
|
|
.map((o) => [o.name, o.parents![0]]),
|
|
);
|
|
const optionGlobalOnly = new Set(
|
|
options.filter((o) => o.globalOnly).map((o) => o.name),
|
|
);
|
|
|
|
let exposedConfigOptionsText =
|
|
'The following configuration options are passed through for templating: \n\n';
|
|
exposedConfigOptionsText += exposedConfigOptions
|
|
.sort()
|
|
.map((field) => getOptionLink(field, optionParentMap, optionGlobalOnly))
|
|
.join('\n');
|
|
|
|
let runtimeText =
|
|
'The following runtime values are passed through for templating: \n\n';
|
|
for (const [field, description] of Object.entries(allowedFields)) {
|
|
runtimeText += ` - \`${field}\`: ${description}\n`;
|
|
}
|
|
runtimeText += '\n\n';
|
|
|
|
let supportsTemplatingText =
|
|
'The following configuration options accept Handlebars template syntax in their values:\n\n';
|
|
supportsTemplatingText += options
|
|
.filter((o) => o.supportsTemplating)
|
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
.map((o) => getOptionLink(o.name, optionParentMap, optionGlobalOnly))
|
|
.join('\n');
|
|
|
|
let templateContent = await readFile('docs/usage/templates.md');
|
|
templateContent = replaceContent(
|
|
templateContent,
|
|
supportsTemplatingText,
|
|
'<!-- Automatically insert options that support templating here -->',
|
|
);
|
|
templateContent = replaceContent(templateContent, exposedConfigOptionsText);
|
|
templateContent = replaceContent(templateContent, runtimeText);
|
|
await updateFile(`${dist}/templates.md`, templateContent);
|
|
}
|