Skip to main content
Glama
BaseBundlerService.ts3.46 kB
/** * BaseBundlerService * * DESIGN PATTERNS: * - Abstract base class for bundler service implementations * - Template method pattern for extensible bundling logic * - Strategy pattern allowing different bundler/framework combinations * * CODING STANDARDS: * - Abstract classes define interface contracts for subclasses * - Protected methods allow subclass customization * - Use async/await for all I/O operations * - Throw descriptive errors with context * * AVOID: * - Direct instantiation of abstract class * - Bundler-specific logic in base class * - Synchronous file operations */ import type { BundlerServiceConfig, DevServerResult, PrerenderResult, RenderOptions, ServeComponentResult, } from './types'; /** * Abstract base class for bundler service implementations. * * Subclasses must implement the abstract methods to provide * bundler-specific (Vite, Webpack, etc.) and framework-specific * (React, Vue, etc.) component rendering logic. * * @example * ```typescript * class MyCustomBundlerService extends BaseBundlerService { * async startDevServer(appPath: string): Promise<DevServerResult> { * // Custom dev server logic * } * // ... implement other abstract methods * } * ``` */ export abstract class BaseBundlerService { protected config: BundlerServiceConfig; /** * Creates a new bundler service instance. * @param config - Service configuration options */ constructor(config: BundlerServiceConfig = {}) { this.config = config; } /** * Get the bundler identifier for this service. * @returns Bundler identifier string (e.g., 'vite', 'webpack') */ abstract getBundlerId(): string; /** * Get the framework identifier for this service. * @returns Framework identifier string (e.g., 'react', 'vue') */ abstract getFrameworkId(): string; /** * Start a dev server for hot reload and caching. * * @param appPath - Absolute or relative path to the app directory * @returns Promise resolving to server URL and port * @throws Error if server fails to start */ abstract startDevServer(appPath: string): Promise<DevServerResult>; /** * Serve a component dynamically through the dev server. * * @param options - Component rendering options * @returns Promise resolving to the component URL and HTML file path * @throws Error if dev server is not running or rendering fails */ abstract serveComponent(options: RenderOptions): Promise<ServeComponentResult>; /** * Pre-render a component to a static HTML file. * * @param options - Component rendering options * @returns Promise resolving to the HTML file path * @throws Error if build fails */ abstract prerenderComponent(options: RenderOptions): Promise<PrerenderResult>; /** * Check if the dev server is running. * @returns True if server is running */ abstract isServerRunning(): boolean; /** * Get the current server URL. * @returns Server URL or null if not running */ abstract getServerUrl(): string | null; /** * Get the current server port. * @returns Server port or null if not running */ abstract getServerPort(): number | null; /** * Get the current app path being served. * @returns App path or null if not running */ abstract getCurrentAppPath(): string | null; /** * Clean up server resources and reset state. */ abstract cleanup(): Promise<void>; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgiFlow/aicode-toolkit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server