From 3b94d364157daa9925f917e5e37c0da0cf2745ce Mon Sep 17 00:00:00 2001 From: "F. Talha Altinel" Date: Fri, 19 Jul 2024 00:12:05 +0100 Subject: [PATCH 1/3] add biome --- .github/workflows/build.yaml | 33 +++--- .github/workflows/publish.yaml | 2 +- Taskfile.yaml | 18 ---- biome.json | 20 ++++ package.json | 50 ++++----- pnpm-lock.yaml | 91 ++++++++++++++++ src/app.d.ts | 14 +-- src/lib/Footer.svelte | 2 +- src/lib/Header.svelte | 2 +- src/lib/InvoiceForm.svelte | 192 +++++++++++++++++---------------- src/lib/InvoicePrint.svelte | 36 +++---- src/lib/decimal.ts | 2 +- src/routes/+layout.svelte | 2 +- src/routes/+layout.ts | 2 +- src/routes/+page.svelte | 6 +- src/routes/print/+layout.ts | 2 +- src/routes/print/+page.svelte | 2 +- src/store.ts | 14 +-- static/manifest.json | 20 +++- svelte.config.js | 22 ++-- tsconfig.json | 32 +++--- vite.config.ts | 6 +- 22 files changed, 344 insertions(+), 226 deletions(-) create mode 100644 biome.json diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f9d22db..831bd14 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,37 +2,40 @@ name: Build with PNPM on: push: - branches: [ "master" ] + branches: [ "master", "main" ] pull_request: - branches: [ "master" ] + branches: [ "master", "main" ] jobs: build: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Setup node + - name: Setup Biome + uses: biomejs/setup-biome@v2 + with: + version: latest + + - name: Run Biome + run: biome ci . + + - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.5 - - - name: Install Task - uses: arduino/setup-task@v1 - with: - version: 3.x + version: latest - - name: PNPM install - run: task install + - name: Fetch Deps + run: pnpm install - - name: PNPM build - run: task build + - name: Build + run: pnpm build diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index a95b33b..5f4e5ec 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/Taskfile.yaml b/Taskfile.yaml index 30e1e65..9fe3a66 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -2,24 +2,6 @@ version: '3' silent: true tasks: - install: - desc: installs deps - cmds: - - | - pnpm install - - run: - desc: runs on localhost - cmds: - - | - pnpm dev - - build: - desc: builds the bundle - cmds: - - | - pnpm build - docker:build: desc: builds the docker image vars: diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..fe72def --- /dev/null +++ b/biome.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "files": { + "ignore": ["generated/", ".svelte-kit/", "build/", "node_modules/"] + }, + "formatter": { + "indentStyle": "space", + "indentWidth": 4, + "lineWidth": 80 + } +} diff --git a/package.json b/package.json index 407626a..e611694 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,28 @@ { - "name": "lamia", - "version": "0.0.1", - "private": true, - "scripts": { - "dev": "vite dev", - "build": "vite build", - "preview": "vite preview", - "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "prepare": "svelte-kit sync" - }, - "devDependencies": { - "@sveltejs/adapter-static": "^3.0.2", - "@sveltejs/kit": "^2.5.14", - "@sveltejs/vite-plugin-svelte": "^3.1.1", - "bulma": "^0.9.4", - "sass": "^1.77.5", - "svelte": "^4.2.18", - "svelte-check": "^3.8.0", - "tslib": "^2.6.3", - "typescript": "^5.4.5", - "vite": "^5.3.1" - }, - "type": "module" + "name": "lamia", + "version": "0.0.1", + "private": true, + "scripts": { + "dev": "vite dev", + "build": "vite build", + "preview": "vite preview", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", + "prepare": "svelte-kit sync", + "biome": "pnpx @biomejs/biome check" + }, + "devDependencies": { + "@biomejs/biome": "1.8.3", + "@sveltejs/adapter-static": "^3.0.2", + "@sveltejs/kit": "^2.5.14", + "@sveltejs/vite-plugin-svelte": "^3.1.1", + "bulma": "^0.9.4", + "sass": "^1.77.5", + "svelte": "^4.2.18", + "svelte-check": "^3.8.0", + "tslib": "^2.6.3", + "typescript": "^5.4.5", + "vite": "^5.3.1" + }, + "type": "module" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 65e626c..ddaa3f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: devDependencies: + '@biomejs/biome': + specifier: 1.8.3 + version: 1.8.3 '@sveltejs/adapter-static': specifier: ^3.0.2 version: 3.0.2(@sveltejs/kit@2.5.14(@sveltejs/vite-plugin-svelte@3.1.1(svelte@4.2.18)(vite@5.3.1(sass@1.77.5)))(svelte@4.2.18)(vite@5.3.1(sass@1.77.5))) @@ -45,6 +48,59 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} + '@biomejs/biome@1.8.3': + resolution: {integrity: sha512-/uUV3MV+vyAczO+vKrPdOW0Iaet7UnJMU4bNMinggGJTAnBPjCoLEYcyYtYHNnUNYlv4xZMH6hVIQCAozq8d5w==} + engines: {node: '>=14.21.3'} + hasBin: true + + '@biomejs/cli-darwin-arm64@1.8.3': + resolution: {integrity: sha512-9DYOjclFpKrH/m1Oz75SSExR8VKvNSSsLnVIqdnKexj6NwmiMlKk94Wa1kZEdv6MCOHGHgyyoV57Cw8WzL5n3A==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [darwin] + + '@biomejs/cli-darwin-x64@1.8.3': + resolution: {integrity: sha512-UeW44L/AtbmOF7KXLCoM+9PSgPo0IDcyEUfIoOXYeANaNXXf9mLUwV1GeF2OWjyic5zj6CnAJ9uzk2LT3v/wAw==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [darwin] + + '@biomejs/cli-linux-arm64-musl@1.8.3': + resolution: {integrity: sha512-9yjUfOFN7wrYsXt/T/gEWfvVxKlnh3yBpnScw98IF+oOeCYb5/b/+K7YNqKROV2i1DlMjg9g/EcN9wvj+NkMuQ==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [linux] + + '@biomejs/cli-linux-arm64@1.8.3': + resolution: {integrity: sha512-fed2ji8s+I/m8upWpTJGanqiJ0rnlHOK3DdxsyVLZQ8ClY6qLuPc9uehCREBifRJLl/iJyQpHIRufLDeotsPtw==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [linux] + + '@biomejs/cli-linux-x64-musl@1.8.3': + resolution: {integrity: sha512-UHrGJX7PrKMKzPGoEsooKC9jXJMa28TUSMjcIlbDnIO4EAavCoVmNQaIuUSH0Ls2mpGMwUIf+aZJv657zfWWjA==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [linux] + + '@biomejs/cli-linux-x64@1.8.3': + resolution: {integrity: sha512-I8G2QmuE1teISyT8ie1HXsjFRz9L1m5n83U1O6m30Kw+kPMPSKjag6QGUn+sXT8V+XWIZxFFBoTDEDZW2KPDDw==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [linux] + + '@biomejs/cli-win32-arm64@1.8.3': + resolution: {integrity: sha512-J+Hu9WvrBevfy06eU1Na0lpc7uR9tibm9maHynLIoAjLZpQU3IW+OKHUtyL8p6/3pT2Ju5t5emReeIS2SAxhkQ==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [win32] + + '@biomejs/cli-win32-x64@1.8.3': + resolution: {integrity: sha512-/PJ59vA1pnQeKahemaQf4Nyj7IKUvGQSc3Ze1uIGi+Wvr1xF7rGobSrAAG01T/gUDG21vkDsZYM03NAmPiVkqg==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [win32] + '@esbuild/aix-ppc64@0.21.5': resolution: {integrity: sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==} engines: {node: '>=12'} @@ -759,6 +815,41 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 + '@biomejs/biome@1.8.3': + optionalDependencies: + '@biomejs/cli-darwin-arm64': 1.8.3 + '@biomejs/cli-darwin-x64': 1.8.3 + '@biomejs/cli-linux-arm64': 1.8.3 + '@biomejs/cli-linux-arm64-musl': 1.8.3 + '@biomejs/cli-linux-x64': 1.8.3 + '@biomejs/cli-linux-x64-musl': 1.8.3 + '@biomejs/cli-win32-arm64': 1.8.3 + '@biomejs/cli-win32-x64': 1.8.3 + + '@biomejs/cli-darwin-arm64@1.8.3': + optional: true + + '@biomejs/cli-darwin-x64@1.8.3': + optional: true + + '@biomejs/cli-linux-arm64-musl@1.8.3': + optional: true + + '@biomejs/cli-linux-arm64@1.8.3': + optional: true + + '@biomejs/cli-linux-x64-musl@1.8.3': + optional: true + + '@biomejs/cli-linux-x64@1.8.3': + optional: true + + '@biomejs/cli-win32-arm64@1.8.3': + optional: true + + '@biomejs/cli-win32-x64@1.8.3': + optional: true + '@esbuild/aix-ppc64@0.21.5': optional: true diff --git a/src/app.d.ts b/src/app.d.ts index f59b884..ac2945d 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,12 +1,12 @@ // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { - namespace App { - // interface Error {} - // interface Locals {} - // interface PageData {} - // interface Platform {} - } + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface Platform {} + } } -export {}; +export type {}; diff --git a/src/lib/Footer.svelte b/src/lib/Footer.svelte index f2ed737..a7d1653 100644 --- a/src/lib/Footer.svelte +++ b/src/lib/Footer.svelte @@ -1,5 +1,5 @@ diff --git a/src/lib/Header.svelte b/src/lib/Header.svelte index 5e4f39d..c51bc75 100644 --- a/src/lib/Header.svelte +++ b/src/lib/Header.svelte @@ -1,5 +1,5 @@
diff --git a/src/lib/InvoiceForm.svelte b/src/lib/InvoiceForm.svelte index e2927bc..170bc9c 100644 --- a/src/lib/InvoiceForm.svelte +++ b/src/lib/InvoiceForm.svelte @@ -1,120 +1,124 @@
- import { onMount } from "svelte"; - import { invoice } from "../store"; - import { DecimalFixed } from "./decimal"; +import { onMount } from "svelte"; +import { invoice } from "../store"; +import { DecimalFixed } from "./decimal"; - export let title = "Invoice"; +export let title = "Invoice"; - let from: Array = []; - let to: Array = []; - let notes: Array = []; +let from: Array = []; +let to: Array = []; +let notes: Array = []; - onMount(() => { - if ($invoice.invoiceNumber.trim() != "") { - title = $invoice.invoiceNumber; - } +onMount(() => { + if ($invoice.invoiceNumber.trim() !== "") { + title = $invoice.invoiceNumber; + } - from = $invoice.from.split("\n"); - to = $invoice.to.split("\n"); - notes = $invoice.notes.split("\n"); + from = $invoice.from.split("\n"); + to = $invoice.to.split("\n"); + notes = $invoice.notes.split("\n"); - setTimeout(() => { - window.print(); - }, 1000); - }); + setTimeout(() => { + window.print(); + }, 1000); +}); diff --git a/src/lib/decimal.ts b/src/lib/decimal.ts index df24151..0d7fbba 100644 --- a/src/lib/decimal.ts +++ b/src/lib/decimal.ts @@ -3,7 +3,7 @@ export function DecimalFixed(n: number): string { } export function DecimalFixedNum(n: number) { - let res: number = parseFloat((n * 100).toFixed(2)); + let res: number = Number.parseFloat((n * 100).toFixed(2)); res = Math.floor(res) / 100; return res; } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 2a4c112..00ebdea 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,5 +1,5 @@ diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 593dda3..6618e46 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -1 +1 @@ -export const prerender = true; // used for SSG(static site generation) \ No newline at end of file +export const prerender = true; // used for SSG(static site generation) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 75e4f57..71f3053 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,7 +1,7 @@
diff --git a/src/routes/print/+layout.ts b/src/routes/print/+layout.ts index 593dda3..6618e46 100644 --- a/src/routes/print/+layout.ts +++ b/src/routes/print/+layout.ts @@ -1 +1 @@ -export const prerender = true; // used for SSG(static site generation) \ No newline at end of file +export const prerender = true; // used for SSG(static site generation) diff --git a/src/routes/print/+page.svelte b/src/routes/print/+page.svelte index 697089f..38bfd42 100644 --- a/src/routes/print/+page.svelte +++ b/src/routes/print/+page.svelte @@ -1,5 +1,5 @@ diff --git a/src/store.ts b/src/store.ts index 36accc7..46b0158 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,12 +1,12 @@ -import { writable } from "svelte/store"; import { browser } from "$app/environment"; +import { writable } from "svelte/store"; type InvoiceRow = { description: string; rate: number | undefined; quantity: number | undefined; amount: string; -} +}; type InvoiceData = { rows: Array; @@ -20,14 +20,14 @@ type InvoiceData = { dueDate: string; logoFilename: string; logoBase64Img: string; -} +}; export const invoice = writable(fromLocalStorage()); invoice.subscribe(toLocalStorage); // Get the values from localStorage if in browser and the value is stored -function fromLocalStorage(key: string = "lamia-invoice-data"): InvoiceData { - let empty: InvoiceData = { +function fromLocalStorage(key = "lamia-invoice-data"): InvoiceData { + const empty: InvoiceData = { rows: [ { description: "", @@ -50,7 +50,7 @@ function fromLocalStorage(key: string = "lamia-invoice-data"): InvoiceData { if (!browser) { return empty; } - + const stored = window.localStorage.getItem(key); if (stored != null) { return JSON.parse(stored); @@ -65,4 +65,4 @@ function toLocalStorage(d: InvoiceData) { return; } localStorage.setItem("lamia-invoice-data", JSON.stringify(d)); -} \ No newline at end of file +} diff --git a/static/manifest.json b/static/manifest.json index a1cdef8..32a7b7d 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -1 +1,19 @@ -{"name":"Lamia","short_name":"Lamia","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file +{ + "name": "Lamia", + "short_name": "Lamia", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} diff --git a/svelte.config.js b/svelte.config.js index f94c348..b832320 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -3,18 +3,16 @@ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; /** @type {import('@sveltejs/kit').Config} */ const config = { - preprocess: [ - vitePreprocess(), - ], - kit: { - adapter: adapter({ - pages: "build", - assets: "build", - fallback: undefined, - precompress: false, - strict: true - }), - }, + preprocess: [vitePreprocess()], + kit: { + adapter: adapter({ + pages: "build", + assets: "build", + fallback: undefined, + precompress: false, + strict: true, + }), + }, }; export default config; diff --git a/tsconfig.json b/tsconfig.json index fe1b114..9960ed4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,18 @@ { - "extends": "./.svelte-kit/tsconfig.json", - "compilerOptions": { - "allowJs": true, - "checkJs": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "moduleResolution": "bundler", - } - // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias - // - // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes - // from the referenced tsconfig.json - TypeScript does not merge them in + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "bundler" + } + // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias + // + // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes + // from the referenced tsconfig.json - TypeScript does not merge them in } diff --git a/vite.config.ts b/vite.config.ts index bbf8c7d..4a79a4b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,6 @@ -import { sveltekit } from '@sveltejs/kit/vite'; -import { defineConfig } from 'vite'; +import { sveltekit } from "@sveltejs/kit/vite"; +import { defineConfig } from "vite"; export default defineConfig({ - plugins: [sveltekit()] + plugins: [sveltekit()], }); From b67eb2d84a46c2c905214e2f36a8143e16bcaa8b Mon Sep 17 00:00:00 2001 From: "F. Talha Altinel" Date: Fri, 19 Jul 2024 22:33:51 +0100 Subject: [PATCH 2/3] test biome --- .github/workflows/build.yaml | 2 -- biome.json | 3 +-- src/store.ts | 3 ++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 831bd14..b7ced41 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -15,8 +15,6 @@ jobs: - name: Setup Biome uses: biomejs/setup-biome@v2 - with: - version: latest - name: Run Biome run: biome ci . diff --git a/biome.json b/biome.json index fe72def..bb9feec 100644 --- a/biome.json +++ b/biome.json @@ -14,7 +14,6 @@ }, "formatter": { "indentStyle": "space", - "indentWidth": 4, - "lineWidth": 80 + "indentWidth": 4 } } diff --git a/src/store.ts b/src/store.ts index 46b0158..00e32d5 100644 --- a/src/store.ts +++ b/src/store.ts @@ -12,7 +12,8 @@ type InvoiceData = { rows: Array; currencySymbol: string; totalAmount: number; - notes: string; + +notes: string; from: string; to: string; invoiceNumber: string; From 69d4612d46b9fcd0eaa1370d87c17117551890c1 Mon Sep 17 00:00:00 2001 From: "F. Talha Altinel" Date: Fri, 19 Jul 2024 22:45:47 +0100 Subject: [PATCH 3/3] final biome fixes --- src/lib/InvoiceForm.svelte | 8 ++------ src/lib/InvoicePrint.svelte | 2 +- src/store.ts | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/lib/InvoiceForm.svelte b/src/lib/InvoiceForm.svelte index 170bc9c..c2e3304 100644 --- a/src/lib/InvoiceForm.svelte +++ b/src/lib/InvoiceForm.svelte @@ -38,11 +38,7 @@ $: if (browser) { function setLogo(event: Event) { const target = event.target as HTMLInputElement; - if ( - target.files !== undefined && - target.files != null && - target.files.length > 0 - ) { + if (target.files && target.files.length > 0) { const file = target.files[0]; if (!validImageTypes.includes(file.type)) { @@ -63,7 +59,7 @@ function setLogo(event: Event) { const reader: FileReader = new FileReader(); reader.onload = () => { - if (reader.result !== undefined && reader.result != null) { + if (reader.result) { $invoice.logoBase64Img = reader.result.toString(); $invoice.logoFilename = file.name; } diff --git a/src/lib/InvoicePrint.svelte b/src/lib/InvoicePrint.svelte index 039eb1c..66e39ea 100644 --- a/src/lib/InvoicePrint.svelte +++ b/src/lib/InvoicePrint.svelte @@ -92,7 +92,7 @@ onMount(() => { - {#if notes.length > 0} + {#if notes.length > 0 && notes.join().trim() != ""}
NOTES

diff --git a/src/store.ts b/src/store.ts index 00e32d5..886d0ac 100644 --- a/src/store.ts +++ b/src/store.ts @@ -12,8 +12,8 @@ type InvoiceData = { rows: Array; currencySymbol: string; totalAmount: number; - -notes: string; + + notes: string; from: string; to: string; invoiceNumber: string;