Skip to content

Commit

Permalink
fix: types complain
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored May 9, 2024
1 parent 8247cc1 commit da87d2b
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions packages/ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,50 @@ app.use(VueToast)

app.mount('#app')

const originalConsoleMethods = {
interface ConsoleMethod {
(...args: any[]): void;
}

interface OriginalConsoleMethods {
log: ConsoleMethod;
warn: ConsoleMethod;
error: ConsoleMethod;
info: ConsoleMethod;
}

type LogType = 'log' | 'warn' | 'error' | 'info';

const originalConsoleMethods: OriginalConsoleMethods = {
log: console.log,
warn: console.warn,
error: console.error,
info: console.info
}

function interceptConsole(type) {
return (...args) => {
const timestampStyle = 'color: #4CAF50;'
const logMessage = `%c${getCurrentTimestamp()} - [${type.toUpperCase()}] - %c${ type === 'error' ? args.join(' ') : argsMapping(args)}`
const resetStyle = 'color: inherit;'
function interceptConsole(type: LogType): ConsoleMethod {
return (...args: any[]) => {
const timestampStyle = 'color: #4CAF50;';

Check failure on line 37 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
const logMessage = `%c${getCurrentTimestamp()} - [${type.toUpperCase()}] - %c${ type === 'error' ? args.join(' ') : argsMapping(args)}`;

Check failure on line 38 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
const resetStyle = 'color: inherit;';

Check failure on line 39 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon

originalConsoleMethods[type](logMessage, timestampStyle, resetStyle)
storeLog(type, args)
originalConsoleMethods[type](logMessage, timestampStyle, resetStyle);

Check failure on line 41 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
storeLog(type, args);

Check failure on line 42 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
}
}

console.log = interceptConsole('log')
console.warn = interceptConsole('warn')
console.error = interceptConsole('error')
console.info = interceptConsole('info')
console.log = interceptConsole('log');

Check failure on line 46 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
console.warn = interceptConsole('warn');

Check failure on line 47 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
console.error = interceptConsole('error');

Check failure on line 48 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
console.info = interceptConsole('info');

Check failure on line 49 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon

function storeLog(type, args) {
function storeLog(type: LogType, args: any[]): void {
try {
store.commit('addConsoleLog', { type, message: `${getCurrentTimestamp()} - [${type.toUpperCase()}] - ${argsMapping(args)}` })
store.commit('addConsoleLog', { type, message: `${getCurrentTimestamp()} - [${type.toUpperCase()}] - ${argsMapping(args)}` });

Check failure on line 53 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
} catch (error) {
console.error('Failed to store log:', error)
console.error('Failed to store log:', error);
}
}

function argsMapping(args) {
return args.map(arg => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg).join(' ')
}
function argsMapping(args: any[]): string {
return args.map(arg => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg).join(' ');
}

0 comments on commit da87d2b

Please sign in to comment.