@gyoll/builder 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,10 +40,14 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
40
40
  }
41
41
  const routes = [];
42
42
  if (routeFiles.page) {
43
+ const pathInfo = buildRoutePath(segments);
43
44
  const route = {
44
- path: buildRoutePath(segments),
45
+ path: pathInfo.path,
45
46
  component: import_path.default.relative(baseDir, routeFiles.page)
46
47
  };
48
+ if (pathInfo.catchAllParam) {
49
+ route.catchAllParam = pathInfo.catchAllParam;
50
+ }
47
51
  if (currentLayouts.length > 0) {
48
52
  route.layouts = [...currentLayouts];
49
53
  }
@@ -104,8 +108,9 @@ function parseSegment(segment) {
104
108
  if (/^\(.+\)$/.test(segment)) {
105
109
  return null;
106
110
  }
107
- if (/^\[\.\.\.(.+)\]$/.test(segment)) {
108
- return "*";
111
+ const catchAllMatch = /^\[\.\.\.(.+)\]$/.exec(segment);
112
+ if (catchAllMatch) {
113
+ return { type: "catchall", param: catchAllMatch[1] };
109
114
  }
110
115
  if (/^\[(.+)\]$/.test(segment)) {
111
116
  const param = segment.slice(1, -1);
@@ -114,11 +119,25 @@ function parseSegment(segment) {
114
119
  return segment;
115
120
  }
116
121
  function buildRoutePath(segments) {
117
- const filtered = segments.filter((s) => s !== null);
118
- if (filtered.length === 0) {
119
- return "/";
122
+ const filtered = [];
123
+ let catchAllParam = null;
124
+ for (const segment of segments) {
125
+ if (segment === null) {
126
+ continue;
127
+ }
128
+ if (typeof segment === "object" && segment.type === "catchall") {
129
+ catchAllParam = segment.param;
130
+ filtered.push("*");
131
+ } else {
132
+ filtered.push(segment);
133
+ }
134
+ }
135
+ const path3 = filtered.length === 0 ? "/" : "/" + filtered.join("/");
136
+ const result = { path: path3 };
137
+ if (catchAllParam) {
138
+ result.catchAllParam = catchAllParam;
120
139
  }
121
- return "/" + filtered.join("/");
140
+ return result;
122
141
  }
123
142
  async function generateManifest(routes, outFile, routesDir) {
124
143
  const outDir = import_path.default.dirname(outFile);
@@ -18,10 +18,14 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
18
18
  }
19
19
  const routes = [];
20
20
  if (routeFiles.page) {
21
+ const pathInfo = buildRoutePath(segments);
21
22
  const route = {
22
- path: buildRoutePath(segments),
23
+ path: pathInfo.path,
23
24
  component: path.relative(baseDir, routeFiles.page)
24
25
  };
26
+ if (pathInfo.catchAllParam) {
27
+ route.catchAllParam = pathInfo.catchAllParam;
28
+ }
25
29
  if (currentLayouts.length > 0) {
26
30
  route.layouts = [...currentLayouts];
27
31
  }
@@ -82,8 +86,9 @@ function parseSegment(segment) {
82
86
  if (/^\(.+\)$/.test(segment)) {
83
87
  return null;
84
88
  }
85
- if (/^\[\.\.\.(.+)\]$/.test(segment)) {
86
- return "*";
89
+ const catchAllMatch = /^\[\.\.\.(.+)\]$/.exec(segment);
90
+ if (catchAllMatch) {
91
+ return { type: "catchall", param: catchAllMatch[1] };
87
92
  }
88
93
  if (/^\[(.+)\]$/.test(segment)) {
89
94
  const param = segment.slice(1, -1);
@@ -92,11 +97,25 @@ function parseSegment(segment) {
92
97
  return segment;
93
98
  }
94
99
  function buildRoutePath(segments) {
95
- const filtered = segments.filter((s) => s !== null);
96
- if (filtered.length === 0) {
97
- return "/";
100
+ const filtered = [];
101
+ let catchAllParam = null;
102
+ for (const segment of segments) {
103
+ if (segment === null) {
104
+ continue;
105
+ }
106
+ if (typeof segment === "object" && segment.type === "catchall") {
107
+ catchAllParam = segment.param;
108
+ filtered.push("*");
109
+ } else {
110
+ filtered.push(segment);
111
+ }
112
+ }
113
+ const path3 = filtered.length === 0 ? "/" : "/" + filtered.join("/");
114
+ const result = { path: path3 };
115
+ if (catchAllParam) {
116
+ result.catchAllParam = catchAllParam;
98
117
  }
99
- return "/" + filtered.join("/");
118
+ return result;
100
119
  }
101
120
  async function generateManifest(routes, outFile, routesDir) {
102
121
  const outDir = path.dirname(outFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gyoll/builder",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "CLI tool for generating route manifests from file-system structure",
6
6
  "bin": {