Skip to content

Commit

Permalink
feat: support splat route config file
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe committed Sep 18, 2023
1 parent b165f17 commit 63977ee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-seas-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/app-tools': patch
---

feat: support splat route config file
feat: 支持通配路由配置文件
1 change: 1 addition & 0 deletions packages/solutions/app-tools/src/analyze/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const NESTED_ROUTE = {
PAGE_DATA_FILE: 'page.data',
PAGE_CLIENT_LOADER: 'page.data.client',
SPLATE_FILE: '$',
SPLATE_CONFIG_FILE: '$.config',
SPLATE_LOADER_FILE: '$.loader',
SPLATE_DATA_FILE: '$.data',
SPLATE_CLIENT_DATA: '$.data.client',
Expand Down
10 changes: 10 additions & 0 deletions packages/solutions/app-tools/src/analyze/nestedRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const walk = async (
let splatData = '';
let splatRoute: NestedRouteForCli | null = null;
let pageConfigFile = '';
let splatConfigFile = '';

const items = await fs.readdir(dirname);

Expand Down Expand Up @@ -257,6 +258,12 @@ export const walk = async (
splatClientData = itemPath;
}

if (itemWithoutExt === NESTED_ROUTE.SPLATE_CONFIG_FILE) {
if (!route.config) {
splatConfigFile = itemPath;
}
}

if (itemWithoutExt === NESTED_ROUTE.SPLATE_DATA_FILE) {
splatData = itemPath;
}
Expand All @@ -282,6 +289,9 @@ export const walk = async (
if (splatData) {
splatRoute.data = splatData;
}
if (splatConfigFile) {
splatRoute.config = splatConfigFile;
}
route.children?.push(splatRoute);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports[`nested routes walk 1`] = `
{
"_component": "@_modern_js_src/user/$.tsx",
"clientData": "<ROOT>/tests/analyze/fixtures/nested-routes/user/$.data.client.ts",
"config": "<ROOT>/tests/analyze/fixtures/nested-routes/user/$.config.ts",
"data": "<ROOT>/tests/analyze/fixtures/nested-routes/user/$.data.ts",
"id": "user/$",
"path": "*",
Expand Down
Empty file.

0 comments on commit 63977ee

Please sign in to comment.