Skip to content

Commit

Permalink
Merge pull request #40 from jy95/minifyJson
Browse files Browse the repository at this point in the history
perf: minify json assets
  • Loading branch information
jy95 authored Apr 24, 2024
2 parents 8d226a1 + a9c1e29 commit 438abe3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/package-size-report.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: "lts/*"

- name: Package size report
uses: pkg-size/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
hide-files: "*.{js,css}.map"
30 changes: 26 additions & 4 deletions copyAssets.mjs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
}
}
}),
);
Expand Down
1 change: 1 addition & 0 deletions documentation/src/components/multiple_dosage_to_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
1 change: 1 addition & 0 deletions documentation/src/components/single_dosage_to_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down

0 comments on commit 438abe3

Please sign in to comment.