UNPKG

kirbyup

Version:

Zero-config bundler for Kirby Panel plugins

42 lines (40 loc) 1.98 kB
import { name, version } from "../package.js"; import { build, serve } from "./index.js"; import { cac } from "cac"; //#region src/node/cli-start.ts async function startCli(cwd = process.cwd(), argv = process.argv) { const cli = cac(name); cli.command("<file>", "Compile the Kirby Panel plugin to index.js and index.css").option("-d, --out-dir <dir>", "Output directory", { default: cwd }).option("-w, --watch [path]", "Watch for file changes. If no path is specified, the folder of the input file will be watched", { default: false }).example("kirbyup src/index.js").example("kirbyup src/index.js --out-dir ~/kirby-site/site/plugins/demo").example("kirbyup src/index.js --watch src/**/*.{js,css} --watch assets/*\n").action(async (file, options) => { process.env.NODE_ENV ||= options.watch ? "development" : "production"; await build({ cwd, entry: file, ...options }); }); cli.command("serve <file>", "Start development server with live reload").option("--no-watch", "Don't watch .php files for changes", { default: "\0" }).option("-w, --watch <path>", "Watch additional files", { default: "./**/*.php" }).option("-p, --port <number>", "Port for the development server", { default: 5177 }).option("-d, --out-dir <dir>", "Output directory").example("kirbyup serve src/index.js").example("kirbyup serve src/index.js --no-watch --port 3003").example("kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n").action(async (file, options) => { process.env.NODE_ENV ||= "development"; const server = await serve({ cwd, entry: file, ...options }); const exitProcess = async () => { try { await server.close(); } finally { process.exit(); } }; process.once("SIGINT", exitProcess); }); cli.help((s) => s.map((msg) => ({ ...msg, body: msg.body.replace(" (default: \0)", "") }))); cli.version(version); cli.parse(argv, { run: false }); await cli.runMatchedCommand(); } //#endregion export { startCli };