Skip to content

Commit 7b1718b

Browse files
committed
chore: replace console logging with afLogger for consistent logging across components
1 parent 9541c4d commit 7b1718b

File tree

14 files changed

+90
-91
lines changed

14 files changed

+90
-91
lines changed

adminforth/commands/bundle.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { callTsProxy, findAdminInstance } from "./callTsProxy.js";
2+
import { afLogger } from '../modules/logger.js';
23

34

45
async function bundle() {
5-
console.log("Bundling admin SPA...");
6+
afLogger.info("Bundling admin SPA...");
67
const instance = await findAdminInstance();
78

89

@@ -16,7 +17,7 @@ async function bundle() {
1617
`);
1718

1819
} catch (e) {
19-
console.log(`Running budndle failed`, e);
20+
afLogger.error(`Running bundle failed`, e);
2021
}
2122
}
2223

adminforth/commands/callTsProxy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function callTsProxy(tsCode, silent=false) {
4343
const parsed = JSON.parse(stdout);
4444
if (!silent) {
4545
parsed.capturedLogs.forEach((log) => {
46-
console.log(...log);
46+
afLogger.log(...log);
4747
});
4848
}
4949

@@ -131,4 +131,4 @@ export async function findAdminInstance() {
131131
// function exec() {
132132
// return admin.doX();
133133
// }
134-
// `).then(console.log).catch(console.error);
134+
// `).then(afLogger.info).catch(afLogger.error);

adminforth/commands/createApp/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { exec } from 'child_process';
1212
import Handlebars from 'handlebars';
1313
import { promisify } from 'util';
1414
import { getVersion } from '../cli.js';
15+
import { afLogger } from '../modules/logger.js';
1516

1617
const execAsync = promisify(exec);
1718

@@ -335,7 +336,6 @@ async function installDependencies(ctx, cwd) {
335336
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
336337
]);
337338
}
338-
// console.log(chalk.dim(`Dependencies installed in ${cwd} and ${customDir}: \n${res[0].stdout}${res[1].stdout}`));
339339
}
340340

341341
function generateFinalInstructions(skipPrismaSetup, options) {
@@ -390,9 +390,9 @@ export function prepareWorkflow(options) {
390390
{
391391
title: '📝 Preparing final instructions...',
392392
task: (ctx) => {
393-
console.log(chalk.green(`✅ Successfully created your new Adminforth project in ${ctx.projectDir}!\n`));
394-
console.log(generateFinalInstructions(ctx.skipPrismaSetup, options));
395-
console.log('\n\n');
393+
afLogger.info(chalk.green(`✅ Successfully created your new Adminforth project in ${ctx.projectDir}!\n`));
394+
afLogger.info(generateFinalInstructions(ctx.skipPrismaSetup, options));
395+
afLogger.info('\n\n');
396396
}
397397
}
398398
],

adminforth/commands/createCustomComponent/configLoader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import chalk from 'chalk';
44
import jiti from 'jiti';
55
import dotenv, { config } from "dotenv";
6+
import { afLogger } from '../modules/logger.js';
67

78
dotenv.config({ path: '.env.local', override: true });
89
dotenv.config({ path: '.env', override: true });
@@ -59,12 +60,12 @@ export async function loadAdminForthConfig() {
5960
}
6061

6162

62-
console.log(chalk.dim(`Loaded configuration from ${configPath}`));
63+
afLogger.info(chalk.dim(`Loaded configuration from ${configPath}`));
6364
return config;
6465

6566
} catch (error) {
66-
console.error(chalk.red(`\nError loading or parsing configuration file: ${configPath}, error: ${error}`));
67-
console.error(error);
67+
afLogger.error(chalk.red(`\nError loading or parsing configuration file: ${configPath}, error: ${error}`));
68+
afLogger.error(error);
6869
process.exit(1);
6970
}
7071
}

adminforth/commands/createCustomComponent/configUpdater.js

Lines changed: 43 additions & 42 deletions
Large diffs are not rendered by default.

adminforth/commands/createCustomComponent/fileGenerator.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
import chalk from 'chalk';
55
import Handlebars from 'handlebars';
66
import { fileURLToPath } from 'url';
7+
import { afLogger } from '../modules/logger.js';
78

89
async function renderHBSTemplate(templatePath, data) {
910
try {
@@ -31,7 +32,7 @@ async function generateVueContent(fieldType, { resource, column }) {
3132
? path.join(__dirname, 'templates', 'customFields', `${fieldType}.vue.hbs`)
3233
: path.join(__dirname, 'templates', 'customCrud', `${fieldType}.vue.hbs`);
3334

34-
console.log(chalk.dim(`Using template: ${templatePath}`));
35+
afLogger.info(chalk.dim(`Using template: ${templatePath}`));
3536

3637
const context = {
3738
componentName,
@@ -61,24 +62,24 @@ export async function generateComponentFile(componentFileName, fieldType, contex
6162
const customDirPath = path.resolve(projectRoot, customDirRelative);
6263
const absoluteComponentPath = path.resolve(customDirPath, componentFileName);
6364
if (fsSync.existsSync(absoluteComponentPath)) {
64-
console.log(chalk.yellow(`⚠️ Component file already exists: ${absoluteComponentPath}`));
65+
afLogger.warn(chalk.yellow(`⚠️ Component file already exists: ${absoluteComponentPath}`));
6566
return {"alreadyExists": true, "path": absoluteComponentPath}
6667
}
6768
try {
6869
await fs.mkdir(customDirPath, { recursive: true });
69-
console.log(chalk.dim(`Ensured custom directory exists: ${customDirPath}`));
70+
afLogger.info(chalk.dim(`Ensured custom directory exists: ${customDirPath}`));
7071

7172
const fileContent = await generateVueContent(fieldType, context);
7273

7374
await fs.writeFile(absoluteComponentPath, fileContent, 'utf-8');
74-
console.log(chalk.green(`✅ Generated component file: ${absoluteComponentPath}`));
75+
afLogger.info(chalk.green(`✅ Generated component file: ${absoluteComponentPath}`));
7576

7677
return {"alreadyExists": false, "path": absoluteComponentPath}
7778

7879
} catch (error) {
79-
console.error(chalk.red(`❌ Error creating component file at ${absoluteComponentPath}:`));
80+
afLogger.error(chalk.red(`❌ Error creating component file at ${absoluteComponentPath}:`));
8081
if (!error.message.includes('template')) {
81-
console.error(error);
82+
afLogger.error(error);
8283
}
8384
throw error;
8485
}
@@ -91,22 +92,22 @@ export async function generateCrudInjectionComponent(componentFileName, crudType
9192
const absoluteComponentPath = path.resolve(customDirPath, componentFileName);
9293

9394
if (fsSync.existsSync(absoluteComponentPath)) {
94-
console.log(chalk.yellow(`⚠️ Component file already exists: ${absoluteComponentPath}`));
95+
afLogger.warn(chalk.yellow(`⚠️ Component file already exists: ${absoluteComponentPath}`));
9596
return { alreadyExists: true, path: absoluteComponentPath };
9697
}
9798

9899
try {
99100
await fs.mkdir(customDirPath, { recursive: true });
100-
console.log(chalk.dim(`Ensured custom directory exists: ${customDirPath}`));
101+
afLogger.warn(chalk.dim(`Ensured custom directory exists: ${customDirPath}`));
101102

102103
const fileContent = await generateVueContent(crudType, context);
103104

104105
await fs.writeFile(absoluteComponentPath, fileContent, 'utf-8');
105-
console.log(chalk.green(`✅ Generated component file: ${absoluteComponentPath}`));
106+
afLogger.info(chalk.green(`✅ Generated component file: ${absoluteComponentPath}`));
106107

107108
return { alreadyExists: false, path: absoluteComponentPath };
108109
} catch (error) {
109-
console.error(chalk.red(`❌ Error creating component file at ${absoluteComponentPath}:`));
110+
afLogger.error(chalk.red(`❌ Error creating component file at ${absoluteComponentPath}:`));
110111
throw error;
111112
}
112113
}
@@ -118,13 +119,13 @@ export async function generateLoginOrGlobalComponentFile(componentFileName, inje
118119
const absoluteComponentPath = path.resolve(customDirPath, componentFileName);
119120

120121
if (fsSync.existsSync(absoluteComponentPath)) {
121-
console.log(chalk.yellow(`⚠️ Component file already exists: ${absoluteComponentPath}`));
122+
afLogger.warn(chalk.yellow(`⚠️ Component file already exists: ${absoluteComponentPath}`));
122123
return { alreadyExists: true, path: absoluteComponentPath };
123124
}
124125

125126
try {
126127
await fs.mkdir(customDirPath, { recursive: true });
127-
console.log(chalk.dim(`Ensured custom directory exists: ${customDirPath}`));
128+
afLogger.warn(chalk.dim(`Ensured custom directory exists: ${customDirPath}`));
128129

129130
const __filename = fileURLToPath(import.meta.url);
130131
const __dirname = path.dirname(__filename);
@@ -138,11 +139,11 @@ export async function generateLoginOrGlobalComponentFile(componentFileName, inje
138139
const fileContent = await renderHBSTemplate(templatePath, context);
139140

140141
await fs.writeFile(absoluteComponentPath, fileContent, 'utf-8');
141-
console.log(chalk.green(`✅ Generated login injection component: ${absoluteComponentPath}`));
142+
afLogger.info(chalk.green(`✅ Generated login injection component: ${absoluteComponentPath}`));
142143

143144
return { alreadyExists: false, path: absoluteComponentPath };
144145
} catch (error) {
145-
console.error(chalk.red(`❌ Error creating login component at ${absoluteComponentPath}`));
146+
afLogger.error(chalk.red(`❌ Error creating login component at ${absoluteComponentPath}`));
146147
throw error;
147148
}
148149
}

adminforth/commands/createCustomComponent/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
import { loadAdminForthConfig } from './configLoader.js'; // Helper to load config
55
import { generateComponentFile, generateLoginOrGlobalComponentFile, generateCrudInjectionComponent } from './fileGenerator.js'; // Helper to create the .vue file
66
import { updateResourceConfig, injectLoginComponent, injectGlobalComponent, updateCrudInjectionConfig } from './configUpdater.js'; // Helper to modify resource .ts file
7+
import { afLogger } from '../modules/logger.js';
78

89
function sanitizeLabel(input){
910
return input
@@ -14,7 +15,7 @@ function sanitizeLabel(input){
1415
}
1516

1617
export default async function createComponent(args) {
17-
console.log('This command will help you to generate boilerplate for component.\n');
18+
afLogger.info('This command will help you to generate boilerplate for component.\n');
1819

1920
const config = await loadAdminForthConfig();
2021
const resources = config.resources;

adminforth/commands/postinstall.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import fs from 'fs';
22
import path from 'path';
33

44
import { execSync } from 'child_process';
5+
import { afLogger } from '../modules/logger.js';
6+
57
const spaPath = path.join(import.meta.dirname, 'dist', 'spa');
68

79

810
if (fs.existsSync(spaPath)){
9-
console.log('Installing SPA dependencies...');
11+
afLogger.info('Installing SPA dependencies...');
1012
execSync('npm ci', { cwd: spaPath, stdio: 'inherit' });
11-
console.log('Installed spa dependencies');
13+
afLogger.info('Installed spa dependencies');
1214
} else {
13-
console.log('SPA dependencies not found');
14-
console.log('current directory', import.meta.dirname);
15+
afLogger.warn('SPA dependencies not found');
16+
afLogger.info('current directory', import.meta.dirname);
1517
}

adminforth/commands/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "path";
22
import { execSync } from "child_process";
33
import fs from "fs";
4+
import { afLogger } from '../modules/logger.js';
45

56
export const toPascalCase = (str) => {
67
return str
@@ -131,7 +132,7 @@ export async function getInstance(file, currentDirectory) {
131132
let filePath = initialFilePath;
132133

133134
if (file.endsWith(".ts")) {
134-
console.log(`Compiling TypeScript file: ${file}`);
135+
afLogger.info(`Compiling TypeScript file: ${file}`);
135136
try {
136137
execSync(
137138
`./node_modules/.bin/tsc ${filePath} --module ESNext --outDir ./dist`,
@@ -140,7 +141,7 @@ export async function getInstance(file, currentDirectory) {
140141
}
141142
);
142143
} catch (error) {
143-
//console.log(`Error: Could not compile TypeScript file '${file}'`);
144+
afLogger.error(`Error: Could not compile TypeScript file '${file}'`);
144145
}
145146
const distDir = path.join(currentDirectory, "dist");
146147
processJsFilesInDir(distDir);

adminforth/dataConnectors/baseConnector.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
8181
// in case column isArray and enumerator/foreign resource - IN filter must be transformed into OR filter
8282
if (filterValidation.ok && f.operator == AdminForthFilterOperators.IN) {
8383
const column = resource.dataSourceColumns.find((col) => col.name == (f as IAdminForthSingleFilter).field);
84-
// console.log(`\n~~~ column: ${JSON.stringify(column, null, 2)}\n~~~ resource.columns: ${JSON.stringify(resource.dataSourceColumns, null, 2)}\n~~~ filter: ${JSON.stringify(f, null, 2)}\n`);
8584
if (column.isArray?.enabled && (column.enum || column.foreignResource)) {
8685
filters[fIndex] = {
8786
operator: AdminForthFilterOperators.OR,

0 commit comments

Comments
 (0)