UNPKG

kirbyup

Version:

Zero-config bundler for Kirby Panel plugins

59 lines (56 loc) 2.57 kB
import { cac } from 'cac'; import { n as name, b as build, s as serve, v as version, h as handleError } from '../shared/kirbyup.BtejYnwg.mjs'; import 'node:fs'; import 'node:fs/promises'; import '@vitejs/plugin-vue2'; import '@vitejs/plugin-vue2-jsx'; import 'consola'; import 'consola/utils'; import 'pathe'; import 'perfect-debounce'; import 'rollup-plugin-external-globals'; import 'vite'; import 'vite-plugin-full-reload'; import 'vue/compiler-sfc'; import 'c12'; import 'postcss-load-config'; import 'magic-string'; import 'node:module'; import 'child_process'; import 'path'; import 'process'; import 'stream'; import 'readline'; import 'node:buffer'; import 'node:util'; import 'node:zlib'; 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(); } startCli().catch(handleError);