/** * @jobo/scraper-sdk — Build Compiler * * Compiles a scraper provider project into deployable JavaScript. * Uses esbuild for fast TypeScript → JavaScript compilation. * * The compiler: * 1. Reads the provider's `manifest.json` * 2. Discovers all `.ts` source files * 3. Bundles everything into a single `provider.js` (IIFE format) * 4. Copies `manifest.json` to the output directory * 5. Optionally watches for changes and recompiles */ /** * Build configuration for a scraper provider package. */ interface BuildConfig { /** Root directory of the provider project. */ projectDir: string; /** Output directory. Defaults to `dist/` within the project directory. */ outDir?: string; /** Whether to minify the output. Default: `false`. */ minify?: boolean; /** Whether to generate source maps. Default: `true`. */ sourcemap?: boolean; } /** * Result of a build operation. */ interface BuildResult { /** Whether the build completed without errors. */ success: boolean; /** Absolute path to the output directory. */ outputDir: string; /** List of output file paths relative to `outputDir`. */ files: string[]; /** Build errors, if any. */ errors: string[]; /** Build warnings, if any. */ warnings: string[]; /** Total build time in milliseconds. */ duration: number; } /** * Compile a scraper provider project into a deployable bundle. * * Expects the following project structure: * ``` * my-scraper/ * ├── src/ * │ ├── manifest.json ← Provider manifest (required) * │ ├── provider.ts ← Entry point (required) * │ └── helpers.ts ← Optional helper modules * └── package.json * ``` * * Produces: * ``` * my-scraper/dist/ * ├── manifest.json * ├── provider.js * └── provider.js.map * ``` * * @param config — Build configuration. * @returns Build result with output file list and any errors. * * @example * ```ts * import { compileProvider } from "@jobo/scraper-sdk/build"; * * const result = await compileProvider({ projectDir: "./my-scraper" }); * if (result.success) { * console.log(`Built ${result.files.length} files in ${result.duration}ms`); * } else { * console.error("Build failed:", result.errors); * } * ``` */ declare function compileProvider(config: BuildConfig): Promise; /** * Watch a provider project for changes and recompile automatically. * * @param config — Build configuration. * @param onChange — Callback invoked after each recompilation. * @returns A handle with a `stop()` method to terminate watching. * * @example * ```ts * const watcher = await watchProvider( * { projectDir: "./my-scraper" }, * (result) => console.log(result.success ? "✓ Built" : "✗ Failed"), * ); * * // Later... * watcher.stop(); * ``` */ declare function watchProvider(config: BuildConfig, onChange?: (result: BuildResult) => void): Promise<{ stop: () => void; }>; export { type BuildConfig, type BuildResult, compileProvider, watchProvider };