Phase 1-2: Migrate to Deno with npm: and node: specifiers
- 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
This commit is contained in:
34
deno.json
Normal file
34
deno.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"name": "@serve.zone/nupst",
|
||||||
|
"version": "4.0.0",
|
||||||
|
"exports": "./mod.ts",
|
||||||
|
"tasks": {
|
||||||
|
"dev": "deno run --allow-all mod.ts",
|
||||||
|
"compile": "deno task compile:all",
|
||||||
|
"compile:all": "bash scripts/compile-all.sh",
|
||||||
|
"test": "deno test --allow-all tests/",
|
||||||
|
"check": "deno check mod.ts",
|
||||||
|
"fmt": "deno fmt",
|
||||||
|
"lint": "deno lint"
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"rules": {
|
||||||
|
"tags": ["recommended"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fmt": {
|
||||||
|
"useTabs": false,
|
||||||
|
"lineWidth": 100,
|
||||||
|
"indentWidth": 2,
|
||||||
|
"semiColons": true
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["deno.window"],
|
||||||
|
"strict": true
|
||||||
|
},
|
||||||
|
"imports": {
|
||||||
|
"@std/cli": "jsr:@std/cli@^1.0.0",
|
||||||
|
"@std/fmt": "jsr:@std/fmt@^1.0.0",
|
||||||
|
"@std/path": "jsr:@std/path@^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
44
mod.ts
Normal file
44
mod.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env -S deno run --allow-all
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NUPST - UPS Shutdown Tool
|
||||||
|
*
|
||||||
|
* A command-line tool for monitoring SNMP-enabled UPS devices and
|
||||||
|
* initiating system shutdown when power conditions are critical.
|
||||||
|
*
|
||||||
|
* Required Permissions:
|
||||||
|
* - --allow-net: SNMP communication with UPS devices
|
||||||
|
* - --allow-read: Read configuration files (/etc/nupst/config.json)
|
||||||
|
* - --allow-write: Write configuration files
|
||||||
|
* - --allow-run: Execute system commands (systemctl, shutdown, git, bash)
|
||||||
|
* - --allow-sys: Access system information (hostname, OS details)
|
||||||
|
* - --allow-env: Read environment variables
|
||||||
|
*
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { NupstCli } from './ts/cli.ts';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main entry point for the NUPST application
|
||||||
|
* Parses command-line arguments and executes the requested command
|
||||||
|
*/
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const cli = new NupstCli();
|
||||||
|
|
||||||
|
// Deno.args is already 0-indexed (unlike Node's process.argv which starts at index 2)
|
||||||
|
// We need to prepend placeholder args to match the existing CLI parser expectations
|
||||||
|
const args = ['deno', 'mod.ts', ...Deno.args];
|
||||||
|
|
||||||
|
await cli.parseAndExecute(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute main and handle errors
|
||||||
|
if (import.meta.main) {
|
||||||
|
try {
|
||||||
|
await main();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from "node:child_process";
|
||||||
import { Nupst } from './nupst.js';
|
import { Nupst } from './nupst.ts';
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling CLI commands
|
* Class for handling CLI commands
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Nupst } from '../nupst.js';
|
import { Nupst } from '../nupst.ts';
|
||||||
import { logger } from '../logger.js';
|
import { logger } from '../logger.ts';
|
||||||
import * as helpers from '../helpers/index.js';
|
import * as helpers from '../helpers/index.ts';
|
||||||
import { type IGroupConfig } from '../daemon.js';
|
import { type IGroupConfig } from '../daemon.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling group-related CLI commands
|
* Class for handling group-related CLI commands
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from "node:child_process";
|
||||||
import { Nupst } from '../nupst.js';
|
import { Nupst } from '../nupst.ts';
|
||||||
import { logger } from '../logger.js';
|
import { logger } from '../logger.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling service-related CLI commands
|
* Class for handling service-related CLI commands
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from "node:child_process";
|
||||||
import { Nupst } from '../nupst.js';
|
import { Nupst } from '../nupst.ts';
|
||||||
import { logger } from '../logger.js';
|
import { logger } from '../logger.ts';
|
||||||
import * as helpers from '../helpers/index.js';
|
import * as helpers from '../helpers/index.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling UPS-related CLI commands
|
* Class for handling UPS-related CLI commands
|
||||||
|
14
ts/daemon.ts
14
ts/daemon.ts
@@ -1,10 +1,10 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from "node:fs";
|
||||||
import * as path from 'path';
|
import * as path from "node:path";
|
||||||
import { exec, execFile } from 'child_process';
|
import { exec, execFile } from "node:child_process";
|
||||||
import { promisify } from 'util';
|
import { promisify } from "node:util";
|
||||||
import { NupstSnmp } from './snmp/manager.js';
|
import { NupstSnmp } from './snmp/manager.ts';
|
||||||
import type { ISnmpConfig } from './snmp/types.js';
|
import type { ISnmpConfig } from './snmp/types.ts';
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.ts';
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
|
@@ -1 +1 @@
|
|||||||
export * from './shortid.js';
|
export * from './shortid.ts';
|
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { NupstCli } from './cli.js';
|
import { NupstCli } from './cli.ts';
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point for NUPST
|
* Main entry point for NUPST
|
||||||
|
18
ts/nupst.ts
18
ts/nupst.ts
@@ -1,12 +1,12 @@
|
|||||||
import { NupstSnmp } from './snmp/manager.js';
|
import { NupstSnmp } from './snmp/manager.ts';
|
||||||
import { NupstDaemon } from './daemon.js';
|
import { NupstDaemon } from './daemon.ts';
|
||||||
import { NupstSystemd } from './systemd.js';
|
import { NupstSystemd } from './systemd.ts';
|
||||||
import { commitinfo } from './00_commitinfo_data.js';
|
import { commitinfo } from './00_commitinfo_data.ts';
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.ts';
|
||||||
import { UpsHandler } from './cli/ups-handler.js';
|
import { UpsHandler } from './cli/ups-handler.ts';
|
||||||
import { GroupHandler } from './cli/group-handler.js';
|
import { GroupHandler } from './cli/group-handler.ts';
|
||||||
import { ServiceHandler } from './cli/service-handler.js';
|
import { ServiceHandler } from './cli/service-handler.ts';
|
||||||
import * as https from 'https';
|
import * as https from "node:https";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Nupst class that coordinates all components
|
* Main Nupst class that coordinates all components
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Re-export all public types
|
// Re-export all public types
|
||||||
export type { IUpsStatus, IOidSet, TUpsModel, ISnmpConfig } from './types.js';
|
export type { IUpsStatus, IOidSet, TUpsModel, ISnmpConfig } from './types.ts';
|
||||||
|
|
||||||
// Re-export the SNMP manager class
|
// Re-export the SNMP manager class
|
||||||
export { NupstSnmp } from './manager.js';
|
export { NupstSnmp } from './manager.ts';
|
@@ -1,6 +1,6 @@
|
|||||||
import * as snmp from 'net-snmp';
|
import * as snmp from "npm:net-snmp@3.20.0";
|
||||||
import type { IOidSet, ISnmpConfig, TUpsModel, IUpsStatus } from './types.js';
|
import type { IOidSet, ISnmpConfig, TUpsModel, IUpsStatus } from './types.ts';
|
||||||
import { UpsOidSets } from './oid-sets.js';
|
import { UpsOidSets } from './oid-sets.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for SNMP communication with UPS devices
|
* Class for SNMP communication with UPS devices
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import type { IOidSet, TUpsModel } from './types.js';
|
import type { IOidSet, TUpsModel } from './types.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OID sets for different UPS models
|
* OID sets for different UPS models
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from "node:fs";
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from "node:child_process";
|
||||||
import { NupstDaemon } from './daemon.js';
|
import { NupstDaemon } from './daemon.ts';
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for managing systemd service
|
* Class for managing systemd service
|
||||||
|
Reference in New Issue
Block a user