@lark-apaas/devtool-kits 1.2.17-alpha.50 → 1.2.17-alpha.52

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.
@@ -27,22 +27,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  // src/bin/generate-page-routes.ts
28
28
  var import_fs = __toESM(require("fs"), 1);
29
29
  var import_path = __toESM(require("path"), 1);
30
+
31
+ // src/route-parser.ts
32
+ var fs = __toESM(require("fs"), 1);
33
+ var path = __toESM(require("path"), 1);
30
34
  var import_parser = require("@babel/parser");
31
35
  var import_traverse = __toESM(require("@babel/traverse"), 1);
32
36
  var t = __toESM(require("@babel/types"), 1);
33
37
  var traverse = typeof import_traverse.default === "function" ? import_traverse.default : import_traverse.default.default;
34
- var args = process.argv.slice(2);
35
- function getArg(name, defaultValue) {
36
- const index = args.indexOf(name);
37
- if (index !== -1 && args[index + 1]) {
38
- return args[index + 1];
38
+ function routeParserLog(level, message, ...args2) {
39
+ const prefix = "[route-parser]";
40
+ const logMessage = `${prefix} ${message}`;
41
+ switch (level) {
42
+ case "warn":
43
+ console.warn(logMessage, ...args2);
44
+ break;
45
+ case "error":
46
+ console.error(logMessage, ...args2);
47
+ break;
48
+ case "info":
49
+ console.info(logMessage, ...args2);
50
+ break;
51
+ default:
52
+ console.log(logMessage, ...args2);
39
53
  }
40
- return defaultValue;
41
54
  }
42
- __name(getArg, "getArg");
43
- var appPath = import_path.default.resolve(process.cwd(), getArg("--app-path", "./client/src/app.tsx"));
44
- var outDir = import_path.default.resolve(process.cwd(), getArg("--out-dir", "./dist"));
45
- var filename = getArg("--filename", "page-routes.json");
55
+ __name(routeParserLog, "routeParserLog");
46
56
  function isRouteComponent(openingElement) {
47
57
  return t.isJSXIdentifier(openingElement.name) && openingElement.name.name === "Route";
48
58
  }
@@ -56,7 +66,7 @@ function evaluateTemplateLiteral(templateLiteral) {
56
66
  return quasis.map((q) => q.value.raw).join("");
57
67
  }
58
68
  __name(evaluateTemplateLiteral, "evaluateTemplateLiteral");
59
- function extractRouteInfo(openingElement) {
69
+ function extractPageRouteInfo(openingElement) {
60
70
  const routeInfo = {};
61
71
  openingElement.attributes.forEach((attr) => {
62
72
  if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
@@ -83,7 +93,7 @@ function extractRouteInfo(openingElement) {
83
93
  });
84
94
  return routeInfo;
85
95
  }
86
- __name(extractRouteInfo, "extractRouteInfo");
96
+ __name(extractPageRouteInfo, "extractPageRouteInfo");
87
97
  function buildFullPath(routeStack, currentRoute) {
88
98
  let fullPath = "";
89
99
  for (let i = 0; i < routeStack.length; i++) {
@@ -115,62 +125,88 @@ function buildFullPath(routeStack, currentRoute) {
115
125
  return null;
116
126
  }
117
127
  __name(buildFullPath, "buildFullPath");
118
- function parsePageRoutes(appFilePath) {
119
- if (!import_fs.default.existsSync(appFilePath)) {
120
- throw new Error(`App file does not exist: ${appFilePath}`);
121
- }
122
- const sourceCode = import_fs.default.readFileSync(appFilePath, "utf-8");
123
- const ast = (0, import_parser.parse)(sourceCode, {
124
- sourceType: "module",
125
- plugins: [
126
- "jsx",
127
- "typescript",
128
- "decorators-legacy",
129
- "classProperties",
130
- "objectRestSpread",
131
- "functionBind",
132
- "exportDefaultFrom",
133
- "exportNamespaceFrom",
134
- "dynamicImport",
135
- "nullishCoalescingOperator",
136
- "optionalChaining"
137
- ]
138
- });
139
- const routeSet = /* @__PURE__ */ new Set();
140
- const routeStack = [];
141
- traverse(ast, {
142
- JSXElement: {
143
- enter(nodePath) {
144
- const { openingElement } = nodePath.node;
145
- if (isRouteComponent(openingElement)) {
146
- routeStack.push(extractRouteInfo(openingElement));
147
- }
148
- },
149
- exit(nodePath) {
150
- const { openingElement } = nodePath.node;
151
- if (isRouteComponent(openingElement)) {
152
- const currentRoute = routeStack.pop();
153
- if (currentRoute && currentRoute.path === "*") return;
154
- if (currentRoute && (currentRoute.path || currentRoute.index)) {
155
- const fullPath = buildFullPath(routeStack, currentRoute);
156
- if (fullPath) routeSet.add(fullPath);
128
+ function parseRoutesFromFile(appPath2, basePath, options = {}) {
129
+ const { applyBasePath = true } = options;
130
+ const defaultPath = applyBasePath && basePath ? `${basePath}/` : "/";
131
+ try {
132
+ const appFilePath = path.resolve(process.cwd(), appPath2);
133
+ if (!fs.existsSync(appFilePath)) {
134
+ throw new Error(`App file does not exist: ${appFilePath}`);
135
+ }
136
+ const sourceCode = fs.readFileSync(appFilePath, "utf-8");
137
+ const ast = (0, import_parser.parse)(sourceCode, {
138
+ sourceType: "module",
139
+ plugins: [
140
+ "jsx",
141
+ "typescript",
142
+ "decorators-legacy",
143
+ "classProperties",
144
+ "objectRestSpread",
145
+ "functionBind",
146
+ "exportDefaultFrom",
147
+ "exportNamespaceFrom",
148
+ "dynamicImport",
149
+ "nullishCoalescingOperator",
150
+ "optionalChaining"
151
+ ]
152
+ });
153
+ const routeSet = /* @__PURE__ */ new Set();
154
+ const routeStack = [];
155
+ traverse(ast, {
156
+ JSXElement: {
157
+ enter(nodePath) {
158
+ const { openingElement } = nodePath.node;
159
+ if (isRouteComponent(openingElement)) {
160
+ routeStack.push(extractPageRouteInfo(openingElement));
161
+ }
162
+ },
163
+ exit(nodePath) {
164
+ const { openingElement } = nodePath.node;
165
+ if (isRouteComponent(openingElement)) {
166
+ const currentRoute = routeStack.pop();
167
+ if (currentRoute && currentRoute.path === "*") return;
168
+ if (currentRoute && (currentRoute.path || currentRoute.index)) {
169
+ const fullPath = buildFullPath(routeStack, currentRoute);
170
+ if (fullPath) routeSet.add(fullPath);
171
+ }
157
172
  }
158
173
  }
159
174
  }
160
- }
161
- });
162
- const routes = Array.from(routeSet).map((routePath) => ({
163
- path: routePath
164
- }));
165
- return routes.length > 0 ? routes : [
166
- {
167
- path: "/"
168
- }
169
- ];
175
+ });
176
+ const routes = Array.from(routeSet).map((routePath) => ({
177
+ path: applyBasePath && basePath ? `${basePath}${routePath}` : routePath
178
+ }));
179
+ return routes.length > 0 ? routes : [
180
+ {
181
+ path: defaultPath
182
+ }
183
+ ];
184
+ } catch (error) {
185
+ routeParserLog("warn", "Route parsing failed, using default routes:", error.message);
186
+ return [
187
+ {
188
+ path: defaultPath
189
+ }
190
+ ];
191
+ }
192
+ }
193
+ __name(parseRoutesFromFile, "parseRoutesFromFile");
194
+
195
+ // src/bin/generate-page-routes.ts
196
+ var args = process.argv.slice(2);
197
+ function getArg(name, defaultValue) {
198
+ const index = args.indexOf(name);
199
+ if (index !== -1 && args[index + 1]) {
200
+ return args[index + 1];
201
+ }
202
+ return defaultValue;
170
203
  }
171
- __name(parsePageRoutes, "parsePageRoutes");
204
+ __name(getArg, "getArg");
205
+ var appPath = getArg("--app-path", "./client/src/app.tsx");
206
+ var outDir = import_path.default.resolve(process.cwd(), getArg("--out-dir", "./dist"));
207
+ var filename = getArg("--filename", "page-routes.json");
172
208
  try {
173
- const routes = parsePageRoutes(appPath);
209
+ const routes = parseRoutesFromFile(appPath, "");
174
210
  if (!import_fs.default.existsSync(outDir)) {
175
211
  import_fs.default.mkdirSync(outDir, {
176
212
  recursive: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/generate-page-routes.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from 'fs';\nimport path from 'path';\nimport { parse } from '@babel/parser';\nimport _traverse from '@babel/traverse';\n// Handle CJS default export interop in ESM context\nconst traverse = typeof _traverse === 'function' ? _traverse : (_traverse as any).default;\nimport * as t from '@babel/types';\n\nconst args = process.argv.slice(2);\n\nfunction getArg(name: string, defaultValue: string): string {\n const index = args.indexOf(name);\n if (index !== -1 && args[index + 1]) {\n return args[index + 1];\n }\n return defaultValue;\n}\n\nconst appPath = path.resolve(process.cwd(), getArg('--app-path', './client/src/app.tsx'));\nconst outDir = path.resolve(process.cwd(), getArg('--out-dir', './dist'));\nconst filename = getArg('--filename', 'page-routes.json');\n\ninterface RouteInfo {\n path?: string;\n index?: boolean;\n [key: string]: unknown;\n}\n\nfunction isRouteComponent(openingElement: t.JSXOpeningElement): boolean {\n return (\n t.isJSXIdentifier(openingElement.name) &&\n openingElement.name.name === 'Route'\n );\n}\n\nfunction evaluateTemplateLiteral(templateLiteral: t.TemplateLiteral): string {\n const quasis = templateLiteral.quasis;\n const expressions = templateLiteral.expressions;\n\n if (quasis.length === 1 && expressions.length === 0) {\n return quasis[0].value.raw;\n }\n\n return quasis.map((q) => q.value.raw).join('');\n}\n\nfunction extractRouteInfo(openingElement: t.JSXOpeningElement): RouteInfo {\n const routeInfo: RouteInfo = {};\n\n openingElement.attributes.forEach((attr) => {\n if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {\n const name = attr.name.name;\n let value: unknown;\n\n if (attr.value) {\n if (t.isStringLiteral(attr.value)) {\n value = attr.value.value;\n } else if (t.isJSXExpressionContainer(attr.value)) {\n const expression = attr.value.expression;\n if (t.isStringLiteral(expression)) {\n value = expression.value;\n } else if (t.isTemplateLiteral(expression)) {\n value = evaluateTemplateLiteral(expression);\n } else {\n value = true;\n }\n }\n } else {\n value = true;\n }\n\n routeInfo[name] = value;\n }\n });\n\n return routeInfo;\n}\n\nfunction buildFullPath(routeStack: RouteInfo[], currentRoute: RouteInfo): string | null {\n let fullPath = '';\n\n for (let i = 0; i < routeStack.length; i++) {\n if (routeStack[i].path) {\n let parentPath = routeStack[i].path!;\n if (!parentPath.startsWith('/')) parentPath = `/${parentPath}`;\n if (parentPath.endsWith('/') && parentPath !== '/') {\n parentPath = parentPath.slice(0, -1);\n }\n\n fullPath += parentPath === '/' ? '' : parentPath;\n }\n }\n\n if (currentRoute.index) {\n return fullPath || '/';\n } else if (currentRoute.path) {\n const routePath = currentRoute.path;\n\n if (routePath === '*') {\n return null;\n }\n\n if (!routePath.startsWith('/')) {\n fullPath = `${fullPath}/${routePath}`;\n } else {\n fullPath = routePath;\n }\n\n if (fullPath === '') fullPath = '/';\n if (!fullPath.startsWith('/')) fullPath = `/${fullPath}`;\n\n return fullPath;\n }\n\n return null;\n}\n\nfunction parsePageRoutes(appFilePath: string): Array<{ path: string }> {\n if (!fs.existsSync(appFilePath)) {\n throw new Error(`App file does not exist: ${appFilePath}`);\n }\n\n const sourceCode = fs.readFileSync(appFilePath, 'utf-8');\n\n const ast = parse(sourceCode, {\n sourceType: 'module',\n plugins: [\n 'jsx',\n 'typescript',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n });\n\n const routeSet = new Set<string>();\n const routeStack: RouteInfo[] = [];\n\n traverse(ast, {\n JSXElement: {\n enter(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n routeStack.push(extractRouteInfo(openingElement));\n }\n },\n exit(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n const currentRoute = routeStack.pop();\n if (currentRoute && currentRoute.path === '*') return;\n if (currentRoute && (currentRoute.path || currentRoute.index)) {\n const fullPath = buildFullPath(routeStack, currentRoute);\n if (fullPath) routeSet.add(fullPath);\n }\n }\n },\n },\n });\n\n // page-routes 不带 basePath 前缀,供日志服务消费\n const routes = Array.from(routeSet).map((routePath) => ({ path: routePath }));\n return routes.length > 0 ? routes : [{ path: '/' }];\n}\n\ntry {\n const routes = parsePageRoutes(appPath);\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n const outPath = path.resolve(outDir, filename);\n fs.writeFileSync(outPath, JSON.stringify(routes, null, 2));\n console.log(`[page-routes] Generated ${outPath} (${routes.length} routes)`);\n} catch (error) {\n console.warn('[page-routes] Failed to generate page-routes.json, writing empty fallback:', error);\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n fs.writeFileSync(path.resolve(outDir, filename), JSON.stringify([], null, 2));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gB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AA,QAAGC,WAAWrC,MAAAA,GAAS;AAC1BoC,cAAAA,QAAGsB,UAAU1D,QAAQ;MAAE2D,WAAW;IAAK,CAAA;EACzC;AACA,QAAMC,UAAU/D,YAAAA,QAAKC,QAAQE,QAAQC,QAAAA;AACrCmC,YAAAA,QAAGyB,cAAcD,SAASE,KAAKC,UAAUR,QAAQ,MAAM,CAAA,CAAA;AACvDS,UAAQC,IAAI,2BAA2BL,OAAAA,KAAYL,OAAO9C,MAAM,UAAU;AAC5E,SAASyD,OAAO;AACdF,UAAQG,KAAK,8EAA8ED,KAAAA;AAC3F,MAAI,CAAC9B,UAAAA,QAAGC,WAAWrC,MAAAA,GAAS;AAC1BoC,cAAAA,QAAGsB,UAAU1D,QAAQ;MAAE2D,WAAW;IAAK,CAAA;EACzC;AACAvB,YAAAA,QAAGyB,cAAchE,YAAAA,QAAKC,QAAQE,QAAQC,QAAAA,GAAW6D,KAAKC,UAAU,CAAA,GAAI,MAAM,CAAA,CAAA;AAC5E;","names":["traverse","_traverse","default","args","process","argv","slice","getArg","name","defaultValue","index","indexOf","appPath","path","resolve","cwd","outDir","filename","isRouteComponent","openingElement","isJSXIdentifier","evaluateTemplateLiteral","templateLiteral","quasis","expressions","length","value","raw","map","q","join","extractRouteInfo","routeInfo","attributes","forEach","attr","isJSXAttribute","isStringLiteral","isJSXExpressionContainer","expression","isTemplateLiteral","buildFullPath","routeStack","currentRoute","fullPath","i","parentPath","startsWith","endsWith","routePath","parsePageRoutes","appFilePath","fs","existsSync","Error","sourceCode","readFileSync","ast","parse","sourceType","plugins","routeSet","Set","JSXElement","enter","nodePath","node","push","exit","pop","add","routes","Array","from","mkdirSync","recursive","outPath","writeFileSync","JSON","stringify","console","log","error","warn"]}
1
+ {"version":3,"sources":["../../src/bin/generate-page-routes.ts","../../src/route-parser.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from 'fs';\nimport path from 'path';\nimport { parseRoutesFromFile } from '../route-parser';\n\nconst args = process.argv.slice(2);\n\nfunction getArg(name: string, defaultValue: string): string {\n const index = args.indexOf(name);\n if (index !== -1 && args[index + 1]) {\n return args[index + 1];\n }\n return defaultValue;\n}\n\nconst appPath = getArg('--app-path', './client/src/app.tsx');\nconst outDir = path.resolve(process.cwd(), getArg('--out-dir', './dist'));\nconst filename = getArg('--filename', 'page-routes.json');\n\ntry {\n // page-routes 不带 basePath 前缀(basePath 为空),供日志服务消费\n const routes = parseRoutesFromFile(appPath, '');\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n const outPath = path.resolve(outDir, filename);\n fs.writeFileSync(outPath, JSON.stringify(routes, null, 2));\n console.log(`[page-routes] Generated ${outPath} (${routes.length} routes)`);\n} catch (error) {\n console.warn('[page-routes] Failed to generate page-routes.json, writing empty fallback:', error);\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n fs.writeFileSync(path.resolve(outDir, filename), JSON.stringify([], null, 2));\n}\n","import * as fs from 'fs';\nimport * as path from 'path';\nimport * as crypto from 'crypto';\nimport { parse } from '@babel/parser';\nimport _traverse from '@babel/traverse';\nimport * as t from '@babel/types';\n\n// Handle CJS default export interop in ESM context\nconst traverse = typeof _traverse === 'function' ? _traverse : (_traverse as any).default;\n\nexport interface PageRouteInfo {\n path?: string;\n index?: boolean;\n [key: string]: unknown;\n}\n\nexport interface ParseRoutesOptions {\n /** If true, prefix all routes with basePath. Default: true */\n applyBasePath?: boolean;\n}\n\nexport function routeParserLog(\n level: 'log' | 'warn' | 'error' | 'info',\n message: string,\n ...args: unknown[]\n): void {\n const prefix = '[route-parser]';\n const logMessage = `${prefix} ${message}`;\n switch (level) {\n case 'warn':\n console.warn(logMessage, ...args);\n break;\n case 'error':\n console.error(logMessage, ...args);\n break;\n case 'info':\n console.info(logMessage, ...args);\n break;\n default:\n console.log(logMessage, ...args);\n }\n}\n\nexport function calculateFileHash(filePath: string): string | null {\n try {\n const content = fs.readFileSync(filePath, 'utf-8');\n return crypto.createHash('md5').update(content).digest('hex');\n } catch (error) {\n routeParserLog('warn', 'Failed to calculate file hash:', (error as Error).message);\n return null;\n }\n}\n\nexport function isRouteComponent(openingElement: t.JSXOpeningElement): boolean {\n return (\n t.isJSXIdentifier(openingElement.name) &&\n openingElement.name.name === 'Route'\n );\n}\n\nexport function evaluateTemplateLiteral(templateLiteral: t.TemplateLiteral): string {\n const quasis = templateLiteral.quasis;\n const expressions = templateLiteral.expressions;\n\n if (quasis.length === 1 && expressions.length === 0) {\n return quasis[0].value.raw;\n }\n\n return quasis.map((q) => q.value.raw).join('');\n}\n\nexport function extractPageRouteInfo(openingElement: t.JSXOpeningElement): PageRouteInfo {\n const routeInfo: PageRouteInfo = {};\n\n openingElement.attributes.forEach((attr) => {\n if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {\n const name = attr.name.name;\n let value: unknown;\n\n if (attr.value) {\n if (t.isStringLiteral(attr.value)) {\n value = attr.value.value;\n } else if (t.isJSXExpressionContainer(attr.value)) {\n const expression = attr.value.expression;\n if (t.isStringLiteral(expression)) {\n value = expression.value;\n } else if (t.isTemplateLiteral(expression)) {\n value = evaluateTemplateLiteral(expression);\n } else {\n value = true;\n }\n }\n } else {\n value = true;\n }\n\n routeInfo[name] = value;\n }\n });\n\n return routeInfo;\n}\n\nexport function buildFullPath(\n routeStack: PageRouteInfo[],\n currentRoute: PageRouteInfo\n): string | null {\n let fullPath = '';\n\n for (let i = 0; i < routeStack.length; i++) {\n if (routeStack[i].path) {\n let parentPath = routeStack[i].path!;\n if (!parentPath.startsWith('/')) parentPath = `/${parentPath}`;\n if (parentPath.endsWith('/') && parentPath !== '/') {\n parentPath = parentPath.slice(0, -1);\n }\n\n fullPath += parentPath === '/' ? '' : parentPath;\n }\n }\n\n if (currentRoute.index) {\n return fullPath || '/';\n } else if (currentRoute.path) {\n const routePath = currentRoute.path;\n\n if (routePath === '*') {\n return null;\n }\n\n if (!routePath.startsWith('/')) {\n fullPath = `${fullPath}/${routePath}`;\n } else {\n fullPath = routePath;\n }\n\n if (fullPath === '') fullPath = '/';\n if (!fullPath.startsWith('/')) fullPath = `/${fullPath}`;\n\n return fullPath;\n }\n\n return null;\n}\n\n/**\n * Parse routes from the app file at build time.\n * @param appPath - Path to app.tsx (relative to cwd or absolute)\n * @param basePath - Normalized base path prefix (e.g., '/my_plugin', or '' for no prefix)\n * @param options - Parse options\n * @returns Array of route definitions\n */\nexport function parseRoutesFromFile(\n appPath: string,\n basePath: string,\n options: ParseRoutesOptions = {}\n): Array<{ path: string }> {\n const { applyBasePath = true } = options;\n const defaultPath = applyBasePath && basePath ? `${basePath}/` : '/';\n\n try {\n const appFilePath = path.resolve(process.cwd(), appPath);\n\n if (!fs.existsSync(appFilePath)) {\n throw new Error(`App file does not exist: ${appFilePath}`);\n }\n\n const sourceCode = fs.readFileSync(appFilePath, 'utf-8');\n\n const ast = parse(sourceCode, {\n sourceType: 'module',\n plugins: [\n 'jsx',\n 'typescript',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n });\n\n const routeSet = new Set<string>();\n const routeStack: PageRouteInfo[] = [];\n\n traverse(ast, {\n JSXElement: {\n enter(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n routeStack.push(extractPageRouteInfo(openingElement));\n }\n },\n exit(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n const currentRoute = routeStack.pop();\n if (currentRoute && currentRoute.path === '*') return;\n if (currentRoute && (currentRoute.path || currentRoute.index)) {\n const fullPath = buildFullPath(routeStack, currentRoute);\n if (fullPath) routeSet.add(fullPath);\n }\n }\n },\n },\n });\n\n const routes = Array.from(routeSet).map((routePath) => ({\n path: applyBasePath && basePath ? `${basePath}${routePath}` : routePath,\n }));\n return routes.length > 0 ? routes : [{ path: defaultPath }];\n } catch (error) {\n routeParserLog('warn', 'Route parsing failed, using default routes:', (error as Error).message);\n return [{ path: defaultPath }];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gBAAe;AACf,kBAAiB;;;ACFjB,SAAoB;AACpB,WAAsB;AAEtB,oBAAsB;AACtB,sBAAsB;AACtB,QAAmB;AAGnB,IAAMA,WAAW,OAAOC,gBAAAA,YAAc,aAAaA,gBAAAA,UAAaA,gBAAAA,QAAkBC;AAa3E,SAASC,eACdC,OACAC,YACGC,OAAe;AAElB,QAAMC,SAAS;AACf,QAAMC,aAAa,GAAGD,MAAAA,IAAUF,OAAAA;AAChC,UAAQD,OAAAA;IACN,KAAK;AACHK,cAAQC,KAAKF,YAAAA,GAAeF,KAAAA;AAC5B;IACF,KAAK;AACHG,cAAQE,MAAMH,YAAAA,GAAeF,KAAAA;AAC7B;IACF,KAAK;AACHG,cAAQG,KAAKJ,YAAAA,GAAeF,KAAAA;AAC5B;IACF;AACEG,cAAQI,IAAIL,YAAAA,GAAeF,KAAAA;EAC/B;AACF;AApBgBH;AAgCT,SAASW,iBAAiBC,gBAAmC;AAClE,SACIC,kBAAgBD,eAAeE,IAAI,KACrCF,eAAeE,KAAKA,SAAS;AAEjC;AALgBH;AAOT,SAASI,wBAAwBC,iBAAkC;AACxE,QAAMC,SAASD,gBAAgBC;AAC/B,QAAMC,cAAcF,gBAAgBE;AAEpC,MAAID,OAAOE,WAAW,KAAKD,YAAYC,WAAW,GAAG;AACnD,WAAOF,OAAO,CAAA,EAAGG,MAAMC;EACzB;AAEA,SAAOJ,OAAOK,IAAI,CAACC,MAAMA,EAAEH,MAAMC,GAAG,EAAEG,KAAK,EAAA;AAC7C;AATgBT;AAWT,SAASU,qBAAqBb,gBAAmC;AACtE,QAAMc,YAA2B,CAAC;AAElCd,iBAAee,WAAWC,QAAQ,CAACC,SAAAA;AACjC,QAAMC,iBAAeD,IAAAA,KAAWhB,kBAAgBgB,KAAKf,IAAI,GAAG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AAUT,QAAQ;MAAEU,WAAW;IAAK,CAAA;EACzC;AACAH,YAAAA,QAAGK,cAAcX,YAAAA,QAAKC,QAAQF,QAAQI,QAAAA,GAAWS,KAAKC,UAAU,CAAA,GAAI,MAAM,CAAA,CAAA;AAC5E;","names":["traverse","_traverse","default","routeParserLog","level","message","args","prefix","logMessage","console","warn","error","info","log","isRouteComponent","openingElement","isJSXIdentifier","name","evaluateTemplateLiteral","templateLiteral","quasis","expressions","length","value","raw","map","q","join","extractPageRouteInfo","routeInfo","attributes","forEach","attr","isJSXAttribute","isStringLiteral","isJSXExpressionContainer","expression","isTemplateLiteral","buildFullPath","routeStack","currentRoute","fullPath","i","path","parentPath","startsWith","endsWith","slice","index","routePath","parseRoutesFromFile","appPath","basePath","options","applyBasePath","defaultPath","appFilePath","resolve","process","cwd","existsSync","Error","sourceCode","readFileSync","ast","parse","sourceType","plugins","routeSet","Set","traverse","JSXElement","enter","nodePath","node","push","exit","pop","add","routes","Array","from","error","routeParserLog","message","args","process","argv","slice","getArg","name","defaultValue","index","indexOf","appPath","outDir","path","resolve","cwd","filename","routes","parseRoutesFromFile","fs","existsSync","mkdirSync","recursive","outPath","writeFileSync","JSON","stringify","console","log","length","error","warn"]}
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ parseRoutesFromFile
4
+ } from "../chunk-YPNLFWHQ.js";
2
5
  import {
3
6
  __name
4
7
  } from "../chunk-7QVYU63E.js";
@@ -6,10 +9,6 @@ import {
6
9
  // src/bin/generate-page-routes.ts
7
10
  import fs from "fs";
8
11
  import path from "path";
9
- import { parse } from "@babel/parser";
10
- import _traverse from "@babel/traverse";
11
- import * as t from "@babel/types";
12
- var traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
13
12
  var args = process.argv.slice(2);
14
13
  function getArg(name, defaultValue) {
15
14
  const index = args.indexOf(name);
@@ -19,137 +18,11 @@ function getArg(name, defaultValue) {
19
18
  return defaultValue;
20
19
  }
21
20
  __name(getArg, "getArg");
22
- var appPath = path.resolve(process.cwd(), getArg("--app-path", "./client/src/app.tsx"));
21
+ var appPath = getArg("--app-path", "./client/src/app.tsx");
23
22
  var outDir = path.resolve(process.cwd(), getArg("--out-dir", "./dist"));
24
23
  var filename = getArg("--filename", "page-routes.json");
25
- function isRouteComponent(openingElement) {
26
- return t.isJSXIdentifier(openingElement.name) && openingElement.name.name === "Route";
27
- }
28
- __name(isRouteComponent, "isRouteComponent");
29
- function evaluateTemplateLiteral(templateLiteral) {
30
- const quasis = templateLiteral.quasis;
31
- const expressions = templateLiteral.expressions;
32
- if (quasis.length === 1 && expressions.length === 0) {
33
- return quasis[0].value.raw;
34
- }
35
- return quasis.map((q) => q.value.raw).join("");
36
- }
37
- __name(evaluateTemplateLiteral, "evaluateTemplateLiteral");
38
- function extractRouteInfo(openingElement) {
39
- const routeInfo = {};
40
- openingElement.attributes.forEach((attr) => {
41
- if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
42
- const name = attr.name.name;
43
- let value;
44
- if (attr.value) {
45
- if (t.isStringLiteral(attr.value)) {
46
- value = attr.value.value;
47
- } else if (t.isJSXExpressionContainer(attr.value)) {
48
- const expression = attr.value.expression;
49
- if (t.isStringLiteral(expression)) {
50
- value = expression.value;
51
- } else if (t.isTemplateLiteral(expression)) {
52
- value = evaluateTemplateLiteral(expression);
53
- } else {
54
- value = true;
55
- }
56
- }
57
- } else {
58
- value = true;
59
- }
60
- routeInfo[name] = value;
61
- }
62
- });
63
- return routeInfo;
64
- }
65
- __name(extractRouteInfo, "extractRouteInfo");
66
- function buildFullPath(routeStack, currentRoute) {
67
- let fullPath = "";
68
- for (let i = 0; i < routeStack.length; i++) {
69
- if (routeStack[i].path) {
70
- let parentPath = routeStack[i].path;
71
- if (!parentPath.startsWith("/")) parentPath = `/${parentPath}`;
72
- if (parentPath.endsWith("/") && parentPath !== "/") {
73
- parentPath = parentPath.slice(0, -1);
74
- }
75
- fullPath += parentPath === "/" ? "" : parentPath;
76
- }
77
- }
78
- if (currentRoute.index) {
79
- return fullPath || "/";
80
- } else if (currentRoute.path) {
81
- const routePath = currentRoute.path;
82
- if (routePath === "*") {
83
- return null;
84
- }
85
- if (!routePath.startsWith("/")) {
86
- fullPath = `${fullPath}/${routePath}`;
87
- } else {
88
- fullPath = routePath;
89
- }
90
- if (fullPath === "") fullPath = "/";
91
- if (!fullPath.startsWith("/")) fullPath = `/${fullPath}`;
92
- return fullPath;
93
- }
94
- return null;
95
- }
96
- __name(buildFullPath, "buildFullPath");
97
- function parsePageRoutes(appFilePath) {
98
- if (!fs.existsSync(appFilePath)) {
99
- throw new Error(`App file does not exist: ${appFilePath}`);
100
- }
101
- const sourceCode = fs.readFileSync(appFilePath, "utf-8");
102
- const ast = parse(sourceCode, {
103
- sourceType: "module",
104
- plugins: [
105
- "jsx",
106
- "typescript",
107
- "decorators-legacy",
108
- "classProperties",
109
- "objectRestSpread",
110
- "functionBind",
111
- "exportDefaultFrom",
112
- "exportNamespaceFrom",
113
- "dynamicImport",
114
- "nullishCoalescingOperator",
115
- "optionalChaining"
116
- ]
117
- });
118
- const routeSet = /* @__PURE__ */ new Set();
119
- const routeStack = [];
120
- traverse(ast, {
121
- JSXElement: {
122
- enter(nodePath) {
123
- const { openingElement } = nodePath.node;
124
- if (isRouteComponent(openingElement)) {
125
- routeStack.push(extractRouteInfo(openingElement));
126
- }
127
- },
128
- exit(nodePath) {
129
- const { openingElement } = nodePath.node;
130
- if (isRouteComponent(openingElement)) {
131
- const currentRoute = routeStack.pop();
132
- if (currentRoute && currentRoute.path === "*") return;
133
- if (currentRoute && (currentRoute.path || currentRoute.index)) {
134
- const fullPath = buildFullPath(routeStack, currentRoute);
135
- if (fullPath) routeSet.add(fullPath);
136
- }
137
- }
138
- }
139
- }
140
- });
141
- const routes = Array.from(routeSet).map((routePath) => ({
142
- path: routePath
143
- }));
144
- return routes.length > 0 ? routes : [
145
- {
146
- path: "/"
147
- }
148
- ];
149
- }
150
- __name(parsePageRoutes, "parsePageRoutes");
151
24
  try {
152
- const routes = parsePageRoutes(appPath);
25
+ const routes = parseRoutesFromFile(appPath, "");
153
26
  if (!fs.existsSync(outDir)) {
154
27
  fs.mkdirSync(outDir, {
155
28
  recursive: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/generate-page-routes.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from 'fs';\nimport path from 'path';\nimport { parse } from '@babel/parser';\nimport _traverse from '@babel/traverse';\n// Handle CJS default export interop in ESM context\nconst traverse = typeof _traverse === 'function' ? _traverse : (_traverse as any).default;\nimport * as t from '@babel/types';\n\nconst args = process.argv.slice(2);\n\nfunction getArg(name: string, defaultValue: string): string {\n const index = args.indexOf(name);\n if (index !== -1 && args[index + 1]) {\n return args[index + 1];\n }\n return defaultValue;\n}\n\nconst appPath = path.resolve(process.cwd(), getArg('--app-path', './client/src/app.tsx'));\nconst outDir = path.resolve(process.cwd(), getArg('--out-dir', './dist'));\nconst filename = getArg('--filename', 'page-routes.json');\n\ninterface RouteInfo {\n path?: string;\n index?: boolean;\n [key: string]: unknown;\n}\n\nfunction isRouteComponent(openingElement: t.JSXOpeningElement): boolean {\n return (\n t.isJSXIdentifier(openingElement.name) &&\n openingElement.name.name === 'Route'\n );\n}\n\nfunction evaluateTemplateLiteral(templateLiteral: t.TemplateLiteral): string {\n const quasis = templateLiteral.quasis;\n const expressions = templateLiteral.expressions;\n\n if (quasis.length === 1 && expressions.length === 0) {\n return quasis[0].value.raw;\n }\n\n return quasis.map((q) => q.value.raw).join('');\n}\n\nfunction extractRouteInfo(openingElement: t.JSXOpeningElement): RouteInfo {\n const routeInfo: RouteInfo = {};\n\n openingElement.attributes.forEach((attr) => {\n if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {\n const name = attr.name.name;\n let value: unknown;\n\n if (attr.value) {\n if (t.isStringLiteral(attr.value)) {\n value = attr.value.value;\n } else if (t.isJSXExpressionContainer(attr.value)) {\n const expression = attr.value.expression;\n if (t.isStringLiteral(expression)) {\n value = expression.value;\n } else if (t.isTemplateLiteral(expression)) {\n value = evaluateTemplateLiteral(expression);\n } else {\n value = true;\n }\n }\n } else {\n value = true;\n }\n\n routeInfo[name] = value;\n }\n });\n\n return routeInfo;\n}\n\nfunction buildFullPath(routeStack: RouteInfo[], currentRoute: RouteInfo): string | null {\n let fullPath = '';\n\n for (let i = 0; i < routeStack.length; i++) {\n if (routeStack[i].path) {\n let parentPath = routeStack[i].path!;\n if (!parentPath.startsWith('/')) parentPath = `/${parentPath}`;\n if (parentPath.endsWith('/') && parentPath !== '/') {\n parentPath = parentPath.slice(0, -1);\n }\n\n fullPath += parentPath === '/' ? '' : parentPath;\n }\n }\n\n if (currentRoute.index) {\n return fullPath || '/';\n } else if (currentRoute.path) {\n const routePath = currentRoute.path;\n\n if (routePath === '*') {\n return null;\n }\n\n if (!routePath.startsWith('/')) {\n fullPath = `${fullPath}/${routePath}`;\n } else {\n fullPath = routePath;\n }\n\n if (fullPath === '') fullPath = '/';\n if (!fullPath.startsWith('/')) fullPath = `/${fullPath}`;\n\n return fullPath;\n }\n\n return null;\n}\n\nfunction parsePageRoutes(appFilePath: string): Array<{ path: string }> {\n if (!fs.existsSync(appFilePath)) {\n throw new Error(`App file does not exist: ${appFilePath}`);\n }\n\n const sourceCode = fs.readFileSync(appFilePath, 'utf-8');\n\n const ast = parse(sourceCode, {\n sourceType: 'module',\n plugins: [\n 'jsx',\n 'typescript',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n });\n\n const routeSet = new Set<string>();\n const routeStack: RouteInfo[] = [];\n\n traverse(ast, {\n JSXElement: {\n enter(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n routeStack.push(extractRouteInfo(openingElement));\n }\n },\n exit(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n const currentRoute = routeStack.pop();\n if (currentRoute && currentRoute.path === '*') return;\n if (currentRoute && (currentRoute.path || currentRoute.index)) {\n const fullPath = buildFullPath(routeStack, currentRoute);\n if (fullPath) routeSet.add(fullPath);\n }\n }\n },\n },\n });\n\n // page-routes 不带 basePath 前缀,供日志服务消费\n const routes = Array.from(routeSet).map((routePath) => ({ path: routePath }));\n return routes.length > 0 ? routes : [{ path: '/' }];\n}\n\ntry {\n const routes = parsePageRoutes(appPath);\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n const outPath = path.resolve(outDir, filename);\n fs.writeFileSync(outPath, JSON.stringify(routes, null, 2));\n console.log(`[page-routes] Generated ${outPath} (${routes.length} routes)`);\n} catch (error) {\n console.warn('[page-routes] Failed to generate page-routes.json, writing empty fallback:', error);\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n fs.writeFileSync(path.resolve(outDir, filename), JSON.stringify([], null, 2));\n}\n"],"mappings":";;;;;;AACA,OAAOA,QAAQ;AACf,OAAOC,UAAU;AACjB,SAASC,aAAa;AACtB,OAAOC,eAAe;AAGtB,YAAYC,OAAO;AADnB,IAAMC,WAAW,OAAOC,cAAc,aAAaA,YAAaA,UAAkBC;AAGlF,IAAMC,OAAOC,QAAQC,KAAKC,MAAM,CAAA;AAEhC,SAASC,OAAOC,MAAcC,cAAoB;AAChD,QAAMC,QAAQP,KAAKQ,QAAQH,IAAAA;AAC3B,MAAIE,UAAU,MAAMP,KAAKO,QAAQ,CAAA,GAAI;AACnC,WAAOP,KAAKO,QAAQ,CAAA;EACtB;AACA,SAAOD;AACT;AANSF;AAQT,IAAMK,UAAUC,KAAKC,QAAQV,QAAQW,IAAG,GAAIR,OAAO,cAAc,sBAAA,CAAA;AACjE,IAAMS,SAASH,KAAKC,QAAQV,QAAQW,IAAG,GAAIR,OAAO,aAAa,QAAA,CAAA;AAC/D,IAAMU,WAAWV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","args","process","argv","slice","getArg","name","defaultValue","index","indexOf","appPath","path","resolve","cwd","outDir","filename","isRouteComponent","openingElement","isJSXIdentifier","evaluateTemplateLiteral","templateLiteral","quasis","expressions","length","value","raw","map","q","join","extractRouteInfo","routeInfo","attributes","forEach","attr","isJSXAttribute","isStringLiteral","isJSXExpressionContainer","expression","isTemplateLiteral","buildFullPath","routeStack","currentRoute","fullPath","i","parentPath","startsWith","endsWith","routePath","parsePageRoutes","appFilePath","fs","existsSync","Error","sourceCode","readFileSync","ast","parse","sourceType","plugins","routeSet","Set","JSXElement","enter","nodePath","node","push","exit","pop","add","routes","Array","from","mkdirSync","recursive","outPath","writeFileSync","JSON","stringify","console","log","error","warn"]}
1
+ {"version":3,"sources":["../../src/bin/generate-page-routes.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from 'fs';\nimport path from 'path';\nimport { parseRoutesFromFile } from '../route-parser';\n\nconst args = process.argv.slice(2);\n\nfunction getArg(name: string, defaultValue: string): string {\n const index = args.indexOf(name);\n if (index !== -1 && args[index + 1]) {\n return args[index + 1];\n }\n return defaultValue;\n}\n\nconst appPath = getArg('--app-path', './client/src/app.tsx');\nconst outDir = path.resolve(process.cwd(), getArg('--out-dir', './dist'));\nconst filename = getArg('--filename', 'page-routes.json');\n\ntry {\n // page-routes 不带 basePath 前缀(basePath 为空),供日志服务消费\n const routes = parseRoutesFromFile(appPath, '');\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n const outPath = path.resolve(outDir, filename);\n fs.writeFileSync(outPath, JSON.stringify(routes, null, 2));\n console.log(`[page-routes] Generated ${outPath} (${routes.length} routes)`);\n} catch (error) {\n console.warn('[page-routes] Failed to generate page-routes.json, writing empty fallback:', error);\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n fs.writeFileSync(path.resolve(outDir, filename), JSON.stringify([], null, 2));\n}\n"],"mappings":";;;;;;;;;AACA,OAAOA,QAAQ;AACf,OAAOC,UAAU;AAGjB,IAAMC,OAAOC,QAAQC,KAAKC,MAAM,CAAA;AAEhC,SAASC,OAAOC,MAAcC,cAAoB;AAChD,QAAMC,QAAQP,KAAKQ,QAAQH,IAAAA;AAC3B,MAAIE,UAAU,MAAMP,KAAKO,QAAQ,CAAA,GAAI;AACnC,WAAOP,KAAKO,QAAQ,CAAA;EACtB;AACA,SAAOD;AACT;AANSF;AAQT,IAAMK,UAAUL,OAAO,cAAc,sBAAA;AACrC,IAAMM,SAASC,KAAKC,QAAQX,QAAQY,IAAG,GAAIT,OAAO,aAAa,QAAA,CAAA;AAC/D,IAAMU,WAAWV,OAAO,cAAc,kBAAA;AAEtC,IAAI;AAEF,QAAMW,SAASC,oBAAoBP,SAAS,EAAA;AAC5C,MAAI,CAACQ,GAAGC,WAAWR,MAAAA,GAAS;AAC1BO,OAAGE,UAAUT,QAAQ;MAAEU,WAAW;IAAK,CAAA;EACzC;AACA,QAAMC,UAAUV,KAAKC,QAAQF,QAAQI,QAAAA;AACrCG,KAAGK,cAAcD,SAASE,KAAKC,UAAUT,QAAQ,MAAM,CAAA,CAAA;AACvDU,UAAQC,IAAI,2BAA2BL,OAAAA,KAAYN,OAAOY,MAAM,UAAU;AAC5E,SAASC,OAAO;AACdH,UAAQI,KAAK,8EAA8ED,KAAAA;AAC3F,MAAI,CAACX,GAAGC,WAAWR,MAAAA,GAAS;AAC1BO,OAAGE,UAAUT,QAAQ;MAAEU,WAAW;IAAK,CAAA;EACzC;AACAH,KAAGK,cAAcX,KAAKC,QAAQF,QAAQI,QAAAA,GAAWS,KAAKC,UAAU,CAAA,GAAI,MAAM,CAAA,CAAA;AAC5E;","names":["fs","path","args","process","argv","slice","getArg","name","defaultValue","index","indexOf","appPath","outDir","path","resolve","cwd","filename","routes","parseRoutesFromFile","fs","existsSync","mkdirSync","recursive","outPath","writeFileSync","JSON","stringify","console","log","length","error","warn"]}
@@ -0,0 +1,189 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-7QVYU63E.js";
4
+
5
+ // src/route-parser.ts
6
+ import * as fs from "fs";
7
+ import * as path from "path";
8
+ import * as crypto from "crypto";
9
+ import { parse } from "@babel/parser";
10
+ import _traverse from "@babel/traverse";
11
+ import * as t from "@babel/types";
12
+ var traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
13
+ function routeParserLog(level, message, ...args) {
14
+ const prefix = "[route-parser]";
15
+ const logMessage = `${prefix} ${message}`;
16
+ switch (level) {
17
+ case "warn":
18
+ console.warn(logMessage, ...args);
19
+ break;
20
+ case "error":
21
+ console.error(logMessage, ...args);
22
+ break;
23
+ case "info":
24
+ console.info(logMessage, ...args);
25
+ break;
26
+ default:
27
+ console.log(logMessage, ...args);
28
+ }
29
+ }
30
+ __name(routeParserLog, "routeParserLog");
31
+ function calculateFileHash(filePath) {
32
+ try {
33
+ const content = fs.readFileSync(filePath, "utf-8");
34
+ return crypto.createHash("md5").update(content).digest("hex");
35
+ } catch (error) {
36
+ routeParserLog("warn", "Failed to calculate file hash:", error.message);
37
+ return null;
38
+ }
39
+ }
40
+ __name(calculateFileHash, "calculateFileHash");
41
+ function isRouteComponent(openingElement) {
42
+ return t.isJSXIdentifier(openingElement.name) && openingElement.name.name === "Route";
43
+ }
44
+ __name(isRouteComponent, "isRouteComponent");
45
+ function evaluateTemplateLiteral(templateLiteral) {
46
+ const quasis = templateLiteral.quasis;
47
+ const expressions = templateLiteral.expressions;
48
+ if (quasis.length === 1 && expressions.length === 0) {
49
+ return quasis[0].value.raw;
50
+ }
51
+ return quasis.map((q) => q.value.raw).join("");
52
+ }
53
+ __name(evaluateTemplateLiteral, "evaluateTemplateLiteral");
54
+ function extractPageRouteInfo(openingElement) {
55
+ const routeInfo = {};
56
+ openingElement.attributes.forEach((attr) => {
57
+ if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
58
+ const name = attr.name.name;
59
+ let value;
60
+ if (attr.value) {
61
+ if (t.isStringLiteral(attr.value)) {
62
+ value = attr.value.value;
63
+ } else if (t.isJSXExpressionContainer(attr.value)) {
64
+ const expression = attr.value.expression;
65
+ if (t.isStringLiteral(expression)) {
66
+ value = expression.value;
67
+ } else if (t.isTemplateLiteral(expression)) {
68
+ value = evaluateTemplateLiteral(expression);
69
+ } else {
70
+ value = true;
71
+ }
72
+ }
73
+ } else {
74
+ value = true;
75
+ }
76
+ routeInfo[name] = value;
77
+ }
78
+ });
79
+ return routeInfo;
80
+ }
81
+ __name(extractPageRouteInfo, "extractPageRouteInfo");
82
+ function buildFullPath(routeStack, currentRoute) {
83
+ let fullPath = "";
84
+ for (let i = 0; i < routeStack.length; i++) {
85
+ if (routeStack[i].path) {
86
+ let parentPath = routeStack[i].path;
87
+ if (!parentPath.startsWith("/")) parentPath = `/${parentPath}`;
88
+ if (parentPath.endsWith("/") && parentPath !== "/") {
89
+ parentPath = parentPath.slice(0, -1);
90
+ }
91
+ fullPath += parentPath === "/" ? "" : parentPath;
92
+ }
93
+ }
94
+ if (currentRoute.index) {
95
+ return fullPath || "/";
96
+ } else if (currentRoute.path) {
97
+ const routePath = currentRoute.path;
98
+ if (routePath === "*") {
99
+ return null;
100
+ }
101
+ if (!routePath.startsWith("/")) {
102
+ fullPath = `${fullPath}/${routePath}`;
103
+ } else {
104
+ fullPath = routePath;
105
+ }
106
+ if (fullPath === "") fullPath = "/";
107
+ if (!fullPath.startsWith("/")) fullPath = `/${fullPath}`;
108
+ return fullPath;
109
+ }
110
+ return null;
111
+ }
112
+ __name(buildFullPath, "buildFullPath");
113
+ function parseRoutesFromFile(appPath, basePath, options = {}) {
114
+ const { applyBasePath = true } = options;
115
+ const defaultPath = applyBasePath && basePath ? `${basePath}/` : "/";
116
+ try {
117
+ const appFilePath = path.resolve(process.cwd(), appPath);
118
+ if (!fs.existsSync(appFilePath)) {
119
+ throw new Error(`App file does not exist: ${appFilePath}`);
120
+ }
121
+ const sourceCode = fs.readFileSync(appFilePath, "utf-8");
122
+ const ast = parse(sourceCode, {
123
+ sourceType: "module",
124
+ plugins: [
125
+ "jsx",
126
+ "typescript",
127
+ "decorators-legacy",
128
+ "classProperties",
129
+ "objectRestSpread",
130
+ "functionBind",
131
+ "exportDefaultFrom",
132
+ "exportNamespaceFrom",
133
+ "dynamicImport",
134
+ "nullishCoalescingOperator",
135
+ "optionalChaining"
136
+ ]
137
+ });
138
+ const routeSet = /* @__PURE__ */ new Set();
139
+ const routeStack = [];
140
+ traverse(ast, {
141
+ JSXElement: {
142
+ enter(nodePath) {
143
+ const { openingElement } = nodePath.node;
144
+ if (isRouteComponent(openingElement)) {
145
+ routeStack.push(extractPageRouteInfo(openingElement));
146
+ }
147
+ },
148
+ exit(nodePath) {
149
+ const { openingElement } = nodePath.node;
150
+ if (isRouteComponent(openingElement)) {
151
+ const currentRoute = routeStack.pop();
152
+ if (currentRoute && currentRoute.path === "*") return;
153
+ if (currentRoute && (currentRoute.path || currentRoute.index)) {
154
+ const fullPath = buildFullPath(routeStack, currentRoute);
155
+ if (fullPath) routeSet.add(fullPath);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ });
161
+ const routes = Array.from(routeSet).map((routePath) => ({
162
+ path: applyBasePath && basePath ? `${basePath}${routePath}` : routePath
163
+ }));
164
+ return routes.length > 0 ? routes : [
165
+ {
166
+ path: defaultPath
167
+ }
168
+ ];
169
+ } catch (error) {
170
+ routeParserLog("warn", "Route parsing failed, using default routes:", error.message);
171
+ return [
172
+ {
173
+ path: defaultPath
174
+ }
175
+ ];
176
+ }
177
+ }
178
+ __name(parseRoutesFromFile, "parseRoutesFromFile");
179
+
180
+ export {
181
+ routeParserLog,
182
+ calculateFileHash,
183
+ isRouteComponent,
184
+ evaluateTemplateLiteral,
185
+ extractPageRouteInfo,
186
+ buildFullPath,
187
+ parseRoutesFromFile
188
+ };
189
+ //# sourceMappingURL=chunk-YPNLFWHQ.js.map