#!/usr/bin/env node import { consola } from "consola"; import { defineCommand } from "citty"; import { commonArgs } from "../common.mjs"; import { existsSync, writeFileSync, appendFileSync } from "node:fs"; import { execSync as exec } from "child_process"; export default defineCommand({ meta: { name: "prepare", description: "Prepares the McFly workspace.", }, args: { ...commonArgs, }, async run({ args }) { const typeDefinition = `\n/// `; const globalDefinition = `import {WebComponent as W} from "web-component-base/WebComponent.mjs"; declare global {class WebComponent extends W {}}export {WebComponent} from 'web-component-base/WebComponent.mjs';`; let hasErrors = false; consola.start("Preparing McFly workspace..."); try { exec("npx nitropack prepare", { stdio: "inherit" }); } catch (e) { consola.error(e); hasErrors = true; } if (existsSync(".nitro/types/nitro.d.ts")) { try { writeFileSync(".nitro/types/mcfly-imports.d.ts", globalDefinition); } catch (e) { consola.error(e); hasErrors = true; } try { appendFileSync(".nitro/types/nitro.d.ts", typeDefinition); } catch (e) { consola.error(e); hasErrors = true; } } else { consola.fail( "Preparation Failed. Please run:\n> npx nitropack prepare && npx mcfly prepare" ); hasErrors = true; } if (!hasErrors) { consola.success("Done!"); } }, });