@ordojs/core
Version:
Core compiler and runtime for OrdoJS framework
92 lines (81 loc) • 1.93 kB
text/typescript
/**
* @fileoverview OrdoJS File System Router - Route definitions and file system routing
*/
import type { ComponentAST } from '../types/index.js';
/**
* Route configuration
*/
export interface Route {
/** Route path */
path: string;
/** Component name for this route */
componentName: string;
/** Route metadata */
meta?: Record<string, any>;
/** Child routes */
children?: Route[];
}
/**
* Router options
*/
export interface RouterOptions {
/** Base directory for route files */
baseDir?: string;
/** File extensions to scan */
extensions?: string[];
/** Whether to enable dynamic imports */
dynamicImports?: boolean;
/** Route file naming convention */
namingConvention?: 'kebab-case' | 'camelCase' | 'snake_case';
}
/**
* File system router for automatic route generation
*/
export class FileSystemRouter {
private options: RouterOptions;
private routes: Route[] = [];
constructor(options: RouterOptions = {}) {
this.options = {
baseDir: './src/routes',
extensions: ['.ordo', '.ts', '.js'],
dynamicImports: true,
namingConvention: 'kebab-case',
...options
};
}
/**
* Scan file system for routes
*/
scanRoutes(): Route[] {
// This would implement file system scanning
// For now, return empty array
return [];
}
/**
* Generate routes from component ASTs
*/
generateRoutes(components: ComponentAST[]): Route[] {
return components.map(component => ({
path: `/${component.component.name.toLowerCase()}`,
componentName: component.component.name
}));
}
/**
* Get all routes
*/
getRoutes(): Route[] {
return this.routes;
}
/**
* Add a route
*/
addRoute(route: Route): void {
this.routes.push(route);
}
/**
* Find route by path
*/
findRoute(path: string): Route | undefined {
return this.routes.find(route => route.path === path);
}
}