Skip to content

Commit af48ed4

Browse files
committed
fix(tools): calculate path to demo files
Closes #2376
1 parent ede6758 commit af48ed4

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

.changeset/famous-cars-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/pfe-tools": patch
3+
---
4+
5+
11ty plugin: calculate path to demo files in more circumstances

tools/pfe-tools/11ty/plugins/custom-elements-manifest.cjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ const isDir = dir => stat(dir).then(x => x.isDirectory, () => false);
1818
// TODO: programmable package scopes, etc
1919
/**
2020
* @param {*} eleventyConfig
21-
* @param {import('./types').PluginOptions} _options
21+
* @param {import('./types').PluginOptions} pluginOpts
2222
*/
23-
module.exports = function configFunction(eleventyConfig, _options = {}) {
23+
module.exports = function configFunction(eleventyConfig, pluginOpts = {}) {
2424
eleventyConfig.addPlugin(EleventyRenderPlugin);
2525

2626
eleventyConfig.addGlobalData('env', () => process.env);
2727

2828
eleventyConfig.addGlobalData('demos', async function demos() {
2929
const { Manifest } = await import('../../custom-elements-manifest/lib/Manifest.js');
3030
const { getPfeConfig } = await import('../../config.js');
31-
const options = { ...getPfeConfig(), ..._options };
31+
const options = { ...getPfeConfig(), ...pluginOpts };
3232
const extraDemos = options?.extraDemos ?? [];
3333

3434
// 1. get all packages
@@ -45,7 +45,7 @@ module.exports = function configFunction(eleventyConfig, _options = {}) {
4545
const { Manifest } = await import('../../custom-elements-manifest/lib/Manifest.js');
4646
const { DocsPage } = await import('../DocsPage.js');
4747
const { getPfeConfig } = await import('../../config.js');
48-
const options = { ...getPfeConfig(), ..._options };
48+
const options = { ...getPfeConfig(), ...pluginOpts };
4949
const rootDir = options?.rootDir ?? process.cwd();
5050

5151
// 1. get all packages
@@ -54,16 +54,16 @@ module.exports = function configFunction(eleventyConfig, _options = {}) {
5454
return Manifest.getAll(rootDir)
5555
.flatMap(manifest =>
5656
Array.from(manifest.declarations.values(), decl => {
57-
// NB: not a great proxy for monorepo
58-
const isSinglepackage = decl.module?.path?.startsWith?.('elements/') ?? false;
59-
const root = isSinglepackage ? dirname(decl.module.path) : '.';
6057
const { tagName } = decl;
61-
const docsTemplatePath = join(manifest.location, root, tagName, 'docs', `${tagName}.md`);
58+
const elementsDir = options.elementsDir ?? 'elements';
59+
const root = manifest.location ?? options.rootDir;
60+
const docsTemplatePath = join(root, elementsDir, `${tagName}`, 'docs', `${tagName}.md`);
6261
return new DocsPage(manifest, {
6362
...options,
6463
tagName,
6564
// only include the template if it exists
66-
...Object.fromEntries(Object.entries({ docsTemplatePath }).filter(([, v]) => existsSync(v)))
65+
...Object.fromEntries(Object.entries({ docsTemplatePath }).filter(([, path]) =>
66+
existsSync(path)))
6767
});
6868
}));
6969
});

tools/pfe-tools/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface PfeConfig {
2020
rootDir?: string;
2121
/** object mapping custom element name to page title */
2222
aliases?: Record<string, string> ;
23+
/** Directory containing the custom elements, defaults to `elements` */
24+
elementsDir?: string;
2325
/** absolute URL to the web page representing the repo root in source control, with trailing slash. default 'https://github.com/patternfly/patternfly-elements/tree/main/' */
2426
sourceControlURLPrefix?: string ;
2527
/** absolute URL prefix for demos, with trailing slash. Default 'https://patternflyelements.org/' */

0 commit comments

Comments
 (0)