@4pm/cli 0.2.1 → 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/index.js +74 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3930,7 +3930,7 @@ MCowBQYDK2VwAyEARlfzjaFhe5bhRrMp/ZuH6sVqg/S7f8B1dliuF21iDTw=
|
|
|
3930
3930
|
`;
|
|
3931
3931
|
|
|
3932
3932
|
// src/version.ts
|
|
3933
|
-
var CLI_VERSION = "0.2.
|
|
3933
|
+
var CLI_VERSION = "0.2.2";
|
|
3934
3934
|
|
|
3935
3935
|
// src/core/update.ts
|
|
3936
3936
|
function compareSemver(a, b) {
|
|
@@ -3978,6 +3978,27 @@ async function updateViaDownload(tarballUrl, checksum, signature) {
|
|
|
3978
3978
|
stdio: "inherit"
|
|
3979
3979
|
});
|
|
3980
3980
|
}
|
|
3981
|
+
async function updateToLatest(serverUrl) {
|
|
3982
|
+
const meta = await fetchCliVersion(serverUrl);
|
|
3983
|
+
if (compareSemver(CLI_VERSION, meta.latest) >= 0) {
|
|
3984
|
+
return { action: "already-latest", version: CLI_VERSION };
|
|
3985
|
+
}
|
|
3986
|
+
console.log(`Updating ${CLI_VERSION} \u2192 ${meta.latest}\u2026`);
|
|
3987
|
+
try {
|
|
3988
|
+
if (installedViaNpm()) {
|
|
3989
|
+
updateViaNpm(meta.latest);
|
|
3990
|
+
} else {
|
|
3991
|
+
await updateViaDownload(
|
|
3992
|
+
meta.source.tarballUrl,
|
|
3993
|
+
meta.source.checksum,
|
|
3994
|
+
meta.source.signature
|
|
3995
|
+
);
|
|
3996
|
+
}
|
|
3997
|
+
return { action: "updated", version: meta.latest };
|
|
3998
|
+
} catch (err) {
|
|
3999
|
+
return { action: "failed", error: String(err) };
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
3981
4002
|
async function checkAndUpdate(serverUrl, autoUpdate) {
|
|
3982
4003
|
let meta;
|
|
3983
4004
|
try {
|
|
@@ -5176,6 +5197,47 @@ function runUnlink(profileDir2, profileName) {
|
|
|
5176
5197
|
console.log("\u2714 Deleted .cre \u2014 revoke the server-side link at web /machines.");
|
|
5177
5198
|
}
|
|
5178
5199
|
|
|
5200
|
+
// src/commands/update.ts
|
|
5201
|
+
async function runUpdate(profileDir2, profileName, serverUrlFlag) {
|
|
5202
|
+
const serverUrl = (serverUrlFlag ?? readCredential(profileDir2, profileName)?.serverUrl ?? process.env.FOURPM_SERVER ?? "http://localhost:3001").replace(/\/$/, "");
|
|
5203
|
+
let result;
|
|
5204
|
+
try {
|
|
5205
|
+
result = await updateToLatest(serverUrl);
|
|
5206
|
+
} catch (err) {
|
|
5207
|
+
console.error(`Could not check for updates: ${err}`);
|
|
5208
|
+
process.exitCode = 1;
|
|
5209
|
+
return;
|
|
5210
|
+
}
|
|
5211
|
+
switch (result.action) {
|
|
5212
|
+
case "already-latest":
|
|
5213
|
+
console.log(`Already up to date (${result.version}).`);
|
|
5214
|
+
break;
|
|
5215
|
+
case "updated":
|
|
5216
|
+
console.log(`\u2714 Updated to ${result.version}. Run \`4pm start\` to reconnect.`);
|
|
5217
|
+
break;
|
|
5218
|
+
case "failed":
|
|
5219
|
+
console.error(`Update failed: ${result.error}`);
|
|
5220
|
+
process.exitCode = 1;
|
|
5221
|
+
break;
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5225
|
+
// src/commands/version.ts
|
|
5226
|
+
async function runVersion(profileDir2, profileName, serverUrlFlag) {
|
|
5227
|
+
console.log(`4pm cli ${CLI_VERSION}`);
|
|
5228
|
+
const serverUrl = serverUrlFlag ?? readCredential(profileDir2, profileName)?.serverUrl ?? process.env.FOURPM_SERVER;
|
|
5229
|
+
if (!serverUrl) return;
|
|
5230
|
+
try {
|
|
5231
|
+
const meta = await fetchCliVersion(serverUrl.replace(/\/$/, ""));
|
|
5232
|
+
const outdated = compareSemver(CLI_VERSION, meta.latest) < 0;
|
|
5233
|
+
const hint = outdated ? " (update available \u2014 run `4pm update`)" : " (up to date)";
|
|
5234
|
+
console.log(`latest: ${meta.latest}${hint}`);
|
|
5235
|
+
console.log(`minSupported: ${meta.minSupported}`);
|
|
5236
|
+
} catch (err) {
|
|
5237
|
+
console.warn(`Could not reach the server for the latest version: ${err}`);
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
|
|
5179
5241
|
// src/index.ts
|
|
5180
5242
|
function flagValue(args, name) {
|
|
5181
5243
|
const index = args.indexOf(`--${name}`);
|
|
@@ -5197,6 +5259,15 @@ async function main() {
|
|
|
5197
5259
|
case "unlink":
|
|
5198
5260
|
runUnlink(dir, profileName);
|
|
5199
5261
|
break;
|
|
5262
|
+
case "version":
|
|
5263
|
+
case "--version":
|
|
5264
|
+
case "-v":
|
|
5265
|
+
await runVersion(dir, profileName, flagValue(rest, "server"));
|
|
5266
|
+
break;
|
|
5267
|
+
case "update":
|
|
5268
|
+
case "upgrade":
|
|
5269
|
+
await runUpdate(dir, profileName, flagValue(rest, "server"));
|
|
5270
|
+
break;
|
|
5200
5271
|
default:
|
|
5201
5272
|
console.log(
|
|
5202
5273
|
[
|
|
@@ -5206,6 +5277,8 @@ async function main() {
|
|
|
5206
5277
|
" 4pm [--profile <name>] link [--server URL] Pair with the server (hashcode 1\u21922\u21923)",
|
|
5207
5278
|
" 4pm [--profile <name>] start Connect WS, receive commands from the server",
|
|
5208
5279
|
" 4pm [--profile <name>] unlink Delete the local credential (.cre)",
|
|
5280
|
+
" 4pm version [--server URL] Show the installed version (+ latest from the server)",
|
|
5281
|
+
" 4pm update [--server URL] Update to the latest version now",
|
|
5209
5282
|
"",
|
|
5210
5283
|
"Without --profile \u21D2 the `default` profile (ADR-0014)."
|
|
5211
5284
|
].join("\n")
|