Skip to content

Commit a66db2a

Browse files
committed
chore: revert afLogger updates for the commands
1 parent 84a02a1 commit a66db2a

File tree

13 files changed

+87
-129
lines changed

13 files changed

+87
-129
lines changed

adminforth/commands/bundle.js

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

43

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

98

@@ -17,7 +16,7 @@ async function bundle() {
1716
`);
1817

1918
} catch (e) {
20-
afLogger.error(`Running bundle failed`, e);
19+
console.log(`Running budndle failed`, e);
2120
}
2221
}
2322

adminforth/commands/callTsProxy.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import path from "path";
44
import fs from "fs";
55
import chalk from "chalk";
66
import dotenv from "dotenv";
7-
import { afLogger } from '../modules/logger.js';
87

98
const currentFilePath = import.meta.url;
109
const currentFileFolder = path.dirname(currentFilePath).replace("file:", "");
@@ -21,7 +20,7 @@ export function callTsProxy(tsCode, silent=false) {
2120
dotenv.config({ path: envPath, override: true });
2221
}
2322

24-
afLogger.trace("🌐 Calling tsproxy with code:", path.join(currentFileFolder, "proxy.ts"));
23+
process.env.HEAVY_DEBUG && console.log("🌐 Calling tsproxy with code:", path.join(currentFileFolder, "proxy.ts"));
2524
return new Promise((resolve, reject) => {
2625
const child = spawn("tsx", [path.join(currentFileFolder, "proxy.ts")], {
2726
env: process.env,
@@ -43,7 +42,7 @@ export function callTsProxy(tsCode, silent=false) {
4342
const parsed = JSON.parse(stdout);
4443
if (!silent) {
4544
parsed.capturedLogs.forEach((log) => {
46-
afLogger.info(...log);
45+
console.log(...log);
4746
});
4847
}
4948

@@ -55,19 +54,19 @@ export function callTsProxy(tsCode, silent=false) {
5554
reject(new Error("Invalid JSON from tsproxy: " + stdout));
5655
}
5756
} else {
58-
afLogger.error(`tsproxy exited with non-0, this should never happen, stdout: ${stdout}, stderr: ${stderr}`);
57+
console.error(`tsproxy exited with non-0, this should never happen, stdout: ${stdout}, stderr: ${stderr}`);
5958
reject(new Error(stderr));
6059
}
6160
});
6261

63-
afLogger.trace("🪲 Writing to tsproxy stdin...\n'''", tsCode, "'''");
62+
process.env.HEAVY_DEBUG && console.log("🪲 Writing to tsproxy stdin...\n'''", tsCode, "'''");
6463
child.stdin.write(tsCode);
6564
child.stdin.end();
6665
});
6766
}
6867

6968
export async function findAdminInstance() {
70-
afLogger.trace("🌐 Finding admin instance...");
69+
process.env.HEAVY_DEBUG && console.log("🌐 Finding admin instance...");
7170
const currentDirectory = process.cwd();
7271

7372
let files = fs.readdirSync(currentDirectory);
@@ -84,7 +83,7 @@ export async function findAdminInstance() {
8483
for (const file of files) {
8584
if (file.endsWith(".ts")) {
8685
const fileNoTs = file.replace(/\.ts$/, "");
87-
afLogger.trace(`🪲 Trying bundleing ${file}...`);
86+
process.env.HEAVY_DEBUG && console.log(`🪲 Trying bundleing ${file}...`);
8887
try {
8988
const res = await callTsProxy(`
9089
import { admin } from './${fileNoTs}.js';
@@ -102,10 +101,10 @@ export async function findAdminInstance() {
102101
// and show the error so user can fix it
103102
const fileContent = fs.readFileSync(file, "utf-8");
104103
if (fileContent.includes("export const admin")) {
105-
afLogger.error(`Error running ${file}: ${e}`);
104+
console.error(chalk.red(`Error running ${file}:`, e));
106105
process.exit(1);
107106
}
108-
afLogger.trace(`🪲 File ${file} failed`, e);
107+
process.env.HEAVY_DEBUG && console.log(`🪲 File ${file} failed`, e);
109108
}
110109
}
111110
}
@@ -131,4 +130,4 @@ export async function findAdminInstance() {
131130
// function exec() {
132131
// return admin.doX();
133132
// }
134-
// `).then(afLogger.info).catch(afLogger.error);
133+
// `).then(console.log).catch(console.error);

adminforth/commands/createApp/templates/adminuser.ts.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import AdminForth, { AdminForthDataTypes } from 'adminforth';
22
import type { AdminForthResourceInput, AdminForthResource, AdminUser } from 'adminforth';
3-
import { logger } from 'adminforth';
43
import { randomUUID } from 'crypto';
54

65
async function allowedForSuperAdmin({ adminUser }: { adminUser: AdminUser }): Promise<boolean> {
@@ -95,7 +94,7 @@ export default {
9594
},
9695
edit: {
9796
beforeSave: async ({ oldRecord, updates, adminUser, resource }: { oldRecord: any, updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
98-
logger.info('Updating user', updates);
97+
console.log('Updating user', updates);
9998
if (oldRecord.id === adminUser.dbUser.id && updates.role) {
10099
return { ok: false, error: 'You cannot change your own role' };
101100
}

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6-
import { Filters, logger } from 'adminforth';
6+
import { Filters } from 'adminforth';
77
import { initApi } from './api.js';
88

99
const ADMIN_BASE_URL = '';
@@ -75,7 +75,7 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
7575
const port = 3500;
7676

7777
admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' }).then(() => {
78-
logger.info('Bundling AdminForth SPA done.');
78+
console.log('Bundling AdminForth SPA done.');
7979
});
8080

8181
admin.express.serve(app);
@@ -91,6 +91,6 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
9191
});
9292

9393
admin.express.listen(port, () => {
94-
logger.info(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`);
94+
console.log(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`);
9595
});
9696
}

adminforth/commands/createApp/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ 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';
1615

1716
const execAsync = promisify(exec);
1817

@@ -336,6 +335,7 @@ async function installDependencies(ctx, cwd) {
336335
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
337336
]);
338337
}
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-
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');
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');
396396
}
397397
}
398398
],

adminforth/commands/createCustomComponent/configLoader.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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';
76

87
dotenv.config({ path: '.env.local', override: true });
98
dotenv.config({ path: '.env', override: true });
@@ -60,12 +59,12 @@ export async function loadAdminForthConfig() {
6059
}
6160

6261

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

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

0 commit comments

Comments
 (0)