archivo del paquete→ .shtukbase/packages/design-components/actions/sync.ts
actions/sync.ts
39 líneas, 2.2 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // design-components `sync`: reads every component header under /design/*/components/** and the folders listed in
- // `sources:` of /design/components.md, and writes one page per id to /design/components/, the data file for lenses
- // (lib/design/components.data.js), the resolved library CSS (lib/design/ui.css), the Custom Elements Manifest and the Storybook stories
- // (/design/stories/<id>.stories.js). The text under a page's header is kept. A header that does not parse stops
- // the run: nothing is written, the problems are printed, exit 1.
- // By hand: `shtuk run design-components sync [--prune]` (`--prune` also deletes pages whose component has no header).
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
- import { dirname, join } from 'node:path';
- import { plan } from '../lib/outputs.ts';
- import { collect } from '../lib/project.ts';
- const root = process.cwd();
- const prune = process.argv.includes('--prune');
- const col = collect(root);
- if (col.problems.length) {
- console.log(`design-components: nothing written — headers with errors:\n${col.problems.join('\n')}`);
- process.exit(1);
- }
- const p = plan(root, col);
- let wrote = 0;
- const put = (rel: string, text: string) => {
- const abs = join(root, rel);
- if (existsSync(abs) && readFileSync(abs, 'utf8') === text) return;
- mkdirSync(dirname(abs), { recursive: true });
- writeFileSync(abs, text);
- wrote++;
- };
- for (const page of p.pages) put(page.rel, page.text);
- for (const [rel, text] of p.files) put(rel, text);
- for (const rel of p.orphanStories) { rmSync(join(root, rel)); wrote++; }
- for (const n of col.notes) console.log(`note: ${n}`);
- for (const { library, message } of col.overrideWarnings) console.log(`warning: ${library}: ${message}`);
- for (const rel of p.orphanPages) {
- if (prune) { rmSync(join(root, rel)); wrote++; console.log(`removed: ${rel} (no header any more)`); }
- else console.log(`note: ${rel} has no component header any more; delete it, or run with --prune`);
- }
- const html = col.comps.filter((c) => c.html).length;
- const react = col.comps.filter((c) => c.react).length;
- console.log(`design-components: ${col.comps.length} components (${html} html, ${react} react), ${wrote} files written`);