zumito-framework 1.20.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/launcher.js CHANGED
@@ -6,16 +6,15 @@ import fs from 'fs';
6
6
  import { pathToFileURL } from 'url';
7
7
  import dotenv from 'dotenv';
8
8
  import { RecursiveObjectMerger } from './services/utilities/RecursiveObjectMerger';
9
+ import { EnvValidator } from './services/utilities/EnvValidator';
10
+ import { BotReadyLogger } from './services/utilities/BotReadyLogger';
9
11
  dotenv.config();
10
- if (!process.env.DISCORD_TOKEN) {
11
- throw new Error("Discord Token not found (DISCORD_TOKEN)");
12
- }
13
- else if (!process.env.DISCORD_CLIENT_ID) {
14
- throw new Error("Discord Client ID not found (DISCORD_CLIENT_ID)");
15
- }
16
- else if (!process.env.MONGO_URI) {
17
- throw new Error("No MongoDB connection string specified in .env file (MONGO_URI)");
18
- }
12
+ const REQUIRED_ENV_VARS = {
13
+ DISCORD_TOKEN: 'Discord Bot Token',
14
+ DISCORD_CLIENT_ID: 'Discord Client ID',
15
+ MONGO_URI: 'MongoDB connection URI',
16
+ };
17
+ EnvValidator.validate(REQUIRED_ENV_VARS);
19
18
  const defaultConfig = {
20
19
  discordClientOptions: {
21
20
  intents: 3276799,
@@ -35,16 +34,7 @@ import(pathToFileURL(configFilePath).href)
35
34
  .then(({ config: userConfig }) => {
36
35
  const config = RecursiveObjectMerger.merge(defaultConfig, userConfig);
37
36
  new ZumitoFramework(config, (bot) => {
38
- // Log number of commands loaded
39
- console.log(`Loaded ${bot.commands.size} commands`);
40
- // Log number of events loaded
41
- console.log(`Loaded ${bot.events.size} events`);
42
- // Log number of modules loaded
43
- console.log(`Loaded ${bot.modules.size} modules`);
44
- // Log number of translations loaded
45
- console.log(`Loaded ${bot.translations.getAll().size} translations`);
46
- // Log number of routes registered
47
- console.log(`Loaded ${bot.routes.length} routes`);
37
+ BotReadyLogger.log(bot);
48
38
  userConfig.callbacks?.load?.(bot);
49
39
  });
50
40
  })
@@ -0,0 +1,7 @@
1
+ import { ZumitoFramework } from '../../ZumitoFramework';
2
+ export declare class BotReadyLogger {
3
+ /**
4
+ * Log standard bot startup statistics (commands, events, modules, etc).
5
+ */
6
+ static log(bot: ZumitoFramework): void;
7
+ }
@@ -0,0 +1,12 @@
1
+ export class BotReadyLogger {
2
+ /**
3
+ * Log standard bot startup statistics (commands, events, modules, etc).
4
+ */
5
+ static log(bot) {
6
+ console.log(`Loaded ${bot.commands.size} commands`);
7
+ console.log(`Loaded ${bot.events.size} events`);
8
+ console.log(`Loaded ${bot.modules.size} modules`);
9
+ console.log(`Loaded ${bot.translations.getAll().size} translations`);
10
+ console.log(`Loaded ${bot.routes.length} routes`);
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ export type EnvVarDefinitions = Record<string, string>;
2
+ export declare class EnvValidator {
3
+ /**
4
+ * Validate that all required env vars are present. If any are missing,
5
+ * renders a visual error report and exits the process.
6
+ * @param required - Map of { KEY: 'Human label' }
7
+ */
8
+ static validate(required: EnvVarDefinitions): void;
9
+ }
@@ -0,0 +1,50 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import chalk from 'chalk';
4
+ export class EnvValidator {
5
+ /**
6
+ * Validate that all required env vars are present. If any are missing,
7
+ * renders a visual error report and exits the process.
8
+ * @param required - Map of { KEY: 'Human label' }
9
+ */
10
+ static validate(required) {
11
+ const missing = [];
12
+ const present = [];
13
+ for (const [key] of Object.entries(required)) {
14
+ if (process.env[key]) {
15
+ present.push(key);
16
+ }
17
+ else {
18
+ missing.push(key);
19
+ }
20
+ }
21
+ if (missing.length === 0)
22
+ return;
23
+ const divider = chalk.yellow('━'.repeat(54));
24
+ const envPath = path.join(process.cwd(), '.env');
25
+ const hasEnvFile = fs.existsSync(envPath);
26
+ console.error(`\n${divider}`);
27
+ console.error(` ${chalk.bold.red('CONFIGURATION ERROR')} — Missing environment variables`);
28
+ console.error(divider);
29
+ for (const key of present) {
30
+ const label = required[key];
31
+ const value = process.env[key];
32
+ const display = value.length > 28 ? value.slice(0, 25) + '...' : value;
33
+ console.error(` ${chalk.green('✓')} ${chalk.green(key.padEnd(20))} ${chalk.dim(display)}`);
34
+ }
35
+ for (const key of missing) {
36
+ const label = required[key];
37
+ console.error(` ${chalk.red('✗')} ${chalk.red(key.padEnd(20))} ${chalk.bold(label)}`);
38
+ }
39
+ console.error(divider);
40
+ if (!hasEnvFile) {
41
+ console.error(` ${chalk.yellow('No .env file found in project root.')}`);
42
+ console.error(` ${chalk.dim('Create one from .env.example and fill in the missing values.')}`);
43
+ }
44
+ else {
45
+ console.error(` ${chalk.dim('.env file found but missing required variables.')}`);
46
+ }
47
+ console.error(divider + '\n');
48
+ process.exit(1);
49
+ }
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",