The v3→v4 migration was only renaming upsList to upsDevices without
transforming the device structure. V3 had a flat structure with SNMP
fields directly on the device object, while v4 expects a nested 'snmp'
object.
This commit fixes the migration to:
- Move host, port, community, version, etc. into nested snmp object
- Convert version from string to number
- Add default timeout (5000ms)
- Create thresholds object with defaults
- Preserve all SNMPv1, v2c, and v3 authentication fields
Also includes install.sh fix for better non-interactive handling.
- Create abstract BaseMigration class with order, shouldRun(), migrate()
- Add MigrationRunner to execute migrations in order
- Add Migration v1→v2 (snmp → upsDevices)
- Add Migration v3→v4 (upsList → upsDevices)
- Update INupstConfig with version field
- Update loadConfig() to run migrations automatically
- Update saveConfig() to ensure version field and remove legacy fields
- Update Docker test scripts to use real UPS data from .nogit/env.json
- Remove colors.bright (not available in @std/fmt/colors)
Config migrations allow users to jump versions (e.g., v1→v4) with all
intermediate migrations running automatically. Version field tracks
config format for future migrations.
Major improvements:
- Created color theme system (ts/colors.ts) with ANSI colors
- Enhanced logger with colors, table formatting, and styled boxes
- Fixed daemon exit bug - now stays running when no UPS configured
- Added config hot-reload with file watcher for live updates
- Beautified CLI help output with color-coded commands
- Added showcase test demonstrating all output features
- Fixed ANSI code handling for perfect table/box alignment
Features:
- Color-coded messages (success=green, error=red, warning=yellow, info=cyan)
- Status symbols (●○◐◯ for running/stopped/starting/unknown)
- Battery level colors (green>60%, yellow 30-60%, red<30%)
- Table formatting with auto-sizing and column alignment
- Styled boxes (success, error, warning, info styles)
- Hot-reload: daemon watches config file and reloads automatically
- Idle mode: daemon stays alive when no devices, checks periodically
Daemon improvements:
- No longer exits when no UPS devices configured
- Enters idle monitoring loop waiting for config
- File watcher detects config changes in real-time
- Auto-reloads and starts monitoring when devices added
- Logs warnings instead of errors for missing devices
Technical fixes:
- Strip ANSI codes when calculating text width for alignment
- Use visible length for padding calculations in tables and boxes
- Properly handle colored text in table cells and box lines
Breaking changes: None (backward compatible)
Critical fixes for v3→v4 migration:
1. install.sh: Auto-update systemd service file during migration
- Calls 'nupst service enable' before restarting service
- Only when migrating from v3 (OLD_NODE_INSTALL=1)
- Ensures service file has correct v4 paths
2. ts/systemd.ts: Fix hardcoded v3 paths in service template
- ExecStart: /opt/nupst/bin/nupst daemon-start (v3, broken)
→ /usr/local/bin/nupst service start-daemon (v4, correct)
- Description: Updated to 'Deno-powered UPS Monitoring Tool'
- Added RestartSec=10 (prevent rapid restart loops)
- Removed NODE_ENV=production (not needed for Deno)
- WorkingDirectory: /tmp → /opt/nupst
Without these fixes:
- Service fails to start after migration
- Service file points to non-existent /opt/nupst/bin/nupst
- Users must manually run 'nupst service enable'
Discovered via Docker migration testing in test/manualdocker/
- Replace hardcoded version in 00_commitinfo_data.ts
- Now dynamically imports deno.json and reads version
- Version will auto-update when deno.json is changed
- Fixes version showing 3.1.2 instead of 4.0.0
test: add Docker test scripts for v3→v4 migration
- 01-setup-v3-container.sh: Creates systemd container with v3
- 02-test-v3-to-v4-migration.sh: Tests migration (now fixed)
- 03-cleanup.sh: Removes test container
- README.md: Complete documentation
Tested: Version now correctly shows 4.0.0
- Remove async from functions that don't use await
- Change return types from Promise<void> to void for synchronous functions
- Fixes all 8 require-await lint warnings
- Reduces total lint warnings from 63 to 55
Comprehensive type safety improvements across all CLI handlers and daemon:
**Error handling type fixes:**
- Add 'error instanceof Error' checks before accessing error.message throughout
- Fix all error/retryError/stdError/upsError type assertions
- Replace direct error.message with proper type guards
**Switch case improvements:**
- Wrap case block declarations in braces to satisfy deno-lint
- Fix no-case-declarations warnings in CLI command handlers
**Null/undefined safety:**
- Add checks for config.snmp and config.thresholds before access
- Fix IUpsStatus lastStatusChange to handle undefined with default value
- Add proper null checks in legacy configuration paths
**Type annotations:**
- Add explicit type annotations to lambda parameters (groupId, updateAvailable, etc.)
- Add TUpsModel type cast for 'cyberpower' default
- Import and use INupstConfig type where needed
**Parameter type fixes:**
- Fix implicit 'any' type errors in array callbacks
- Add type annotations to filter/find/map parameters
Files modified:
- ts/cli.ts: config.snmp/thresholds null checks, unused error variable fixes
- ts/cli/group-handler.ts: 4 error.message fixes + 2 parameter type annotations
- ts/cli/service-handler.ts: 3 error.message fixes
- ts/cli/ups-handler.ts: 5 error.message fixes + config checks + TUpsModel import
- ts/daemon.ts: 8 error.message fixes + IUpsStatus lastStatusChange fix + updateAvailable type
- ts/nupst.ts: 1 error.message fix
- ts/systemd.ts: 5 error.message fixes + parameter type annotation
All tests passing (3/3 SNMP tests + 10/10 logger tests)
Type check: ✓ No errors
- Add Buffer import from node:buffer to manager.ts and types.ts
- Fix error handling type assertions (error/retryError/stdError as unknown)
- Add explicit type annotation to byte parameter in isPrintableAscii check
- All tests now passing (3 SNMP tests + 10 logger tests)
Major Changes:
- Reorganized commands into logical groups (service, ups, group)
- Added new subcommand structure:
- nupst service <enable|disable|start|stop|restart|status|logs|start-daemon>
- nupst ups <add|edit|remove|list|test>
- nupst group <add|edit|remove|list>
- nupst config [show]
- Added --version/-v flag support
- Added restart subcommand for service
- Added command aliases (ls, rm)
- Renamed delete() to remove() in handlers
- Maintained backward compatibility with deprecation warnings
- Updated all help messages to reflect new structure
- Added showVersion(), showServiceHelp(), showUpsHelp() methods
- Fixed readline imports to use node:readline
Breaking Changes:
- Old command format (e.g. 'nupst add') is deprecated
- Users should migrate to new format (e.g. 'nupst ups add')
- Backward compatibility maintained with warnings for now
- Created deno.json configuration
- Updated all imports to use npm:net-snmp@3.20.0
- Changed all Node.js built-in imports to node: specifiers
- Updated all .js extensions to .ts in imports
- Created mod.ts as Deno entry point
- Ready for Phase 3: CLI simplification