@kaooffline/quickhost 0.2.0 → 0.2.1
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/bin/quickhost.js +58 -17
- package/package.json +1 -1
package/bin/quickhost.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
import { readFileSync, writeFileSync, existsSync, readdirSync } from "node:fs";
|
|
10
10
|
import { join, relative, resolve, basename } from "node:path";
|
|
11
11
|
import { homedir } from "node:os";
|
|
12
|
-
import { execSync } from "node:child_process";
|
|
12
|
+
import { execSync, spawn } from "node:child_process";
|
|
13
13
|
|
|
14
|
-
const VERSION = "0.2.
|
|
14
|
+
const VERSION = "0.2.1";
|
|
15
15
|
|
|
16
16
|
// ---------- tiny UI kit (no deps) ----------
|
|
17
17
|
const TTY = !!process.stdout.isTTY && !process.env.NO_COLOR && process.env.TERM !== "dumb";
|
|
@@ -209,7 +209,46 @@ function ssrError(fw, hints, checked) {
|
|
|
209
209
|
hint("quickHOST is the wrong host for it — use `vinext start` / `wrangler deploy`.");
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
// Run the project's build quietly: live one-line status, full log only on failure.
|
|
213
|
+
// Pass --verbose to stream the raw build output (old behavior, for debugging).
|
|
214
|
+
function runBuild(cmd, { verbose }) {
|
|
215
|
+
if (verbose) {
|
|
216
|
+
const t0 = Date.now();
|
|
217
|
+
try {
|
|
218
|
+
execSync(cmd, { stdio: "inherit" });
|
|
219
|
+
return Promise.resolve({ code: 0, log: "", secs: (Date.now() - t0) / 1000 });
|
|
220
|
+
} catch (e) {
|
|
221
|
+
return Promise.resolve({ code: e.status ?? 1, log: "", secs: (Date.now() - t0) / 1000 });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return new Promise((resolve) => {
|
|
225
|
+
const t0 = Date.now();
|
|
226
|
+
const child = spawn(cmd, { shell: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
227
|
+
let log = "";
|
|
228
|
+
let last = "";
|
|
229
|
+
const tick = TTY ? setInterval(() => {
|
|
230
|
+
const s = ((Date.now() - t0) / 1000).toFixed(0);
|
|
231
|
+
const tail = last ? dim(" " + last.slice(0, 72)) : "";
|
|
232
|
+
process.stdout.write(`\r${cyan("…")} building… ${dim(s + "s")}${tail} `);
|
|
233
|
+
}, 250) : null;
|
|
234
|
+
if (!TTY) console.log(dim("building… (quiet — rerun with --verbose for the full log)"));
|
|
235
|
+
const sniff = (d) => {
|
|
236
|
+
log += d;
|
|
237
|
+
const lines = String(d).split("\n").map((l) => l.replace(/\x1b\[\d+m/g, "").trim()).filter(Boolean);
|
|
238
|
+
if (lines.length) last = lines[lines.length - 1];
|
|
239
|
+
};
|
|
240
|
+
child.stdout.on("data", sniff);
|
|
241
|
+
child.stderr.on("data", sniff);
|
|
242
|
+
const finish = (code) => {
|
|
243
|
+
if (tick) { clearInterval(tick); process.stdout.write("\r" + " ".repeat(110) + "\r"); }
|
|
244
|
+
resolve({ code, log, secs: (Date.now() - t0) / 1000 });
|
|
245
|
+
};
|
|
246
|
+
child.on("close", (code) => finish(code ?? 1));
|
|
247
|
+
child.on("error", (e) => { log += String(e?.message || e); finish(1); });
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function detectDir() {
|
|
213
252
|
const manual = arg("--dir") || arg("-d");
|
|
214
253
|
const pkg = readPkg();
|
|
215
254
|
const fw = detectFramework(pkg);
|
|
@@ -221,22 +260,24 @@ function detectDir() {
|
|
|
221
260
|
}
|
|
222
261
|
const found = findBuiltDir();
|
|
223
262
|
if (found) return { dir: found, fw, built: false };
|
|
224
|
-
// try build once
|
|
263
|
+
// try build once (quiet by default, --verbose streams raw output)
|
|
225
264
|
if (pkg?.scripts?.build) {
|
|
226
265
|
const { run } = pm();
|
|
227
|
-
|
|
228
|
-
console.log(`${gray("[build]")} ${dim("
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
try {
|
|
232
|
-
execSync(run, { stdio: "inherit" });
|
|
233
|
-
} catch {
|
|
266
|
+
const verbose = has("--verbose");
|
|
267
|
+
console.log(`${gray("[build]")} ${dim("no built dir yet, running:")} ${bold(run)}${verbose ? "" : dim(" (quiet)")}`);
|
|
268
|
+
const { code, log, secs } = await runBuild(run, { verbose });
|
|
269
|
+
if (code !== 0) {
|
|
234
270
|
console.log("");
|
|
235
|
-
errBox(
|
|
271
|
+
errBox(`Build failed (exit ${code}) — fix the errors, then retry.`, [`ran: ${run} (${pkg.scripts.build})`]);
|
|
272
|
+
const tail = log.split("\n").filter((l) => l.trim()).slice(-25);
|
|
273
|
+
if (tail.length && !verbose) {
|
|
274
|
+
console.log("");
|
|
275
|
+
for (const l of tail) console.log(` ${dim(l.slice(0, 160))}`);
|
|
276
|
+
hint("full log: rerun with --verbose");
|
|
277
|
+
}
|
|
236
278
|
process.exit(1);
|
|
237
279
|
}
|
|
238
|
-
|
|
239
|
-
done(`build finished in ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
280
|
+
done(`build finished in ${secs.toFixed(1)}s`);
|
|
240
281
|
const again = findBuiltDir();
|
|
241
282
|
if (again) return { dir: again, fw, built: true };
|
|
242
283
|
}
|
|
@@ -270,7 +311,7 @@ async function deploy() {
|
|
|
270
311
|
|
|
271
312
|
const TOTAL = 3;
|
|
272
313
|
step(1, TOTAL, `locating static output ${dim(`(${cfg.username}/${app})`)}`);
|
|
273
|
-
const { dir, fw, built } = detectDir();
|
|
314
|
+
const { dir, fw, built } = await detectDir();
|
|
274
315
|
info(`${dim("dir")} ${bold(relative(process.cwd(), dir) || ".")} ${dim("·")} ${dim(fw.label)}${built ? dim(" · just built") : ""}`);
|
|
275
316
|
|
|
276
317
|
step(2, TOTAL, "collecting files");
|
|
@@ -339,7 +380,7 @@ function help() {
|
|
|
339
380
|
${bold("Usage:")} ${cyan("quickhost")} ${dim("<command> [options]")}
|
|
340
381
|
|
|
341
382
|
${bold("Commands")}
|
|
342
|
-
${cyan("deploy")} [--app x] [--dir ./dist] [--api URL] upload a static dir
|
|
383
|
+
${cyan("deploy")} [--app x] [--dir ./dist] [--api URL] [--verbose] upload a static dir
|
|
343
384
|
${cyan("register")} -u <name> claim a username
|
|
344
385
|
${cyan("login")} -u <name> log in on this machine
|
|
345
386
|
${cyan("list")} live apps + expiry
|
|
@@ -348,7 +389,7 @@ function help() {
|
|
|
348
389
|
|
|
349
390
|
${bold("Deploy")}
|
|
350
391
|
auto-finds ${dim("dist dist/client(vinext) build out .output/public public")}
|
|
351
|
-
runs your ${dim("build")} script once if nothing is built yet.
|
|
392
|
+
runs your ${dim("build")} script once if nothing is built yet (quiet — ${dim("--verbose")} streams it).
|
|
352
393
|
needs ${bold("index.html")} at the publish dir root. static only, SPA fallback on.
|
|
353
394
|
|
|
354
395
|
${bold("Limits")} ${dim("50MB/app · 500 files · 25MB/file · 20 apps/user · 30-day rolling expiry")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaooffline/quickhost",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "quickHOST CLI - one-command static hosting (Vite/Astro/HTML) to username.kaooffline.top/app. Free, 30-day rolling expiry.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": { "quickhost": "bin/quickhost.js" },
|