From 7722bb2ddf3da65b7ed71d59c09fab7c60b84905 Mon Sep 17 00:00:00 2001 From: "Azat S." Date: Sun, 10 Nov 2024 19:21:30 +0300 Subject: [PATCH] refactor: refactor preview code --- bin/todoctor.js | 11 ++++++---- env.d.ts => environment.d.ts | 0 preview/blocks/footer.svelte | 6 +++++- preview/blocks/graph.svelte | 4 ++-- preview/blocks/header.svelte | 18 ++++++++++------ preview/blocks/info.svelte | 14 ++++++------ preview/elements/avatar.svelte | 2 +- preview/elements/chart-doughnut.svelte | 8 +++++-- preview/elements/chart.svelte | 14 ++++++------ preview/elements/note.svelte | 15 ++++++++----- preview/elements/table-comment.svelte | 4 ++-- preview/elements/table.svelte | 13 +++++------ preview/stores/data.ts | 30 +++++++++++++------------- preview/stores/theme.ts | 10 +++++---- preview/view/app.svelte | 4 +++- preview/view/index.ts | 4 ++-- scripts/build.js | 24 ++++++++++----------- scripts/create-packages.js | 26 ++++++++++++++-------- scripts/get-package-json.js | 2 +- scripts/version.js | 7 ++---- vite.config.ts | 22 +++++++++---------- 21 files changed, 135 insertions(+), 103 deletions(-) rename env.d.ts => environment.d.ts (100%) diff --git a/bin/todoctor.js b/bin/todoctor.js index ac52210..12ad8d1 100755 --- a/bin/todoctor.js +++ b/bin/todoctor.js @@ -28,10 +28,13 @@ try { process.exit(1) } -let distPath = path.join(dirname, '../dist') -let args = process.argv.slice(2) -let env = { ...process.env, DIST_PATH: distPath } -let child = spawn(binaryPath, args, { stdio: 'inherit', env }) +let distributionPath = path.join(dirname, '../dist') +let arguments_ = process.argv.slice(2) +let environment = { ...process.env, DIST_PATH: distributionPath } +let child = spawn(binaryPath, arguments_, { + stdio: 'inherit', + env: environment, +}) child.on('exit', code => { process.exit(code) diff --git a/env.d.ts b/environment.d.ts similarity index 100% rename from env.d.ts rename to environment.d.ts diff --git a/preview/blocks/footer.svelte b/preview/blocks/footer.svelte index 7e15db8..1f5f59e 100644 --- a/preview/blocks/footer.svelte +++ b/preview/blocks/footer.svelte @@ -12,7 +12,11 @@ Released under the MIT License Copyright © {currentYear} Azat S. - + Source code on GitHub diff --git a/preview/blocks/graph.svelte b/preview/blocks/graph.svelte index fa82ecc..62e2845 100644 --- a/preview/blocks/graph.svelte +++ b/preview/blocks/graph.svelte @@ -8,8 +8,8 @@ $data.history?.sort( (a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(), ) ?? [] - $: labels = history?.map(({ date }) => date) - $: values = history?.map(({ count }) => count) + $: labels = history.map(({ date }) => date) + $: values = history.map(({ count }) => count)
diff --git a/preview/blocks/header.svelte b/preview/blocks/header.svelte index 4cdd41e..480a299 100644 --- a/preview/blocks/header.svelte +++ b/preview/blocks/header.svelte @@ -7,6 +7,8 @@ // eslint-disable-next-line no-unused-expressions $theme + + let { version, name } = $data
@@ -18,21 +20,25 @@
Todoctor - {#if $data.version} - v{$data.version} + {#if version} + v{version} {/if}
- {#if $data.name} - {$data.name} + {#if name} + {name} {/if}
diff --git a/preview/blocks/info.svelte b/preview/blocks/info.svelte index 79932e3..a543fd4 100644 --- a/preview/blocks/info.svelte +++ b/preview/blocks/info.svelte @@ -10,12 +10,12 @@ $: todosByKind = $data.data?.reduce((accumulator: Record, { kind }) => { if (kind in accumulator) { - accumulator[kind] = accumulator[kind] + 1 + accumulator[kind] += 1 } else { accumulator[kind] = 1 } return accumulator - }, {}) || {} + }, {}) ?? {} $: todosEntries = Object.entries(todosByKind).sort(([, a], [, b]) => b - a) @@ -42,7 +42,7 @@ 'senary', ] - $: notes = [] as { + let notes = [] as { content: string[] title: string }[] @@ -69,7 +69,7 @@ let todosByAuthors = $data.data.reduce( (accumulator: Record, { blame }) => { if (blame.author in accumulator) { - accumulator[blame.author] = accumulator[blame.author] + 1 + accumulator[blame.author] += 1 } else { accumulator[blame.author] = 1 } @@ -128,7 +128,7 @@
Did You Know That?
- {#each notes as { content, title }} + {#each notes as { content, title } (title)} {/each}
@@ -143,12 +143,12 @@
- {#each finalTodosEntries as [kind], index} + {#each finalTodosEntries as [kind], index (kind)}
+ /> {kind.toUpperCase()}
{/each} diff --git a/preview/elements/avatar.svelte b/preview/elements/avatar.svelte index 814d1f8..83504db 100644 --- a/preview/elements/avatar.svelte +++ b/preview/elements/avatar.svelte @@ -9,7 +9,7 @@ let transformToCode = (string: string, length: number): number => { let hash = 0 - for (let len = string.length, i = 0; i < len; i++) { + for (let stringLength = string.length, i = 0; i < stringLength; i++) { let chr = string.charCodeAt(i) hash = (hash << 5) - hash + chr hash |= 0 diff --git a/preview/elements/chart-doughnut.svelte b/preview/elements/chart-doughnut.svelte index 2b9d52a..5a5f6b6 100644 --- a/preview/elements/chart-doughnut.svelte +++ b/preview/elements/chart-doughnut.svelte @@ -1,12 +1,14 @@ diff --git a/preview/elements/chart.svelte b/preview/elements/chart.svelte index 99d6a23..09fa014 100644 --- a/preview/elements/chart.svelte +++ b/preview/elements/chart.svelte @@ -14,17 +14,17 @@ export let options: ChartOptions export let height: number | null = null - let canvasRef: HTMLCanvasElement + let canvasReference: HTMLCanvasElement let chart: Chart | null = null - let resizeObserver: ResizeObserver + let resizeObserver: ResizeObserver | null = null - let createChart = () => { + let createChart = (): void => { if (chart) { chart.destroy() } - chart = new Chart(canvasRef, { + chart = new Chart(canvasReference, { options: { ...options, maintainAspectRatio: false, @@ -42,8 +42,8 @@ chart?.resize() }) - if (canvasRef.parentElement) { - resizeObserver.observe(canvasRef.parentElement) + if (canvasReference.parentElement) { + resizeObserver.observe(canvasReference.parentElement) } }) @@ -63,7 +63,7 @@ }) - +