mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-03-13 10:30:18 +08:00
fix(core): package mode (#20580)
This commit is contained in:
@@ -88,8 +88,58 @@ for (const namespace in namespaces) {
|
||||
}
|
||||
}
|
||||
|
||||
// Generate route paths type
|
||||
const allRoutePaths: string[] = [];
|
||||
for (const namespace in namespaces) {
|
||||
for (const path in namespaces[namespace].routes) {
|
||||
const fullPath = `/${namespace}${path}`;
|
||||
|
||||
// Split path into segments to handle optional parameters
|
||||
const segments = fullPath.split('/');
|
||||
let hasOptional = false;
|
||||
|
||||
// Process each segment
|
||||
const processedSegments = segments.map((segment) => {
|
||||
if (segment.endsWith('?')) {
|
||||
hasOptional = true;
|
||||
return '${string}';
|
||||
} else if (segment.startsWith(':')) {
|
||||
return '${string}';
|
||||
}
|
||||
return segment;
|
||||
});
|
||||
|
||||
if (hasOptional) {
|
||||
// Generate both versions: with and without optional parameters
|
||||
// Find the index where optional parameters start
|
||||
const firstOptionalIndex = segments.findIndex((s) => s.endsWith('?'));
|
||||
|
||||
// Version without optional parameters
|
||||
const requiredPath = processedSegments.slice(0, firstOptionalIndex).join('/');
|
||||
allRoutePaths.push(requiredPath);
|
||||
|
||||
// Version with optional parameters
|
||||
const fullProcessedPath = processedSegments.join('/');
|
||||
allRoutePaths.push(fullProcessedPath);
|
||||
} else {
|
||||
allRoutePaths.push(processedSegments.join('/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicates and sort
|
||||
const uniquePaths = [...new Set(allRoutePaths)].toSorted();
|
||||
|
||||
const routePathsType = `// This file is auto-generated by scripts/workflow/build-routes.ts
|
||||
// Do not edit manually
|
||||
|
||||
export type RoutePath =
|
||||
${uniquePaths.map((path) => ` | \`${path}\``).join('\n')};
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, '../../assets/build/radar-rules.json'), JSON.stringify(radar, null, 2));
|
||||
fs.writeFileSync(path.join(__dirname, '../../assets/build/radar-rules.js'), `(${toSource(radar)})`);
|
||||
fs.writeFileSync(path.join(__dirname, '../../assets/build/maintainers.json'), JSON.stringify(maintainers, null, 2));
|
||||
fs.writeFileSync(path.join(__dirname, '../../assets/build/routes.json'), JSON.stringify(namespaces, null, 2));
|
||||
fs.writeFileSync(path.join(__dirname, '../../assets/build/routes.js'), `export default ${JSON.stringify(namespaces, null, 2)}`.replaceAll(/"module": "(.*)"\n/g, `"module": $1\n`));
|
||||
fs.writeFileSync(path.join(__dirname, '../../assets/build/route-paths.ts'), routePathsType);
|
||||
|
||||
Reference in New Issue
Block a user