qatools-cli 1.1.9 → 1.1.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/qatools.js +44 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qatools-cli",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "CLI for QA Tools — requirements, epics, sprints, sessions, App Context sync, project agenda. The companion to qa-tools.com.",
5
5
  "scripts": {
6
6
  "release": "npm version patch --no-git-tag-version && npm publish",
package/qatools.js CHANGED
@@ -129,6 +129,50 @@ program
129
129
  .description("CLI for QA Tools")
130
130
  .version(require("./package.json").version);
131
131
 
132
+ // Update nudge: before every command, print (from cache) if the installed CLI is behind npm,
133
+ // and refresh the cache in the background (throttled to once/day). sync can't upgrade the tool itself.
134
+ // Kept fully non-blocking and fail-open so it never slows or breaks a command (parse() is sync).
135
+ const VERSION_CACHE_FILE = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".qatools-version");
136
+ function cmpVersion(a, b) {
137
+ const pa = String(a).split(".").map(Number), pb = String(b).split(".").map(Number);
138
+ for (let i = 0; i < 3; i++) { const d = (pa[i] || 0) - (pb[i] || 0); if (d) return d < 0 ? -1 : 1; }
139
+ return 0;
140
+ }
141
+ function printUpdateNoticeFromCache() {
142
+ try {
143
+ const current = require("./package.json").version;
144
+ const cache = JSON.parse(fs.readFileSync(VERSION_CACHE_FILE, "utf8"));
145
+ if (cache.latest && cmpVersion(current, cache.latest) < 0) {
146
+ // stderr so it never corrupts parseable stdout (e.g. -o json output)
147
+ console.error(`\n⚠ qatools-cli ${current} → ${cache.latest} available. Upgrade: npm i -g qatools-cli@latest\n`);
148
+ }
149
+ } catch { /* no cache yet or unreadable — skip */ }
150
+ }
151
+ function refreshVersionCacheInBackground() {
152
+ try {
153
+ let cache = {};
154
+ try { cache = JSON.parse(fs.readFileSync(VERSION_CACHE_FILE, "utf8")); } catch { /* none */ }
155
+ if (cache.checkedAt && Date.now() - cache.checkedAt < 24 * 3600 * 1000) return; // throttled: at most once/day
156
+ const req = require("https").get("https://registry.npmjs.org/qatools-cli/latest", { timeout: 3000 }, (res) => {
157
+ let body = "";
158
+ res.on("data", (c) => (body += c));
159
+ res.on("end", () => {
160
+ try {
161
+ const latest = JSON.parse(body).version;
162
+ if (latest) fs.writeFileSync(VERSION_CACHE_FILE, JSON.stringify({ latest, checkedAt: Date.now() }));
163
+ } catch { /* malformed — skip */ }
164
+ });
165
+ });
166
+ req.on("error", () => {});
167
+ req.on("timeout", () => req.destroy());
168
+ if (req.unref) req.unref(); // don't keep the process alive for this
169
+ } catch { /* never block the command */ }
170
+ }
171
+ program.hook("preAction", () => {
172
+ printUpdateNoticeFromCache();
173
+ refreshVersionCacheInBackground();
174
+ });
175
+
132
176
  program
133
177
  .command("upload-analysis")
134
178
  .description("Upload a Claude analysis JSON to a test session")