feat(cli): show changelog entries before running upgrades

This commit is contained in:
2026-04-16 13:09:21 +00:00
parent 6b2fa65611
commit ba4e56338c
8 changed files with 493 additions and 897 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/nupst',
version: '5.10.0',
version: '5.11.0',
description: 'Network UPS Shutdown Tool - Monitor SNMP-enabled UPS devices and orchestrate graceful system shutdowns during power emergencies'
}
+38 -2
View File
@@ -1,13 +1,14 @@
import process from 'node:process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { execSync } from 'node:child_process';
import { execFileSync, execSync } from 'node:child_process';
import { Nupst } from '../nupst.ts';
import { logger } from '../logger.ts';
import { theme } from '../colors.ts';
import { PAUSE } from '../constants.ts';
import type { IPauseState } from '../pause-state.ts';
import * as helpers from '../helpers/index.ts';
import { renderUpgradeChangelog } from '../upgrade-changelog.ts';
/**
* Class for handling service-related CLI commands
@@ -270,7 +271,7 @@ export class ServiceHandler {
// Fetch latest version from Gitea API
const apiUrl = 'https://code.foss.global/api/v1/repos/serve.zone/nupst/releases/latest';
const response = execSync(`curl -sSL ${apiUrl}`).toString();
const response = this.fetchRemoteText(apiUrl);
const release = JSON.parse(response);
const latestVersion = release.tag_name; // e.g., "v4.0.7"
@@ -294,6 +295,7 @@ export class ServiceHandler {
}
logger.info(`New version available: ${latestVersion}`);
this.showUpgradeChangelog(normalizedCurrent, normalizedLatest);
logger.dim('Downloading and installing...');
console.log('');
@@ -321,6 +323,40 @@ export class ServiceHandler {
}
}
private fetchRemoteText(url: string): string {
return execFileSync('curl', ['-fsSL', url], {
encoding: 'utf8',
});
}
private showUpgradeChangelog(currentVersion: string, latestVersion: string): void {
const changelogUrl = 'https://code.foss.global/serve.zone/nupst/raw/branch/main/changelog.md';
try {
const changelogMarkdown = this.fetchRemoteText(changelogUrl);
const renderedChanges = renderUpgradeChangelog(
changelogMarkdown,
currentVersion,
latestVersion,
);
if (!renderedChanges) {
return;
}
logger.info(`What's changed:`);
logger.log('');
for (const line of renderedChanges.split('\n')) {
logger.log(line);
}
logger.log('');
} catch (error) {
logger.warn('Could not load changelog for this upgrade. Continuing anyway.');
logger.dim(`${error instanceof Error ? error.message : String(error)}`);
logger.log('');
}
}
/**
* Completely uninstall NUPST from the system
*/
+16
View File
@@ -0,0 +1,16 @@
import { SmartChangelog } from 'npm:@push.rocks/smartchangelog@^0.1.0';
export const renderUpgradeChangelog = (
changelogMarkdown: string,
currentVersion: string,
latestVersion: string,
): string => {
const changelog = SmartChangelog.fromMarkdown(changelogMarkdown);
const entries = changelog.getEntriesBetween(currentVersion, latestVersion);
if (entries.length === 0) {
return '';
}
return entries.map((entry) => entry.toCliString()).join('\n\n');
};