olovastart 0.0.13 → 0.0.14
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.
- package/dist/olova.cjs +80 -41
- package/dist/olova.cjs.map +1 -1
- package/dist/olova.js +80 -41
- package/dist/olova.js.map +1 -1
- package/package.json +1 -1
package/dist/olova.cjs
CHANGED
|
@@ -148,31 +148,21 @@ function generateRouteTree(routes, notFoundPages, layouts, srcDir) {
|
|
|
148
148
|
};
|
|
149
149
|
const routeImports = routes.map((route, index) => {
|
|
150
150
|
const relativePath = "./" + path5__default.default.relative(srcDir, route.component).replace(/\\/g, "/").replace(/\.tsx?$/, "");
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
const hasInlineMetadata = !!route.metadataSource;
|
|
154
|
-
if (route.hasMetadata && !hasInlineMetadata || route.hasRoute || route.hasGetStaticPaths) {
|
|
155
|
-
return "import * as " + moduleName + " from '" + relativePath + "';";
|
|
156
|
-
} else if (route.hasDefault) {
|
|
157
|
-
return "const " + importName + " = lazy(() => import('" + relativePath + "'));";
|
|
158
|
-
} else if (route.namedExport) {
|
|
159
|
-
return "const " + importName + " = lazy(() => import('" + relativePath + "').then(module => ({ default: module." + route.namedExport + " })));";
|
|
160
|
-
} else {
|
|
161
|
-
return "import " + importName + " from '" + relativePath + "';";
|
|
162
|
-
}
|
|
151
|
+
const moduleName = getRouteName2(route.component, index, "RouteModule");
|
|
152
|
+
return `import * as ${moduleName} from '${relativePath}';`;
|
|
163
153
|
}).join("\n");
|
|
164
154
|
const notFoundImports = notFoundPages.map((nf, index) => {
|
|
165
155
|
const relativePath = "./" + path5__default.default.relative(srcDir, nf.filePath).replace(/\\/g, "/").replace(/\.tsx?$/, "");
|
|
166
156
|
const importName = getRouteName2(nf.filePath, index, "NotFound");
|
|
167
157
|
const moduleName = importName + "Module";
|
|
168
158
|
if (nf.hasMetadata) {
|
|
169
|
-
return
|
|
159
|
+
return `import * as ${moduleName} from '${relativePath}';`;
|
|
170
160
|
} else if (nf.hasDefault) {
|
|
171
|
-
return
|
|
161
|
+
return `import ${importName} from '${relativePath}';`;
|
|
172
162
|
} else if (nf.namedExport) {
|
|
173
|
-
return
|
|
163
|
+
return `import { ${nf.namedExport} as ${importName} } from '${relativePath}';`;
|
|
174
164
|
} else {
|
|
175
|
-
return
|
|
165
|
+
return `import ${importName} from '${relativePath}';`;
|
|
176
166
|
}
|
|
177
167
|
}).join("\n");
|
|
178
168
|
const layoutImports = layouts.map((layout, index) => {
|
|
@@ -180,54 +170,103 @@ function generateRouteTree(routes, notFoundPages, layouts, srcDir) {
|
|
|
180
170
|
const importName = getRouteName2(layout.filePath, index, "Layout");
|
|
181
171
|
const moduleName = importName + "Module";
|
|
182
172
|
if (layout.hasMetadata) {
|
|
183
|
-
return
|
|
173
|
+
return `import * as ${moduleName} from '${relativePath}';`;
|
|
184
174
|
} else if (layout.hasDefault) {
|
|
185
|
-
return
|
|
175
|
+
return `import ${importName} from '${relativePath}';`;
|
|
186
176
|
} else if (layout.namedExport) {
|
|
187
|
-
return
|
|
177
|
+
return `import { ${layout.namedExport} as ${importName} } from '${relativePath}';`;
|
|
188
178
|
} else {
|
|
189
|
-
return
|
|
179
|
+
return `import ${importName} from '${relativePath}';`;
|
|
190
180
|
}
|
|
191
181
|
}).join("\n");
|
|
192
182
|
const routeObjects = routes.map((route, index) => {
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const usesModule = route.hasMetadata && !route.metadataSource || route.hasRoute || route.hasGetStaticPaths;
|
|
196
|
-
const component = usesModule ? moduleName + ".default" : importName;
|
|
183
|
+
const moduleName = getRouteName2(route.component, index, "RouteModule");
|
|
184
|
+
const component = `${moduleName}.default`;
|
|
197
185
|
let metadata = "";
|
|
198
186
|
if (route.metadataSource) {
|
|
199
|
-
metadata =
|
|
187
|
+
metadata = `,
|
|
188
|
+
metadata: ${route.metadataSource}`;
|
|
200
189
|
} else if (route.hasMetadata) {
|
|
201
|
-
metadata =
|
|
190
|
+
metadata = `,
|
|
191
|
+
metadata: ${moduleName}.metadata`;
|
|
202
192
|
}
|
|
203
193
|
let getStaticPaths = "";
|
|
204
194
|
if (route.hasGetStaticPaths) {
|
|
205
|
-
getStaticPaths =
|
|
195
|
+
getStaticPaths = `,
|
|
196
|
+
getStaticPaths: ${moduleName}.getStaticPaths`;
|
|
206
197
|
}
|
|
207
|
-
return
|
|
198
|
+
return ` {
|
|
199
|
+
path: '${route.path}',
|
|
200
|
+
component: ${component}${metadata}${getStaticPaths}
|
|
201
|
+
}`;
|
|
208
202
|
}).join(",\n");
|
|
209
203
|
const notFoundObjects = notFoundPages.map((nf, index) => {
|
|
210
204
|
const importName = getRouteName2(nf.filePath, index, "NotFound");
|
|
211
205
|
const moduleName = importName + "Module";
|
|
212
|
-
const component = nf.hasMetadata ? moduleName
|
|
213
|
-
const metadata = nf.hasMetadata ?
|
|
214
|
-
|
|
206
|
+
const component = nf.hasMetadata ? `${moduleName}.default` : importName;
|
|
207
|
+
const metadata = nf.hasMetadata ? `,
|
|
208
|
+
metadata: ${moduleName}.metadata` : "";
|
|
209
|
+
return ` {
|
|
210
|
+
pathPrefix: '${nf.pathPrefix}',
|
|
211
|
+
component: ${component}${metadata}
|
|
212
|
+
}`;
|
|
215
213
|
}).join(",\n");
|
|
216
214
|
const layoutObjects = layouts.map((layout, index) => {
|
|
217
215
|
const importName = getRouteName2(layout.filePath, index, "Layout");
|
|
218
216
|
const moduleName = importName + "Module";
|
|
219
|
-
const component = layout.hasMetadata ? moduleName
|
|
220
|
-
const metadata = layout.hasMetadata ?
|
|
221
|
-
|
|
217
|
+
const component = layout.hasMetadata ? `${moduleName}.default` : importName;
|
|
218
|
+
const metadata = layout.hasMetadata ? `,
|
|
219
|
+
metadata: ${moduleName}.metadata` : "";
|
|
220
|
+
return ` {
|
|
221
|
+
path: '${layout.path}',
|
|
222
|
+
layout: ${component}${metadata},
|
|
223
|
+
children: []
|
|
224
|
+
}`;
|
|
222
225
|
}).join(",\n");
|
|
223
|
-
const routePaths = routes.length > 0 ? routes.map((r) =>
|
|
226
|
+
const routePaths = routes.length > 0 ? routes.map((r) => `'${r.path}'`).join(" | ") : "never";
|
|
224
227
|
const allImports = [routeImports, notFoundImports, layoutImports].filter(Boolean).join("\n");
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
return `/* prettier-ignore-start */
|
|
229
|
+
|
|
230
|
+
/* eslint-disable */
|
|
231
|
+
|
|
232
|
+
// @ts-nocheck
|
|
233
|
+
|
|
234
|
+
// noinspection JSUnusedGlobalSymbols
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* This file was automatically generated by Olova Router.
|
|
238
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source route files
|
|
239
|
+
* and regenerate this file by running the dev server or build command.
|
|
240
|
+
*
|
|
241
|
+
* @generated
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
import { createLink, OlovaRouter, useRouter, useParams, useSearchParams, usePathname, Outlet } from 'olovastart/router';
|
|
245
|
+
${allImports}
|
|
246
|
+
|
|
247
|
+
// Route Tree Definition
|
|
248
|
+
export const routes = [
|
|
249
|
+
${routeObjects}
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
export const notFoundPages = [
|
|
253
|
+
${notFoundObjects}
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
export const layouts = [
|
|
257
|
+
${layoutObjects}
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
// Type-safe route paths
|
|
261
|
+
export type RoutePaths = ${routePaths};
|
|
262
|
+
|
|
263
|
+
// Exports
|
|
264
|
+
export const Link = createLink<RoutePaths>();
|
|
265
|
+
export { OlovaRouter, useRouter, useParams, useSearchParams, usePathname, Outlet };
|
|
266
|
+
export type { NotFoundPageConfig, SearchParams, SetSearchParamsOptions, LayoutRoute, Metadata } from 'olovastart/router';
|
|
267
|
+
|
|
268
|
+
/* prettier-ignore-end */
|
|
269
|
+
`;
|
|
231
270
|
}
|
|
232
271
|
function scanDirectory(dir, rootDir, extensions, routes, notFoundPages, layouts, isRoot = false) {
|
|
233
272
|
if (!fs3__default.default.existsSync(dir)) return;
|