Skip to content

Commit

Permalink
fix: remove redundant param (#16)
Browse files Browse the repository at this point in the history
close #15
  • Loading branch information
yesmeck committed Aug 17, 2022
1 parent 8247d12 commit ae3dce7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 36 deletions.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"author": "Wei Zhu",
"license": "MIT",
"devDependencies": {
"@remix-run/dev": "^1.6.4",
"@remix-run/dev": "^1.6.7",
"@types/cli-table": "^0.3.0",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.12",
Expand Down
68 changes: 44 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/__tests__/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const routes = {
\\"season\\",
\\"episode\\"
],
\\"/people/:personId\\": [
\\"personId\\"
],
\\"/people/:personId/:planId/remove-plan\\": [
\\"personId\\",
\\"planId\\"
],
\\"/s/:query\\": [
\\"query\\"
],
Expand Down Expand Up @@ -47,6 +54,16 @@ export declare function $path(
params: { season: string | number; episode: string | number },
query?: Record<string, string | number>
): string;
export declare function $path(
route: \\"/people/:personId\\",
params: { personId: string | number },
query?: Record<string, string | number>
): string;
export declare function $path(
route: \\"/people/:personId/:planId/remove-plan\\",
params: { personId: string | number; planId: string | number },
query?: Record<string, string | number>
): string;
export declare function $path(
route: \\"/blog/rss.xml\\",
query?: Record<string, string | number>
Expand Down Expand Up @@ -115,6 +132,19 @@ export declare function $params(
season: string,
episode: string
};
export declare function $params(
route: \\"/people/:personId\\",
params: { readonly [key: string]: string | undefined }
): {
personId: string
};
export declare function $params(
route: \\"/people/:personId/:planId/remove-plan\\",
params: { readonly [key: string]: string | undefined }
): {
personId: string,
planId: string
};
export declare function $params(
route: \\"/s/:query\\",
params: { readonly [key: string]: string | undefined }
Expand Down
20 changes: 9 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,15 @@ function generateParamsDefinition(routesInfo: RoutesInfo) {
function parse(routes: ConfigRoute[]) {
const paramNames: string[] = [];
routes.forEach((route) => {
if (route.path?.startsWith(':')) {
return paramNames.push(
...route.path.split('/').map((param) => param.replace(':', '')),
);
}
const [_, ...paramOrActions] = route.path!.split('/');
paramOrActions.forEach((paramOrAction) => {
if (paramOrAction.startsWith(':')) {
paramNames.push(paramOrAction.replace(':', ''));
}
});
return (
route.path &&
paramNames.push(
...route.path
.split('/')
.filter((seg) => seg.startsWith(':'))
.map((param) => param.replace(':', '')),
)
);
});
return paramNames;
}
Expand Down

0 comments on commit ae3dce7

Please sign in to comment.