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