Skip to content

Commit a6d0872

Browse files
committed
perf: optimize SVGs
1 parent ab7403d commit a6d0872

File tree

116 files changed

+1215
-932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1215
-932
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ docker/lnd/
9595

9696
#Build
9797
android/app/release/
98+
99+
# Optimized SVGs
100+
src/assets/svgs/optimized/

biome.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": {
3-
"ignore": ["src/polyfills/**"]
3+
"ignore": ["src/polyfills/**", "src/assets/icons/index.ts"]
44
},
55
"linter": {
66
"rules": {

scripts/optimize-svgs.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { execSync } = require('child_process');
4+
5+
// Directory constants
6+
const DIRS = {
7+
RAW_SVGS: path.join(__dirname, '../src/assets/svgs/raw'),
8+
OPTIMIZED_SVGS: path.join(__dirname, '../src/assets/svgs/optimized'),
9+
INDEX: path.join(__dirname, '../src/assets/icons/index.ts'),
10+
};
11+
12+
/**
13+
* Clean and recreate the optimized SVGs directory
14+
*/
15+
function setupDirectories() {
16+
if (fs.existsSync(DIRS.OPTIMIZED_SVGS)) {
17+
fs.rmSync(DIRS.OPTIMIZED_SVGS, { recursive: true, force: true });
18+
}
19+
fs.mkdirSync(DIRS.OPTIMIZED_SVGS, { recursive: true });
20+
}
21+
22+
/**
23+
* Optimize SVGs using SVGO
24+
*/
25+
function optimizeSvgs() {
26+
console.log('\nOptimizing SVGs with SVGO...');
27+
try {
28+
execSync(`npx svgo -rf "${DIRS.RAW_SVGS}" -o "${DIRS.OPTIMIZED_SVGS}"`, {
29+
stdio: 'inherit',
30+
});
31+
console.log('\nSVG optimization completed successfully!');
32+
} catch (error) {
33+
throw new Error(`SVGO optimization failed: ${error.message}`);
34+
}
35+
}
36+
37+
/**
38+
* Generate the icons/index.ts file with optimized SVGs
39+
*/
40+
function generateIndexFile() {
41+
console.log('\nGenerating index.ts...');
42+
const optimizedSvgs = fs
43+
.readdirSync(DIRS.OPTIMIZED_SVGS)
44+
.filter((file) => file.endsWith('.svg'));
45+
46+
const indexContent = `/**
47+
* This file is auto-generated. Do not edit it manually.
48+
* Run \`node scripts/optimize-svgs.js\` to regenerate.
49+
*/
50+
51+
${optimizedSvgs
52+
.map((file) => {
53+
const name = path.basename(file, '.svg');
54+
const svgContent = fs.readFileSync(
55+
path.join(DIRS.OPTIMIZED_SVGS, file),
56+
'utf8',
57+
);
58+
return `export const ${name}Icon = (color = 'white'): string => \`\n${svgContent}\`;`;
59+
})
60+
.join('\n\n')}\n`;
61+
62+
fs.writeFileSync(DIRS.INDEX, indexContent);
63+
console.log(`Generated index.ts with ${optimizedSvgs.length} icons!`);
64+
}
65+
66+
function main() {
67+
try {
68+
// Setup directories
69+
setupDirectories();
70+
71+
// Optimize and generate index
72+
optimizeSvgs();
73+
generateIndexFile();
74+
} catch (error) {
75+
console.error('\nError:', error.message);
76+
process.exit(1);
77+
}
78+
}
79+
80+
main();

src/assets/icons/index.ts

+313
Large diffs are not rendered by default.

src/assets/icons/settings.ts

-274
This file was deleted.

src/assets/icons/tabs.ts

-13
This file was deleted.

src/assets/icons/wallet.ts

-530
This file was deleted.

src/assets/icons/widgets.ts

-60
This file was deleted.

src/assets/svgs/raw/about.svg

+8
Loading

0 commit comments

Comments
 (0)