From f48635de8dafda352548a84f9f0e9aca63a4d366 Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Fri, 23 Feb 2024 16:48:37 +0500 Subject: [PATCH] fix: load env variables --- src/index.ts | 120 +++++++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 51 deletions(-) diff --git a/src/index.ts b/src/index.ts index c8b3620..b06a77c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,68 +1,86 @@ #!/usr/bin/env node -import 'websocket-polyfill'; -import yargs from 'yargs'; -import { hideBin } from 'yargs/helpers'; +import "websocket-polyfill"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; +import * as dotenv from "dotenv"; +dotenv.config(); // Load the environment variables -import { setup } from './commands/setup.js'; -import { addNsec } from './commands/add.js'; -import { start } from './commands/start.js'; +import { setup } from "./commands/setup.js"; +import { addNsec } from "./commands/add.js"; +import { start } from "./commands/start.js"; -const adminNpubs = process.env.ADMIN_NPUBS ? process.env.ADMIN_NPUBS.split(',') : []; +const adminNpubs = process.env.ADMIN_NPUBS + ? process.env.ADMIN_NPUBS.split(",") + : []; const argv = yargs(hideBin(process.argv)) - .command('setup', 'Setup nsecBunker', {}, (argv) => { + .command("setup", "Setup nsecBunker", {}, (argv) => { setup(argv.config as string); }) - .command('start', 'Start nsecBunker', (yargs) => { - yargs - .option('verbose', { - alias: 'v', - type: 'boolean', - description: 'Run with verbose logging', - default: false, - }) - .array('key') - .option('key ', { - type: 'string', - description: 'Name of key to enable', - }) - .array('admin') - .option('admin ', { - alias: 'a', - type: 'string', - description: 'Admin npub', + .command( + "start", + "Start nsecBunker", + (yargs) => { + yargs + .option("verbose", { + alias: "v", + type: "boolean", + description: "Run with verbose logging", + default: false, + }) + .array("key") + .option("key ", { + type: "string", + description: "Name of key to enable", + }) + .array("admin") + .option("admin ", { + alias: "a", + type: "string", + description: "Admin npub", + }); + }, + (argv) => { + start({ + keys: argv.key as string[], + verbose: argv.verbose as boolean, + config: argv.config as string, + adminNpubs: [ + ...new Set([ + ...((argv.admin || []) as string[]), + ...adminNpubs, + ]), + ], }); - }, (argv) => { - start({ - keys: argv.key as string[], - verbose: argv.verbose as boolean, - config: argv.config as string, - adminNpubs: [...new Set([...((argv.admin||[]) as string[]), ...adminNpubs])] - }); - }) + } + ) - .command('add', 'Add an nsec', (yargs) => { - yargs - .option('name', { - alias: 'n', - type: 'string', - description: 'Name of the nsec', + .command( + "add", + "Add an nsec", + (yargs) => { + yargs.option("name", { + alias: "n", + type: "string", + description: "Name of the nsec", demandOption: true, }); - }, (argv) => { - addNsec({ - config: argv.config as string, - name: argv.name as string - }); - }) + }, + (argv) => { + addNsec({ + config: argv.config as string, + name: argv.name as string, + }); + } + ) .options({ - 'config': { - alias: 'c', - type: 'string', - description: 'Path to config file', - default: 'config/nsecbunker.json', + config: { + alias: "c", + type: "string", + description: "Path to config file", + default: "config/nsecbunker.json", }, }) .demandCommand(0, 1)