@kvbox/cli 0.5.32 → 0.5.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kvbox.js +79 -35
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.35" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
170
|
import { Command as Command33 } from "commander";
|
|
@@ -526,6 +526,8 @@ var MachineSchema = z2.object({
|
|
|
526
526
|
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
527
527
|
/** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
|
|
528
528
|
autoHibernateSec: z2.number().int().positive().optional(),
|
|
529
|
+
/** A script inside the box that says it is idle (#102, exit 0): auto-hibernate asks it instead of watching the traffic. */
|
|
530
|
+
idleCheck: z2.string().optional(),
|
|
529
531
|
/** Volumes attached to the box (#52), in drive order; each is mounted at `mountPath` while the box runs. Absent: none. */
|
|
530
532
|
volumes: z2.array(z2.object({ name: z2.string(), sizeGib: z2.number().int(), mountPath: z2.string() })).optional(),
|
|
531
533
|
/** Boxes that may reach this one, each on one port (#98). Absent: none. */
|
|
@@ -643,11 +645,18 @@ var RescaleMachineRequest = z2.object({
|
|
|
643
645
|
size: SizeSchema.optional(),
|
|
644
646
|
vcpu: z2.number().int().min(1).max(64).optional(),
|
|
645
647
|
memMib: z2.number().int().min(256).optional(),
|
|
646
|
-
diskGib: z2.number().int().min(1).optional()
|
|
648
|
+
diskGib: z2.number().int().min(1).optional(),
|
|
649
|
+
/** Skip the capacity guard when a running box grows (#37). */
|
|
650
|
+
force: z2.boolean().optional()
|
|
651
|
+
});
|
|
652
|
+
var StartMachineRequest = z2.object({
|
|
653
|
+
force: z2.boolean().optional()
|
|
647
654
|
});
|
|
648
655
|
var SetMachineRequest = z2.object({
|
|
649
656
|
/** Seconds without network traffic before the box is hibernated (#47); 0: never. */
|
|
650
|
-
autoHibernateSec: z2.number().int().min(0).optional()
|
|
657
|
+
autoHibernateSec: z2.number().int().min(0).optional(),
|
|
658
|
+
/** The box's idle check (#102): an absolute path to a script inside the box, exit 0 = idle; "": none, back to network traffic. */
|
|
659
|
+
idleCheck: z2.union([z2.literal(""), z2.string().max(255).regex(/^\/[^\0\n]*$/, "an absolute path inside the box")]).optional()
|
|
651
660
|
});
|
|
652
661
|
var SnapshotSchema = z2.object({
|
|
653
662
|
name: z2.string(),
|
|
@@ -1175,8 +1184,8 @@ var ServerClient = class {
|
|
|
1175
1184
|
stopMachine(name) {
|
|
1176
1185
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/stop`, MachineSchema);
|
|
1177
1186
|
}
|
|
1178
|
-
startMachine(name) {
|
|
1179
|
-
return this.call("POST", `/machines/${encodeURIComponent(name)}/start`, MachineSchema);
|
|
1187
|
+
startMachine(name, force = false) {
|
|
1188
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/start`, MachineSchema, force ? { force } : void 0);
|
|
1180
1189
|
}
|
|
1181
1190
|
pauseMachine(name) {
|
|
1182
1191
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/pause`, MachineSchema);
|
|
@@ -1187,8 +1196,8 @@ var ServerClient = class {
|
|
|
1187
1196
|
hibernateMachine(name) {
|
|
1188
1197
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/hibernate`, MachineSchema);
|
|
1189
1198
|
}
|
|
1190
|
-
wakeMachine(name) {
|
|
1191
|
-
return this.call("POST", `/machines/${encodeURIComponent(name)}/wake`, MachineSchema);
|
|
1199
|
+
wakeMachine(name, force = false) {
|
|
1200
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/wake`, MachineSchema, force ? { force } : void 0);
|
|
1192
1201
|
}
|
|
1193
1202
|
updateMachine(name) {
|
|
1194
1203
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/update`, MachineSchema);
|
|
@@ -1741,6 +1750,16 @@ function envValueProblem(value) {
|
|
|
1741
1750
|
return null;
|
|
1742
1751
|
}
|
|
1743
1752
|
|
|
1753
|
+
// ../shared/src/duration.ts
|
|
1754
|
+
var UNIT_SEC = { m: 60, h: 3600, d: 86400 };
|
|
1755
|
+
function parseDuration(text2) {
|
|
1756
|
+
const t = text2.trim().toLowerCase();
|
|
1757
|
+
if (!/^(\d+[mhd])+$/.test(t)) return void 0;
|
|
1758
|
+
let sec = 0;
|
|
1759
|
+
for (const [, n, unit] of t.matchAll(/(\d+)([mhd])/g)) sec += Number(n) * UNIT_SEC[unit];
|
|
1760
|
+
return sec;
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1744
1763
|
// src/commands/vm/new.ts
|
|
1745
1764
|
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
1746
1765
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
@@ -1777,7 +1796,7 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
1777
1796
|
info(`${color.green("\u2713")} ${describe(box, user)}`);
|
|
1778
1797
|
if (opts.from !== void 0) info(` connect with: kvbox connect ${displayName(box, user)} (already up: everything that ran in the snapshot is running)`);
|
|
1779
1798
|
else info(` connect with: kvbox connect ${displayName(box, user)} (SSH is up a couple of seconds after boot)`);
|
|
1780
|
-
if (box.autoHibernateSec) info(` it ${autoHibernateText(box.autoHibernateSec)}`);
|
|
1799
|
+
if (box.autoHibernateSec) info(` it ${autoHibernateText(box.autoHibernateSec, box.idleCheck)}`);
|
|
1781
1800
|
if (box.connect !== void 0) {
|
|
1782
1801
|
info(` reach it at: ${box.connect}`);
|
|
1783
1802
|
info(` from another box once linked: kvbox vm link <box> ${displayName(box, user)} --port <port>`);
|
|
@@ -1803,8 +1822,10 @@ function describe(box, user) {
|
|
|
1803
1822
|
const from = box.source.startsWith("snapshot:") ? ` from snapshot ${shortRef(box.source.slice("snapshot:".length), box.owner)}` : box.source.startsWith("fork:") ? `, a fork of ${shortRef(box.source.slice("fork:".length), box.owner)}` : "";
|
|
1804
1823
|
return `box ${color.bold(displayName(box, user))} is ${box.status} at ${box.ip}${from}: ${box.vcpu} vCPU, ${gb(box.memMib * 1024 ** 2)} RAM, ${gb(box.diskBytes)} disk`;
|
|
1805
1824
|
}
|
|
1806
|
-
function autoHibernateText(sec) {
|
|
1807
|
-
|
|
1825
|
+
function autoHibernateText(sec, idleCheck) {
|
|
1826
|
+
if (!sec) return "never hibernates on its own";
|
|
1827
|
+
const quiet = idleCheck === void 0 ? "without network traffic" : `idle by ${idleCheck}`;
|
|
1828
|
+
return `hibernates after ${duration(sec)} ${quiet} (kvbox connect wakes it)`;
|
|
1808
1829
|
}
|
|
1809
1830
|
function collect(value, previous) {
|
|
1810
1831
|
return [...previous, value];
|
|
@@ -1822,13 +1843,11 @@ function parseEnvFlags(flags) {
|
|
|
1822
1843
|
}
|
|
1823
1844
|
return [...out].map(([name, value]) => ({ name, value }));
|
|
1824
1845
|
}
|
|
1825
|
-
var UNIT_SEC = { m: 60, h: 3600, d: 86400 };
|
|
1826
1846
|
function parseIdleTimeout(text2) {
|
|
1827
1847
|
const t = text2.trim().toLowerCase();
|
|
1828
1848
|
if (t === "off" || t === "never" || t === "0") return 0;
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
for (const [, n, unit] of t.matchAll(/(\d+)([mhd])/g)) sec += Number(n) * UNIT_SEC[unit];
|
|
1849
|
+
const sec = parseDuration(t);
|
|
1850
|
+
if (sec === void 0) throw new KvboxError(`--auto-hibernate ${text2}: give a duration like 30m, 4h or 1d, or off`);
|
|
1832
1851
|
return sec;
|
|
1833
1852
|
}
|
|
1834
1853
|
|
|
@@ -1989,7 +2008,7 @@ var forkCommand = new Command4("fork").description("copy a box, running or stopp
|
|
|
1989
2008
|
`);
|
|
1990
2009
|
info(`${color.green("\u2713")} ${describe(box, user)}`);
|
|
1991
2010
|
info(` connect with: kvbox connect ${displayName(box, user)}`);
|
|
1992
|
-
info(` it ${autoHibernateText(box.autoHibernateSec)}; published ports and HTTPS names stay with ${source}`);
|
|
2011
|
+
info(` it ${autoHibernateText(box.autoHibernateSec, box.idleCheck)}; published ports and HTTPS names stay with ${source}`);
|
|
1993
2012
|
} finally {
|
|
1994
2013
|
await client.close();
|
|
1995
2014
|
}
|
|
@@ -2116,7 +2135,9 @@ function getRows(box, sub, user) {
|
|
|
2116
2135
|
const ports = rowsOf(box, user).map((r) => `${r.guestPort}/${r.proto} \u2192 ${reaches(r, true)}`);
|
|
2117
2136
|
rows2.push(["ports", ports.length === 0 ? "-" : ports.join(", ")]);
|
|
2118
2137
|
rows2.push(["volumes", box.volumes?.length ? box.volumes.map((v) => `${v.name} ${color.dim(`(${v.sizeGib} GB at ${v.mountPath})`)}`).join(", ") : "-"]);
|
|
2119
|
-
|
|
2138
|
+
const quiet = box.idleCheck === void 0 ? "without network traffic" : `idle by ${box.idleCheck}`;
|
|
2139
|
+
rows2.push(["auto-hibernate", box.autoHibernateSec ? `after ${duration(box.autoHibernateSec)} ${quiet}` : "off"]);
|
|
2140
|
+
if (!box.autoHibernateSec && box.idleCheck !== void 0) rows2.push(["idle check", `${box.idleCheck} ${color.dim("(used once auto-hibernate is on)")}`]);
|
|
2120
2141
|
rows2.push(["source", box.source]);
|
|
2121
2142
|
rows2.push(["base", box.image === void 0 ? box.base : `${box.image} ${box.base}`]);
|
|
2122
2143
|
rows2.push(["created", `${age(box.createdAt)} ${color.dim(`(${box.createdAt})`)}`]);
|
|
@@ -2552,7 +2573,7 @@ for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this
|
|
|
2552
2573
|
|
|
2553
2574
|
// src/commands/vm/rescale.ts
|
|
2554
2575
|
import { Command as Command22, Option as Option3 } from "commander";
|
|
2555
|
-
var rescaleCommand = new Command22("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2576
|
+
var rescaleCommand = new Command22("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2556
2577
|
const req = {
|
|
2557
2578
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
2558
2579
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -2560,11 +2581,12 @@ var rescaleCommand = new Command22("rescale").description("change a box's vCPUs,
|
|
|
2560
2581
|
...opts.disk !== void 0 ? { diskGib: parseGib("--disk", opts.disk) } : {}
|
|
2561
2582
|
};
|
|
2562
2583
|
if (Object.keys(req).length === 0) throw new KvboxError("nothing to change: give --size, --vcpu, --mem or --disk");
|
|
2584
|
+
const body = opts.force ? { ...req, force: true } : req;
|
|
2563
2585
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2564
2586
|
try {
|
|
2565
2587
|
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
2566
2588
|
if (!before) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
2567
|
-
const box = await spin(`rescaling ${name}\u2026`, client.rescaleMachine(displayName(before, me(client)),
|
|
2589
|
+
const box = await spin(`rescaling ${name}\u2026`, client.rescaleMachine(displayName(before, me(client)), body));
|
|
2568
2590
|
if (opts.json) {
|
|
2569
2591
|
json(box);
|
|
2570
2592
|
return;
|
|
@@ -2632,30 +2654,44 @@ var rmCommand3 = new Command24("rm").description("destroy a box (its disk is del
|
|
|
2632
2654
|
|
|
2633
2655
|
// src/commands/vm/set.ts
|
|
2634
2656
|
import { Command as Command25 } from "commander";
|
|
2635
|
-
var setCommand = new Command25("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never)").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2636
|
-
if (opts.autoHibernate === void 0) throw new KvboxError("nothing to change: give --auto-hibernate");
|
|
2637
|
-
const autoHibernateSec = parseIdleTimeout(opts.autoHibernate);
|
|
2657
|
+
var setCommand = new Command25("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2658
|
+
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0) throw new KvboxError("nothing to change: give --auto-hibernate or --idle-check");
|
|
2659
|
+
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
2660
|
+
const idleCheck = opts.idleCheck === void 0 ? void 0 : parseIdleCheck(opts.idleCheck);
|
|
2638
2661
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2639
2662
|
try {
|
|
2640
2663
|
const found = pickRef(await boxesFor(client, name), name, me(client));
|
|
2641
2664
|
if (!found) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
2642
|
-
const box = await spin(`updating ${name}\u2026`, client.setMachine(displayName(found, me(client)), { autoHibernateSec }));
|
|
2665
|
+
const box = await spin(`updating ${name}\u2026`, client.setMachine(displayName(found, me(client)), { ...autoHibernateSec !== void 0 ? { autoHibernateSec } : {}, ...idleCheck !== void 0 ? { idleCheck } : {} }));
|
|
2666
|
+
if (!idleCheckKept(idleCheck, box)) {
|
|
2667
|
+
throw new KvboxError(`box ${name}: its host runs a kvbox-server too old for --idle-check; it needs updating first${autoHibernateSec !== void 0 ? " (--auto-hibernate was applied)" : ""}`);
|
|
2668
|
+
}
|
|
2643
2669
|
if (opts.json) {
|
|
2644
2670
|
json(box);
|
|
2645
2671
|
return;
|
|
2646
2672
|
}
|
|
2647
|
-
info(`${color.green("\u2713")} box ${color.bold(name)}: ${autoHibernateText(box.autoHibernateSec)}`);
|
|
2673
|
+
info(`${color.green("\u2713")} box ${color.bold(name)}: ${autoHibernateText(box.autoHibernateSec, box.idleCheck)}`);
|
|
2674
|
+
if (idleCheck && !box.autoHibernateSec) info(color.dim(` the idle check is used once auto-hibernate is on: kvbox vm set ${name} --auto-hibernate 10m`));
|
|
2648
2675
|
} finally {
|
|
2649
2676
|
await client.close();
|
|
2650
2677
|
}
|
|
2651
2678
|
});
|
|
2679
|
+
function idleCheckKept(asked, box) {
|
|
2680
|
+
return asked === void 0 || (box.idleCheck ?? "") === asked;
|
|
2681
|
+
}
|
|
2682
|
+
function parseIdleCheck(text2) {
|
|
2683
|
+
const t = text2.trim();
|
|
2684
|
+
if (t === "" || t === "off" || t === "none") return "";
|
|
2685
|
+
if (!t.startsWith("/")) throw new KvboxError(`--idle-check ${text2}: give the script's absolute path inside the box (/home/kvbox/idle.sh), or off`);
|
|
2686
|
+
return t;
|
|
2687
|
+
}
|
|
2652
2688
|
|
|
2653
2689
|
// src/commands/vm/start.ts
|
|
2654
2690
|
import { Command as Command26 } from "commander";
|
|
2655
|
-
var startCommand = new Command26("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2691
|
+
var startCommand = new Command26("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2656
2692
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2657
2693
|
try {
|
|
2658
|
-
const box = await spin(`booting ${name}\u2026`, client.startMachine(name));
|
|
2694
|
+
const box = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
|
|
2659
2695
|
if (opts.json) json(box);
|
|
2660
2696
|
else info(`${color.green("\u2713")} ${describe(box)}`);
|
|
2661
2697
|
} finally {
|
|
@@ -2832,10 +2868,10 @@ function block(u) {
|
|
|
2832
2868
|
|
|
2833
2869
|
// src/commands/vm/wake.ts
|
|
2834
2870
|
import { Command as Command32 } from "commander";
|
|
2835
|
-
var wakeCommand = new Command32("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2871
|
+
var wakeCommand = new Command32("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2836
2872
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2837
2873
|
try {
|
|
2838
|
-
const box = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name));
|
|
2874
|
+
const box = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name, opts.force ?? false));
|
|
2839
2875
|
if (opts.json) json(box);
|
|
2840
2876
|
else info(`${color.green("\u2713")} box ${name} is awake, running where it left off`);
|
|
2841
2877
|
} finally {
|
|
@@ -3695,9 +3731,10 @@ function serverRemote(opts) {
|
|
|
3695
3731
|
var nextjsTemplate = {
|
|
3696
3732
|
id: "nextjs",
|
|
3697
3733
|
label: "Next.js",
|
|
3698
|
-
hint: "source shipped; installed, built and run in the box on
|
|
3734
|
+
hint: "source shipped; installed, built and run in the box on $PORT (3000)",
|
|
3699
3735
|
size: "s",
|
|
3700
3736
|
port: 3e3,
|
|
3737
|
+
customPort: true,
|
|
3701
3738
|
detect(pkg) {
|
|
3702
3739
|
if (!pkg) return false;
|
|
3703
3740
|
return "next" in { ...pkg.dependencies, ...pkg.devDependencies };
|
|
@@ -3836,7 +3873,7 @@ var DeployConfigSchema = z5.object({
|
|
|
3836
3873
|
size: z5.enum(SIZE_NAMES).optional(),
|
|
3837
3874
|
/** The build output directory, relative to the app; the template's default when absent. */
|
|
3838
3875
|
dist: z5.string().optional(),
|
|
3839
|
-
/** The port
|
|
3876
|
+
/** The port a Next.js app or Node server serves; the template's (3000) when absent. */
|
|
3840
3877
|
port: z5.number().int().min(1).max(65535).optional()
|
|
3841
3878
|
});
|
|
3842
3879
|
async function readConfig(dir) {
|
|
@@ -3926,7 +3963,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
3926
3963
|
var shipping = { ship, measure, waitForSsh };
|
|
3927
3964
|
|
|
3928
3965
|
// src/commands/deploy/index.ts
|
|
3929
|
-
var deployCommand = new Command57("deploy").description("put the app in this directory (React, Next.js or a Node server) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the port a Node server listens on
|
|
3966
|
+
var deployCommand = new Command57("deploy").description("put the app in this directory (React, Next.js or a Node server) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the port a Next.js app or Node server listens on (default 3000; saved to kvbox.json)", parsePort).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
|
|
3930
3967
|
const dir = resolve2(dirArg ?? ".");
|
|
3931
3968
|
const pkg = await readPackageJson(dir);
|
|
3932
3969
|
const saved = await readConfig(dir);
|
|
@@ -3998,10 +4035,13 @@ ${result.output.trim()}`);
|
|
|
3998
4035
|
await client.close();
|
|
3999
4036
|
}
|
|
4000
4037
|
});
|
|
4001
|
-
function
|
|
4038
|
+
function portProblem(v) {
|
|
4002
4039
|
const n = Number(v);
|
|
4003
|
-
|
|
4004
|
-
|
|
4040
|
+
return !/^\d+$/.test(v) || n < 1 || n > 65535;
|
|
4041
|
+
}
|
|
4042
|
+
function parsePort(v) {
|
|
4043
|
+
if (portProblem(v)) throw new InvalidArgumentError2("expected a port, 1-65535");
|
|
4044
|
+
return Number(v);
|
|
4005
4045
|
}
|
|
4006
4046
|
async function readPackageJson(dir) {
|
|
4007
4047
|
try {
|
|
@@ -4065,8 +4105,12 @@ async function settle(dir, pkg, saved, opts, orgFlag, cloud) {
|
|
|
4065
4105
|
if (open.size && ask) {
|
|
4066
4106
|
size = await select("Box size", SIZE_NAMES.map((s) => ({ value: s, label: s, hint: `${SIZES[s].vcpu} vCPU, ${SIZES[s].memMib / 1024} GB RAM, ${SIZES[s].diskGib} GB disk` })), SIZE_NAMES.indexOf(template.size));
|
|
4067
4107
|
}
|
|
4068
|
-
if (opts.port !== void 0 && !template.customPort) throw new KvboxError(`--port is for a Node server; the ${template.label} template serves port ${template.port}`);
|
|
4069
|
-
|
|
4108
|
+
if (opts.port !== void 0 && !template.customPort) throw new KvboxError(`--port is for a Next.js app or a Node server; the ${template.label} template serves port ${template.port}`);
|
|
4109
|
+
let port = opts.port ?? (template.customPort ? saved?.port : void 0);
|
|
4110
|
+
if (template.customPort && port === void 0 && fresh && ask) {
|
|
4111
|
+
const answer = await text("Port", { default: String(template.port), validate: (a) => portProblem(a) ? "expected a port, 1-65535" : void 0 });
|
|
4112
|
+
port = Number(answer);
|
|
4113
|
+
}
|
|
4070
4114
|
const org = orgFlag ?? saved?.org;
|
|
4071
4115
|
const config = {
|
|
4072
4116
|
template: template.id,
|