feat(cli): initial commands new and generate
This commit is contained in:
parent
82d4131b7e
commit
9584c2731c
6 changed files with 63 additions and 38 deletions
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const { consola } = require("consola");
|
|
||||||
|
|
||||||
consola.prompt("Name your new custom element");
|
|
18
packages/cli/commands/generate.mjs
Normal file
18
packages/cli/commands/generate.mjs
Normal file
|
@ -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");
|
||||||
|
},
|
||||||
|
});
|
|
@ -8,18 +8,17 @@ import { commonArgs } from "../common.mjs";
|
||||||
export default defineCommand({
|
export default defineCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: "prepare",
|
name: "prepare",
|
||||||
description: "Generate types for the project",
|
description: "Creates a new McFly project.",
|
||||||
},
|
},
|
||||||
args: {
|
args: {
|
||||||
...commonArgs,
|
...commonArgs,
|
||||||
},
|
},
|
||||||
async run({ args }) {
|
async run({ args }) {
|
||||||
const [directory] = args._;
|
const [directory] = args._;
|
||||||
consola.info(directory);
|
try {
|
||||||
// try {
|
exec(`npm create mcfly@latest ${directory ?? ""}`, { stdio: "inherit" });
|
||||||
// exec("npm create mcfly@latest", { stdio: "inherit" });
|
} catch (e) {
|
||||||
// } catch (e) {
|
consola.error(e);
|
||||||
// consola.error(e);
|
}
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const { existsSync, writeFileSync, appendFileSync } = require("node:fs");
|
|
||||||
|
|
||||||
const typeDefinition = `\n/// <reference path="./mcfly-imports.d.ts" />`;
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
}
|
|
37
packages/cli/commands/prepare.mjs
Executable file
37
packages/cli/commands/prepare.mjs
Executable file
|
@ -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/// <reference path="./mcfly-imports.d.ts" />`;
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
|
@ -9,8 +9,8 @@ const main = defineCommand({
|
||||||
version: pkg.version,
|
version: pkg.version,
|
||||||
},
|
},
|
||||||
subCommands: {
|
subCommands: {
|
||||||
prepare: () => import("./commands/prepare.js").then((r) => r.default),
|
prepare: () => import("./commands/prepare.mjs").then((r) => r.default),
|
||||||
generate: () => import("./commands/generate.js").then((r) => r.default),
|
generate: () => import("./commands/generate.mjs").then((r) => r.default),
|
||||||
new: () => import("./commands/new.mjs").then((r) => r.default),
|
new: () => import("./commands/new.mjs").then((r) => r.default),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue