@zerodeploy/cli 0.1.4 → 0.1.5
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 +155 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5940,6 +5940,53 @@ Error: Build failed`);
|
|
|
5940
5940
|
if (branch) {
|
|
5941
5941
|
deployPayload.branch = branch;
|
|
5942
5942
|
}
|
|
5943
|
+
if (!isPreview && commitSha) {
|
|
5944
|
+
const findRes = await client.orgs[":orgSlug"].sites[":siteSlug"].deployments["by-commit"][":commitSha"].$get({
|
|
5945
|
+
param: { orgSlug, siteSlug, commitSha }
|
|
5946
|
+
});
|
|
5947
|
+
if (findRes.ok) {
|
|
5948
|
+
const { data: existingDeployment } = await findRes.json();
|
|
5949
|
+
if (existingDeployment && existingDeployment.status === "ready") {
|
|
5950
|
+
console.log(`Found existing deployment for commit ${commitSha.slice(0, 8)}`);
|
|
5951
|
+
console.log("Promoting to production instead of re-uploading...");
|
|
5952
|
+
console.log("");
|
|
5953
|
+
const promoteRes = await client.deployments[":id"].rollback.$post({
|
|
5954
|
+
param: { id: existingDeployment.id }
|
|
5955
|
+
});
|
|
5956
|
+
if (!promoteRes.ok) {
|
|
5957
|
+
const body = await promoteRes.json();
|
|
5958
|
+
displayError(parseApiError(body));
|
|
5959
|
+
return;
|
|
5960
|
+
}
|
|
5961
|
+
const { data: promoteData } = await promoteRes.json();
|
|
5962
|
+
console.log("Deployment promoted!");
|
|
5963
|
+
if (options.githubOutput) {
|
|
5964
|
+
const domain = "zerodeploy.app";
|
|
5965
|
+
const deploymentUrl = `https://${siteSlug}.${domain}`;
|
|
5966
|
+
const previewUrl = `https://${promoteData.deployment.id.slice(0, 8)}-${siteSlug}.${domain}`;
|
|
5967
|
+
const githubOutputFile = process.env.GITHUB_OUTPUT;
|
|
5968
|
+
if (githubOutputFile) {
|
|
5969
|
+
const { appendFileSync } = await import("node:fs");
|
|
5970
|
+
appendFileSync(githubOutputFile, `deployment_id=${promoteData.deployment.id}
|
|
5971
|
+
`);
|
|
5972
|
+
appendFileSync(githubOutputFile, `deployment_url=${deploymentUrl}
|
|
5973
|
+
`);
|
|
5974
|
+
appendFileSync(githubOutputFile, `preview_url=${previewUrl}
|
|
5975
|
+
`);
|
|
5976
|
+
appendFileSync(githubOutputFile, `is_preview=false
|
|
5977
|
+
`);
|
|
5978
|
+
} else {
|
|
5979
|
+
console.log("");
|
|
5980
|
+
console.log("::set-output name=deployment_id::" + promoteData.deployment.id);
|
|
5981
|
+
console.log("::set-output name=deployment_url::" + deploymentUrl);
|
|
5982
|
+
console.log("::set-output name=preview_url::" + previewUrl);
|
|
5983
|
+
console.log("::set-output name=is_preview::false");
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5986
|
+
return;
|
|
5987
|
+
}
|
|
5988
|
+
}
|
|
5989
|
+
}
|
|
5943
5990
|
const createRes = await client.deployments.$post({
|
|
5944
5991
|
json: deployPayload
|
|
5945
5992
|
});
|
|
@@ -6814,8 +6861,10 @@ var accountCommand = new Command2("account").description("Manage your ZeroDeploy
|
|
|
6814
6861
|
}
|
|
6815
6862
|
}));
|
|
6816
6863
|
|
|
6864
|
+
// src/lib/version.ts
|
|
6865
|
+
var VERSION = "0.1.5";
|
|
6866
|
+
|
|
6817
6867
|
// src/commands/inspect.ts
|
|
6818
|
-
var VERSION = "0.1.3";
|
|
6819
6868
|
function getCommandByPath(rootCommand, path3) {
|
|
6820
6869
|
let current = rootCommand;
|
|
6821
6870
|
for (const name of path3) {
|
|
@@ -6893,7 +6942,7 @@ function generateExamples(cmd, fullPath) {
|
|
|
6893
6942
|
examples.push('zerodeploy site create acme "My Site"');
|
|
6894
6943
|
} else if (cmdName === "deploy") {
|
|
6895
6944
|
examples.push("zerodeploy deploy");
|
|
6896
|
-
examples.push("zerodeploy deploy
|
|
6945
|
+
examples.push("zerodeploy deploy web --org acme --dir ./dist");
|
|
6897
6946
|
}
|
|
6898
6947
|
return examples;
|
|
6899
6948
|
}
|
|
@@ -6941,9 +6990,110 @@ function createInspectCommand(rootProgram) {
|
|
|
6941
6990
|
});
|
|
6942
6991
|
}
|
|
6943
6992
|
|
|
6993
|
+
// src/lib/version.ts
|
|
6994
|
+
var VERSION2 = "0.1.5";
|
|
6995
|
+
|
|
6996
|
+
// src/lib/update-check.ts
|
|
6997
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
6998
|
+
import { homedir } from "os";
|
|
6999
|
+
import { join as join2 } from "path";
|
|
7000
|
+
var PACKAGE_NAME = "@zerodeploy/cli";
|
|
7001
|
+
var CACHE_FILE = join2(homedir(), ".zerodeploy", "update-check.json");
|
|
7002
|
+
var CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
7003
|
+
function compareVersions(current, latest) {
|
|
7004
|
+
const currentParts = current.split(".").map(Number);
|
|
7005
|
+
const latestParts = latest.split(".").map(Number);
|
|
7006
|
+
for (let i2 = 0;i2 < Math.max(currentParts.length, latestParts.length); i2++) {
|
|
7007
|
+
const a = currentParts[i2] || 0;
|
|
7008
|
+
const b = latestParts[i2] || 0;
|
|
7009
|
+
if (a < b)
|
|
7010
|
+
return -1;
|
|
7011
|
+
if (a > b)
|
|
7012
|
+
return 1;
|
|
7013
|
+
}
|
|
7014
|
+
return 0;
|
|
7015
|
+
}
|
|
7016
|
+
function readCache() {
|
|
7017
|
+
try {
|
|
7018
|
+
if (!existsSync3(CACHE_FILE))
|
|
7019
|
+
return null;
|
|
7020
|
+
const data = JSON.parse(readFileSync2(CACHE_FILE, "utf-8"));
|
|
7021
|
+
if (typeof data.latestVersion !== "string" || typeof data.checkedAt !== "number") {
|
|
7022
|
+
return null;
|
|
7023
|
+
}
|
|
7024
|
+
return data;
|
|
7025
|
+
} catch {
|
|
7026
|
+
return null;
|
|
7027
|
+
}
|
|
7028
|
+
}
|
|
7029
|
+
function writeCache(cache) {
|
|
7030
|
+
try {
|
|
7031
|
+
const dir = join2(homedir(), ".zerodeploy");
|
|
7032
|
+
if (!existsSync3(dir)) {
|
|
7033
|
+
mkdirSync(dir, { recursive: true });
|
|
7034
|
+
}
|
|
7035
|
+
writeFileSync2(CACHE_FILE, JSON.stringify(cache), "utf-8");
|
|
7036
|
+
} catch {}
|
|
7037
|
+
}
|
|
7038
|
+
async function fetchLatestVersion() {
|
|
7039
|
+
try {
|
|
7040
|
+
const controller = new AbortController;
|
|
7041
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
7042
|
+
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
|
|
7043
|
+
signal: controller.signal,
|
|
7044
|
+
headers: { Accept: "application/json" }
|
|
7045
|
+
});
|
|
7046
|
+
clearTimeout(timeout);
|
|
7047
|
+
if (!res.ok)
|
|
7048
|
+
return null;
|
|
7049
|
+
const data = await res.json();
|
|
7050
|
+
return data.version || null;
|
|
7051
|
+
} catch {
|
|
7052
|
+
return null;
|
|
7053
|
+
}
|
|
7054
|
+
}
|
|
7055
|
+
async function checkForUpdates() {
|
|
7056
|
+
if (process.env.CI || process.env.ZERODEPLOY_NO_UPDATE_CHECK) {
|
|
7057
|
+
return;
|
|
7058
|
+
}
|
|
7059
|
+
try {
|
|
7060
|
+
const cache = readCache();
|
|
7061
|
+
const now = Date.now();
|
|
7062
|
+
let latestVersion = null;
|
|
7063
|
+
if (cache && now - cache.checkedAt < CACHE_TTL_MS) {
|
|
7064
|
+
latestVersion = cache.latestVersion;
|
|
7065
|
+
} else {
|
|
7066
|
+
latestVersion = await fetchLatestVersion();
|
|
7067
|
+
if (latestVersion) {
|
|
7068
|
+
writeCache({ latestVersion, checkedAt: now });
|
|
7069
|
+
} else if (cache) {
|
|
7070
|
+
latestVersion = cache.latestVersion;
|
|
7071
|
+
}
|
|
7072
|
+
}
|
|
7073
|
+
if (!latestVersion)
|
|
7074
|
+
return;
|
|
7075
|
+
if (compareVersions(VERSION, latestVersion) < 0) {
|
|
7076
|
+
printUpdateBanner(latestVersion);
|
|
7077
|
+
}
|
|
7078
|
+
} catch {}
|
|
7079
|
+
}
|
|
7080
|
+
function printUpdateBanner(latestVersion) {
|
|
7081
|
+
const message = `Update available: ${VERSION} → ${latestVersion}`;
|
|
7082
|
+
const command = "Run `npm update -g @zerodeploy/cli` to update";
|
|
7083
|
+
const width = Math.max(message.length, command.length) + 4;
|
|
7084
|
+
const top = "╭" + "─".repeat(width) + "╮";
|
|
7085
|
+
const bottom = "╰" + "─".repeat(width) + "╯";
|
|
7086
|
+
const pad = (s) => "│ " + s.padEnd(width - 2) + "│";
|
|
7087
|
+
console.error("");
|
|
7088
|
+
console.error(top);
|
|
7089
|
+
console.error(pad(message));
|
|
7090
|
+
console.error(pad(command));
|
|
7091
|
+
console.error(bottom);
|
|
7092
|
+
}
|
|
7093
|
+
|
|
6944
7094
|
// src/index.ts
|
|
6945
7095
|
var program3 = new Command;
|
|
6946
|
-
program3.name("zerodeploy").description("ZeroDeploy CLI").version(
|
|
7096
|
+
program3.name("zerodeploy").description("ZeroDeploy CLI").version(VERSION2).enablePositionalOptions();
|
|
6947
7097
|
program3.addCommand(loginCommand);
|
|
6948
7098
|
program3.addCommand(logoutCommand);
|
|
6949
7099
|
program3.addCommand(whoamiCommand);
|
|
@@ -6960,4 +7110,5 @@ program3.addCommand(billingCommand);
|
|
|
6960
7110
|
program3.addCommand(initCommand);
|
|
6961
7111
|
program3.addCommand(accountCommand);
|
|
6962
7112
|
program3.addCommand(createInspectCommand(program3));
|
|
6963
|
-
program3.
|
|
7113
|
+
await program3.parseAsync(process.argv);
|
|
7114
|
+
await checkForUpdates();
|