UNPKG

@the-teacher/the-router

Version:

Simple router for Express.js, making routes and actions easy to manage.

54 lines (46 loc) 1.34 kB
import esbuild from "esbuild"; import { execSync } from "child_process"; // Check if watch flag is present in command line arguments const isWatch = process.argv.includes("--watch"); /** @type {import('esbuild').BuildOptions} */ const config = { entryPoints: ["src.ts/index.ts"], bundle: true, outdir: "src", platform: "node", target: "node18", format: "esm", // Using ESM format sourcemap: true, external: ["express", "express/*"], // Exclude express and all its subpaths banner: { js: ` import { createRequire } from 'module'; const require = createRequire(import.meta.url); ` } }; async function build() { // Run esbuild if (isWatch) { // Start watch mode for development const ctx = await esbuild.context(config); await ctx.watch(); console.log("Watching for changes..."); // Run TypeScript declaration generation in watch mode execSync("tsc --declaration --emitDeclarationOnly --outDir src --watch", { stdio: "inherit" }); } else { // Run single build await esbuild.build(config); // Generate TypeScript declaration files execSync("tsc --declaration --emitDeclarationOnly --outDir src", { stdio: "inherit" }); console.log("Build complete"); } } build().catch((err) => { console.error(err); process.exit(1); });