gitea源码

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env node
  2. import {readdirSync, readFileSync, globSync} from 'node:fs';
  3. import {parse, relative} from 'node:path';
  4. import {fileURLToPath} from 'node:url';
  5. import {exit} from 'node:process';
  6. const knownSvgs = new Set<string>();
  7. for (const file of readdirSync(new URL('../public/assets/img/svg', import.meta.url))) {
  8. knownSvgs.add(parse(file).name);
  9. }
  10. const rootPath = fileURLToPath(new URL('..', import.meta.url));
  11. let hadErrors = false;
  12. for (const file of globSync(fileURLToPath(new URL('../templates/**/*.tmpl', import.meta.url)))) {
  13. const content = readFileSync(file, 'utf8');
  14. for (const [_, name] of content.matchAll(/svg ["'`]([^"'`]+)["'`]/g)) {
  15. if (!knownSvgs.has(name)) {
  16. console.info(`SVG "${name}" not found, used in ${relative(rootPath, file)}`);
  17. hadErrors = true;
  18. }
  19. }
  20. }
  21. exit(hadErrors ? 1 : 0);