Skip to content

Commit 0ba0b29

Browse files
committed
fix(tools): improve variable naming in router and use destructuring
1 parent 80ea119 commit 0ba0b29

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,29 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
114114
ctx.type = 'application/javascript';
115115
})
116116
// Redirect `elements/jazz-hands/*.js` to `elements/pf-jazz-hands/*.ts`
117-
.get(`/${componentSubpath}/:componentDir/:fileName.js`, async ctx => {
118-
ctx.redirect(`/${componentSubpath}/${ctx.params.componentDir}/${ctx.params.fileName}.ts`);
117+
.get(`/${componentSubpath}/:element/:fileName.js`, async ctx => {
118+
const { element, fileName } = ctx.params;
119+
ctx.redirect(`/${componentSubpath}/${element}/${fileName}.ts`);
119120
})
120121
// Redirect `elements/jazz-hands/demo/*.js|css` to `elements/pf-jazz-hands/demo/*.js|css`
121122
// If request is `elements/jazz-hands/demo/some-other-demo/*.js|css redirect files to `elements/pf-jazz-hands/demo/*.js|css`
122-
.get(`/${componentSubpath}/:componentDir/demo/:demoSubDir?/:fileName.:ext`, async (ctx, next) => {
123-
if (!ctx.params.componentDir.includes(tagPrefix)) {
124-
ctx.redirect(`/${componentSubpath}/${tagPrefix}-${ctx.params.componentDir}/demo/${ctx.params.fileName}.${ctx.params.ext}`);
123+
.get(`/${componentSubpath}/:element/demo/:demoSubDir?/:fileName.:ext`, async (ctx, next) => {
124+
const { element, fileName, ext } = ctx.params;
125+
if (!element.includes(tagPrefix)) {
126+
ctx.redirect(`/${componentSubpath}/${tagPrefix}-${element}/demo/${fileName}.${ext}`);
125127
} else {
126128
return next();
127129
}
128130
})
129131
// Redirect `elements/jazz-hands/*` to `elements/pf-jazz-hands/*` for files not previously handled
130-
.get(`/${componentSubpath}/:componentDir/:any*`, async (ctx, next) => {
131-
if (ctx.params.any.includes('demo')) {
132+
.get(`/${componentSubpath}/:element/:splatPath*`, async (ctx, next) => {
133+
const { element, splatPath } = ctx.params;
134+
if (splatPath.includes('demo')) {
132135
/* if its the demo directory return */
133136
return next();
134137
}
135-
if (!ctx.params.componentDir.includes(tagPrefix)) {
136-
ctx.redirect(`/${componentSubpath}/${tagPrefix}-${ctx.params.componentDir}/${ctx.params.any}`);
138+
if (!element.includes(tagPrefix)) {
139+
ctx.redirect(`/${componentSubpath}/${tagPrefix}-${element}/${splatPath}`);
137140
} else {
138141
return next();
139142
}

0 commit comments

Comments
 (0)