Skip to content

Commit 8b89488

Browse files
committed
fix(tools): use elementsDir option instead of creating a new option
1 parent 0ba0b29 commit 8b89488

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

tools/pfe-tools/config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ interface SiteOptions {
1515
title?: string;
1616
/** Site subpath for components. e.g. 'elements'. default: 'elements' */
1717
componentSubpath?: string;
18-
//* Docs site subpath for components. e.g. 'components'. default: 'components' */
19-
docsComponentSubpath?: string;
2018
}
2119

2220
export interface PfeConfig {
@@ -42,13 +40,13 @@ const SITE_DEFAULTS: Required<SiteOptions> = {
4240
logoUrl: '/docs/images/pfe-logo-inverse-white.svg',
4341
stylesheets: [],
4442
title: 'PatternFly Elements',
45-
componentSubpath: 'elements',
46-
docsComponentSubpath: 'components',
43+
componentSubpath: 'components',
4744
};
4845

4946
const DEFAULT_CONFIG: PfeConfig = {
5047
demoURLPrefix: 'https://patternflyelements.org/',
5148
sourceControlURLPrefix: 'https://github.com/patternfly/patternfly-elements/tree/main/',
49+
elementsDir: 'elements',
5250
tagPrefix: 'pf',
5351
aliases: {},
5452
};

tools/pfe-tools/custom-elements-manifest/demos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import slugify from 'slugify';
2929
export function demosPlugin(options?: PfeConfig): Plugin {
3030
const fileOptions = getPfeConfig(options?.rootDir);
3131
const config = { ...fileOptions, ...options };
32-
const subpath = config.site.docsComponentSubpath ?? 'components';
32+
const subpath = config.site.componentSubpath ?? 'components';
3333
const { rootDir, demoURLPrefix, sourceControlURLPrefix } = config;
3434
return {
3535
name: 'demos-plugin',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class Manifest {
274274
* > **ANY** (_>= 0x_)
275275
* `/demo`
276276
*/
277-
const DEMO_PATH_RE = new RegExp(`/${options.site.docsComponentSubpath}/(.*)/demo`);
277+
const DEMO_PATH_RE = new RegExp(`/${options.site.componentSubpath}/(.*)/demo`);
278278
let [, slug = ''] = permalink.match(DEMO_PATH_RE) ?? [];
279279
// strict removes all special characters from slug
280280
slug = slugify(slug, { strict: true, lower: true });

tools/pfe-tools/dev-server/config.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function renderURL(context: Context, options: PfeDevServerInternalConfig):
7878
/* Rewrite the permalink to match location of the dev server componentSubpath */
7979
demos.forEach(demo => {
8080
if (demo?.permalink) {
81-
demo.permalink = demo.permalink.replace(options.site.docsComponentSubpath, options.site.componentSubpath);
81+
demo.permalink = demo.permalink.replace(options.site.componentSubpath, options.elementsDir);
8282
}
8383
});
8484
const demo = demos.find(x => x.permalink === url.pathname);
@@ -100,8 +100,7 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
100100
return {
101101
name: 'pfe-dev-server',
102102
async serverStart({ fileWatcher, app }) {
103-
const { componentSubpath } = options.site;
104-
const { tagPrefix } = options;
103+
const { elementsDir, tagPrefix } = options;
105104

106105
const router =
107106
new Router()
@@ -114,29 +113,29 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
114113
ctx.type = 'application/javascript';
115114
})
116115
// Redirect `elements/jazz-hands/*.js` to `elements/pf-jazz-hands/*.ts`
117-
.get(`/${componentSubpath}/:element/:fileName.js`, async ctx => {
116+
.get(`/${elementsDir}/:element/:fileName.js`, async ctx => {
118117
const { element, fileName } = ctx.params;
119-
ctx.redirect(`/${componentSubpath}/${element}/${fileName}.ts`);
118+
ctx.redirect(`/${elementsDir}/${element}/${fileName}.ts`);
120119
})
121120
// Redirect `elements/jazz-hands/demo/*.js|css` to `elements/pf-jazz-hands/demo/*.js|css`
122121
// If request is `elements/jazz-hands/demo/some-other-demo/*.js|css redirect files to `elements/pf-jazz-hands/demo/*.js|css`
123-
.get(`/${componentSubpath}/:element/demo/:demoSubDir?/:fileName.:ext`, async (ctx, next) => {
122+
.get(`/${elementsDir}/:element/demo/:demoSubDir?/:fileName.:ext`, async (ctx, next) => {
124123
const { element, fileName, ext } = ctx.params;
125124
if (!element.includes(tagPrefix)) {
126-
ctx.redirect(`/${componentSubpath}/${tagPrefix}-${element}/demo/${fileName}.${ext}`);
125+
ctx.redirect(`/${elementsDir}/${tagPrefix}-${element}/demo/${fileName}.${ext}`);
127126
} else {
128127
return next();
129128
}
130129
})
131130
// Redirect `elements/jazz-hands/*` to `elements/pf-jazz-hands/*` for files not previously handled
132-
.get(`/${componentSubpath}/:element/:splatPath*`, async (ctx, next) => {
131+
.get(`/${elementsDir}/:element/:splatPath*`, async (ctx, next) => {
133132
const { element, splatPath } = ctx.params;
134133
if (splatPath.includes('demo')) {
135134
/* if its the demo directory return */
136135
return next();
137136
}
138137
if (!element.includes(tagPrefix)) {
139-
ctx.redirect(`/${componentSubpath}/${tagPrefix}-${element}/${splatPath}`);
138+
ctx.redirect(`/${elementsDir}/${tagPrefix}-${element}/${splatPath}`);
140139
} else {
141140
return next();
142141
}

0 commit comments

Comments
 (0)