"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const yargs = require("yargs"); const cssVarExtract = require("css-var-extract"); const path = require("node:path"); const chokidar = require("chokidar"); function _interopNamespaceDefault(e) { const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); if (e) { for (const k in e) { if (k !== "default") { const d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: () => e[k] }); } } } n.default = e; return Object.freeze(n); } const yargs__namespace = /* @__PURE__ */ _interopNamespaceDefault(yargs); const generate = async (nocreate) => { try { await cssVarExtract.generator(cssVarExtract.getConfig(nocreate)); process.exit(0); } catch (err) { console.error(err); process.exit(1); } }; const watch = async (nocreate) => { const configWatcher = chokidar.watch( path.resolve(process.cwd(), "cve.config.json") ); let watcher = new chokidar.FSWatcher({}); const generatorWatcher = () => { const config = cssVarExtract.getConfig(nocreate); watcher.close(); console.info(`CVE: Watching files (${config.files})...`); watcher = chokidar.watch(config.files); watcher.on("ready", async () => { const handle = async () => { try { await cssVarExtract.generator(config); } catch (err) { console.error(err); console.info(); } }; await handle(); let timeout; const deduped = (_file) => { if (timeout) { clearTimeout(timeout); } timeout = setTimeout(handle, 10); }; watcher.on("change", deduped); watcher.on("add", deduped); watcher.on("unlink", deduped); }); }; configWatcher.on("ready", generatorWatcher); configWatcher.on("change", generatorWatcher); }; main(); function main() { yargs__namespace.scriptName("cve").usage("$0 [args]").command( "generate", "Generate the .ts file from CSS files", (yargs2) => yargs2.option("nocreate", { describe: "Disable the creation of a config file", type: "boolean" }), async ({ nocreate }) => generate(nocreate) ).command( "watch", "Continuously watch and generate the .ts file from CSS files", (yargs2) => yargs2.option("nocreate", { describe: "Disable the creation of a config file", type: "boolean" }), async ({ nocreate }) => watch(nocreate) ).strict().demandCommand(1).parse(); } exports.main = main; //# sourceMappingURL=index.cjs.map