diff --git a/.changeset/fancy-keys-hug.md b/.changeset/fancy-keys-hug.md new file mode 100644 index 0000000000..59c216edc0 --- /dev/null +++ b/.changeset/fancy-keys-hug.md @@ -0,0 +1,5 @@ +--- +"@patternfly/pfe-tools": minor +--- + +Accept `tagPrefix` as an array of strings, supporting repos with multiple element prefixes diff --git a/.pfe.config.json b/.pfe.config.json index 02fa929c23..396a061159 100644 --- a/.pfe.config.json +++ b/.pfe.config.json @@ -1,4 +1,4 @@ { "renderTitleInOverview": false, - "tagPrefix": "pf-v5" + "tagPrefix": ["pf-v5", "pf-v6"] } diff --git a/tools/pfe-tools/11ty/DocsPage.ts b/tools/pfe-tools/11ty/DocsPage.ts index 108687687b..db7b7264bc 100644 --- a/tools/pfe-tools/11ty/DocsPage.ts +++ b/tools/pfe-tools/11ty/DocsPage.ts @@ -26,7 +26,8 @@ export class DocsPage { this.docsTemplatePath = options?.docsTemplatePath; this.summary = this.manifest.getSummary(this.tagName); this.description = this.manifest.getDescription(this.tagName); - const prefix = `${config.tagPrefix.replace(/-$/, '')}-`; + const prefixes = [config.tagPrefix].flat().map(p => `${p.replace(/-$/, '')}-`); + const prefix = prefixes.find(p => this.tagName.startsWith(p)) ?? prefixes[0]; const aliased = config.aliases[this.tagName] ?? this.tagName.replace(prefix, ''); this.title = options?.title ?? Manifest.prettyTag(this.tagName, config.aliases, prefix); this.slug = slugify(aliased, { strict: true, lower: true }); diff --git a/tools/pfe-tools/11ty/plugins/types.ts b/tools/pfe-tools/11ty/plugins/types.ts index f8ac6ef0f1..f1da145515 100644 --- a/tools/pfe-tools/11ty/plugins/types.ts +++ b/tools/pfe-tools/11ty/plugins/types.ts @@ -4,7 +4,7 @@ import type { Manifest } from '@patternfly/pfe-tools/custom-elements-manifest/li export interface DemoRecord { title: string; tagName: string; - tagPrefix: string; + tagPrefix: string | string[]; primaryElementName: string; manifest: Manifest; slug: string; diff --git a/tools/pfe-tools/config.ts b/tools/pfe-tools/config.ts index 11921bfdff..895fde4de3 100644 --- a/tools/pfe-tools/config.ts +++ b/tools/pfe-tools/config.ts @@ -30,8 +30,8 @@ export interface PfeConfig { sourceControlURLPrefix?: string ; /** absolute URL prefix for demos, with trailing slash. Default 'https://patternflyelements.org/' */ demoURLPrefix?: string ; - /** custom elements namespace. Default 'pf' */ - tagPrefix?: string; + /** custom elements namespace. Default 'pf'. Accepts an array for repos with multiple prefixes. */ + tagPrefix?: string | string[]; /** Dev Server site options */ site?: SiteOptions; } @@ -102,6 +102,8 @@ export function deslugify( rootDir: string = process.cwd(), ): string { const { slugs, config } = getSlugsMap(rootDir); - const prefixedSlug = (slug.startsWith(`${config.tagPrefix}-`)) ? slug : `${config.tagPrefix}-${slug}`; + const prefixes = [config.tagPrefix].flat(); + const hasPrefix = prefixes.some(p => slug.startsWith(`${p}-`)); + const prefixedSlug = hasPrefix ? slug : `${prefixes[0]}-${slug}`; return slugs.get(slug) ?? prefixedSlug; } diff --git a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts index 032e3ccfeb..b6f11967ab 100644 --- a/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts +++ b/tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts @@ -324,7 +324,8 @@ export class Manifest { const [last = ''] = filePath.split(path.sep).reverse(); const filename = last.replace('.html', ''); const isMainElementDemo = filename === 'index'; - const prefix = `${options.tagPrefix.replace(/-$/, '')}-`; + const prefixes = [options.tagPrefix].flat().map(p => `${p.replace(/-$/, '')}-`); + const prefix = prefixes.find(p => tagName.startsWith(p)) ?? prefixes[0]; const title = isMainElementDemo ? prettyTag(tagName, options.aliases, prefix) : last .replace(/(?:^|[-/\s])\w/g, x => x.toUpperCase()) diff --git a/tools/pfe-tools/test/config.ts b/tools/pfe-tools/test/config.ts index cfce355d59..60b7c897ba 100644 --- a/tools/pfe-tools/test/config.ts +++ b/tools/pfe-tools/test/config.ts @@ -50,7 +50,8 @@ const exists = async (path: string | URL) => { export function pfeTestRunnerConfig(opts: PfeTestRunnerConfigOptions): TestRunnerConfig { const { open, ...devServerConfig } = pfeDevServerConfig({ ...opts, loadDemo: false }); - const { elementsDir, tagPrefix } = getPfeConfig(); + const { elementsDir, tagPrefix: rawPrefix } = getPfeConfig(); + const tagPrefixes = [rawPrefix].flat(); const configuredReporter = opts.reporter ?? 'default'; @@ -121,7 +122,7 @@ export function pfeTestRunnerConfig(opts: PfeTestRunnerConfigOptions): TestRunne */ async function(ctx, next) { if (ctx.path.endsWith('.js') - && ctx.path.startsWith(`/${elementsDir}/${tagPrefix}-`) + && tagPrefixes.some(p => ctx.path.startsWith(`/${elementsDir}/${p}-`)) && await exists(`./${ctx.path}`.replace('.js', '.ts').replace('//', '/'))) { ctx.redirect(ctx.path.replace('.js', '.ts')); } else {