fix(daemon): replace require() with ES6 imports for Deno compatibility
- Add proper ES6 imports at top of file for theme, symbols, colors - Remove all require() calls that were causing 'require is not defined' errors - Daemon now starts properly with modernized logging intact
This commit is contained in:
10
ts/daemon.ts
10
ts/daemon.ts
@@ -5,8 +5,9 @@ import { exec, execFile } from 'node:child_process';
|
|||||||
import { promisify } from 'node:util';
|
import { promisify } from 'node:util';
|
||||||
import { NupstSnmp } from './snmp/manager.ts';
|
import { NupstSnmp } from './snmp/manager.ts';
|
||||||
import type { ISnmpConfig } from './snmp/types.ts';
|
import type { ISnmpConfig } from './snmp/types.ts';
|
||||||
import { logger } from './logger.ts';
|
import { logger, type ITableColumn } from './logger.ts';
|
||||||
import { MigrationRunner } from './migrations/index.ts';
|
import { MigrationRunner } from './migrations/index.ts';
|
||||||
|
import { theme, symbols, getBatteryColor, getRuntimeColor, formatPowerStatus } from './colors.ts';
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
@@ -310,7 +311,6 @@ export class NupstDaemon {
|
|||||||
* Log the loaded configuration settings
|
* Log the loaded configuration settings
|
||||||
*/
|
*/
|
||||||
private logConfigLoaded(): void {
|
private logConfigLoaded(): void {
|
||||||
const { theme } = require('./colors.ts');
|
|
||||||
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
logger.logBoxTitle('Configuration Loaded', 70, 'success');
|
logger.logBoxTitle('Configuration Loaded', 70, 'success');
|
||||||
@@ -457,7 +457,6 @@ export class NupstDaemon {
|
|||||||
|
|
||||||
// Check if power status changed
|
// Check if power status changed
|
||||||
if (currentStatus && currentStatus.powerStatus !== status.powerStatus) {
|
if (currentStatus && currentStatus.powerStatus !== status.powerStatus) {
|
||||||
const { theme, formatPowerStatus } = require('./colors.ts');
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
logger.logBoxTitle(`Power Status Change: ${ups.name}`, 60, 'warning');
|
logger.logBoxTitle(`Power Status Change: ${ups.name}`, 60, 'warning');
|
||||||
logger.logBoxLine(`Previous: ${formatPowerStatus(currentStatus.powerStatus)}`);
|
logger.logBoxLine(`Previous: ${formatPowerStatus(currentStatus.powerStatus)}`);
|
||||||
@@ -493,9 +492,6 @@ export class NupstDaemon {
|
|||||||
logger.logBoxEnd();
|
logger.logBoxEnd();
|
||||||
logger.log('');
|
logger.log('');
|
||||||
|
|
||||||
// Import theme and symbols for coloring
|
|
||||||
const { theme, symbols, getBatteryColor, getRuntimeColor, formatPowerStatus } = require('./colors.ts');
|
|
||||||
|
|
||||||
// Build table data
|
// Build table data
|
||||||
const columns: Array<{ header: string; key: string; align?: 'left' | 'right'; color?: (val: string) => string }> = [
|
const columns: Array<{ header: string; key: string; align?: 'left' | 'right'; color?: (val: string) => string }> = [
|
||||||
{ header: 'UPS Name', key: 'name', align: 'left', color: theme.highlight },
|
{ header: 'UPS Name', key: 'name', align: 'left', color: theme.highlight },
|
||||||
@@ -799,8 +795,6 @@ export class NupstDaemon {
|
|||||||
const MAX_MONITORING_TIME = 5 * 60 * 1000; // Max 5 minutes of monitoring
|
const MAX_MONITORING_TIME = 5 * 60 * 1000; // Max 5 minutes of monitoring
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
const { theme, getBatteryColor, getRuntimeColor } = require('./colors.ts');
|
|
||||||
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
logger.logBoxTitle('Shutdown Monitoring Active', 60, 'warning');
|
logger.logBoxTitle('Shutdown Monitoring Active', 60, 'warning');
|
||||||
logger.logBoxLine(`Emergency threshold: ${EMERGENCY_RUNTIME_THRESHOLD} minutes runtime`);
|
logger.logBoxLine(`Emergency threshold: ${EMERGENCY_RUNTIME_THRESHOLD} minutes runtime`);
|
||||||
|
Reference in New Issue
Block a user