From e7313f4521d02694f2965c86cbfd7458a1afe359 Mon Sep 17 00:00:00 2001 From: Nikhil Saraf Date: Fri, 1 Dec 2023 06:48:27 +0530 Subject: [PATCH] docs(changeset): feat: vinxi start command (just works with node target right now) --- .changeset/spicy-lemons-exercise.md | 5 ++++ packages/vinxi/bin/cli.mjs | 45 ++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 .changeset/spicy-lemons-exercise.md diff --git a/.changeset/spicy-lemons-exercise.md b/.changeset/spicy-lemons-exercise.md new file mode 100644 index 00000000..7566dfaf --- /dev/null +++ b/.changeset/spicy-lemons-exercise.md @@ -0,0 +1,5 @@ +--- +"vinxi": patch +--- + +feat: vinxi start command (just works with node target right now) diff --git a/packages/vinxi/bin/cli.mjs b/packages/vinxi/bin/cli.mjs index 817e60dd..8bf3401b 100755 --- a/packages/vinxi/bin/cli.mjs +++ b/packages/vinxi/bin/cli.mjs @@ -1,15 +1,8 @@ #!/usr/bin/env node -import chokidar from "chokidar"; import { defineCommand, runMain } from "citty"; import fs from "fs"; -// import mri from "mri"; import { fileURLToPath } from "url"; -import { exec } from "node:child_process"; - -import { loadApp } from "../lib/load-app.js"; -import { log } from "../lib/logger.js"; - const packageJson = JSON.parse( fs.readFileSync( fileURLToPath(new URL("../package.json", import.meta.url)), @@ -64,6 +57,9 @@ const command = defineCommand({ }, }, async run({ args }) { + const chokidar = await import("chokidar"); + const { loadApp } = await import("../lib/load-app.js"); + const { log } = await import("../lib/logger.js"); const configFile = args.config; globalThis.MANIFEST = {}; const app = await loadApp(configFile, args); @@ -153,12 +149,47 @@ const command = defineCommand({ async run({ args }) { const configFile = args.config; globalThis.MANIFEST = {}; + const { loadApp } = await import("../lib/load-app.js"); const app = await loadApp(configFile, args); process.env.NODE_ENV = "production"; const { createBuild } = await import("../lib/build.js"); await createBuild(app, { preset: args.preset }); }, }, + start: { + meta: { + name: "start", + version: packageJson.version, + description: "Start your built Vinxi app", + }, + args: { + config: { + type: "string", + description: "Path to config file (default: app.config.js)", + }, + stack: { + type: "string", + description: "Stacks", + }, + preset: { + type: "string", + description: "Server preset (default: node-server)", + }, + port: { + type: "number", + description: "Port to listen on (default: 3000)", + }, + host: { + type: "boolean", + description: "Expose to host (default: false)", + }, + }, + async run({ args }) { + process.env.PORT ??= args.port ?? 3000; + process.env.HOST ??= args.host; + await import(process.cwd() + "/.output/server/index.mjs"); + }, + }, }), });