@zerodeploy/cli 0.1.14 → 0.1.15
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/README.md +44 -584
- package/dist/cli.js +83 -14
- package/package.json +1 -1
- package/dist/index.js +0 -6915
package/dist/cli.js
CHANGED
|
@@ -7085,7 +7085,7 @@ var deployPromoteCommand = new Command2("promote").description("Promote a previe
|
|
|
7085
7085
|
});
|
|
7086
7086
|
|
|
7087
7087
|
// src/lib/version.ts
|
|
7088
|
-
var VERSION = "0.1.
|
|
7088
|
+
var VERSION = "0.1.15";
|
|
7089
7089
|
|
|
7090
7090
|
// src/commands/deploy/index.ts
|
|
7091
7091
|
function slugify(input) {
|
|
@@ -8612,11 +8612,10 @@ function createInspectCommand(rootProgram) {
|
|
|
8612
8612
|
});
|
|
8613
8613
|
}
|
|
8614
8614
|
|
|
8615
|
-
// src/
|
|
8616
|
-
|
|
8615
|
+
// src/commands/update.ts
|
|
8616
|
+
import { execSync } from "child_process";
|
|
8617
8617
|
|
|
8618
8618
|
// src/lib/update-check.ts
|
|
8619
|
-
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
8620
8619
|
import { homedir } from "os";
|
|
8621
8620
|
import { join as join2 } from "path";
|
|
8622
8621
|
var PACKAGE_NAME = "@zerodeploy/cli";
|
|
@@ -8635,11 +8634,80 @@ function compareVersions(current, latest) {
|
|
|
8635
8634
|
}
|
|
8636
8635
|
return 0;
|
|
8637
8636
|
}
|
|
8637
|
+
async function fetchLatestVersion() {
|
|
8638
|
+
try {
|
|
8639
|
+
const controller = new AbortController;
|
|
8640
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
8641
|
+
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
|
|
8642
|
+
signal: controller.signal,
|
|
8643
|
+
headers: { Accept: "application/json" }
|
|
8644
|
+
});
|
|
8645
|
+
clearTimeout(timeout);
|
|
8646
|
+
if (!res.ok)
|
|
8647
|
+
return null;
|
|
8648
|
+
const data = await res.json();
|
|
8649
|
+
return data.version || null;
|
|
8650
|
+
} catch {
|
|
8651
|
+
return null;
|
|
8652
|
+
}
|
|
8653
|
+
}
|
|
8654
|
+
|
|
8655
|
+
// src/commands/update.ts
|
|
8656
|
+
var updateCommand = new Command2("update").description("Update ZeroDeploy CLI to the latest version").action(async () => {
|
|
8657
|
+
console.log(`Current version: ${VERSION}`);
|
|
8658
|
+
console.log("Checking for updates...");
|
|
8659
|
+
const latest = await fetchLatestVersion();
|
|
8660
|
+
if (!latest) {
|
|
8661
|
+
console.error("Failed to check for updates. Please try again later.");
|
|
8662
|
+
process.exit(6);
|
|
8663
|
+
}
|
|
8664
|
+
if (compareVersions(VERSION, latest) >= 0) {
|
|
8665
|
+
console.log(`Already up to date (${VERSION}).`);
|
|
8666
|
+
return;
|
|
8667
|
+
}
|
|
8668
|
+
console.log(`New version available: ${latest}`);
|
|
8669
|
+
console.log(`Updating...
|
|
8670
|
+
`);
|
|
8671
|
+
try {
|
|
8672
|
+
execSync("npm update -g @zerodeploy/cli", { stdio: "inherit" });
|
|
8673
|
+
console.log(`
|
|
8674
|
+
Updated to ${latest}.`);
|
|
8675
|
+
} catch {
|
|
8676
|
+
console.error(`
|
|
8677
|
+
Update failed. Try manually:`);
|
|
8678
|
+
console.error(" npm update -g @zerodeploy/cli");
|
|
8679
|
+
process.exit(1);
|
|
8680
|
+
}
|
|
8681
|
+
});
|
|
8682
|
+
|
|
8683
|
+
// src/lib/version.ts
|
|
8684
|
+
var VERSION2 = "0.1.15";
|
|
8685
|
+
|
|
8686
|
+
// src/lib/update-check.ts
|
|
8687
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
8688
|
+
import { homedir as homedir2 } from "os";
|
|
8689
|
+
import { join as join3 } from "path";
|
|
8690
|
+
var PACKAGE_NAME2 = "@zerodeploy/cli";
|
|
8691
|
+
var CACHE_FILE2 = join3(homedir2(), ".zerodeploy", "update-check.json");
|
|
8692
|
+
var CACHE_TTL_MS2 = 24 * 60 * 60 * 1000;
|
|
8693
|
+
function compareVersions2(current, latest) {
|
|
8694
|
+
const currentParts = current.split(".").map(Number);
|
|
8695
|
+
const latestParts = latest.split(".").map(Number);
|
|
8696
|
+
for (let i2 = 0;i2 < Math.max(currentParts.length, latestParts.length); i2++) {
|
|
8697
|
+
const a = currentParts[i2] || 0;
|
|
8698
|
+
const b = latestParts[i2] || 0;
|
|
8699
|
+
if (a < b)
|
|
8700
|
+
return -1;
|
|
8701
|
+
if (a > b)
|
|
8702
|
+
return 1;
|
|
8703
|
+
}
|
|
8704
|
+
return 0;
|
|
8705
|
+
}
|
|
8638
8706
|
function readCache() {
|
|
8639
8707
|
try {
|
|
8640
|
-
if (!existsSync3(
|
|
8708
|
+
if (!existsSync3(CACHE_FILE2))
|
|
8641
8709
|
return null;
|
|
8642
|
-
const data = JSON.parse(readFileSync2(
|
|
8710
|
+
const data = JSON.parse(readFileSync2(CACHE_FILE2, "utf-8"));
|
|
8643
8711
|
if (typeof data.latestVersion !== "string" || typeof data.checkedAt !== "number") {
|
|
8644
8712
|
return null;
|
|
8645
8713
|
}
|
|
@@ -8650,18 +8718,18 @@ function readCache() {
|
|
|
8650
8718
|
}
|
|
8651
8719
|
function writeCache(cache) {
|
|
8652
8720
|
try {
|
|
8653
|
-
const dir =
|
|
8721
|
+
const dir = join3(homedir2(), ".zerodeploy");
|
|
8654
8722
|
if (!existsSync3(dir)) {
|
|
8655
8723
|
mkdirSync(dir, { recursive: true });
|
|
8656
8724
|
}
|
|
8657
|
-
writeFileSync2(
|
|
8725
|
+
writeFileSync2(CACHE_FILE2, JSON.stringify(cache), "utf-8");
|
|
8658
8726
|
} catch {}
|
|
8659
8727
|
}
|
|
8660
|
-
async function
|
|
8728
|
+
async function fetchLatestVersion2() {
|
|
8661
8729
|
try {
|
|
8662
8730
|
const controller = new AbortController;
|
|
8663
8731
|
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
8664
|
-
const res = await fetch(`https://registry.npmjs.org/${
|
|
8732
|
+
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME2}/latest`, {
|
|
8665
8733
|
signal: controller.signal,
|
|
8666
8734
|
headers: { Accept: "application/json" }
|
|
8667
8735
|
});
|
|
@@ -8682,10 +8750,10 @@ async function checkForUpdates() {
|
|
|
8682
8750
|
const cache = readCache();
|
|
8683
8751
|
const now = Date.now();
|
|
8684
8752
|
let latestVersion = null;
|
|
8685
|
-
if (cache && now - cache.checkedAt <
|
|
8753
|
+
if (cache && now - cache.checkedAt < CACHE_TTL_MS2) {
|
|
8686
8754
|
latestVersion = cache.latestVersion;
|
|
8687
8755
|
} else {
|
|
8688
|
-
latestVersion = await
|
|
8756
|
+
latestVersion = await fetchLatestVersion2();
|
|
8689
8757
|
if (latestVersion) {
|
|
8690
8758
|
writeCache({ latestVersion, checkedAt: now });
|
|
8691
8759
|
} else if (cache) {
|
|
@@ -8694,14 +8762,14 @@ async function checkForUpdates() {
|
|
|
8694
8762
|
}
|
|
8695
8763
|
if (!latestVersion)
|
|
8696
8764
|
return;
|
|
8697
|
-
if (
|
|
8765
|
+
if (compareVersions2(VERSION, latestVersion) < 0) {
|
|
8698
8766
|
printUpdateBanner(latestVersion);
|
|
8699
8767
|
}
|
|
8700
8768
|
} catch {}
|
|
8701
8769
|
}
|
|
8702
8770
|
function printUpdateBanner(latestVersion) {
|
|
8703
8771
|
const message = `Update available: ${VERSION} → ${latestVersion}`;
|
|
8704
|
-
const command = "Run `
|
|
8772
|
+
const command = "Run `zerodeploy update` to update";
|
|
8705
8773
|
const width = Math.max(message.length, command.length) + 4;
|
|
8706
8774
|
const top = "╭" + "─".repeat(width) + "╮";
|
|
8707
8775
|
const bottom = "╰" + "─".repeat(width) + "╯";
|
|
@@ -8731,6 +8799,7 @@ program3.addCommand(tokenCommand);
|
|
|
8731
8799
|
program3.addCommand(billingCommand);
|
|
8732
8800
|
program3.addCommand(initCommand);
|
|
8733
8801
|
program3.addCommand(accountCommand);
|
|
8802
|
+
program3.addCommand(updateCommand);
|
|
8734
8803
|
program3.addCommand(createInspectCommand(program3));
|
|
8735
8804
|
await program3.parseAsync(process.argv);
|
|
8736
8805
|
await checkForUpdates();
|