11import * as fs from "node:fs" ;
2- import path from "path" ;
3- import { pathToFileURL } from "url" ;
2+ import path from "node: path" ;
3+ import { pathToFileURL } from "node: url" ;
44import { Client , type ClientOptions , type Interaction } from "discord.js" ;
55import { StelliaUtils } from "@client/index.js" ;
66import {
@@ -14,8 +14,8 @@ import {
1414 SelectMenuManager
1515} from "@managers/index.js" ;
1616import {
17- type ClientEnvironment , type GuildConfiguration ,
18- type GuildConfigurationType ,
17+ type ClientEnvironment ,
18+ type GuildConfiguration ,
1919 type GuildsConfiguration ,
2020 type Manager ,
2121 type Managers
@@ -102,26 +102,24 @@ export class StelliaClient<Ready extends boolean = boolean> extends Client<Ready
102102 return new Promise ( ( resolve , reject ) => {
103103 fs . readFile ( filePath , async ( err , data ) => {
104104 if ( err ) {
105- return reject ( err ) ;
105+ return reject ( new Error ( "stellia.json file not found" ) ) ;
106106 }
107107
108- try {
109- const environments = JSON . parse ( data . toString ( ) ) . environments ;
110- if ( ! Object . keys ( environments ) . includes ( chosenEnvironment ) ) {
111- return reject ( new Error ( "Invalid environment" ) ) ;
112- }
113-
114- const environmentData = environments [ chosenEnvironment ] ;
115- const environmentPath = environmentData . production
116- ? StelliaClient . convertFilePathToProduction ( environmentData . file )
117- : environmentData . file ;
118- const environmentAbsolutePath = pathToFileURL ( path . join ( srcPath , ".." , environmentPath ) ) . href ;
119- const environmentFile = await import ( environmentAbsolutePath ) ;
120- resolve ( environmentFile . environment ) ;
121- } catch ( error ) {
122- reject ( error ) ;
123- }
124- } ) ;
108+ const environments = JSON . parse ( data . toString ( ) ) . environments ;
109+ if ( ! Object . keys ( environments ) . includes ( chosenEnvironment ) ) {
110+ return reject ( new Error ( "Invalid environment" ) ) ;
111+ }
112+
113+ const environmentData = environments [ chosenEnvironment ] ;
114+ const environmentPath = environmentData . production
115+ ? StelliaClient . convertFilePathToProduction ( environmentData . file )
116+ : environmentData . file ;
117+
118+ const environmentAbsolutePath = pathToFileURL ( path . join ( srcPath , ".." , environmentPath ) ) . href ;
119+ import ( environmentAbsolutePath )
120+ . then ( ( environmentFile ) => resolve ( environmentFile . environment ) )
121+ . catch ( ( ) => reject ( new Error ( "Error parsing stellia.json file" ) ) ) ;
122+ } ) ;
125123 } ) ;
126124 } ;
127125
@@ -133,14 +131,14 @@ export class StelliaClient<Ready extends boolean = boolean> extends Client<Ready
133131 await this . utils . handleInteraction ( interaction ) ;
134132 } ;
135133
136- private areManagersLoaded = ( ) : boolean => {
134+ private readonly areManagersLoaded = ( ) : boolean => {
137135 const managers = Object . values ( this . managers ) ;
138136 return managers . length === 0
139137 ? true
140138 : managers . every ( ( manager : Manager ) => manager . isManagerLoaded ( ) ) ;
141139 } ;
142140
143- private static convertFilePathToProduction = ( filePath : string ) : string => {
141+ private static readonly convertFilePathToProduction = ( filePath : string ) : string => {
144142 return filePath . replace ( "src" , "dist" ) . replace ( ".ts" , ".js" ) ;
145143 } ;
146144}
0 commit comments