code.gitea.io/gitea@v1.22.3/tools/lint-templates-svg.js (about) 1 #!/usr/bin/env node 2 import {readdirSync, readFileSync} from 'node:fs'; 3 import {parse, relative} from 'node:path'; 4 import {fileURLToPath} from 'node:url'; 5 import {exit} from 'node:process'; 6 import fastGlob from 'fast-glob'; 7 8 const knownSvgs = new Set(); 9 for (const file of readdirSync(new URL('../public/assets/img/svg', import.meta.url))) { 10 knownSvgs.add(parse(file).name); 11 } 12 13 const rootPath = fileURLToPath(new URL('..', import.meta.url)); 14 let hadErrors = false; 15 16 for (const file of fastGlob.sync(fileURLToPath(new URL('../templates/**/*.tmpl', import.meta.url)))) { 17 const content = readFileSync(file, 'utf8'); 18 for (const [_, name] of content.matchAll(/svg ["'`]([^"'`]+)["'`]/g)) { 19 if (!knownSvgs.has(name)) { 20 console.info(`SVG "${name}" not found, used in ${relative(rootPath, file)}`); 21 hadErrors = true; 22 } 23 } 24 } 25 26 exit(hadErrors ? 1 : 0);