Skip to content

Commit 2116c46

Browse files
committed
fix(tools): support tagPrefix as an array of tags
1 parent 8fedd86 commit 2116c46

6 files changed

Lines changed: 14 additions & 9 deletions

File tree

.pfe.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"renderTitleInOverview": false,
3-
"tagPrefix": "pf-v5"
3+
"tagPrefix": ["pf-v5", "pf-v6"]
44
}

tools/pfe-tools/11ty/DocsPage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export class DocsPage {
2626
this.docsTemplatePath = options?.docsTemplatePath;
2727
this.summary = this.manifest.getSummary(this.tagName);
2828
this.description = this.manifest.getDescription(this.tagName);
29-
const prefix = `${config.tagPrefix.replace(/-$/, '')}-`;
29+
const prefixes = [config.tagPrefix].flat().map(p => `${p.replace(/-$/, '')}-`);
30+
const prefix = prefixes.find(p => this.tagName.startsWith(p)) ?? prefixes[0];
3031
const aliased = config.aliases[this.tagName] ?? this.tagName.replace(prefix, '');
3132
this.title = options?.title ?? Manifest.prettyTag(this.tagName, config.aliases, prefix);
3233
this.slug = slugify(aliased, { strict: true, lower: true });

tools/pfe-tools/11ty/plugins/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Manifest } from '@patternfly/pfe-tools/custom-elements-manifest/li
44
export interface DemoRecord {
55
title: string;
66
tagName: string;
7-
tagPrefix: string;
7+
tagPrefix: string | string[];
88
primaryElementName: string;
99
manifest: Manifest;
1010
slug: string;

tools/pfe-tools/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export interface PfeConfig {
3030
sourceControlURLPrefix?: string ;
3131
/** absolute URL prefix for demos, with trailing slash. Default 'https://patternflyelements.org/' */
3232
demoURLPrefix?: string ;
33-
/** custom elements namespace. Default 'pf' */
34-
tagPrefix?: string;
33+
/** custom elements namespace. Default 'pf'. Accepts an array for repos with multiple prefixes. */
34+
tagPrefix?: string | string[];
3535
/** Dev Server site options */
3636
site?: SiteOptions;
3737
}
@@ -102,6 +102,8 @@ export function deslugify(
102102
rootDir: string = process.cwd(),
103103
): string {
104104
const { slugs, config } = getSlugsMap(rootDir);
105-
const prefixedSlug = (slug.startsWith(`${config.tagPrefix}-`)) ? slug : `${config.tagPrefix}-${slug}`;
105+
const prefixes = [config.tagPrefix].flat();
106+
const hasPrefix = prefixes.some(p => slug.startsWith(`${p}-`));
107+
const prefixedSlug = hasPrefix ? slug : `${prefixes[0]}-${slug}`;
106108
return slugs.get(slug) ?? prefixedSlug;
107109
}

tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ export class Manifest {
324324
const [last = ''] = filePath.split(path.sep).reverse();
325325
const filename = last.replace('.html', '');
326326
const isMainElementDemo = filename === 'index';
327-
const prefix = `${options.tagPrefix.replace(/-$/, '')}-`;
327+
const prefixes = [options.tagPrefix].flat().map(p => `${p.replace(/-$/, '')}-`);
328+
const prefix = prefixes.find(p => tagName.startsWith(p)) ?? prefixes[0];
328329
const title = isMainElementDemo ? prettyTag(tagName, options.aliases, prefix)
329330
: last
330331
.replace(/(?:^|[-/\s])\w/g, x => x.toUpperCase())

tools/pfe-tools/test/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const exists = async (path: string | URL) => {
5050
export function pfeTestRunnerConfig(opts: PfeTestRunnerConfigOptions): TestRunnerConfig {
5151
const { open, ...devServerConfig } = pfeDevServerConfig({ ...opts, loadDemo: false });
5252

53-
const { elementsDir, tagPrefix } = getPfeConfig();
53+
const { elementsDir, tagPrefix: rawPrefix } = getPfeConfig();
54+
const tagPrefixes = [rawPrefix].flat();
5455

5556
const configuredReporter = opts.reporter ?? 'default';
5657

@@ -121,7 +122,7 @@ export function pfeTestRunnerConfig(opts: PfeTestRunnerConfigOptions): TestRunne
121122
*/
122123
async function(ctx, next) {
123124
if (ctx.path.endsWith('.js')
124-
&& ctx.path.startsWith(`/${elementsDir}/${tagPrefix}-`)
125+
&& tagPrefixes.some(p => ctx.path.startsWith(`/${elementsDir}/${p}-`))
125126
&& await exists(`./${ctx.path}`.replace('.js', '.ts').replace('//', '/'))) {
126127
ctx.redirect(ctx.path.replace('.js', '.ts'));
127128
} else {

0 commit comments

Comments
 (0)