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