From 14060b4799c8659f83e53bdb8d3b42b0cd89dbcd Mon Sep 17 00:00:00 2001 From: Xaroz Date: Thu, 19 Dec 2024 12:02:15 -0600 Subject: [PATCH] chore: check for raster image, update svg with raster images --- chains/bitlayer/logo.svg | 2 +- chains/dogechain/logo.svg | 2 +- chains/endurance/logo.svg | 2 +- chains/ham/logo.svg | 4 +--- scripts/optimize-svg.js | 24 ++++++++++++++++++------ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/chains/bitlayer/logo.svg b/chains/bitlayer/logo.svg index f45921231..dd5c9019f 100644 --- a/chains/bitlayer/logo.svg +++ b/chains/bitlayer/logo.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/chains/dogechain/logo.svg b/chains/dogechain/logo.svg index 8a384109e..13695753e 100644 --- a/chains/dogechain/logo.svg +++ b/chains/dogechain/logo.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/chains/endurance/logo.svg b/chains/endurance/logo.svg index d6e2b2ba5..a40e2ec70 100644 --- a/chains/endurance/logo.svg +++ b/chains/endurance/logo.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/chains/ham/logo.svg b/chains/ham/logo.svg index d8d1c2dbf..7812b3beb 100644 --- a/chains/ham/logo.svg +++ b/chains/ham/logo.svg @@ -1,3 +1 @@ - - - + \ No newline at end of file diff --git a/scripts/optimize-svg.js b/scripts/optimize-svg.js index af1744780..efbd6e2da 100644 --- a/scripts/optimize-svg.js +++ b/scripts/optimize-svg.js @@ -2,20 +2,31 @@ import fs from 'fs'; import path from 'path'; const directories = ['./chains', './deployments']; -const MAX_FILE_SIZE = 20 * 1024; // 20KBs +const MAX_FILE_SIZE = 100 * 1024; // 100KBs +const RASTER_IMAGE_REGEX = /]*>/i; -function isValidSvg(filePath) { +function isValidSvg(filePath, fileContent) { const fileName = path.basename(filePath); const stats = fs.statSync(filePath); + const currentFileSize = (stats.size / 1024).toFixed(2); if (!fileName.endsWith('logo.svg')) { console.error(`Error: File does not end with 'logo.svg' -> ${filePath}`); - process.exit(1); // Exit immediately if criteria is not met + process.exit(1); } if (stats.size > MAX_FILE_SIZE) { - console.error(`Error: File size exceeds 20KBs -> ${filePath}`); - process.exit(1); // Exit immediately if criteria is not met + console.error( + `Error: File size exceeds 100KBs (Current size: ${currentFileSize}KB) -> ${filePath}`, + ); + process.exit(1); + } + + if (RASTER_IMAGE_REGEX.test(fileContent)) { + console.error( + `Error: File contains an tag, likely embedding a raster image -> ${filePath}`, + ); + process.exit(1); } } @@ -29,7 +40,8 @@ function findAndProcessSVGs(directory) { if (stats.isDirectory()) { findAndProcessSVGs(fullPath); // Recurse into subdirectories } else if (path.extname(fullPath) === '.svg') { - isValidSvg(fullPath); // Validate file, exits on failure + const content = fs.readFileSync(fullPath, 'utf8'); + isValidSvg(fullPath, content); // Validate file, exits on failure } }); }