@vizamodo/viza-cli 1.2.9 → 1.2.14
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/src/core/dispatch.js +11 -1
- package/dist/src/core/version.js +100 -2
- package/package.json +2 -2
- package/dist/src/index.js +0 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { dispatcherDispatch, } from "@vizamodo/viza-dispatcher";
|
|
2
|
+
import chalk from "chalk";
|
|
2
3
|
import { startSpinner, stopSpinner } from "../ui/spinner.js";
|
|
3
4
|
import { renderLog } from "../ui/logRenderer.js";
|
|
4
5
|
import { showDispatchBanner } from "../ui/banner.js";
|
|
5
|
-
import { getCliVersion } from "./version.js";
|
|
6
|
+
import { getCliVersion, checkForCliUpdateSoft } from "./version.js";
|
|
6
7
|
/**
|
|
7
8
|
* KISS log rendering.
|
|
8
9
|
* - success + hide => no log
|
|
@@ -49,6 +50,15 @@ export async function dispatchIntentAndWait(input, opts = {}) {
|
|
|
49
50
|
showDispatchBanner(input, meta);
|
|
50
51
|
const handle = await dispatchIntent(input, mode);
|
|
51
52
|
const spinner = startSpinner("Waiting for dispatch session");
|
|
53
|
+
// Fast update check (kept before wait/log so the hint is not lost)
|
|
54
|
+
const updateInfo = await checkForCliUpdateSoft().catch(() => null);
|
|
55
|
+
if (updateInfo?.hasUpdate) {
|
|
56
|
+
const title = chalk.gray.bold("⬆️ Update available");
|
|
57
|
+
const ver = chalk.yellow(`${updateInfo.current} → ${updateInfo.latest}`);
|
|
58
|
+
const cmd = chalk.cyan("npm i -g @vizamodo/viza-cli");
|
|
59
|
+
console.log(`\n${title} ${ver}`);
|
|
60
|
+
console.log(chalk.dim(" Run:") + " " + cmd + "\n");
|
|
61
|
+
}
|
|
52
62
|
try {
|
|
53
63
|
const result = await handle.wait();
|
|
54
64
|
stopSpinner(spinner, result.status === "success" ? "✅ Done" : "❌ Failed");
|
package/dist/src/core/version.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { resolve, join, dirname } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
+
import os from "node:os";
|
|
4
5
|
let _cached;
|
|
5
6
|
/**
|
|
6
7
|
* Returns the current viza-cli version.
|
|
@@ -51,3 +52,100 @@ export function getCliVersion() {
|
|
|
51
52
|
_cached = "dev";
|
|
52
53
|
return _cached;
|
|
53
54
|
}
|
|
55
|
+
function resolveVizaConfigDir() {
|
|
56
|
+
if (process.platform === "win32") {
|
|
57
|
+
const appData = process.env.APPDATA || join(process.env.USERPROFILE || "", "AppData", "Roaming");
|
|
58
|
+
return join(appData, "viza");
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return join(os.homedir(), ".config", "viza");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function resolveUpdateCachePath() {
|
|
65
|
+
const configDir = resolveVizaConfigDir();
|
|
66
|
+
return join(configDir, "update.json");
|
|
67
|
+
}
|
|
68
|
+
function semverCompare(a, b) {
|
|
69
|
+
// minimal semver compare for x.y.z numeric only
|
|
70
|
+
const parse = (v) => {
|
|
71
|
+
const parts = v.split(".");
|
|
72
|
+
if (parts.length !== 3)
|
|
73
|
+
return null;
|
|
74
|
+
const nums = parts.map(p => {
|
|
75
|
+
const n = Number(p);
|
|
76
|
+
return Number.isNaN(n) ? null : n;
|
|
77
|
+
});
|
|
78
|
+
if (nums.includes(null))
|
|
79
|
+
return null;
|
|
80
|
+
return nums;
|
|
81
|
+
};
|
|
82
|
+
const pa = parse(a);
|
|
83
|
+
const pb = parse(b);
|
|
84
|
+
if (!pa || !pb) {
|
|
85
|
+
// fallback to string compare
|
|
86
|
+
if (a === b)
|
|
87
|
+
return 0;
|
|
88
|
+
return a > b ? 1 : -1;
|
|
89
|
+
}
|
|
90
|
+
for (let i = 0; i < 3; i++) {
|
|
91
|
+
if (pa[i] > pb[i])
|
|
92
|
+
return 1;
|
|
93
|
+
if (pa[i] < pb[i])
|
|
94
|
+
return -1;
|
|
95
|
+
}
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Checks npm for the latest published version of @vizamodo/viza-cli without throwing and without blocking the main flow.
|
|
100
|
+
*
|
|
101
|
+
* Returns null on failure.
|
|
102
|
+
*/
|
|
103
|
+
export async function checkForCliUpdateSoft() {
|
|
104
|
+
const cachePath = resolveUpdateCachePath();
|
|
105
|
+
const now = Date.now();
|
|
106
|
+
const ttl = 3 * 60 * 60 * 1000; // 3 hours
|
|
107
|
+
try {
|
|
108
|
+
if (existsSync(cachePath)) {
|
|
109
|
+
const raw = readFileSync(cachePath, "utf8");
|
|
110
|
+
const cached = JSON.parse(raw);
|
|
111
|
+
if (cached.checkedAt && (now - cached.checkedAt) < ttl) {
|
|
112
|
+
return cached;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// ignore cache read errors
|
|
118
|
+
}
|
|
119
|
+
const current = getCliVersion();
|
|
120
|
+
try {
|
|
121
|
+
const res = await fetch("https://registry.npmjs.org/@vizamodo/viza-cli/latest", { cache: "no-store" });
|
|
122
|
+
if (!res.ok)
|
|
123
|
+
return null;
|
|
124
|
+
const json = await res.json();
|
|
125
|
+
const latest = json.version;
|
|
126
|
+
if (!latest || typeof latest !== "string")
|
|
127
|
+
return null;
|
|
128
|
+
const cmp = semverCompare(latest, current);
|
|
129
|
+
const hasUpdate = cmp > 0;
|
|
130
|
+
const info = {
|
|
131
|
+
current,
|
|
132
|
+
latest,
|
|
133
|
+
hasUpdate,
|
|
134
|
+
checkedAt: now,
|
|
135
|
+
};
|
|
136
|
+
try {
|
|
137
|
+
const configDir = dirname(cachePath);
|
|
138
|
+
if (!existsSync(configDir)) {
|
|
139
|
+
mkdirSync(configDir, { recursive: true });
|
|
140
|
+
}
|
|
141
|
+
writeFileSync(cachePath, JSON.stringify(info), "utf8");
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// ignore write errors
|
|
145
|
+
}
|
|
146
|
+
return info;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizamodo/viza-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Viza unified command line interface",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"release:prod": "rm -rf dist && npx npm-check-updates -u && npm install && git add package.json package-lock.json && git commit -m 'chore(deps): auto update dependencies before release' || echo 'No changes' && node versioning.js && npm login && npm publish --tag latest --access public && git push"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@vizamodo/viza-dispatcher": "^1.4.
|
|
19
|
+
"@vizamodo/viza-dispatcher": "^1.4.33",
|
|
20
20
|
"adm-zip": "^0.5.16",
|
|
21
21
|
"chalk": "^5.6.2",
|
|
22
22
|
"commander": "^14.0.2",
|
package/dist/src/index.js
DELETED