diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-08-12 19:54:46 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-08-12 19:54:46 +0200 |
commit | d22c3b0c257f5daf5b401988a35ab9ce981a2341 (patch) | |
tree | 0a661c927c37b52197326d1c05e211daf9bd19e5 /subprojects/frontend/src/utils | |
parent | fix(language): rule parsing test (diff) | |
download | refinery-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.ts | 6 | ||||
-rw-r--r-- | subprojects/frontend/src/utils/PendingTask.ts | 4 | ||||
-rw-r--r-- | subprojects/frontend/src/utils/Timer.ts | 2 | ||||
-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 @@ | |||
1 | import { getLogger } from './logger'; | 1 | import PendingTask from './PendingTask'; |
2 | import { PendingTask } from './PendingTask'; | 2 | import getLogger from './getLogger'; |
3 | 3 | ||
4 | const log = getLogger('utils.ConditionVariable'); | 4 | const log = getLogger('utils.ConditionVariable'); |
5 | 5 | ||
6 | export type Condition = () => boolean; | 6 | export type Condition = () => boolean; |
7 | 7 | ||
8 | export class ConditionVariable { | 8 | export 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 @@ | |||
1 | import { getLogger } from './logger'; | 1 | import getLogger from './getLogger'; |
2 | 2 | ||
3 | const log = getLogger('utils.PendingTask'); | 3 | const log = getLogger('utils.PendingTask'); |
4 | 4 | ||
5 | export class PendingTask<T> { | 5 | export 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 @@ | |||
1 | export class Timer { | 1 | export 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 @@ | |||
1 | import styles, { CSPair } from 'ansi-styles'; | 1 | import styles, { type CSPair } from 'ansi-styles'; |
2 | import log from 'loglevel'; | 2 | import log from 'loglevel'; |
3 | import * as prefix from 'loglevel-plugin-prefix'; | 3 | import prefix from 'loglevel-plugin-prefix'; |
4 | 4 | ||
5 | const colors: Partial<Record<string, CSPair>> = { | 5 | const 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 | ||
13 | prefix.reg(log); | 13 | prefix.reg(log); |
14 | 14 | ||
15 | if (DEBUG) { | 15 | if (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 | ||
38 | const appLogger = log.getLogger(PACKAGE_NAME); | 42 | const appLogger = log.getLogger(import.meta.env.VITE_PACKAGE_NAME); |
39 | 43 | ||
40 | appLogger.info('Version:', PACKAGE_NAME, PACKAGE_VERSION); | 44 | appLogger.info( |
41 | appLogger.info('Debug mode:', DEBUG); | 45 | 'Version:', |
46 | import.meta.env.VITE_PACKAGE_NAME, | ||
47 | import.meta.env.VITE_PACKAGE_VERSION, | ||
48 | ); | ||
49 | appLogger.info('Debug mode:', import.meta.env.DEV); | ||
42 | 50 | ||
43 | export function getLoggerFromRoot(name: string | symbol): log.Logger { | 51 | export 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 | ); | |
47 | export function getLogger(name: string | symbol): log.Logger { | ||
48 | return getLoggerFromRoot(`${PACKAGE_NAME}.${name.toString()}`); | ||
49 | } | 55 | } |