@zalify/cli 0.2.0 → 0.2.2
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/cli.js +75 -17
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11352,6 +11352,7 @@ async function login(options) {
|
|
|
11352
11352
|
const result = await new Promise((resolvePromise, reject) => {
|
|
11353
11353
|
const timer = setTimeout(() => {
|
|
11354
11354
|
server.close();
|
|
11355
|
+
server.closeAllConnections();
|
|
11355
11356
|
reject(new Error("Login timed out after 5 minutes."));
|
|
11356
11357
|
}, LOGIN_TIMEOUT_MS);
|
|
11357
11358
|
const server = createServer((req, res) => {
|
|
@@ -11360,11 +11361,18 @@ async function login(options) {
|
|
|
11360
11361
|
res.writeHead(404).end();
|
|
11361
11362
|
return;
|
|
11362
11363
|
}
|
|
11363
|
-
const done = (message) => {
|
|
11364
|
-
res.writeHead(200, {
|
|
11364
|
+
const done = (message, after) => {
|
|
11365
|
+
res.writeHead(200, {
|
|
11366
|
+
"Content-Type": "text/html",
|
|
11367
|
+
Connection: "close"
|
|
11368
|
+
});
|
|
11365
11369
|
res.end(`<!doctype html><meta charset="utf-8"><title>Zalify CLI</title>
|
|
11366
11370
|
<body style="font-family:system-ui;display:grid;place-items:center;height:100vh;margin:0">
|
|
11367
|
-
<p>${message} You can close this tab.</p></body
|
|
11371
|
+
<p>${message} You can close this tab.</p></body>`, after);
|
|
11372
|
+
};
|
|
11373
|
+
const teardown = () => {
|
|
11374
|
+
server.close();
|
|
11375
|
+
server.closeAllConnections();
|
|
11368
11376
|
};
|
|
11369
11377
|
if (url.searchParams.get("state") !== state) {
|
|
11370
11378
|
done("Login failed: state mismatch.");
|
|
@@ -11373,25 +11381,28 @@ async function login(options) {
|
|
|
11373
11381
|
clearTimeout(timer);
|
|
11374
11382
|
const error = url.searchParams.get("error");
|
|
11375
11383
|
if (error) {
|
|
11376
|
-
done("Authorization was denied.")
|
|
11377
|
-
|
|
11378
|
-
|
|
11384
|
+
done("Authorization was denied.", () => {
|
|
11385
|
+
teardown();
|
|
11386
|
+
reject(new Error(`Authorization denied (${error}).`));
|
|
11387
|
+
});
|
|
11379
11388
|
return;
|
|
11380
11389
|
}
|
|
11381
11390
|
const key = url.searchParams.get("key");
|
|
11382
11391
|
if (!key) {
|
|
11383
|
-
done("Login failed: no key in callback.")
|
|
11384
|
-
|
|
11385
|
-
|
|
11392
|
+
done("Login failed: no key in callback.", () => {
|
|
11393
|
+
teardown();
|
|
11394
|
+
reject(new Error("Callback did not include a key."));
|
|
11395
|
+
});
|
|
11386
11396
|
return;
|
|
11387
11397
|
}
|
|
11388
|
-
done("Logged in!")
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
|
|
11394
|
-
|
|
11398
|
+
done("Logged in!", () => {
|
|
11399
|
+
teardown();
|
|
11400
|
+
resolvePromise({
|
|
11401
|
+
key,
|
|
11402
|
+
workspaceId: url.searchParams.get("workspace_id") ?? "",
|
|
11403
|
+
workspaceName: url.searchParams.get("workspace_name") ?? "",
|
|
11404
|
+
workspaceSlug: url.searchParams.get("workspace_slug") ?? ""
|
|
11405
|
+
});
|
|
11395
11406
|
});
|
|
11396
11407
|
});
|
|
11397
11408
|
server.listen(0, "127.0.0.1", () => {
|
|
@@ -11475,8 +11486,13 @@ async function assetsPush(storeDir) {
|
|
|
11475
11486
|
body: JSON.stringify(body)
|
|
11476
11487
|
});
|
|
11477
11488
|
const json = await res.json().catch(() => ({}));
|
|
11478
|
-
if (!res.ok)
|
|
11489
|
+
if (!res.ok) {
|
|
11490
|
+
if (json.code === "UPGRADE_REQUIRED") {
|
|
11491
|
+
throw new Error(`${json.error ?? "This feature requires a paid plan."}
|
|
11492
|
+
` + ` Upgrade this workspace at ${config.appUrl} (Settings → Billing).`);
|
|
11493
|
+
}
|
|
11479
11494
|
throw new Error(`${path9} ${res.status}: ${JSON.stringify(json)}`);
|
|
11495
|
+
}
|
|
11480
11496
|
return json;
|
|
11481
11497
|
}
|
|
11482
11498
|
const files = readdirSync(imagesDir).filter((f) => f.endsWith(".png")).map((name) => {
|
|
@@ -11555,10 +11571,51 @@ async function assetsPush(storeDir) {
|
|
|
11555
11571
|
console.log("Done.");
|
|
11556
11572
|
}
|
|
11557
11573
|
|
|
11574
|
+
// src/self-update.ts
|
|
11575
|
+
import { spawnSync } from "node:child_process";
|
|
11576
|
+
import { realpathSync } from "node:fs";
|
|
11577
|
+
function detectManager() {
|
|
11578
|
+
let binPath = process.argv[1] ?? "";
|
|
11579
|
+
try {
|
|
11580
|
+
binPath = realpathSync(binPath);
|
|
11581
|
+
} catch {}
|
|
11582
|
+
if (binPath.includes("/pnpm/") || binPath.includes("/.pnpm/")) {
|
|
11583
|
+
return { cmd: "pnpm", args: ["add", "-g", "@zalify/cli@latest"] };
|
|
11584
|
+
}
|
|
11585
|
+
if (binPath.includes("/.bun/")) {
|
|
11586
|
+
return { cmd: "bun", args: ["add", "-g", "@zalify/cli@latest"] };
|
|
11587
|
+
}
|
|
11588
|
+
return { cmd: "npm", args: ["install", "-g", "@zalify/cli@latest"] };
|
|
11589
|
+
}
|
|
11590
|
+
function selfUpdate(currentVersion) {
|
|
11591
|
+
const { cmd, args } = detectManager();
|
|
11592
|
+
console.log(`Current version: ${currentVersion}`);
|
|
11593
|
+
console.log(`Updating via: ${cmd} ${args.join(" ")}
|
|
11594
|
+
`);
|
|
11595
|
+
const result = spawnSync(cmd, args, { stdio: "inherit" });
|
|
11596
|
+
if (result.error || result.status !== 0) {
|
|
11597
|
+
console.error(`
|
|
11598
|
+
Update failed${result.error ? `: ${result.error.message}` : ""}.` + `
|
|
11599
|
+
Try manually: ${cmd} ${args.join(" ")}`);
|
|
11600
|
+
process.exit(result.status ?? 1);
|
|
11601
|
+
}
|
|
11602
|
+
const check = spawnSync("zalify", ["--version"], { encoding: "utf8" });
|
|
11603
|
+
const updated = check.stdout?.trim();
|
|
11604
|
+
console.log(updated && updated !== currentVersion ? `
|
|
11605
|
+
✓ Updated ${currentVersion} → ${updated}` : `
|
|
11606
|
+
✓ Done${updated ? ` (version: ${updated})` : ""}`);
|
|
11607
|
+
}
|
|
11608
|
+
|
|
11558
11609
|
// src/cli.ts
|
|
11559
11610
|
var __dirname4 = dirname(fileURLToPath3(import.meta.url));
|
|
11560
11611
|
var require2 = createRequire2(import.meta.url);
|
|
11561
11612
|
var pkg = require2(join3(__dirname4, "..", "package.json"));
|
|
11613
|
+
try {
|
|
11614
|
+
updateNotifier({ pkg }).notify({
|
|
11615
|
+
isGlobal: true,
|
|
11616
|
+
message: "Update available {currentVersion} → {latestVersion}\nRun `zalify self-update`"
|
|
11617
|
+
});
|
|
11618
|
+
} catch {}
|
|
11562
11619
|
var program2 = new Command;
|
|
11563
11620
|
program2.name("zalify").description("Zalify CLI - command-line interface for Zalify").version(pkg.version, "-v, --version", "output the current version");
|
|
11564
11621
|
program2.command("version").description("Print Zalify CLI version and check for updates").action(async () => {
|
|
@@ -11581,6 +11638,7 @@ A new version (${update.latest}) is available. Run "npm i -g @zalify/cli@latest"
|
|
|
11581
11638
|
}
|
|
11582
11639
|
} catch {}
|
|
11583
11640
|
});
|
|
11641
|
+
program2.command("self-update").description("Update the CLI to the latest version (auto-detects pnpm/bun/npm)").action(() => selfUpdate(pkg.version));
|
|
11584
11642
|
program2.command("login").description("Authenticate via the browser and store a workspace API key").option("--app-url <url>", "Zalify app origin (default: https://app.zalify.com)").action(async (options) => {
|
|
11585
11643
|
await login(options);
|
|
11586
11644
|
});
|