diff --git a/packages/cli/commands/generate.js b/packages/cli/commands/generate.js deleted file mode 100644 index 485cffc..0000000 --- a/packages/cli/commands/generate.js +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env node - -const { consola } = require("consola"); - -consola.prompt("Name your new custom element"); diff --git a/packages/cli/commands/generate.mjs b/packages/cli/commands/generate.mjs new file mode 100644 index 0000000..f58861d --- /dev/null +++ b/packages/cli/commands/generate.mjs @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +import { consola } from "consola"; +import { defineCommand } from "citty"; +import { commonArgs } from "../common.mjs"; + +export default defineCommand({ + meta: { + name: "prepare", + description: "Generates building blocks for a McFly app.", + }, + args: { + ...commonArgs, + }, + async run({ args }) { + consola.box("Generate a McFly building block"); + }, +}); diff --git a/packages/cli/commands/new.mjs b/packages/cli/commands/new.mjs index c78a9c1..cac603f 100644 --- a/packages/cli/commands/new.mjs +++ b/packages/cli/commands/new.mjs @@ -8,18 +8,17 @@ import { commonArgs } from "../common.mjs"; export default defineCommand({ meta: { name: "prepare", - description: "Generate types for the project", + description: "Creates a new McFly project.", }, args: { ...commonArgs, }, async run({ args }) { const [directory] = args._; - consola.info(directory); - // try { - // exec("npm create mcfly@latest", { stdio: "inherit" }); - // } catch (e) { - // consola.error(e); - // } + try { + exec(`npm create mcfly@latest ${directory ?? ""}`, { stdio: "inherit" }); + } catch (e) { + consola.error(e); + } }, }); diff --git a/packages/cli/commands/prepare.js b/packages/cli/commands/prepare.js deleted file mode 100755 index 5a29853..0000000 --- a/packages/cli/commands/prepare.js +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env node - -const { existsSync, writeFileSync, appendFileSync } = require("node:fs"); - -const typeDefinition = `\n/// `; -const globalDefinition = `import {WebComponent as W} from "web-component-base/WebComponent.mjs"; declare global {const WebComponent: typeof W;}export {WebComponent};`; - -if (existsSync(".nitro/types/nitro.d.ts")) { - console.log("has directory"); - try { - writeFileSync(".nitro/types/mcfly-imports.d.ts", globalDefinition); - } catch (e) { - console.error(e); - } - try { - appendFileSync(".nitro/types/nitro.d.ts", typeDefinition); - } catch (e) { - console.error(e); - } -} else { - console.log( - "Preparation Failed. Please run:\n> npx nitropack prepare && npx mcfly prepare" - ); -} diff --git a/packages/cli/commands/prepare.mjs b/packages/cli/commands/prepare.mjs new file mode 100755 index 0000000..3fb5afc --- /dev/null +++ b/packages/cli/commands/prepare.mjs @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +import { consola } from "consola"; +import { defineCommand } from "citty"; +import { commonArgs } from "../common.mjs"; +import { existsSync, writeFileSync, appendFileSync } from "node:fs"; + +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 {const WebComponent: typeof W;}export {WebComponent};`; + + if (existsSync(".nitro/types/nitro.d.ts")) { + try { + writeFileSync(".nitro/types/mcfly-imports.d.ts", globalDefinition); + } catch (e) { + consola.error(e); + } + try { + appendFileSync(".nitro/types/nitro.d.ts", typeDefinition); + } catch (e) { + consola.error(e); + } + } else { + consola.log( + "Preparation Failed. Please run:\n> npx nitropack prepare && npx mcfly prepare" + ); + } + }, +}); diff --git a/packages/cli/index.js b/packages/cli/index.js index 0a1e35d..afb08a9 100755 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -9,8 +9,8 @@ const main = defineCommand({ version: pkg.version, }, subCommands: { - prepare: () => import("./commands/prepare.js").then((r) => r.default), - generate: () => import("./commands/generate.js").then((r) => r.default), + prepare: () => import("./commands/prepare.mjs").then((r) => r.default), + generate: () => import("./commands/generate.mjs").then((r) => r.default), new: () => import("./commands/new.mjs").then((r) => r.default), }, });