@trinityui/design-system-css 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.mjs ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Build script for @trinityui/design-system-css.
4
+ *
5
+ * Reads the auto-generated CSS source (produced by
6
+ * `scripts/generate-css-from-tokens.ts` from `src/tokens.ts`) and emits:
7
+ * dist/trinity.css — identical copy of source (pretty, with banner)
8
+ * dist/trinity.min.css — minified via esbuild for production consumers
9
+ *
10
+ * The previous hand-maintained `src/styles/trinity.css` has been retired —
11
+ * the canonical CSS is now generated from `tokens.ts`, so token updates
12
+ * (WCAG fixes, new semantic tokens) reach CSS-only consumers automatically.
13
+ * Fails loudly if the source is missing (`cp` would silently ship empty).
14
+ */
15
+ import { readFile, writeFile, mkdir, stat } from "node:fs/promises";
16
+ import { fileURLToPath } from "node:url";
17
+ import { dirname, resolve } from "node:path";
18
+ import { transform } from "esbuild";
19
+
20
+ const here = dirname(fileURLToPath(import.meta.url));
21
+ const SOURCE = resolve(here, "../../src/styles/trinity-generated.css");
22
+ const DIST = resolve(here, "dist");
23
+ const OUT = resolve(DIST, "trinity.css");
24
+ const OUT_MIN = resolve(DIST, "trinity.min.css");
25
+
26
+ async function fileExists(path) {
27
+ try {
28
+ await stat(path);
29
+ return true;
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ async function main() {
36
+ if (!(await fileExists(SOURCE))) {
37
+ console.error(
38
+ `[design-system-css] source CSS not found at ${SOURCE}\n` +
39
+ ` expected the monorepo's src/styles/trinity.css to exist before this package builds.`,
40
+ );
41
+ process.exit(1);
42
+ }
43
+
44
+ const source = await readFile(SOURCE, "utf8");
45
+ if (source.trim().length === 0) {
46
+ console.error(`[design-system-css] source CSS is empty: ${SOURCE}`);
47
+ process.exit(1);
48
+ }
49
+
50
+ await mkdir(DIST, { recursive: true });
51
+
52
+ // 1) Pretty copy — what consumers get with `import '@trinityui/design-system-css'`.
53
+ await writeFile(OUT, source, "utf8");
54
+
55
+ // 2) Minified copy — for consumers that want smaller bytes in production.
56
+ const { code: minified } = await transform(source, {
57
+ loader: "css",
58
+ minify: true,
59
+ });
60
+ await writeFile(OUT_MIN, minified, "utf8");
61
+
62
+ const prettyKB = (source.length / 1024).toFixed(1);
63
+ const minKB = (minified.length / 1024).toFixed(1);
64
+ const savings = ((1 - minified.length / source.length) * 100).toFixed(0);
65
+ console.log(
66
+ `[design-system-css] built dist/trinity.css (${prettyKB} KB) and dist/trinity.min.css (${minKB} KB, -${savings}%)`,
67
+ );
68
+ }
69
+
70
+ main().catch((err) => {
71
+ console.error("[design-system-css] build failed:", err);
72
+ process.exit(1);
73
+ });