feat(cli): new commands build, prepare, dev

This commit is contained in:
Ayo 2023-10-25 22:34:36 +02:00
parent 2be9bfec7f
commit 877a45a44f
9 changed files with 396 additions and 1185 deletions

1501
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,23 @@
#!/usr/bin/env node
import { consola } from "consola";
import { defineCommand } from "citty";
import { commonArgs } from "../common.mjs";
import { execSync as exec } from "child_process";
export default defineCommand({
meta: {
name: "prepare",
description: "Generates the build files for the McFly app.",
},
args: {
...commonArgs,
},
async run({ args }) {
try {
exec(`npx nitropack build`, { stdio: "inherit" });
} catch (e) {
consola.error(e);
}
},
});

View file

@ -0,0 +1,23 @@
#!/usr/bin/env node
import { consola } from "consola";
import { defineCommand } from "citty";
import { commonArgs } from "../common.mjs";
import { execSync as exec } from "child_process";
export default defineCommand({
meta: {
name: "prepare",
description: "Runs the dev server.",
},
args: {
...commonArgs,
},
async run({ args }) {
try {
exec(`npx nitropack dev`, { stdio: "inherit" });
} catch (e) {
consola.error(e);
}
},
});

View file

@ -13,6 +13,6 @@ export default defineCommand({
...commonArgs, ...commonArgs,
}, },
async run({ args }) { async run({ args }) {
consola.box("Generate a McFly building block"); consola.box("Generate a McFly building block (In-progress)");
}, },
}); });

View file

@ -4,6 +4,7 @@ import { consola } from "consola";
import { defineCommand } from "citty"; import { defineCommand } from "citty";
import { commonArgs } from "../common.mjs"; import { commonArgs } from "../common.mjs";
import { existsSync, writeFileSync, appendFileSync } from "node:fs"; import { existsSync, writeFileSync, appendFileSync } from "node:fs";
import { execSync as exec } from "child_process";
export default defineCommand({ export default defineCommand({
meta: { meta: {
@ -17,6 +18,12 @@ export default defineCommand({
const typeDefinition = `\n/// <reference path="./mcfly-imports.d.ts" />`; 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};`; const globalDefinition = `import {WebComponent as W} from "web-component-base/WebComponent.mjs"; declare global {const WebComponent: typeof W;}export {WebComponent};`;
try {
exec("npx nitropack prepare", { stdio: "inherit" });
} catch (e) {
consola.error(e);
}
if (existsSync(".nitro/types/nitro.d.ts")) { if (existsSync(".nitro/types/nitro.d.ts")) {
try { try {
writeFileSync(".nitro/types/mcfly-imports.d.ts", globalDefinition); writeFileSync(".nitro/types/mcfly-imports.d.ts", globalDefinition);

View file

@ -9,9 +9,11 @@ const main = defineCommand({
version: pkg.version, version: pkg.version,
}, },
subCommands: { subCommands: {
new: () => import("./commands/new.mjs").then((r) => r.default),
dev: () => import("./commands/dev.mjs").then((r) => r.default),
build: () => import("./commands/build.mjs").then((r) => r.default),
prepare: () => import("./commands/prepare.mjs").then((r) => r.default), prepare: () => import("./commands/prepare.mjs").then((r) => r.default),
generate: () => import("./commands/generate.mjs").then((r) => r.default), generate: () => import("./commands/generate.mjs").then((r) => r.default),
new: () => import("./commands/new.mjs").then((r) => r.default),
}, },
}); });

View file

@ -1,6 +1,6 @@
{ {
"name": "@mcflyjs/cli", "name": "@mcflyjs/cli",
"version": "0.0.2", "version": "0.0.3",
"description": "McFly CLI tools", "description": "McFly CLI tools",
"main": "index.js", "main": "index.js",
"bin": { "bin": {

View file

@ -3,10 +3,10 @@
"description": "McFly is a full-stack no-framework framework that assists developers in leveraging the web platform.", "description": "McFly is a full-stack no-framework framework that assists developers in leveraging the web platform.",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "nitropack dev", "start": "mcfly dev",
"prepare": "nitropack prepare && mcfly prepare", "prepare": "mcfly prepare",
"dev": "nitropack dev", "dev": "mcfly dev",
"build": "nitropack build", "build": "mcfly build",
"preview": "node .output/server/index.mjs", "preview": "node .output/server/index.mjs",
"build:preview": "npm run build && npm run preview" "build:preview": "npm run build && npm run preview"
}, },

View file

@ -2,11 +2,12 @@
"name": "@templates/basic", "name": "@templates/basic",
"description": "McFly starter project; see more on https://ayco.io/gh/McFly", "description": "McFly starter project; see more on https://ayco.io/gh/McFly",
"scripts": { "scripts": {
"start": "nitropack dev", "start": "mcfly dev",
"prepare": "nitropack prepare", "prepare": "mcfly prepare",
"dev": "nitropack dev", "dev": "mcfly dev",
"build": "nitropack build", "build": "mcfly build",
"preview": "node .output/server/index.mjs" "preview": "node .output/server/index.mjs",
"build:preview": "npm run build && npm run preview"
}, },
"dependencies": { "dependencies": {
"@mcflyjs/cli": "latest", "@mcflyjs/cli": "latest",