From 003ae71fc0a747828831f24644b6cfb769245038 Mon Sep 17 00:00:00 2001 From: smoratino-apogea <> Date: Mon, 6 Apr 2026 13:33:34 +0200 Subject: [PATCH] feat: add update notification to CLI for available package updates --- src/cli/index.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index 46d9fa5..5e01b6f 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -10,7 +10,28 @@ import { localServerCommand } from './commands/local-server'; import { createTestsCommand } from './commands/create-tests'; import { serveTestsCommand } from './commands/serve-tests'; -const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')); +const pkg = JSON.parse( + readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'), +); + +let updateMessage: string | undefined; + +fetch('https://registry.npmjs.org/thatopen-services/latest', { + signal: AbortSignal.timeout(3000), +}) + .then((res) => res.ok && res.json()) + .then((data) => { + if (data?.version && data.version !== pkg.version) { + updateMessage = + `\n ⚠ Update available: ${pkg.version} → ${data.version}` + + `\n Run "npm install -g thatopen-services@latest" to update.\n`; + } + }) + .catch(() => {}); + +process.on('exit', () => { + if (updateMessage) console.log(updateMessage); +}); const program = new Command();