aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/utils
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-12 19:54:46 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-12 19:54:46 +0200
commitd22c3b0c257f5daf5b401988a35ab9ce981a2341 (patch)
tree0a661c927c37b52197326d1c05e211daf9bd19e5 /subprojects/frontend/src/utils
parentfix(language): rule parsing test (diff)
downloadrefinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.tar.gz
refinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.tar.zst
refinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.zip
refactor(frontend): move from Webpack to Vite
Also overhaulds the building and linting for frontend assets.
Diffstat (limited to 'subprojects/frontend/src/utils')
-rw-r--r--subprojects/frontend/src/utils/ConditionVariable.ts6
-rw-r--r--subprojects/frontend/src/utils/PendingTask.ts4
-rw-r--r--subprojects/frontend/src/utils/Timer.ts2
-rw-r--r--subprojects/frontend/src/utils/getLogger.ts (renamed from subprojects/frontend/src/utils/logger.ts)34
4 files changed, 26 insertions, 20 deletions
diff --git a/subprojects/frontend/src/utils/ConditionVariable.ts b/subprojects/frontend/src/utils/ConditionVariable.ts
index 0910dfa6..c8fae9e8 100644
--- a/subprojects/frontend/src/utils/ConditionVariable.ts
+++ b/subprojects/frontend/src/utils/ConditionVariable.ts
@@ -1,11 +1,11 @@
1import { getLogger } from './logger'; 1import PendingTask from './PendingTask';
2import { PendingTask } from './PendingTask'; 2import getLogger from './getLogger';
3 3
4const log = getLogger('utils.ConditionVariable'); 4const log = getLogger('utils.ConditionVariable');
5 5
6export type Condition = () => boolean; 6export type Condition = () => boolean;
7 7
8export class ConditionVariable { 8export default class ConditionVariable {
9 condition: Condition; 9 condition: Condition;
10 10
11 defaultTimeout: number; 11 defaultTimeout: number;
diff --git a/subprojects/frontend/src/utils/PendingTask.ts b/subprojects/frontend/src/utils/PendingTask.ts
index 51b79fb0..086993d4 100644
--- a/subprojects/frontend/src/utils/PendingTask.ts
+++ b/subprojects/frontend/src/utils/PendingTask.ts
@@ -1,8 +1,8 @@
1import { getLogger } from './logger'; 1import getLogger from './getLogger';
2 2
3const log = getLogger('utils.PendingTask'); 3const log = getLogger('utils.PendingTask');
4 4
5export class PendingTask<T> { 5export default class PendingTask<T> {
6 private readonly resolveCallback: (value: T) => void; 6 private readonly resolveCallback: (value: T) => void;
7 7
8 private readonly rejectCallback: (reason?: unknown) => void; 8 private readonly rejectCallback: (reason?: unknown) => void;
diff --git a/subprojects/frontend/src/utils/Timer.ts b/subprojects/frontend/src/utils/Timer.ts
index 8f653070..14e9eb81 100644
--- a/subprojects/frontend/src/utils/Timer.ts
+++ b/subprojects/frontend/src/utils/Timer.ts
@@ -1,4 +1,4 @@
1export class Timer { 1export default class Timer {
2 readonly callback: () => void; 2 readonly callback: () => void;
3 3
4 readonly defaultTimeout: number; 4 readonly defaultTimeout: number;
diff --git a/subprojects/frontend/src/utils/logger.ts b/subprojects/frontend/src/utils/getLogger.ts
index 306d122c..301fd76d 100644
--- a/subprojects/frontend/src/utils/logger.ts
+++ b/subprojects/frontend/src/utils/getLogger.ts
@@ -1,6 +1,6 @@
1import styles, { CSPair } from 'ansi-styles'; 1import styles, { type CSPair } from 'ansi-styles';
2import log from 'loglevel'; 2import log from 'loglevel';
3import * as prefix from 'loglevel-plugin-prefix'; 3import prefix from 'loglevel-plugin-prefix';
4 4
5const colors: Partial<Record<string, CSPair>> = { 5const colors: Partial<Record<string, CSPair>> = {
6 TRACE: styles.magenta, 6 TRACE: styles.magenta,
@@ -12,7 +12,7 @@ const colors: Partial<Record<string, CSPair>> = {
12 12
13prefix.reg(log); 13prefix.reg(log);
14 14
15if (DEBUG) { 15if (import.meta.env.DEV) {
16 log.setLevel(log.levels.DEBUG); 16 log.setLevel(log.levels.DEBUG);
17} else { 17} else {
18 log.setLevel(log.levels.WARN); 18 log.setLevel(log.levels.WARN);
@@ -22,10 +22,14 @@ if ('chrome' in window) {
22 // Only Chromium supports console ANSI escape sequences. 22 // Only Chromium supports console ANSI escape sequences.
23 prefix.apply(log, { 23 prefix.apply(log, {
24 format(level, name, timestamp) { 24 format(level, name, timestamp) {
25 const formattedTimestamp = `${styles.gray.open}[${timestamp.toString()}]${styles.gray.close}`; 25 const formattedTimestamp = `${styles.gray.open}[${timestamp.toString()}]${
26 styles.gray.close
27 }`;
26 const levelColor = colors[level.toUpperCase()] || styles.red; 28 const levelColor = colors[level.toUpperCase()] || styles.red;
27 const formattedLevel = `${levelColor.open}${level}${levelColor.close}`; 29 const formattedLevel = `${levelColor.open}${level}${levelColor.close}`;
28 const formattedName = `${styles.green.open}(${name || 'root'})${styles.green.close}`; 30 const formattedName = `${styles.green.open}(${name || 'root'})${
31 styles.green.close
32 }`;
29 return `${formattedTimestamp} ${formattedLevel} ${formattedName}`; 33 return `${formattedTimestamp} ${formattedLevel} ${formattedName}`;
30 }, 34 },
31 }); 35 });
@@ -35,15 +39,17 @@ if ('chrome' in window) {
35 }); 39 });
36} 40}
37 41
38const appLogger = log.getLogger(PACKAGE_NAME); 42const appLogger = log.getLogger(import.meta.env.VITE_PACKAGE_NAME);
39 43
40appLogger.info('Version:', PACKAGE_NAME, PACKAGE_VERSION); 44appLogger.info(
41appLogger.info('Debug mode:', DEBUG); 45 'Version:',
46 import.meta.env.VITE_PACKAGE_NAME,
47 import.meta.env.VITE_PACKAGE_VERSION,
48);
49appLogger.info('Debug mode:', import.meta.env.DEV);
42 50
43export function getLoggerFromRoot(name: string | symbol): log.Logger { 51export default function getLogger(name: string | symbol): log.Logger {
44 return log.getLogger(name); 52 return log.getLogger(
45} 53 `${import.meta.env.VITE_PACKAGE_NAME}.${name.toString()}`,
46 54 );
47export function getLogger(name: string | symbol): log.Logger {
48 return getLoggerFromRoot(`${PACKAGE_NAME}.${name.toString()}`);
49} 55}