Skip to content

Commit 668417d

Browse files
committed
fix: add detailed debug logging for AdminForth and CodeInjector initialization and plugin activation
1 parent cfcf80a commit 668417d

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

adminforth/index.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,58 @@ class AdminForth implements IAdminForth {
124124
}
125125

126126
constructor(config: AdminForthInputConfig) {
127+
process.env.HEAVY_DEBUG && console.log('🔧 AdminForth constructor started');
128+
127129
if (global.adminforth) {
128130
throw new Error('AdminForth instance already created in this process. '+
129131
'If you want to use multiple instances, consider using different process for each instance');
130132
}
133+
134+
process.env.HEAVY_DEBUG && console.log('🔧 Creating CodeInjector...');
131135
this.codeInjector = new CodeInjector(this);
136+
process.env.HEAVY_DEBUG && console.log('🔧 CodeInjector created');
137+
138+
process.env.HEAVY_DEBUG && console.log('🔧 Creating ConfigValidator...');
132139
this.configValidator = new ConfigValidator(this, config);
140+
process.env.HEAVY_DEBUG && console.log('🔧 ConfigValidator created');
141+
142+
process.env.HEAVY_DEBUG && console.log('🔧 Creating AdminForthRestAPI...');
133143
this.restApi = new AdminForthRestAPI(this);
144+
process.env.HEAVY_DEBUG && console.log('🔧 AdminForthRestAPI created');
145+
146+
process.env.HEAVY_DEBUG && console.log('🔧 Creating SocketBroker...');
134147
this.websocket = new SocketBroker(this);
148+
process.env.HEAVY_DEBUG && console.log('🔧 SocketBroker created');
149+
135150
this.activatedPlugins = [];
136151

152+
process.env.HEAVY_DEBUG && console.log('🔧 Validating config...');
137153
this.configValidator.validateConfig();
154+
process.env.HEAVY_DEBUG && console.log('🔧 Config validated');
155+
156+
process.env.HEAVY_DEBUG && console.log('🔧 Activating plugins...');
138157
this.activatePlugins();
158+
process.env.HEAVY_DEBUG && console.log('🔧 Plugins activated');
139159

160+
process.env.HEAVY_DEBUG && console.log('🔧 Creating ExpressServer...');
140161
this.express = new ExpressServer(this);
162+
process.env.HEAVY_DEBUG && console.log('🔧 ExpressServer created');
163+
141164
// this.fastify = new FastifyServer(this);
165+
process.env.HEAVY_DEBUG && console.log('🔧 Creating AdminForthAuth...');
142166
this.auth = new AdminForthAuth(this);
167+
process.env.HEAVY_DEBUG && console.log('🔧 AdminForthAuth created');
168+
143169
this.connectors = {};
144170
this.statuses = {
145171
dbDiscover: 'running',
146172
};
147173

148-
149-
150174
console.log(`${this.formatAdminForth()} v${ADMINFORTH_VERSION} initializing...`);
175+
process.env.HEAVY_DEBUG && console.log('🔧 About to set global.adminforth...');
151176
global.adminforth = this;
177+
process.env.HEAVY_DEBUG && console.log('🔧 global.adminforth set successfully');
178+
process.env.HEAVY_DEBUG && console.log('🔧 AdminForth constructor completed');
152179
}
153180

154181
formatAdminForth() {
@@ -174,14 +201,21 @@ class AdminForth implements IAdminForth {
174201
process.env.HEAVY_DEBUG && console.log('🔌🔌🔌 Activating plugins');
175202
const allPluginInstances = [];
176203
for (let resource of this.config.resources) {
204+
process.env.HEAVY_DEBUG && console.log(`🔌 Checking plugins for resource: ${resource.resourceId}`);
177205
for (let pluginInstance of resource.plugins || []) {
206+
process.env.HEAVY_DEBUG && console.log(`🔌 Found plugin: ${pluginInstance.constructor.name} for resource ${resource.resourceId}`);
178207
allPluginInstances.push({pi: pluginInstance, resource});
179208
}
180209
}
210+
process.env.HEAVY_DEBUG && console.log(`🔌 Total plugins to activate: ${allPluginInstances.length}`);
181211
allPluginInstances.sort(({pi: a}, {pi: b}) => a.activationOrder - b.activationOrder);
212+
182213
allPluginInstances.forEach(
183-
({pi: pluginInstance, resource}) => {
214+
({pi: pluginInstance, resource}, index) => {
215+
process.env.HEAVY_DEBUG && console.log(`🔌 Activating plugin ${index + 1}/${allPluginInstances.length}: ${pluginInstance.constructor.name} for resource ${resource.resourceId}`);
184216
pluginInstance.modifyResourceConfig(this, resource);
217+
process.env.HEAVY_DEBUG && console.log(`🔌 Plugin ${pluginInstance.constructor.name} modifyResourceConfig completed`);
218+
185219
const plugin = this.activatedPlugins.find((p) => p.pluginInstanceId === pluginInstance.pluginInstanceId);
186220
if (plugin) {
187221
process.env.HEAVY_DEBUG && console.log(`Current plugin pluginInstance.pluginInstanceId ${pluginInstance.pluginInstanceId}`);
@@ -190,8 +224,10 @@ class AdminForth implements IAdminForth {
190224
To support multiple plugin instance pre one resource, plugin should return unique string values for each installation from instanceUniqueRepresentation`);
191225
}
192226
this.activatedPlugins.push(pluginInstance);
227+
process.env.HEAVY_DEBUG && console.log(`🔌 Plugin ${pluginInstance.constructor.name} activated successfully`);
193228
}
194229
);
230+
process.env.HEAVY_DEBUG && console.log('🔌 All plugins activation completed');
195231
}
196232

197233
getPluginsByClassName<T>(className: string): T[] {

adminforth/modules/codeInjector.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ class CodeInjector implements ICodeInjector {
8383
devServerPort: number = null;
8484

8585
spaTmpPath(): string {
86-
const brandSlug = this.adminforth.config.customization.brandNameSlug
86+
const brandSlug = this.adminforth.config.customization?.brandNameSlug;
87+
process.env.HEAVY_DEBUG && console.log(`🔧 spaTmpPath() - brandSlug: "${brandSlug}", TMP_DIR: "${TMP_DIR}"`);
8788
if (!brandSlug) {
8889
throw new Error('brandSlug is empty, but it should be populated at least by config Validator ');
8990
}
90-
return path.join(TMP_DIR, 'adminforth', brandSlug, 'spa_tmp');
91+
const fullPath = path.join(TMP_DIR, 'adminforth', brandSlug, 'spa_tmp');
92+
process.env.HEAVY_DEBUG && console.log(`🔧 spaTmpPath() result: "${fullPath}"`);
93+
return fullPath;
9194
}
9295

9396
cleanup() {
@@ -234,12 +237,18 @@ class CodeInjector implements ICodeInjector {
234237

235238
async prepareSources() {
236239
// collects all files and folders into SPA_TMP_DIR
240+
process.env.HEAVY_DEBUG && console.log(`🔧 prepareSources() started`);
237241

238242
// check spa tmp folder exists and create if not
239243
try {
244+
process.env.HEAVY_DEBUG && console.log(`🔧 Checking if spaTmpPath exists: ${this.spaTmpPath()}`);
240245
await fs.promises.access(this.spaTmpPath(), fs.constants.F_OK);
246+
process.env.HEAVY_DEBUG && console.log(`🔧 spaTmpPath already exists`);
241247
} catch (e) {
242-
await fs.promises.mkdir(this.spaTmpPath(), { recursive: true });
248+
process.env.HEAVY_DEBUG && console.log(`🔧 spaTmpPath doesn't exist, creating directory: ${this.spaTmpPath()}`);
249+
await fs.promises.mkdir(this.spaTmpPath(), { recursive: true });
250+
process.env.HEAVY_DEBUG && console.log(`🔧 Successfully created spaTmpPath directory`);
251+
243252
}
244253

245254
const icons = [];
@@ -809,7 +818,12 @@ class CodeInjector implements ICodeInjector {
809818
console.log(`${this.adminforth.formatAdminForth()} Bundling ${hotReload ? 'and listening for changes (🔥 Hotreload)' : ' (no hot reload)'}`);
810819
this.adminforth.runningHotReload = hotReload;
811820

821+
process.env.HEAVY_DEBUG && console.log(`🔧 Starting prepareSources() - Platform: ${process.platform}, TMP_DIR: ${TMP_DIR}`);
822+
process.env.HEAVY_DEBUG && console.log(`🔧 spaTmpPath: ${this.spaTmpPath()}`);
823+
812824
await this.prepareSources();
825+
process.env.HEAVY_DEBUG && console.log(`🔧 prepareSources() completed successfully`);
826+
813827

814828
if (hotReload) {
815829
await Promise.all([

0 commit comments

Comments
 (0)