UNPKG

microsite

Version:
39 lines (38 loc) 1.27 kB
import { dirExists } from "../utils/fs.js"; import { openInBrowser } from "../utils/open.js"; import { OUT_DIR } from "../utils/build.js"; import { green } from "kleur/colors"; import polka from "polka"; import sirv from "sirv"; import arg from "arg"; function parseArgs(argv) { return arg({ "--port": Number, // Aliases "-p": "--port", }, { permissive: true, argv }); } export default async function start(argv) { var _a; const args = parseArgs(argv); const PORT = (_a = args["--port"]) !== null && _a !== void 0 ? _a : 8888; if (await dirExists(OUT_DIR)) { const assets = sirv("dist", { maxAge: 31536000, immutable: true, }); const server = polka().use(assets); await new Promise((resolve) => server.listen(PORT, (err) => { if (err) throw err; resolve(); })); let protocol = "http:"; let hostname = "localhost"; await openInBrowser(protocol, hostname, PORT, "chrome"); console.log(`${green("✔")} Microsite started on ${green(`${protocol}//${hostname}:${PORT}`)}\n`); } else { console.log(`No dist/ directory found. Did you run "microsite build" first?`); } }