Skip to content

Commit

Permalink
Add "plugin docs generated" remark to plugin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 6, 2024
1 parent 63938f2 commit 3782f97
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/docs/scripts/generate-plugin-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const knipDir = path.join(rootDir, '../../packages/knip');
const pluginsDir = path.join(knipDir, 'src/plugins');
const directories = await fs.opendir(pluginsDir);
const plugins = [];
const srcBaseUrl = new URL('webpro-nl/knip/blob/main/packages/knip/src/plugins', 'https://github.com');

const parseFragment = (text: string) => {
const tree = unified().use(remarkParse).parse(text);
Expand Down Expand Up @@ -61,7 +62,7 @@ for await (const dir of directories) {

const hasDefaultConfig = Object.values(defaults).some(v => v.length > 0);

const en =
const enabledText =
Array.isArray(enablers) && enablers.length > 0
? [
...parseFragment(
Expand All @@ -78,9 +79,9 @@ for await (const dir of directories) {
? parseFragment(enablers)
: [u('paragraph', [u('text', 'N/A')])];

const n = note ? [u('heading', { depth: 2 }, [u('text', 'Note')]), ...parseFragment(note)] : [];
const notes = note ? [u('heading', { depth: 2 }, [u('text', 'Note')]), ...parseFragment(note)] : [];

const def = hasDefaultConfig
const defaultConfig = hasDefaultConfig
? [
u('heading', { depth: 2 }, [u('text', 'Default configuration')]),
...parseFragment('This configuration is added automatically if the plugin is enabled:'),
Expand All @@ -89,7 +90,9 @@ for await (const dir of directories) {
value: JSON.stringify({ [pluginName]: defaults }, null, 2),
}),
...parseFragment('Your custom `config` or `entry` options override default values, they are not merged.'),
...parseFragment('See [Plugins](../../explanations/plugins) for more details.'),
...parseFragment(
'See [Plugins](../../explanations/plugins) for more details about plugins and their `entry` and `config` options.'
),
]
: [];

Expand All @@ -109,13 +112,18 @@ for await (const dir of directories) {
]
: [];

const generated = parseFragment(
`## Generated from source\n\nThis page was generated from the [${pluginName} plugin source code](${srcBaseUrl}/${dir.name}/index.ts')}).`
);

const tree = u('root', [
frontmatter,
u('heading', { depth: 2 }, [u('text', 'Enabled')]),
...en,
...n,
...def,
...enabledText,
...notes,
...defaultConfig,
...argsText,
...generated,
]);

console.log(`Writing ${pluginName} docs to plugins/${pluginName}.md`);
Expand Down

0 comments on commit 3782f97

Please sign in to comment.