mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 06:58:04 +08:00
🔧 Create fixViebox cli.
This commit is contained in:
parent
4cbd522880
commit
c802690de1
62
fix-viewbox/index.js
Normal file
62
fix-viewbox/index.js
Normal file
@ -0,0 +1,62 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const { readdir, stat } = require('fs').promises;
|
||||
const { readFile, writeFile } = require('fs/promises');
|
||||
const { join } = require('path');
|
||||
|
||||
// 🔎 Settings:
|
||||
const dir = '../static/library';
|
||||
|
||||
async function fixViewbox() {
|
||||
const files = await readdir(dir);
|
||||
const fileType = 'svg';
|
||||
let message = '';
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = join(dir, file);
|
||||
const fileStat = await stat(filePath);
|
||||
if (fileStat.isFile() && file.endsWith(fileType)) {
|
||||
const fileContent = await readFile(filePath);
|
||||
const viewBox = getViewBox(fileContent);
|
||||
const width = getWidth(fileContent);
|
||||
const height = getHeight(fileContent);
|
||||
if (!viewBox) {
|
||||
const newFileContent = fileContent
|
||||
.toString()
|
||||
.replace('<svg', `<svg viewBox="0 0 ${width} ${height}"`);
|
||||
await writeFile(filePath, newFileContent);
|
||||
message = `🔔 File ${file} has been fixed.\n`;
|
||||
console.log(message);
|
||||
} else {
|
||||
message = `✅ File ${file} has already a viewBox.\n`;
|
||||
console.log(message);
|
||||
}
|
||||
} else {
|
||||
message = `❌ File ${file} is not a ${fileType} file.\n`;
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
// Log the result:
|
||||
console.log('🚀 Done.');
|
||||
}
|
||||
|
||||
function getViewBox(fileContent) {
|
||||
const viewBoxRegex = /viewBox="(.+?)"/;
|
||||
const viewBox = viewBoxRegex.exec(fileContent);
|
||||
return viewBox ? viewBox[1] : null;
|
||||
}
|
||||
|
||||
function getWidth(fileContent) {
|
||||
const widthRegex = /width="(.+?)"/;
|
||||
const width = widthRegex.exec(fileContent);
|
||||
return width ? width[1] : null;
|
||||
}
|
||||
|
||||
function getHeight(fileContent) {
|
||||
const heightRegex = /height="(.+?)"/;
|
||||
const height = heightRegex.exec(fileContent);
|
||||
return height ? height[1] : null;
|
||||
}
|
||||
|
||||
// Run the function
|
||||
fixViewbox();
|
21
fix-viewbox/package.json
Normal file
21
fix-viewbox/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@svgl/fix-viewbox",
|
||||
"version": "1.0.0",
|
||||
"description": "Add viewbox to svg files if not present.",
|
||||
"main": "index.js",
|
||||
"author": "@pheralb_",
|
||||
"license": "ISC",
|
||||
"keywords": [
|
||||
"svg",
|
||||
"size",
|
||||
"limit",
|
||||
"check"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "1.10.1",
|
||||
"@actions/github": "6.0.0"
|
||||
}
|
||||
}
|
166
fix-viewbox/pnpm-lock.yaml
generated
Normal file
166
fix-viewbox/pnpm-lock.yaml
generated
Normal file
@ -0,0 +1,166 @@
|
||||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
'@actions/core':
|
||||
specifier: 1.10.1
|
||||
version: 1.10.1
|
||||
'@actions/github':
|
||||
specifier: 6.0.0
|
||||
version: 6.0.0
|
||||
|
||||
packages:
|
||||
|
||||
/@actions/core@1.10.1:
|
||||
resolution: {integrity: sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==}
|
||||
dependencies:
|
||||
'@actions/http-client': 2.2.0
|
||||
uuid: 8.3.2
|
||||
dev: false
|
||||
|
||||
/@actions/github@6.0.0:
|
||||
resolution: {integrity: sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==}
|
||||
dependencies:
|
||||
'@actions/http-client': 2.2.0
|
||||
'@octokit/core': 5.0.2
|
||||
'@octokit/plugin-paginate-rest': 9.1.5(@octokit/core@5.0.2)
|
||||
'@octokit/plugin-rest-endpoint-methods': 10.2.0(@octokit/core@5.0.2)
|
||||
dev: false
|
||||
|
||||
/@actions/http-client@2.2.0:
|
||||
resolution: {integrity: sha512-q+epW0trjVUUHboliPb4UF9g2msf+w61b32tAkFEwL/IwP0DQWgbCMM0Hbe3e3WXSKz5VcUXbzJQgy8Hkra/Lg==}
|
||||
dependencies:
|
||||
tunnel: 0.0.6
|
||||
undici: 5.28.2
|
||||
dev: false
|
||||
|
||||
/@fastify/busboy@2.1.0:
|
||||
resolution: {integrity: sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==}
|
||||
engines: {node: '>=14'}
|
||||
dev: false
|
||||
|
||||
/@octokit/auth-token@4.0.0:
|
||||
resolution: {integrity: sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==}
|
||||
engines: {node: '>= 18'}
|
||||
dev: false
|
||||
|
||||
/@octokit/core@5.0.2:
|
||||
resolution: {integrity: sha512-cZUy1gUvd4vttMic7C0lwPed8IYXWYp8kHIMatyhY8t8n3Cpw2ILczkV5pGMPqef7v0bLo0pOHrEHarsau2Ydg==}
|
||||
engines: {node: '>= 18'}
|
||||
dependencies:
|
||||
'@octokit/auth-token': 4.0.0
|
||||
'@octokit/graphql': 7.0.2
|
||||
'@octokit/request': 8.1.6
|
||||
'@octokit/request-error': 5.0.1
|
||||
'@octokit/types': 12.4.0
|
||||
before-after-hook: 2.2.3
|
||||
universal-user-agent: 6.0.1
|
||||
dev: false
|
||||
|
||||
/@octokit/endpoint@9.0.4:
|
||||
resolution: {integrity: sha512-DWPLtr1Kz3tv8L0UvXTDP1fNwM0S+z6EJpRcvH66orY6Eld4XBMCSYsaWp4xIm61jTWxK68BrR7ibO+vSDnZqw==}
|
||||
engines: {node: '>= 18'}
|
||||
dependencies:
|
||||
'@octokit/types': 12.4.0
|
||||
universal-user-agent: 6.0.1
|
||||
dev: false
|
||||
|
||||
/@octokit/graphql@7.0.2:
|
||||
resolution: {integrity: sha512-OJ2iGMtj5Tg3s6RaXH22cJcxXRi7Y3EBqbHTBRq+PQAqfaS8f/236fUrWhfSn8P4jovyzqucxme7/vWSSZBX2Q==}
|
||||
engines: {node: '>= 18'}
|
||||
dependencies:
|
||||
'@octokit/request': 8.1.6
|
||||
'@octokit/types': 12.4.0
|
||||
universal-user-agent: 6.0.1
|
||||
dev: false
|
||||
|
||||
/@octokit/openapi-types@19.1.0:
|
||||
resolution: {integrity: sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==}
|
||||
dev: false
|
||||
|
||||
/@octokit/plugin-paginate-rest@9.1.5(@octokit/core@5.0.2):
|
||||
resolution: {integrity: sha512-WKTQXxK+bu49qzwv4qKbMMRXej1DU2gq017euWyKVudA6MldaSSQuxtz+vGbhxV4CjxpUxjZu6rM2wfc1FiWVg==}
|
||||
engines: {node: '>= 18'}
|
||||
peerDependencies:
|
||||
'@octokit/core': '>=5'
|
||||
dependencies:
|
||||
'@octokit/core': 5.0.2
|
||||
'@octokit/types': 12.4.0
|
||||
dev: false
|
||||
|
||||
/@octokit/plugin-rest-endpoint-methods@10.2.0(@octokit/core@5.0.2):
|
||||
resolution: {integrity: sha512-ePbgBMYtGoRNXDyKGvr9cyHjQ163PbwD0y1MkDJCpkO2YH4OeXX40c4wYHKikHGZcpGPbcRLuy0unPUuafco8Q==}
|
||||
engines: {node: '>= 18'}
|
||||
peerDependencies:
|
||||
'@octokit/core': '>=5'
|
||||
dependencies:
|
||||
'@octokit/core': 5.0.2
|
||||
'@octokit/types': 12.4.0
|
||||
dev: false
|
||||
|
||||
/@octokit/request-error@5.0.1:
|
||||
resolution: {integrity: sha512-X7pnyTMV7MgtGmiXBwmO6M5kIPrntOXdyKZLigNfQWSEQzVxR4a4vo49vJjTWX70mPndj8KhfT4Dx+2Ng3vnBQ==}
|
||||
engines: {node: '>= 18'}
|
||||
dependencies:
|
||||
'@octokit/types': 12.4.0
|
||||
deprecation: 2.3.1
|
||||
once: 1.4.0
|
||||
dev: false
|
||||
|
||||
/@octokit/request@8.1.6:
|
||||
resolution: {integrity: sha512-YhPaGml3ncZC1NfXpP3WZ7iliL1ap6tLkAp6MvbK2fTTPytzVUyUesBBogcdMm86uRYO5rHaM1xIWxigWZ17MQ==}
|
||||
engines: {node: '>= 18'}
|
||||
dependencies:
|
||||
'@octokit/endpoint': 9.0.4
|
||||
'@octokit/request-error': 5.0.1
|
||||
'@octokit/types': 12.4.0
|
||||
universal-user-agent: 6.0.1
|
||||
dev: false
|
||||
|
||||
/@octokit/types@12.4.0:
|
||||
resolution: {integrity: sha512-FLWs/AvZllw/AGVs+nJ+ELCDZZJk+kY0zMen118xhL2zD0s1etIUHm1odgjP7epxYU1ln7SZxEUWYop5bhsdgQ==}
|
||||
dependencies:
|
||||
'@octokit/openapi-types': 19.1.0
|
||||
dev: false
|
||||
|
||||
/before-after-hook@2.2.3:
|
||||
resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==}
|
||||
dev: false
|
||||
|
||||
/deprecation@2.3.1:
|
||||
resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==}
|
||||
dev: false
|
||||
|
||||
/once@1.4.0:
|
||||
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
|
||||
dependencies:
|
||||
wrappy: 1.0.2
|
||||
dev: false
|
||||
|
||||
/tunnel@0.0.6:
|
||||
resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==}
|
||||
engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'}
|
||||
dev: false
|
||||
|
||||
/undici@5.28.2:
|
||||
resolution: {integrity: sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==}
|
||||
engines: {node: '>=14.0'}
|
||||
dependencies:
|
||||
'@fastify/busboy': 2.1.0
|
||||
dev: false
|
||||
|
||||
/universal-user-agent@6.0.1:
|
||||
resolution: {integrity: sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==}
|
||||
dev: false
|
||||
|
||||
/uuid@8.3.2:
|
||||
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/wrappy@1.0.2:
|
||||
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
|
||||
dev: false
|
@ -20,6 +20,7 @@
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"check:size": "cd ./check-size && npm run start",
|
||||
"fix:viewbox": "cd ./fix-viewbox && npm run start",
|
||||
"test": "vitest run",
|
||||
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
||||
"format": "prettier --plugin-search-dir . --write ."
|
||||
|
Loading…
x
Reference in New Issue
Block a user