zyncat-ui 0.13.1 → 0.17.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/LICENSE +21 -0
- package/README.md +4 -3
- package/dist/cli.js +356 -28
- package/package.json +6 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tabsir Ahammed
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -9,9 +9,10 @@ pnpm dlx zyncat-ui init
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
Run it inside a React project. One command installs `@zyncat/ui` (and React 19 if the project
|
|
12
|
-
needs it), imports the base stylesheet at your app root, installs the agent
|
|
13
|
-
`.claude/skills/`, and registers the MCP server in `.mcp.json`.
|
|
14
|
-
`@zyncat/ui`
|
|
12
|
+
needs it), imports the base stylesheet at your app root, writes the theme file, installs the agent
|
|
13
|
+
skill into `.claude/skills/`, and registers the MCP server in `.mcp.json`. In a Tailwind v4 project
|
|
14
|
+
it also imports `@zyncat/ui/tailwind.css` above `tailwindcss`, so the token vocabulary arrives as
|
|
15
|
+
utilities with IntelliSense. Re-run it after upgrading `@zyncat/ui` to refresh everything.
|
|
15
16
|
|
|
16
17
|
This package is where the CLI lives, and it holds the unscoped name so the command works before
|
|
17
18
|
`@zyncat/ui` is installed. It ships one bundled file and declares zero runtime dependencies - the
|
package/dist/cli.js
CHANGED
|
@@ -156,8 +156,8 @@ var require_picocolors = __commonJS({
|
|
|
156
156
|
|
|
157
157
|
// src/detect.ts
|
|
158
158
|
import { spawnSync } from "child_process";
|
|
159
|
-
import { existsSync, readFileSync } from "fs";
|
|
160
|
-
import { dirname, join } from "path";
|
|
159
|
+
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
160
|
+
import { dirname, join, relative, sep } from "path";
|
|
161
161
|
import { fileURLToPath } from "url";
|
|
162
162
|
var PACKAGE_MANAGERS = ["pnpm", "npm", "yarn", "bun"];
|
|
163
163
|
function readJson(path) {
|
|
@@ -237,10 +237,36 @@ function findAppEntry(cwd) {
|
|
|
237
237
|
for (const candidate of ENTRY_CANDIDATES) if (existsSync(join(cwd, candidate))) return candidate;
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
|
+
var TAILWIND_IMPORT = /^\s*@import\s+(['"])tailwindcss(?:\/[\w./-]+)?\1[^;]*;/m;
|
|
241
|
+
var STYLESHEET_SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage", "public"]);
|
|
242
|
+
var STYLESHEET_SEARCH_DEPTH = 4;
|
|
243
|
+
function tailwindMajor(cwd, pkg) {
|
|
244
|
+
const range = pkg?.dependencies?.tailwindcss ?? pkg?.devDependencies?.tailwindcss;
|
|
245
|
+
if (!range) return null;
|
|
246
|
+
return majorOf(installedVersion(cwd, "tailwindcss") ?? void 0) ?? majorOf(range);
|
|
247
|
+
}
|
|
248
|
+
function findTailwindEntry(cwd) {
|
|
249
|
+
const found = [];
|
|
250
|
+
const walk = (dir, depth) => {
|
|
251
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
252
|
+
if (entry.isDirectory()) {
|
|
253
|
+
if (depth < STYLESHEET_SEARCH_DEPTH && !STYLESHEET_SKIP_DIRS.has(entry.name) && !entry.name.startsWith("."))
|
|
254
|
+
walk(join(dir, entry.name), depth + 1);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (!entry.name.endsWith(".css")) continue;
|
|
258
|
+
const path = join(dir, entry.name);
|
|
259
|
+
if (TAILWIND_IMPORT.test(readFileSync(path, "utf8"))) found.push(relative(cwd, path).split(sep).join("/"));
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
walk(cwd, 0);
|
|
263
|
+
found.sort((a2, b) => a2.split("/").length - b.split("/").length || a2.localeCompare(b));
|
|
264
|
+
return found[0] ?? null;
|
|
265
|
+
}
|
|
240
266
|
|
|
241
267
|
// src/init.ts
|
|
242
|
-
import { cpSync, existsSync as existsSync3, mkdirSync, readdirSync as
|
|
243
|
-
import { join as join3 } from "path";
|
|
268
|
+
import { cpSync, existsSync as existsSync3, mkdirSync, readdirSync as readdirSync3, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
269
|
+
import { dirname as dirname3, join as join3 } from "path";
|
|
244
270
|
|
|
245
271
|
// ../../node_modules/.pnpm/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
|
|
246
272
|
import { styleText } from "util";
|
|
@@ -938,7 +964,7 @@ var n$1 = class n extends V {
|
|
|
938
964
|
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
939
965
|
import process$1 from "process";
|
|
940
966
|
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
941
|
-
import { existsSync as existsSync2, lstatSync, readdirSync } from "fs";
|
|
967
|
+
import { existsSync as existsSync2, lstatSync, readdirSync as readdirSync2 } from "fs";
|
|
942
968
|
import { dirname as dirname2, join as join2 } from "path";
|
|
943
969
|
function isUnicodeSupported() {
|
|
944
970
|
if (process$1.platform !== "win32") {
|
|
@@ -1472,7 +1498,7 @@ var teal = { 200: "#a4e5e7", 300: "#6dcfd1", 400: "#28b5b9", 500: "#009ea3", 600
|
|
|
1472
1498
|
var accent = fg(teal[400]);
|
|
1473
1499
|
var accentDeep = fg(teal[500]);
|
|
1474
1500
|
var accentBright = fg(teal[300]);
|
|
1475
|
-
var { dim, bold, red
|
|
1501
|
+
var { dim, bold, red } = import_picocolors.default;
|
|
1476
1502
|
function gradientText(text, from, to) {
|
|
1477
1503
|
if (!truecolor) return import_picocolors.default.isColorSupported ? import_picocolors.default.cyan(text) : text;
|
|
1478
1504
|
const chars = [...text];
|
|
@@ -1480,6 +1506,99 @@ function gradientText(text, from, to) {
|
|
|
1480
1506
|
return chars.map((char, i2) => fg(lerpHex(from, to, i2 / span))(char)).join("");
|
|
1481
1507
|
}
|
|
1482
1508
|
|
|
1509
|
+
// src/theme-file.ts
|
|
1510
|
+
var BASELINE_VERSION = "0.15.0";
|
|
1511
|
+
var TOKEN_HISTORY = {};
|
|
1512
|
+
var ROOT_BLOCK = /^[ \t]*:root\b[^{]*\{/m;
|
|
1513
|
+
var STAMP = /@zyncat-ui\s+(\d+\.\d+\.\d+)/;
|
|
1514
|
+
var COMMENT_OR_DECLARATION = /\/\*[\s\S]*?\*\/|(--[\w-]+)\s*:\s*([^;]+);/g;
|
|
1515
|
+
var COMMENT_OR_NAME = /\/\*[\s\S]*?\*\/|(--[\w-]+)\s*:/g;
|
|
1516
|
+
function rootBlock(css) {
|
|
1517
|
+
const rule = ROOT_BLOCK.exec(css);
|
|
1518
|
+
if (!rule) return null;
|
|
1519
|
+
const start = rule.index + rule[0].length;
|
|
1520
|
+
let depth = 1;
|
|
1521
|
+
for (let i2 = start; i2 < css.length; i2++) {
|
|
1522
|
+
if (css[i2] === "{") depth++;
|
|
1523
|
+
else if (css[i2] === "}" && --depth === 0) return { start, end: i2 };
|
|
1524
|
+
}
|
|
1525
|
+
return null;
|
|
1526
|
+
}
|
|
1527
|
+
function parseDecisions(css) {
|
|
1528
|
+
const block2 = rootBlock(css);
|
|
1529
|
+
if (!block2) return [];
|
|
1530
|
+
const body = css.slice(block2.start, block2.end);
|
|
1531
|
+
const decisions = [];
|
|
1532
|
+
let comment = "";
|
|
1533
|
+
COMMENT_OR_DECLARATION.lastIndex = 0;
|
|
1534
|
+
for (let match = COMMENT_OR_DECLARATION.exec(body); match; match = COMMENT_OR_DECLARATION.exec(body)) {
|
|
1535
|
+
if (match[1] === void 0) {
|
|
1536
|
+
comment = match[0];
|
|
1537
|
+
continue;
|
|
1538
|
+
}
|
|
1539
|
+
decisions.push({ name: match[1], value: match[2].trim(), comment });
|
|
1540
|
+
comment = "";
|
|
1541
|
+
}
|
|
1542
|
+
return decisions;
|
|
1543
|
+
}
|
|
1544
|
+
function declaredNames(css) {
|
|
1545
|
+
const names = /* @__PURE__ */ new Set();
|
|
1546
|
+
COMMENT_OR_NAME.lastIndex = 0;
|
|
1547
|
+
for (let match = COMMENT_OR_NAME.exec(css); match; match = COMMENT_OR_NAME.exec(css))
|
|
1548
|
+
if (match[1] !== void 0) names.add(match[1]);
|
|
1549
|
+
return names;
|
|
1550
|
+
}
|
|
1551
|
+
var readStamp = (css) => STAMP.exec(css)?.[1] ?? null;
|
|
1552
|
+
var stampOf = (css) => readStamp(css) ?? BASELINE_VERSION;
|
|
1553
|
+
function themeDrift(existing, shipped) {
|
|
1554
|
+
const declared = declaredNames(existing);
|
|
1555
|
+
const stamp = stampOf(existing);
|
|
1556
|
+
const added = shipped.filter((decision) => {
|
|
1557
|
+
if (declared.has(decision.name)) return false;
|
|
1558
|
+
const since = TOKEN_HISTORY[decision.name]?.since;
|
|
1559
|
+
return since !== void 0 && isOlder(stamp, since);
|
|
1560
|
+
});
|
|
1561
|
+
const deprecated = [];
|
|
1562
|
+
const removed = [];
|
|
1563
|
+
for (const name of declared) {
|
|
1564
|
+
const note = TOKEN_HISTORY[name];
|
|
1565
|
+
if (!note) continue;
|
|
1566
|
+
if (note.removed) removed.push({ name, note });
|
|
1567
|
+
else if (note.deprecated) deprecated.push({ name, note });
|
|
1568
|
+
}
|
|
1569
|
+
return { added, deprecated, removed };
|
|
1570
|
+
}
|
|
1571
|
+
function renderDecision(decision, indent) {
|
|
1572
|
+
const comment = decision.comment ? `${decision.comment.split("\n").map((line, index) => `${indent}${index === 0 ? "" : " "}${line.trim()}`).join("\n")}
|
|
1573
|
+
` : "";
|
|
1574
|
+
return `${comment}${indent}${decision.name}: ${decision.value};`;
|
|
1575
|
+
}
|
|
1576
|
+
function stampCss(css, version2) {
|
|
1577
|
+
if (STAMP.test(css)) return css.replace(STAMP, `@zyncat-ui ${version2}`);
|
|
1578
|
+
const header = /^\s*\/\*[\s\S]*?\*\//.exec(css);
|
|
1579
|
+
const line = `@zyncat-ui ${version2} - the version whose decisions this mirrors; \`npx zyncat-ui update\` refreshes it.`;
|
|
1580
|
+
if (!header) return `/* ${line} */
|
|
1581
|
+
${css}`;
|
|
1582
|
+
const close = header.index + header[0].length - 2;
|
|
1583
|
+
return `${css.slice(0, close).trimEnd()}
|
|
1584
|
+
${line} */${css.slice(close + 2)}`;
|
|
1585
|
+
}
|
|
1586
|
+
function withDecisions(css, decisions, version2) {
|
|
1587
|
+
const stamped = stampCss(css, version2);
|
|
1588
|
+
if (!decisions.length) return stamped;
|
|
1589
|
+
const body = decisions.map((decision) => renderDecision(decision, " ")).join("\n");
|
|
1590
|
+
const block2 = rootBlock(stamped);
|
|
1591
|
+
if (!block2) return `${stamped.trimEnd()}
|
|
1592
|
+
|
|
1593
|
+
:root {
|
|
1594
|
+
${body}
|
|
1595
|
+
}
|
|
1596
|
+
`;
|
|
1597
|
+
return `${stamped.slice(0, block2.end).trimEnd()}
|
|
1598
|
+
${body}
|
|
1599
|
+
${stamped.slice(block2.end)}`;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1483
1602
|
// src/ui.ts
|
|
1484
1603
|
var SPINNER_FRAMES = unicode ? ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"] : ["-", "\\", "|", "/"];
|
|
1485
1604
|
var SPINNER_DELAY = 80;
|
|
@@ -1536,6 +1655,10 @@ function row(label, value) {
|
|
|
1536
1655
|
var PACKAGE = "@zyncat/ui";
|
|
1537
1656
|
var MCP_SERVER_ENTRY = { command: "node", args: ["./node_modules/@zyncat/ui/dist/mcp.js"] };
|
|
1538
1657
|
var STYLES_IMPORT = "import '@zyncat/ui/styles.css';";
|
|
1658
|
+
var THEME_FILE = "zyncat.theme.css";
|
|
1659
|
+
var THEME_IMPORT = `import './${THEME_FILE}';`;
|
|
1660
|
+
var THEME_SOURCE = "src/tokens/decisions.css";
|
|
1661
|
+
var TAILWIND_BRIDGE = "@zyncat/ui/tailwind.css";
|
|
1539
1662
|
var DOCS_URL = "https://ui.zyncat.app";
|
|
1540
1663
|
var interactive = () => Boolean(process.stdout.isTTY && process.stdin.isTTY);
|
|
1541
1664
|
var installTouchedProject = false;
|
|
@@ -1568,6 +1691,31 @@ var ADD_COMMAND = {
|
|
|
1568
1691
|
yarn: "yarn add",
|
|
1569
1692
|
bun: "bun add"
|
|
1570
1693
|
};
|
|
1694
|
+
function removedWarning(removed) {
|
|
1695
|
+
const one = removed.length === 1;
|
|
1696
|
+
const named = removed.map(({ name, note }) => `${name} (removed in ${note.removed}${note.use ? ` - use ${note.use}` : ""})`).join(", ");
|
|
1697
|
+
const lead = one ? "A token your theme file sets no longer exists" : `${removed.length} tokens your theme file sets no longer exist`;
|
|
1698
|
+
return `${lead}: ${named}. Nothing reads ${one ? "it" : "them"} now, so ${one ? "that line is" : "those lines are"} dead.`;
|
|
1699
|
+
}
|
|
1700
|
+
function deprecatedNote(deprecated) {
|
|
1701
|
+
const one = deprecated.length === 1;
|
|
1702
|
+
const named = deprecated.map(({ name, note }) => `${name} (deprecated in ${note.deprecated}${note.use ? ` - now feeds ${note.use}` : ""})`).join(", ");
|
|
1703
|
+
const lead = one ? "A token your theme file sets is deprecated" : `${deprecated.length} tokens are deprecated`;
|
|
1704
|
+
return `${lead}: ${named}. ${one ? "It still works" : "They still work"} - rename ${one ? "it" : "them"} before the alias goes.`;
|
|
1705
|
+
}
|
|
1706
|
+
var minorOf = (version2) => Number(version2.split(".")[1] ?? 0);
|
|
1707
|
+
function crossedVersions(before, after) {
|
|
1708
|
+
const minors = minorOf(after) - minorOf(before);
|
|
1709
|
+
if (minors < 1) return row("Upgraded", `${before} ${arrow} ${after}`);
|
|
1710
|
+
const releases = `${minors} minor release${minors === 1 ? "" : "s"}`;
|
|
1711
|
+
return row("Upgraded", `${before} ${arrow} ${after} \xB7 ${releases}, each breaking before 1.0`);
|
|
1712
|
+
}
|
|
1713
|
+
function driftHint(drift, command2) {
|
|
1714
|
+
const one = drift.added.length === 1;
|
|
1715
|
+
const names = drift.added.map((decision) => decision.name).join(", ");
|
|
1716
|
+
const running = one ? "it already runs on its default" : "each already runs on its default";
|
|
1717
|
+
return `${names} - ${running}, so nothing is broken. ${command2} adds ${one ? "it" : "them"} to your file.`;
|
|
1718
|
+
}
|
|
1571
1719
|
async function planInstall(cwd, targetPkg, flags, version2) {
|
|
1572
1720
|
const deps = { ...targetPkg.dependencies, ...targetPkg.devDependencies };
|
|
1573
1721
|
const specs = [];
|
|
@@ -1695,13 +1843,13 @@ function wireSkill(cwd, packageRoot, pm) {
|
|
|
1695
1843
|
return {
|
|
1696
1844
|
line: row("Agent skill", `skipped \xB7 ${PACKAGE}${onDisk ? ` ${onDisk}` : ""} ships no skills/`),
|
|
1697
1845
|
done: false,
|
|
1698
|
-
|
|
1846
|
+
hints: [`Upgrade it with ${ADD_COMMAND[pm]} ${PACKAGE}@latest, then re-run init.`]
|
|
1699
1847
|
};
|
|
1700
1848
|
}
|
|
1701
1849
|
const dest = join3(cwd, ".claude/skills");
|
|
1702
1850
|
const existed = existsSync3(join3(dest, "zyncat-ui"));
|
|
1703
1851
|
mkdirSync(dest, { recursive: true });
|
|
1704
|
-
for (const name of
|
|
1852
|
+
for (const name of readdirSync3(source))
|
|
1705
1853
|
cpSync(join3(source, name), join3(dest, name), { recursive: true, force: true });
|
|
1706
1854
|
return { line: row("Agent skill", `.claude/skills/zyncat-ui \xB7 ${existed ? "refreshed" : "installed"}`), done: true };
|
|
1707
1855
|
}
|
|
@@ -1719,25 +1867,132 @@ function wireMcp(cwd) {
|
|
|
1719
1867
|
`);
|
|
1720
1868
|
return { line: row("MCP server", existed ? ".mcp.json \xB7 kept" : `.mcp.json ${arrow} zyncat-ui`), done: true };
|
|
1721
1869
|
}
|
|
1722
|
-
function
|
|
1723
|
-
const
|
|
1870
|
+
function shippedDecisionsCss(packageRoot) {
|
|
1871
|
+
const source = join3(packageRoot, THEME_SOURCE);
|
|
1872
|
+
return existsSync3(source) ? readFileSync2(source, "utf8") : null;
|
|
1873
|
+
}
|
|
1874
|
+
function themeFileText(css, version2) {
|
|
1875
|
+
const rule = /^\s*:root\b[^{]*\{/m.exec(css);
|
|
1876
|
+
if (!rule) return null;
|
|
1877
|
+
const open = rule.index + rule[0].length - 1;
|
|
1878
|
+
const close = css.indexOf("}", open);
|
|
1879
|
+
if (close === -1) return null;
|
|
1880
|
+
const lines = css.slice(open + 1, close).split("\n").filter((line) => line.trim());
|
|
1881
|
+
const indent = Math.min(...lines.map((line) => line.length - line.trimStart().length));
|
|
1882
|
+
const body = lines.map((line) => ` ${line.slice(indent)}`).join("\n");
|
|
1883
|
+
return [
|
|
1884
|
+
`/* ${THEME_FILE} - the decisions every other token derives from, written by zyncat-ui init.`,
|
|
1885
|
+
" Loaded after @zyncat/ui/styles.css, so a value here wins; whatever you delete keeps the default.",
|
|
1886
|
+
" A [data-polarity='dark'] block here extends the dark polarity, a [data-theme='<name>'] one adds a",
|
|
1887
|
+
' palette, and data-theme="default" on a subtree brings these back inside another palette.',
|
|
1888
|
+
" Docs: https://ui.zyncat.app/theming",
|
|
1889
|
+
` @zyncat-ui ${version2} - the version whose decisions this mirrors; \`npx zyncat-ui update\` refreshes it. */`,
|
|
1890
|
+
":root,",
|
|
1891
|
+
"[data-theme='default'] {",
|
|
1892
|
+
body,
|
|
1893
|
+
"}",
|
|
1894
|
+
""
|
|
1895
|
+
].join("\n");
|
|
1896
|
+
}
|
|
1897
|
+
var themePath = (cwd, entry) => {
|
|
1898
|
+
const dir = entry ? dirname3(entry) : ".";
|
|
1899
|
+
const rel = dir === "." ? THEME_FILE : `${dir}/${THEME_FILE}`;
|
|
1900
|
+
return { rel, path: join3(cwd, rel) };
|
|
1901
|
+
};
|
|
1902
|
+
function wireTheme(cwd, packageRoot, pm, entry, version2) {
|
|
1903
|
+
const { rel, path } = themePath(cwd, entry);
|
|
1904
|
+
const css = shippedDecisionsCss(packageRoot);
|
|
1905
|
+
if (!css)
|
|
1906
|
+
return {
|
|
1907
|
+
line: row("Theme file", `skipped \xB7 ${PACKAGE} ships no ${THEME_SOURCE}`),
|
|
1908
|
+
done: false,
|
|
1909
|
+
hints: [`Upgrade it with ${ADD_COMMAND[pm]} ${PACKAGE}@latest, then re-run init.`]
|
|
1910
|
+
};
|
|
1911
|
+
if (existsSync3(path)) {
|
|
1912
|
+
const drift = themeDrift(readFileSync2(path, "utf8"), parseDecisions(css));
|
|
1913
|
+
const news = drift.added.length ? ` \xB7 ${drift.added.length} new decision${drift.added.length === 1 ? "" : "s"} available` : "";
|
|
1914
|
+
const hints = [];
|
|
1915
|
+
if (drift.added.length) hints.push(driftHint(drift, "npx zyncat-ui update"));
|
|
1916
|
+
if (drift.deprecated.length) hints.push(deprecatedNote(drift.deprecated));
|
|
1917
|
+
return {
|
|
1918
|
+
line: row("Theme file", `${rel} \xB7 kept${news}`),
|
|
1919
|
+
done: true,
|
|
1920
|
+
hints,
|
|
1921
|
+
warn: drift.removed.length ? removedWarning(drift.removed) : void 0
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
const text = themeFileText(css, version2);
|
|
1925
|
+
if (!text)
|
|
1926
|
+
return {
|
|
1927
|
+
line: row("Theme file", `skipped \xB7 ${THEME_SOURCE} has no :root block`),
|
|
1928
|
+
done: false,
|
|
1929
|
+
hints: [`Upgrade it with ${ADD_COMMAND[pm]} ${PACKAGE}@latest, then re-run init.`]
|
|
1930
|
+
};
|
|
1931
|
+
writeFileSync(path, text);
|
|
1932
|
+
return { line: row("Theme file", `${rel} \xB7 written`), done: true };
|
|
1933
|
+
}
|
|
1934
|
+
var STYLES_LINE = /^\s*import\s+(['"])@zyncat\/ui\/styles\.css\1;?\s*$/;
|
|
1935
|
+
var THEME_LINE = new RegExp(`^\\s*import\\s+(['"])[^'"]*${THEME_FILE.replace(/\./g, "\\.")}\\1;?\\s*$`);
|
|
1936
|
+
var CSS_LINE = /^\s*import\s+(['"])(\.[^'"]*\.css)\1;?\s*$/;
|
|
1937
|
+
var slashes = (path) => path.split(/[\\/]/).filter(Boolean).join("/");
|
|
1938
|
+
function importsStylesheet(line, fromDir, target) {
|
|
1939
|
+
const spec = CSS_LINE.exec(line)?.[2];
|
|
1940
|
+
return spec !== void 0 && slashes(join3(fromDir, spec)) === slashes(target);
|
|
1941
|
+
}
|
|
1942
|
+
function wireStyles(cwd, entry, tailwindEntry) {
|
|
1943
|
+
const below = tailwindEntry ? `below the ${tailwindEntry} import` : "above your own stylesheets";
|
|
1724
1944
|
if (!entry)
|
|
1725
1945
|
return {
|
|
1726
|
-
line: row("Stylesheet", "no app entry found \xB7 add the
|
|
1946
|
+
line: row("Stylesheet", "no app entry found \xB7 add the imports yourself"),
|
|
1727
1947
|
done: false,
|
|
1728
|
-
|
|
1948
|
+
hints: [`Put ${STYLES_IMPORT} then ${THEME_IMPORT} at your app root, ${below}.`]
|
|
1729
1949
|
};
|
|
1730
1950
|
const path = join3(cwd, entry);
|
|
1731
1951
|
const text = readFileSync2(path, "utf8");
|
|
1732
|
-
if (text.includes("@zyncat/ui/styles.css"))
|
|
1733
|
-
return { line: row("Stylesheet", `${entry} \xB7 already imported`), done: true };
|
|
1734
1952
|
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
1735
|
-
const
|
|
1953
|
+
const dir = dirname3(entry);
|
|
1954
|
+
const hasTheme = existsSync3(join3(cwd, dir, THEME_FILE));
|
|
1955
|
+
const mine = (line) => STYLES_LINE.test(line) || hasTheme && THEME_LINE.test(line);
|
|
1956
|
+
const had = text.split(eol).some(mine);
|
|
1957
|
+
const kept = text.split(eol).filter((line) => !mine(line));
|
|
1958
|
+
const bridgeAt = tailwindEntry ? kept.findIndex((line) => importsStylesheet(line, dir, tailwindEntry)) : -1;
|
|
1736
1959
|
let at = 0;
|
|
1737
|
-
|
|
1738
|
-
|
|
1960
|
+
if (bridgeAt !== -1) at = bridgeAt + 1;
|
|
1961
|
+
else while (at < kept.length && (kept[at].trim() === "" || /^(['"])use [\w-]+\1;?$/.test(kept[at].trim()))) at++;
|
|
1962
|
+
kept.splice(at, 0, STYLES_IMPORT, ...hasTheme ? [THEME_IMPORT] : []);
|
|
1963
|
+
const next = kept.join(eol);
|
|
1964
|
+
if (next === text) return { line: row("Stylesheet", `${entry} \xB7 already imported`), done: true };
|
|
1965
|
+
writeFileSync(path, next);
|
|
1966
|
+
const what = had && bridgeAt !== -1 ? `imports moved below ${tailwindEntry}` : had ? "imports updated" : "imports added";
|
|
1967
|
+
return { line: row("Stylesheet", `${entry} \xB7 ${what}`), done: true };
|
|
1968
|
+
}
|
|
1969
|
+
function wireTailwind(cwd, targetPkg) {
|
|
1970
|
+
const major = tailwindMajor(cwd, targetPkg);
|
|
1971
|
+
if (major === null) return null;
|
|
1972
|
+
if (major < 4)
|
|
1973
|
+
return {
|
|
1974
|
+
line: row("Tailwind", `skipped \xB7 Tailwind ${major} has no @theme`),
|
|
1975
|
+
done: false,
|
|
1976
|
+
hints: [`The bridge needs Tailwind v4 - ${DOCS_URL}/theming#tailwind.`]
|
|
1977
|
+
};
|
|
1978
|
+
const entry = findTailwindEntry(cwd);
|
|
1979
|
+
if (!entry)
|
|
1980
|
+
return {
|
|
1981
|
+
line: row("Tailwind", "no stylesheet imports tailwindcss \xB7 add the line yourself"),
|
|
1982
|
+
done: false,
|
|
1983
|
+
hints: [`Put @import '${TAILWIND_BRIDGE}'; above @import 'tailwindcss'; in the stylesheet Tailwind compiles.`]
|
|
1984
|
+
};
|
|
1985
|
+
const path = join3(cwd, entry);
|
|
1986
|
+
const text = readFileSync2(path, "utf8");
|
|
1987
|
+
if (text.includes(TAILWIND_BRIDGE))
|
|
1988
|
+
return { line: row("Tailwind", `${entry} \xB7 already imported`), done: true, bridge: entry };
|
|
1989
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
1990
|
+
const lines = text.split(eol);
|
|
1991
|
+
const at = lines.findIndex((line) => TAILWIND_IMPORT.test(line));
|
|
1992
|
+
const quote = lines[at].includes('"') ? '"' : "'";
|
|
1993
|
+
lines.splice(at, 0, `@import ${quote}${TAILWIND_BRIDGE}${quote};`);
|
|
1739
1994
|
writeFileSync(path, lines.join(eol));
|
|
1740
|
-
return { line: row("
|
|
1995
|
+
return { line: row("Tailwind", `${entry} \xB7 import added`), done: true, bridge: entry };
|
|
1741
1996
|
}
|
|
1742
1997
|
async function init(flags) {
|
|
1743
1998
|
const startedAt = performance.now();
|
|
@@ -1759,6 +2014,7 @@ async function init(flags) {
|
|
|
1759
2014
|
const pmVer = pmVersion(pm);
|
|
1760
2015
|
const project = targetPkg.name ?? "unnamed project";
|
|
1761
2016
|
log.message(dim(`${project} \xB7 ${pm}${pmVer ? ` ${pmVer}` : ""}`));
|
|
2017
|
+
const before = installedVersion(cwd, PACKAGE);
|
|
1762
2018
|
const plan = await planInstall(cwd, targetPkg, flags, version2);
|
|
1763
2019
|
const installed = await installPhase(pm, plan, cwd);
|
|
1764
2020
|
installTouchedProject = true;
|
|
@@ -1766,17 +2022,86 @@ async function init(flags) {
|
|
|
1766
2022
|
if (plan.reactNote) log.warn(plan.reactNote);
|
|
1767
2023
|
await alignVersion(pm, cwd, version2);
|
|
1768
2024
|
const packageRoot = sourceRoot(cwd, ownRoot);
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
2025
|
+
const landed = installedVersion(cwd, PACKAGE) ?? version2;
|
|
2026
|
+
if (before && isOlder(before, landed)) log.message(crossedVersions(before, landed), { symbol: check });
|
|
2027
|
+
const entry = findAppEntry(cwd);
|
|
2028
|
+
const tailwind = wireTailwind(cwd, targetPkg);
|
|
2029
|
+
const rows = [
|
|
2030
|
+
wireSkill(cwd, packageRoot, pm),
|
|
2031
|
+
wireMcp(cwd),
|
|
2032
|
+
wireTheme(cwd, packageRoot, pm, entry, landed),
|
|
2033
|
+
wireStyles(cwd, entry, tailwind?.bridge ?? null),
|
|
2034
|
+
...tailwind ? [tailwind] : []
|
|
2035
|
+
];
|
|
2036
|
+
for (const [index, entry2] of rows.entries()) {
|
|
2037
|
+
log.message(entry2.line, { symbol: entry2.done ? check : skip, spacing: index === 0 ? 1 : 0 });
|
|
2038
|
+
for (const hint of entry2.hints ?? []) log.message(dim(hint), { spacing: 0 });
|
|
2039
|
+
if (entry2.warn) log.warn(entry2.warn);
|
|
1773
2040
|
}
|
|
1774
2041
|
log.message(`${dim("Docs")} ${arrow} ${accentDeep(DOCS_URL)}`);
|
|
1775
|
-
const skipped = rows.filter((
|
|
2042
|
+
const skipped = rows.filter((entry2) => !entry2.done).length;
|
|
1776
2043
|
const closing = skipped ? `${bold(`Done in ${seconds(performance.now() - startedAt)}.`)} ${skipped} step${skipped === 1 ? "" : "s"} left for you, above.` : `${bold(`Ready in ${seconds(performance.now() - startedAt)}.`)} Restart your agent session to load the skill.`;
|
|
1777
2044
|
outro(closing);
|
|
1778
2045
|
}
|
|
1779
2046
|
|
|
2047
|
+
// src/update.ts
|
|
2048
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
2049
|
+
import { join as join4 } from "path";
|
|
2050
|
+
var PACKAGE2 = "@zyncat/ui";
|
|
2051
|
+
var DOCS_URL2 = "https://ui.zyncat.app";
|
|
2052
|
+
var interactive2 = () => Boolean(process.stdout.isTTY && process.stdin.isTTY);
|
|
2053
|
+
function stop(message, hint) {
|
|
2054
|
+
log.error(message);
|
|
2055
|
+
if (hint) log.message(dim(hint), { spacing: 0 });
|
|
2056
|
+
outro(red("Nothing was changed."));
|
|
2057
|
+
process.exit(1);
|
|
2058
|
+
}
|
|
2059
|
+
async function update(flags) {
|
|
2060
|
+
const { root: ownRoot, version: version2 } = findOwnRoot();
|
|
2061
|
+
const cwd = process.cwd();
|
|
2062
|
+
intro(wordmark(version2));
|
|
2063
|
+
const targetPkg = readJson(join4(cwd, "package.json"));
|
|
2064
|
+
if (!targetPkg) stop("No package.json here - update runs inside a React project that already ran init.");
|
|
2065
|
+
if (targetPkg.name === PACKAGE2 || targetPkg.name === "zyncat-ui")
|
|
2066
|
+
stop("This is the zyncat-ui repository - update runs in a consumer project.");
|
|
2067
|
+
const packageRoot = sourceRoot(cwd, ownRoot);
|
|
2068
|
+
const landed = installedVersion(cwd, PACKAGE2);
|
|
2069
|
+
if (!landed) stop(`${PACKAGE2} is not installed here.`, "Run npx zyncat-ui init first.");
|
|
2070
|
+
log.message(dim(`${targetPkg.name ?? "unnamed project"} \xB7 ${PACKAGE2} ${landed}`));
|
|
2071
|
+
const shipped = shippedDecisionsCss(packageRoot);
|
|
2072
|
+
if (!shipped) stop(`${PACKAGE2} ${landed} ships no decisions to compare against.`);
|
|
2073
|
+
const { rel, path } = themePath(cwd, findAppEntry(cwd));
|
|
2074
|
+
if (!existsSync4(path)) stop(`No ${rel} here.`, "Run npx zyncat-ui init to write one.");
|
|
2075
|
+
const current = readFileSync3(path, "utf8");
|
|
2076
|
+
const stamp = stampOf(current);
|
|
2077
|
+
const drift = themeDrift(current, parseDecisions(shipped));
|
|
2078
|
+
if (drift.deprecated.length) log.message(dim(deprecatedNote(drift.deprecated)), { spacing: 0 });
|
|
2079
|
+
if (drift.removed.length) log.warn(removedWarning(drift.removed));
|
|
2080
|
+
if (!drift.added.length) {
|
|
2081
|
+
if (stamp !== landed) writeFileSync2(path, withDecisions(current, [], landed));
|
|
2082
|
+
log.message(row("Theme file", `${rel} \xB7 every decision in ${landed} is already in your file`), { symbol: check });
|
|
2083
|
+
outro(bold(stamp === landed ? "Up to date." : `Up to date. Stamp ${stamp} ${arrow} ${landed}.`));
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
log.message(
|
|
2087
|
+
`${bold(`${drift.added.length} new decision${drift.added.length === 1 ? "" : "s"}`)} ${dim(`since ${stamp}`)}
|
|
2088
|
+
|
|
2089
|
+
${drift.added.map((decision) => renderDecision(decision, " ")).join("\n")}`
|
|
2090
|
+
);
|
|
2091
|
+
log.message(dim(driftHint(drift, "This")), { spacing: 0 });
|
|
2092
|
+
if (!flags.yes && interactive2()) {
|
|
2093
|
+
const answer = await confirm({ message: `Add ${drift.added.length === 1 ? "it" : "them"} to ${rel}?` });
|
|
2094
|
+
if (isCancel(answer) || !answer) {
|
|
2095
|
+
cancel("Cancelled - nothing was changed.");
|
|
2096
|
+
process.exit(isCancel(answer) ? 130 : 0);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
writeFileSync2(path, withDecisions(current, drift.added, landed));
|
|
2100
|
+
log.message(row("Theme file", `${rel} \xB7 ${drift.added.length} added, stamped ${landed}`), { symbol: check });
|
|
2101
|
+
log.message(`${dim("Docs")} ${arrow} ${accentDeep(`${DOCS_URL2}/theming`)}`);
|
|
2102
|
+
outro(bold("Your values were not touched."));
|
|
2103
|
+
}
|
|
2104
|
+
|
|
1780
2105
|
// src/cli.ts
|
|
1781
2106
|
function parseFlags(args) {
|
|
1782
2107
|
const flags = { yes: false };
|
|
@@ -1797,14 +2122,16 @@ function help(version2) {
|
|
|
1797
2122
|
` ${wordmark(version2)}`,
|
|
1798
2123
|
"",
|
|
1799
2124
|
` ${dim("Sets up @zyncat/ui in a React project: installs the package,")}`,
|
|
1800
|
-
` ${dim("the agent skill, the MCP server
|
|
2125
|
+
` ${dim("the agent skill, the MCP server, the stylesheet, a theme file")}`,
|
|
2126
|
+
` ${dim("and, under Tailwind v4, the utility bridge.")}`,
|
|
1801
2127
|
"",
|
|
1802
2128
|
` ${bold("Usage")}`,
|
|
1803
|
-
` zyncat-ui init ${dim("[flags]")}`,
|
|
2129
|
+
` zyncat-ui init ${dim("[flags]")} ${dim("set the project up, or re-wire it after an upgrade")}`,
|
|
2130
|
+
` zyncat-ui update ${dim("[flags]")} ${dim("add decisions the library gained since your theme file")}`,
|
|
1804
2131
|
"",
|
|
1805
2132
|
` ${bold("Flags")}`,
|
|
1806
2133
|
` --yes, -y ${dim("accept every default, never prompt")}`,
|
|
1807
|
-
` --pm <name> ${dim(`force the package manager (${PACKAGE_MANAGERS.join(", ")})`)}`,
|
|
2134
|
+
` --pm <name> ${dim(`force the package manager (${PACKAGE_MANAGERS.join(", ")}) - init only`)}`,
|
|
1808
2135
|
"",
|
|
1809
2136
|
` ${dim("Docs")} ${arrow} ${accentDeep("https://ui.zyncat.app")}`,
|
|
1810
2137
|
""
|
|
@@ -1815,13 +2142,14 @@ var [command, ...rest] = process.argv.slice(2);
|
|
|
1815
2142
|
var { version } = findOwnRoot();
|
|
1816
2143
|
if (command === "--version" || command === "-v") {
|
|
1817
2144
|
console.log(version);
|
|
1818
|
-
} else if (command === "init") {
|
|
2145
|
+
} else if (command === "init" || command === "update") {
|
|
1819
2146
|
const flags = parseFlags(rest);
|
|
1820
2147
|
if (!flags) {
|
|
1821
2148
|
console.error(help(version));
|
|
1822
2149
|
process.exit(1);
|
|
1823
2150
|
}
|
|
1824
|
-
await init(flags);
|
|
2151
|
+
if (command === "init") await init(flags);
|
|
2152
|
+
else await update({ yes: flags.yes });
|
|
1825
2153
|
} else {
|
|
1826
2154
|
console.log(help(version));
|
|
1827
2155
|
process.exit(command ? 1 : 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zyncat-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Setup CLI for @zyncat/ui - one command installs the package and wires the project.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zyncat",
|
|
@@ -30,11 +30,6 @@
|
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=18"
|
|
32
32
|
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"build": "tsup",
|
|
35
|
-
"typecheck": "tsc -p tsconfig.json",
|
|
36
|
-
"prepublishOnly": "pnpm build"
|
|
37
|
-
},
|
|
38
33
|
"publishConfig": {
|
|
39
34
|
"access": "public"
|
|
40
35
|
},
|
|
@@ -44,5 +39,9 @@
|
|
|
44
39
|
"picocolors": "^1.1.1",
|
|
45
40
|
"tsup": "^8.5.0",
|
|
46
41
|
"typescript": "~6.0.3"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
47
46
|
}
|
|
48
|
-
}
|
|
47
|
+
}
|