mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
📦 Move utilities to a separate folder
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const { readdir, stat } = require('fs').promises;
|
||||
const { join } = require('path');
|
||||
|
||||
// For GitHub Actions:
|
||||
const core = require('@actions/core');
|
||||
|
||||
// 🔎 Settings:
|
||||
const dir = '../static/library';
|
||||
const sizeLimit = 20000; // 20kb;
|
||||
|
||||
function convertBytes(bytes, format = 'KB') {
|
||||
if (format === 'KB') {
|
||||
return (bytes / 1024).toFixed(2) + ' KB';
|
||||
} else if (format === 'MB') {
|
||||
return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
|
||||
} else {
|
||||
return 'Invalid format. Use "KB" or "MB".';
|
||||
}
|
||||
}
|
||||
|
||||
async function checkSize() {
|
||||
const files = await readdir(dir);
|
||||
let maxSize = 0;
|
||||
let maxFiles = [];
|
||||
let message = '';
|
||||
|
||||
try {
|
||||
for (const file of files) {
|
||||
const filePath = join(dir, file);
|
||||
const stats = await stat(filePath);
|
||||
|
||||
if (stats.size >= sizeLimit) {
|
||||
maxFiles.push({
|
||||
filename: file,
|
||||
size: stats.size
|
||||
});
|
||||
if (stats.size > maxSize) {
|
||||
maxSize = stats.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (maxFiles.length === 0) {
|
||||
message = `- ✅ All files are smaller than ${convertBytes(sizeLimit)}`;
|
||||
core.setOutput('message', message);
|
||||
} else {
|
||||
message = `- ❌ There are files bigger than ${convertBytes(sizeLimit)}.`;
|
||||
throw new Error(message);
|
||||
}
|
||||
} catch (err) {
|
||||
core.setFailed(message);
|
||||
} finally {
|
||||
if (maxFiles.length > 0) {
|
||||
console.log('🔎 Files found:');
|
||||
maxFiles.forEach((file) => {
|
||||
console.log(`- 📄 ${file.filename} - ${convertBytes(file.size, 'KB')}`);
|
||||
});
|
||||
}
|
||||
console.log('⚙️ Settings:');
|
||||
console.log(`- 📁 Directory: ${dir}`);
|
||||
console.log(`- 🧱 Size limit: ${convertBytes(sizeLimit)} bytes`);
|
||||
if (maxSize > 0) {
|
||||
console.log(`- 🔔 Max size found: ${convertBytes(maxSize, 'KB')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run the function
|
||||
checkSize();
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@svgl/check-size",
|
||||
"version": "1.0.0",
|
||||
"description": "Limit the size of your SVG files",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
Generated
+166
@@ -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
|
||||
Reference in New Issue
Block a user