-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: optimize-svg | ||
|
||
on: | ||
pull_request: | ||
# Allows you to run this workflow manually | ||
workflow_dispatch: | ||
|
||
jobs: | ||
combine: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref || 'main' }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
**/node_modules | ||
.yarn/cache | ||
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }} | ||
|
||
- name: yarn-install | ||
run: | | ||
yarn install | ||
CHANGES=$(git status -s) | ||
if [[ ! -z $CHANGES ]]; then | ||
echo "Changes found: $CHANGES" | ||
git diff | ||
exit 1 | ||
fi | ||
- name: setup-node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
|
||
- name: validate-optimize-svgs | ||
run: | | ||
node ./scripts/optimize-svg.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const directories = ['./chains', './deployments']; | ||
const MAX_FILE_SIZE = 20 * 1024; // 20KBs | ||
|
||
function isValidSvg(filePath) { | ||
const fileName = path.basename(filePath); | ||
const stats = fs.statSync(filePath); | ||
|
||
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 | ||
} | ||
|
||
if (stats.size > MAX_FILE_SIZE) { | ||
console.error(`Error: File size exceeds 20KBs -> ${filePath}`); | ||
// process.exit(1); // Exit immediately if criteria is not met | ||
} | ||
} | ||
|
||
function findAndProcessSVGs(directory) { | ||
const files = fs.readdirSync(directory); | ||
|
||
files.forEach((file) => { | ||
const fullPath = path.join(directory, file); | ||
const stats = fs.statSync(fullPath); | ||
|
||
if (stats.isDirectory()) { | ||
findAndProcessSVGs(fullPath); // Recurse into subdirectories | ||
} else if (path.extname(fullPath) === '.svg') { | ||
isValidSvg(fullPath); // Validate file, exits on failure | ||
} | ||
}); | ||
} | ||
|
||
directories.forEach((directory) => { | ||
if (fs.existsSync(directory)) { | ||
console.log(`Checking directory: ${directory}`); | ||
findAndProcessSVGs(directory); | ||
} else { | ||
console.log(`Directory does not exist: ${directory}`); | ||
} | ||
}); |