From 079666e3a21b25141fb2bd9cc7535bfb225a343c Mon Sep 17 00:00:00 2001 From: jy95 Date: Wed, 24 Apr 2024 19:40:29 +0200 Subject: [PATCH 1/4] perf: minify json assets --- copyAssets.mjs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/copyAssets.mjs b/copyAssets.mjs index 43bd7554..73c240ed 100644 --- a/copyAssets.mjs +++ b/copyAssets.mjs @@ -1,9 +1,21 @@ -import { mkdir, readdir, stat, copyFile } from "fs/promises"; -import { join } from "path"; +import { + mkdir, + readdir, + stat, + copyFile, + writeFile, + readFile, +} from "fs/promises"; +import { join, extname } from "path"; const sourceDir = "./src/locales"; const destDir = "./dist/locales"; +// Function to minify JSON content +function minifyJSON(content) { + return JSON.stringify(JSON.parse(content)); +} + // Function to recursively copy directories async function copyDirAsync(src, dest) { try { @@ -18,8 +30,18 @@ async function copyDirAsync(src, dest) { // Recursively copy subdirectories await copyDirAsync(srcPath, destPath); } else { - // Copy files - await copyFile(srcPath, destPath); + // Check if it's a JSON file + if (extname(file) === ".json") { + // Read JSON content + const content = await readFile(srcPath, "utf-8"); + // Minify JSON content + const minifiedContent = minifyJSON(content); + // Write minified JSON to destination + await writeFile(destPath, minifiedContent); + } else { + // Copy files + await copyFile(srcPath, destPath); + } } }), ); From 85d9cb5d137f8ac6c270e7f98cebfa511c66e6c5 Mon Sep 17 00:00:00 2001 From: jy95 Date: Wed, 24 Apr 2024 19:54:52 +0200 Subject: [PATCH 2/4] ci: add package size --- .github/workflows/package-size-report.yml | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/package-size-report.yml diff --git a/.github/workflows/package-size-report.yml b/.github/workflows/package-size-report.yml new file mode 100644 index 00000000..5afbec89 --- /dev/null +++ b/.github/workflows/package-size-report.yml @@ -0,0 +1,26 @@ +name: Package Size Report + +on: + pull_request: + branches: [main] + +jobs: + pkg-size-report: + name: Package Size Report + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4.1.3 + + - name: Setup Node.js + uses: actions/setup-node@v4.0.2 + with: + node-version: "lts/*" + + - name: Package size report + uses: pkg-size/action@v1.1.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + hide-files: "*.{js,css}.map" From e53ee659e96fb5a3ae1debae625df298651e296e Mon Sep 17 00:00:00 2001 From: jy95 Date: Wed, 24 Apr 2024 20:09:11 +0200 Subject: [PATCH 3/4] docs: fix rendering of html entities --- documentation/src/components/multiple_dosage_to_text.tsx | 1 + documentation/src/components/single_dosage_to_text.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/documentation/src/components/multiple_dosage_to_text.tsx b/documentation/src/components/multiple_dosage_to_text.tsx index 2bb0459b..f397ef2c 100644 --- a/documentation/src/components/multiple_dosage_to_text.tsx +++ b/documentation/src/components/multiple_dosage_to_text.tsx @@ -13,6 +13,7 @@ type Dosage = DosageR4 | DosageR5; function decodeHtmlEntities(text: string): string { return text .replace(/"/g, '"') + .replace(/&/g, '&') .replace(/&#(\d+);/g, function (match, dec) { return String.fromCharCode(dec); }) diff --git a/documentation/src/components/single_dosage_to_text.tsx b/documentation/src/components/single_dosage_to_text.tsx index b7510c27..218b46ac 100644 --- a/documentation/src/components/single_dosage_to_text.tsx +++ b/documentation/src/components/single_dosage_to_text.tsx @@ -13,6 +13,7 @@ type Dosage = DosageR4 | DosageR5; function decodeHtmlEntities(text: string): string { return text .replace(/"/g, '"') + .replace(/&/g, '&') .replace(/&#(\d+);/g, function (match, dec) { return String.fromCharCode(dec); }) From a9c1e29855f77b002981367f52294f1d7dc0ddef Mon Sep 17 00:00:00 2001 From: jy95 Date: Wed, 24 Apr 2024 20:12:19 +0200 Subject: [PATCH 4/4] chore: linting --- .github/workflows/lint.yml | 2 +- documentation/src/components/multiple_dosage_to_text.tsx | 2 +- documentation/src/components/single_dosage_to_text.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 01f5919f..8363cf46 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,7 +18,7 @@ jobs: with: node-version: "lts/*" - name: 🚧 Install dependencies - run: npm ci + run: npm install - name: 🛂 Enforce linting run: npm run lint-fix - uses: EndBug/add-and-commit@v9.1.4 diff --git a/documentation/src/components/multiple_dosage_to_text.tsx b/documentation/src/components/multiple_dosage_to_text.tsx index f397ef2c..6295c650 100644 --- a/documentation/src/components/multiple_dosage_to_text.tsx +++ b/documentation/src/components/multiple_dosage_to_text.tsx @@ -13,7 +13,7 @@ type Dosage = DosageR4 | DosageR5; function decodeHtmlEntities(text: string): string { return text .replace(/"/g, '"') - .replace(/&/g, '&') + .replace(/&/g, "&") .replace(/&#(\d+);/g, function (match, dec) { return String.fromCharCode(dec); }) diff --git a/documentation/src/components/single_dosage_to_text.tsx b/documentation/src/components/single_dosage_to_text.tsx index 218b46ac..a88904b0 100644 --- a/documentation/src/components/single_dosage_to_text.tsx +++ b/documentation/src/components/single_dosage_to_text.tsx @@ -13,7 +13,7 @@ type Dosage = DosageR4 | DosageR5; function decodeHtmlEntities(text: string): string { return text .replace(/"/g, '"') - .replace(/&/g, '&') + .replace(/&/g, "&") .replace(/&#(\d+);/g, function (match, dec) { return String.fromCharCode(dec); })