ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/icons/actions/lens.ts

actions/lens.ts

23 líneas, 1.4 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // shtuk run icons lens [--check]: writes the data of the icon lens (lib/design/icons.data.js) and its renderer
  2. // (lib/design/icon-render.js) from every icon set's registry and every installed IconStyle page.
  3. // --check: writes nothing, says whether the files are stale (exit code 1 when they are).
  4. import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
  5. import { dirname, join } from 'node:path';
  6. import { DATA_FILE, RENDER_FILE, dataText, lensData } from '../lib/lensdata.ts';
  7. const root = process.cwd();
  8. const d = lensData(root);
  9. const want: Record<string, string> = {
  10. [DATA_FILE]: dataText(d),
  11. [RENDER_FILE]: readFileSync(join(import.meta.dir, '..', 'lib', 'render.js'), 'utf8'),
  12. };
  13. const stale = Object.entries(want).filter(([p, t]) => !existsSync(join(root, p)) || readFileSync(join(root, p), 'utf8') !== t).map(([p]) => p);
  14. for (const e of d.errors) console.log(`(warn) ${e}`);
  15. if (process.argv.includes('--check')) {
  16. if (stale.length) { console.log(`stale: ${stale.join(', ')} → run: shtuk run icons lens`); process.exitCode = 1; }
  17. else console.log('the icon lens data is fresh');
  18. } else {
  19. for (const p of stale) { mkdirSync(dirname(join(root, p)), { recursive: true }); writeFileSync(join(root, p), want[p]); }
  20. const icons = d.sets.reduce((n, s) => n + s.icons.length, 0);
  21. console.log(`${DATA_FILE}: ${d.sets.length} set(s), ${icons} icons, ${d.styles.length} style(s)${stale.length ? '' : ' (unchanged)'}`);
  22. }