файл пакета→ .shtukbase/packages/shtukbase-ui-html/actions/build.ts
actions/build.ts
34 строки, 1.9 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // shtukbase-ui-html `build`: joins the component CSS into /design/shtukbase-ui-html/ui.css and writes demo.html next to it.
- // Runs by itself after install and update; by hand: `shtuk run shtukbase-ui-html build`. The working directory is the
- // project root (`--root <dir>` for another one; in the repository after a CSS edit: `bun actions/build.ts --root pages
- // --css-only`, which refreshes the shipped ui.css). A component that breaks the format
- // (SUI-R01) is named and nothing is written: exit 1.
- import { mkdirSync, writeFileSync } from 'node:fs';
- import { join } from 'node:path';
- import { uiCss } from '../lib/build.ts';
- import { LIB_DIR, scan } from '../lib/components.ts';
- import { demoPage } from '../lib/demo.ts';
- export function build(root: string): { problems: string[]; css: string; demo: string } {
- const comps = scan(root);
- const problems = comps.flatMap((c) => c.problems.map((p) => `${c.html}: ${p}`));
- if (!comps.length) problems.push(`${LIB_DIR}/components: no components found`);
- if (problems.length) return { problems, css: '', demo: '' };
- return { problems, css: uiCss(root, comps), demo: demoPage(comps) };
- }
- if (import.meta.main) {
- const at = process.argv.indexOf('--root');
- const root = at > 0 ? process.argv[at + 1] : process.cwd();
- const { problems, css, demo } = build(root);
- if (problems.length) {
- console.log(`shtukbase-ui-html: not built, components break the format:\n${problems.join('\n')}`);
- process.exitCode = 1;
- } else {
- mkdirSync(join(root, LIB_DIR), { recursive: true });
- writeFileSync(join(root, LIB_DIR, 'ui.css'), css);
- // --css-only: the package's own pages/ ship ui.css prebuilt (design-components sync runs before this build on install)
- if (!process.argv.includes('--css-only')) writeFileSync(join(root, LIB_DIR, 'demo.html'), demo);
- console.log(`shtukbase-ui-html: ${LIB_DIR}/ui.css (${css.length} bytes) and ${LIB_DIR}/demo.html`);
- }
- }