From b67ec7fbf085000bb18880c0734dd7fc777f06c3 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 31 Jul 2025 10:15:39 +0300 Subject: [PATCH 1/6] chore: update node version --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index aebd91c521..564e92d084 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v22.16.0 +v24.4.1 From 2ebbc7d1da9d6cfcf4faf3c22123e8ec1a0c714a Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 31 Jul 2025 10:15:50 +0300 Subject: [PATCH 2/6] fix: demo urls --- elements/package.json | 2 +- scripts/cem-demo-index.ts | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 scripts/cem-demo-index.ts diff --git a/elements/package.json b/elements/package.json index 198d86bd85..37b8c53c1a 100644 --- a/elements/package.json +++ b/elements/package.json @@ -74,7 +74,7 @@ }, "scripts": { "prepublishOnly": "npm run build", - "analyze": "cem generate", + "analyze": "cem generate && node ../scripts/cem-demo-index.ts", "build": "wireit", "test": "wtr --files './test/*.spec.ts' --config ../../web-test-runner.config.js" }, diff --git a/scripts/cem-demo-index.ts b/scripts/cem-demo-index.ts new file mode 100755 index 0000000000..7f07bf06d5 --- /dev/null +++ b/scripts/cem-demo-index.ts @@ -0,0 +1,44 @@ +#!/usr/bin/env node +import { writeFile } from 'node:fs/promises'; +import type * as M from 'custom-elements-manifest/schema'; + +import manifest from '../elements/custom-elements.json' with { type: 'json' }; + +function isCustomElementDeclaration(decl: M.Declaration): decl is M.CustomElementDeclaration { + return !!(decl as M.CustomElementDeclaration).customElement; +} + +const RE = /^https:\/\/patternflyelements\.com\/components\/(?[\w-]+)\//; + +const copy = structuredClone(manifest) as M.Package; + +const getSlug = (demo: M.Demo) => + demo.url.match(RE)?.groups?.slug ?? ''; + +const isMainDemo = (demo: M.Demo): boolean => + demo.url.endsWith(`${getSlug(demo)}/`) +|| demo.url.endsWith('demo/'); + +// replace all canonical demos with / +// e.g. +// from: https://patternflyelements.com/components/button/demo/button/ +// to: https://patternflyelements.com/components/button/demo/ +// This is a stopgap. the ideal would be to either generate the canonical demo from the cem, aka knobs +// or to include it in the jsdoc in an @example tag +// or to rearrange the elements/*/demo/*.html file structure +await writeFile('custom-elements.json', JSON.stringify({ + ...manifest, + modules: copy.modules.map(module => ({ + ...module, + declarations: module.declarations?.map(decl => ({ + ...decl, + demos: + !isCustomElementDeclaration(decl) ? decl + : decl.demos?.map(demo => isMainDemo(demo) ? ({ + ...demo, + url: `https://patternflyelements.com/components/${getSlug(demo)}/demo/`, + }) : demo) + .sort((a, b) => isMainDemo(a) ? -1 : isMainDemo(b) ? 1 : 0), + })), + })), +}, null, 2), 'utf-8'); From b33ea1343b28987a0caf42c18f825a10a96e21cf Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 31 Jul 2025 10:26:26 +0300 Subject: [PATCH 3/6] chore: update deps --- package-lock.json | 58 +++++++++++++++++++++++------------------------ package.json | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 22c8a4b1c6..11b4e577e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@lit/react": "^1.0.5", "@octokit/core": "^6.1.2", "@patternfly/patternfly": "^4.224.5", - "@pwrs/cem": "^0.2.3", + "@pwrs/cem": "^0.2.15", "@rhds/elements": "^1.4.5", "@types/koa__router": "^12.0.4", "@types/node": "^22.15.32", @@ -2908,9 +2908,9 @@ } }, "node_modules/@pwrs/cem": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem/-/cem-0.2.3.tgz", - "integrity": "sha512-EtPwk5uoJX/FtnjcsGa58Pd2vN42pzEA4rq7xYS+4gOpvrjwUrK/e4uQ1wyBkE79iT721mwpZhCfNvT3jdVMvw==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem/-/cem-0.2.15.tgz", + "integrity": "sha512-wlunNIZP8CZDSpN2a9thv9u4GPJ/Y8XUaL+Et0YLdEJ9VmriuLxNq93R3Eq9O61XQiQTgzUvBdYWfjyeAI6N5g==", "dev": true, "hasInstallScript": true, "bin": { @@ -2920,18 +2920,18 @@ "node": ">=22.0.0" }, "optionalDependencies": { - "@pwrs/cem-darwin-arm64": "0.2.3", - "@pwrs/cem-darwin-x64": "0.2.3", - "@pwrs/cem-linux-arm64": "0.2.3", - "@pwrs/cem-linux-x64": "0.2.3", - "@pwrs/cem-win32-arm64": "0.2.3", - "@pwrs/cem-win32-x64": "0.2.3" + "@pwrs/cem-darwin-arm64": "0.2.15", + "@pwrs/cem-darwin-x64": "0.2.15", + "@pwrs/cem-linux-arm64": "0.2.15", + "@pwrs/cem-linux-x64": "0.2.15", + "@pwrs/cem-win32-arm64": "0.2.15", + "@pwrs/cem-win32-x64": "0.2.15" } }, "node_modules/@pwrs/cem-darwin-arm64": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem-darwin-arm64/-/cem-darwin-arm64-0.2.3.tgz", - "integrity": "sha512-vEVtA7ULjFA/ErxEIORkgfi7VKYSeULHO/T+Nsx2tfkkS26UYZgsOMtWidEDPgetoN0/pbT22i+ZMCXI+yOHeg==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem-darwin-arm64/-/cem-darwin-arm64-0.2.15.tgz", + "integrity": "sha512-Vvw1kUqPgQi74NVrKC8ZJkbCtLjqYx1rKw3w1s7WhYRDzBDCv0LscQ229DxFd+Od5i+sWxQxYtM8DZFO5iFyOA==", "cpu": [ "arm64" ], @@ -2945,9 +2945,9 @@ } }, "node_modules/@pwrs/cem-darwin-x64": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem-darwin-x64/-/cem-darwin-x64-0.2.3.tgz", - "integrity": "sha512-wOJZwOTCNmcUmzianKNnqBt9sei54gil0G3b8w7yvsupUaxhd4qOazgUxpt/g070drNFQ94YvlYd5CMEnY8iTw==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem-darwin-x64/-/cem-darwin-x64-0.2.15.tgz", + "integrity": "sha512-Xmowb7gfewulyU0z1pt+R9h35jAdbB5enqE7EFmFzlm34GLxRoBF5z1BdUdKHJaTdZa4d1fSBtm/fBmrPN3i9A==", "cpu": [ "x64" ], @@ -2961,9 +2961,9 @@ } }, "node_modules/@pwrs/cem-linux-arm64": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem-linux-arm64/-/cem-linux-arm64-0.2.3.tgz", - "integrity": "sha512-mHAcg2sSemq5WSK888PccSlO17P1dScpLYblzOxZVNpyILsIpmLrV8czqBzGVFvSK4S95QmkTBD9ziXTl1O84A==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem-linux-arm64/-/cem-linux-arm64-0.2.15.tgz", + "integrity": "sha512-4Rp91Kt1/ThRu4EVZKPJf4nhoRd1G5r/YzZ/XOiMFQfZ0enng4+KlCUbBOvUV816jBSWWkN4Bc0Zb6Ff/o0Lcg==", "cpu": [ "arm64" ], @@ -2977,9 +2977,9 @@ } }, "node_modules/@pwrs/cem-linux-x64": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem-linux-x64/-/cem-linux-x64-0.2.3.tgz", - "integrity": "sha512-iKC9ZXvMa8/P1obooT1kvwT2I6MyjU6Vj3K4ZXQ5FnbA+OBZq8S4/Y5ydUeWlHyNpgsu+IwRBsAKWKOz4hBXOw==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem-linux-x64/-/cem-linux-x64-0.2.15.tgz", + "integrity": "sha512-23adiyYkISVxL9a2inDXyoZMvkkwWUpfVjfgwYkl/a1rA/RwQI0kMB8fR9NfV2Icl/8aUjf75hhVYqbYC1nrTg==", "cpu": [ "x64" ], @@ -2993,9 +2993,9 @@ } }, "node_modules/@pwrs/cem-win32-arm64": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem-win32-arm64/-/cem-win32-arm64-0.2.3.tgz", - "integrity": "sha512-s1eTweuInPZyElmpQActA25cJxlmRY0FO1PfCGVBu+RtbygbiML7jujZnKRDbWssdfa+2cw6I9jnrv4isH9Dag==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem-win32-arm64/-/cem-win32-arm64-0.2.15.tgz", + "integrity": "sha512-UShvjVsQo3Go7nLHVC+Qs2xqhEXxQQ3Yd0sQOksPVZgy2S/GA5ERbEp2uvSQEwOC1xOFGDqjgn8PFjvdU/cU0A==", "cpu": [ "arm64" ], @@ -3010,9 +3010,9 @@ } }, "node_modules/@pwrs/cem-win32-x64": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@pwrs/cem-win32-x64/-/cem-win32-x64-0.2.3.tgz", - "integrity": "sha512-HMHZjbxE51hDB43Gww+2QZvCU1o7ZTJjmdIy7rsAA167vxY5J//F8ElaO7I/fH9JRrzSOyPadkEbX0JHyye/zQ==", + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/@pwrs/cem-win32-x64/-/cem-win32-x64-0.2.15.tgz", + "integrity": "sha512-UPnxcGwM59oIn0CyKFkeeHk8wQ0LgACTNEAfC4md1qvhXh1Og76qTa01mz9QytVwBzQdmQG9v9ApbF9obJGWOA==", "cpu": [ "x64" ], @@ -17398,7 +17398,7 @@ }, "tools/pfe-tools": { "name": "@patternfly/pfe-tools", - "version": "5.0.1", + "version": "5.0.3", "license": "MIT", "devDependencies": { "@types/dedent": "^0.7.2", diff --git a/package.json b/package.json index 657bc129c3..f32814a6b5 100644 --- a/package.json +++ b/package.json @@ -290,7 +290,7 @@ "@lit/react": "^1.0.5", "@octokit/core": "^6.1.2", "@patternfly/patternfly": "^4.224.5", - "@pwrs/cem": "^0.2.3", + "@pwrs/cem": "^0.2.15", "@rhds/elements": "^1.4.5", "@types/koa__router": "^12.0.4", "@types/node": "^22.15.32", From 3c92c14c0efc59e544427cad5fb1563b6e7302e7 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 31 Jul 2025 10:35:43 +0300 Subject: [PATCH 4/6] fix: demo urls --- scripts/cem-demo-index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cem-demo-index.ts b/scripts/cem-demo-index.ts index 7f07bf06d5..f54be378bd 100755 --- a/scripts/cem-demo-index.ts +++ b/scripts/cem-demo-index.ts @@ -8,7 +8,7 @@ function isCustomElementDeclaration(decl: M.Declaration): decl is M.CustomElemen return !!(decl as M.CustomElementDeclaration).customElement; } -const RE = /^https:\/\/patternflyelements\.com\/components\/(?[\w-]+)\//; +const RE = /^https:\/\/patternflyelements\.org\/components\/(?[\w-]+)\//; const copy = structuredClone(manifest) as M.Package; @@ -33,7 +33,7 @@ await writeFile('custom-elements.json', JSON.stringify({ declarations: module.declarations?.map(decl => ({ ...decl, demos: - !isCustomElementDeclaration(decl) ? decl + !isCustomElementDeclaration(decl) ? undefined : decl.demos?.map(demo => isMainDemo(demo) ? ({ ...demo, url: `https://patternflyelements.com/components/${getSlug(demo)}/demo/`, From 693760267e2d372cdb7a0604631868bc8bdbb9d8 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 31 Jul 2025 11:32:45 +0300 Subject: [PATCH 5/6] fix: demo urls in manifest --- docs/components/demos.11tydata.cjs | 16 +--------------- scripts/cem-demo-index.ts | 10 +++++----- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/docs/components/demos.11tydata.cjs b/docs/components/demos.11tydata.cjs index ca77da79f0..c4b05d44a1 100644 --- a/docs/components/demos.11tydata.cjs +++ b/docs/components/demos.11tydata.cjs @@ -1,4 +1,3 @@ -const { dirname } = require('path'); module.exports = { templateEngineOverride: 'njk', permalink: '{{ demo.permalink }}', @@ -6,19 +5,6 @@ module.exports = { data: 'demos', alias: 'demo', size: 1, - // somehow the main pf-icon demo is being printed twice. - // so we'll group by tag name, and only take the first of each. - before: demos => Object.values(Object.groupBy(demos - .filter(demo => demo.permalink?.includes(demo.tagName)) - .map(demo => { - if (demo.filePath?.endsWith(`${demo.tagName}.html`)) { - return { - ...demo, - permalink: `${dirname(demo.permalink)}/`, - }; - } else { - return demo; - } - }), demo => demo.tagName)).map(([x]) => x), + before: demos => demos.filter(demo => demo.tagName === demo.primaryElementName), }, }; diff --git a/scripts/cem-demo-index.ts b/scripts/cem-demo-index.ts index f54be378bd..d7948370f8 100755 --- a/scripts/cem-demo-index.ts +++ b/scripts/cem-demo-index.ts @@ -15,9 +15,8 @@ const copy = structuredClone(manifest) as M.Package; const getSlug = (demo: M.Demo) => demo.url.match(RE)?.groups?.slug ?? ''; -const isMainDemo = (demo: M.Demo): boolean => - demo.url.endsWith(`${getSlug(demo)}/`) -|| demo.url.endsWith('demo/'); +const isMainDemo = (tagName: string, demo: M.Demo): boolean => + demo.url.endsWith(`demo/${tagName}/`); // replace all canonical demos with / // e.g. @@ -34,11 +33,12 @@ await writeFile('custom-elements.json', JSON.stringify({ ...decl, demos: !isCustomElementDeclaration(decl) ? undefined - : decl.demos?.map(demo => isMainDemo(demo) ? ({ + : decl.demos?.map(demo => isMainDemo(decl.tagName!, demo) ? ({ ...demo, url: `https://patternflyelements.com/components/${getSlug(demo)}/demo/`, }) : demo) - .sort((a, b) => isMainDemo(a) ? -1 : isMainDemo(b) ? 1 : 0), + .sort((a, b) => + isMainDemo(decl.tagName!, a) ? -1 : isMainDemo(decl.tagName!, b) ? 1 : 0), })), })), }, null, 2), 'utf-8'); From b7c30c7affe8a7ccd3b4267b8cdd8b10037d8722 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 31 Jul 2025 11:33:03 +0300 Subject: [PATCH 6/6] fix(tools): demo paths in manifest helpers --- .changeset/rotten-sloths-crash.md | 4 ++++ tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/rotten-sloths-crash.md diff --git a/.changeset/rotten-sloths-crash.md b/.changeset/rotten-sloths-crash.md new file mode 100644 index 0000000000..ba0d9679fa --- /dev/null +++ b/.changeset/rotten-sloths-crash.md @@ -0,0 +1,4 @@ +--- +"@patternfly/pfe-tools": patch +--- +Manifest: fixed demo paths in manifest helpers diff --git a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts index f12848a82f..54421bf21d 100644 --- a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts +++ b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts @@ -16,7 +16,7 @@ import type { Slot, } from 'custom-elements-manifest/schema'; -import { join, normalize } from 'node:path'; +import { dirname, join, normalize } from 'node:path'; import { readFileSync } from 'node:fs'; import { getAllPackages } from './get-all-packages.js'; @@ -301,7 +301,7 @@ export class Manifest { const manifest = this; const { prettyTag } = Manifest; return this.getDemos(tagName).map(demo => { - const permalink = demo.url.replace(options.demoURLPrefix, '/'); + const permalink = new URL(demo.url).pathname; /** * `/components/` @@ -328,6 +328,7 @@ export class Manifest { .replace('.html', ''); return { tagName, + isMainElementDemo, primaryElementName, permalink, slug,