import type { Options as MarkoViteOptions } from "@marko/vite"; import type { InlineConfig, Plugin, ResolvedConfig, UserConfig } from "vite"; import type { HttpVerb, RoutableFileType, RoutableFileTypes } from "./constants"; import type { SpawnedServer } from "./utils/server"; export type { HttpVerb, RoutableFileType }; export type StartServer = (port?: number) => Promise; export interface AdapterConfig { root: string; isBuild: boolean; [name: PropertyKey]: any; } export interface StartOptions { cwd: string; args: string[]; port?: number; envFile?: string; } export interface StartDevOptions extends StartOptions { } export interface StartPreviewOptions extends StartOptions { dir: string; entry?: string; } export interface Adapter { readonly name: string; plugins?(event: { root: string; command: "dev" | "build"; }): Promise | Plugin[] | undefined; configure?(config: AdapterConfig): void; pluginOptions?(options: Options): Promise | Options | undefined; viteConfig?(config: UserConfig): Promise | UserConfig | undefined; getEntryFile?(): Promise | string; startDev?(event: { entry: string | undefined; config: InlineConfig; options: StartDevOptions; }): Promise | SpawnedServer; startPreview?(event: { entry: string | undefined; options: StartPreviewOptions; }): Promise | SpawnedServer; buildEnd?(event: { config: ResolvedConfig; routes: BuiltRoutes; builtEntries: string[]; sourceEntries: string[]; }): Promise | void; typeInfo?(writer: (data: string) => void): Promise | string; runtimeInclude?(): Promise | string | undefined; routesGenerated?(event: { routes: BuiltRoutes; virtualFiles: Map; meta: RouteGenerationData; }): Promise | void; isEntryTemplate?(event: { template: string; importer: string; }): boolean; } export interface RouterOptions { trailingSlashes: "Ignore" | "RedirectWithout" | "RedirectWith" | "RewriteWithout" | "RewriteWith"; } export interface MarkoRunOptions extends Partial { routesDir?: string; emitRoutes?(routes: Route[]): void | Promise; adapter?: Adapter | null; } export type Options = MarkoRunOptions & MarkoViteOptions; export interface Route { key: string; index: number; path: PathInfo; layouts: RoutableFile[]; middleware: RoutableFile[]; meta?: RoutableFile; handler?: RoutableFile; page?: RoutableFile; templateFilePath?: string; } export interface PathInfo { id: string; path: string; segments: string[]; params?: Record; isEnd?: boolean; } export interface SpecialRoutes { [RoutableFileTypes.NotFound]?: Route; [RoutableFileTypes.Error]?: Route; } export interface RoutableFile { id: string; name: string; type: RoutableFileType; filePath: string; verbs?: HttpVerb[]; } export type BuiltRoutes = { list: Route[]; special: SpecialRoutes; middleware: RoutableFile[]; }; export interface PackageData { name?: string; version?: string; dependencies?: Record; devDependencies?: Record; } export interface RouteGenerationData { buildTime: number; renderTime: number; } export interface ExplorerData { meta: RouteGenerationData; routes: Record; files: Record; } export interface ExternalRoutes { name: string; routes: { path: string; entryFile: string; verbs: HttpVerb[]; }[]; }