You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lint-templates-svg.js 868B

1234567891011121314151617181920212223242526
  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. const knownSvgs = new Set();
  8. for (const file of readdirSync(new URL('../public/assets/img/svg', import.meta.url))) {
  9. knownSvgs.add(parse(file).name);
  10. }
  11. const rootPath = fileURLToPath(new URL('..', import.meta.url));
  12. let hadErrors = false;
  13. for (const file of fastGlob.sync(fileURLToPath(new URL('../templates/**/*.tmpl', import.meta.url)))) {
  14. const content = readFileSync(file, 'utf8');
  15. for (const [_, name] of content.matchAll(/svg ["'`]([^"'`]+)["'`]/g)) {
  16. if (!knownSvgs.has(name)) {
  17. console.info(`SVG "${name}" not found, used in ${relative(rootPath, file)}`);
  18. hadErrors = true;
  19. }
  20. }
  21. }
  22. exit(hadErrors ? 1 : 0);