synthesisui 0.2.1 → 0.3.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.
@@ -110,6 +110,8 @@ export async function add(slug, opts) {
110
110
  console.log(` philosophy.md → ${sections.length} section(s) (read after rules)`);
111
111
  }
112
112
  console.log(` CLAUDE.md ${claudeMd.created ? "created" : "updated"} (${claudeMd.count} system(s) installed)`);
113
+ if (opts.setupHints === false)
114
+ return;
113
115
  const hasTheme = cssArtifacts.includes("theme.css");
114
116
  // ── DX: concrete paths + copy-pasteable snippets, with breathing room ──
115
117
  console.log(section("One-time setup (once per app)"));
@@ -0,0 +1,140 @@
1
+ import { readdir, readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { generateComponentFiles } from "../component-codegen.js";
4
+ import { readProjectConfig, resolveRegistry } from "../config.js";
5
+ import { body, section, snippet } from "../output.js";
6
+ import { fetchChangelog, fetchComponent, fetchDesignSystem, RegistryError, } from "../registry.js";
7
+ import { add } from "./add.js";
8
+ /**
9
+ * Marco B - `synthesisui upgrade <slug>`: brings the installed system to the
10
+ * latest version, GUIDED. In one run it:
11
+ *
12
+ * 1. compares the installed version (`_synthesisui/ds/<slug>/.lock`) with the
13
+ * registry's latest and re-materializes the artifacts (same flow as `add`;
14
+ * the previous version folder stays for rollback/diff);
15
+ * 2. REGENERATES every component previously materialized into componentsDir
16
+ * from this system (detected by the generated-file header), so YOUR
17
+ * components pick up the new recipes;
18
+ * 3. fetches the deterministic changelog (computed server-side) and writes it
19
+ * to `_synthesisui/ds/<slug>/UPGRADE.md` - the migration brief your agent
20
+ * walks to update the app (breaking changes first).
21
+ */
22
+ export async function upgrade(slug, opts) {
23
+ const base = resolveRegistry(opts.registry);
24
+ const root = opts.dir ?? process.cwd();
25
+ const slugDir = join(root, "_synthesisui", "ds", slug);
26
+ // installed version - upgrade only makes sense over an existing install
27
+ let installed;
28
+ try {
29
+ const lock = JSON.parse(await readFile(join(slugDir, ".lock"), "utf8"));
30
+ if (!Number.isInteger(lock.version))
31
+ throw new Error("no version");
32
+ installed = lock.version;
33
+ }
34
+ catch {
35
+ throw new RegistryError(`"${slug}" is not installed here - run \`synthesisui add ${slug}\` first.`);
36
+ }
37
+ console.log(`→ checking "${slug}" (installed: v${installed}) …`);
38
+ const latest = await fetchDesignSystem(base, slug);
39
+ if (latest.version === installed) {
40
+ console.log(`✓ ${slug} is already at the latest version (v${installed}).`);
41
+ return;
42
+ }
43
+ if (latest.version < installed) {
44
+ console.log(`✓ ${slug} v${installed} is newer than the registry's v${latest.version} - nothing to do.`);
45
+ return;
46
+ }
47
+ // 1. re-materialize the artifacts (v<latest>/ + root re-exports + .lock);
48
+ // setup hints suppressed - an upgrade means the app is already wired.
49
+ await add(slug, { registry: opts.registry, dir: root, setupHints: false });
50
+ // 2. regenerate YOUR materialized components (the ones `component` wrote)
51
+ const config = await readProjectConfig(root);
52
+ const regenerated = [];
53
+ const failed = [];
54
+ if (config.target === "next") {
55
+ const componentsRoot = join(root, config.componentsDir);
56
+ const marker = `from the "${slug}" design system`;
57
+ let entries = [];
58
+ try {
59
+ entries = await readdir(componentsRoot);
60
+ }
61
+ catch {
62
+ // no componentsDir yet - nothing materialized
63
+ }
64
+ for (const entry of entries) {
65
+ const tsxPath = join(componentsRoot, entry, `${entry}.tsx`);
66
+ let head = "";
67
+ try {
68
+ head = (await readFile(tsxPath, "utf8")).slice(0, 300);
69
+ }
70
+ catch {
71
+ continue; // not a materialized component folder
72
+ }
73
+ if (!head.includes("Generated by SynthesisUI") || !head.includes(marker))
74
+ continue;
75
+ try {
76
+ const res = await fetchComponent(base, slug, entry);
77
+ const files = generateComponentFiles(slug, res.name, res.recipe, res.css, res.version, config.styles);
78
+ for (const file of files) {
79
+ await writeFile(join(componentsRoot, entry, file.filename), file.code, "utf8");
80
+ }
81
+ regenerated.push(entry);
82
+ }
83
+ catch {
84
+ failed.push(entry); // e.g. component renamed/removed in the new version
85
+ }
86
+ }
87
+ }
88
+ // 3. deterministic changelog → UPGRADE.md (the agent's migration brief)
89
+ const log = await fetchChangelog(base, slug, installed, latest.version);
90
+ const upgradePath = join(slugDir, "UPGRADE.md");
91
+ const brief = [
92
+ log.markdown,
93
+ "",
94
+ "---",
95
+ "",
96
+ "## How to migrate this app",
97
+ "",
98
+ "- Fix the **Breaking** items first: search the codebase for each removed",
99
+ " token/component/variant and move usages to the closest replacement.",
100
+ "- Changed tokens re-theme automatically (CSS variables) - review screens",
101
+ " that hardcoded values instead of tokens.",
102
+ regenerated.length > 0
103
+ ? `- These materialized components were regenerated and may show in your diff: ${regenerated
104
+ .map((n) => `\`${n}\``)
105
+ .join(", ")}.`
106
+ : "- No materialized components needed regeneration.",
107
+ "- The full new contract lives in `design-system.json` / `GUIDE.md` next to this file.",
108
+ "",
109
+ ].join("\n");
110
+ await writeFile(upgradePath, brief, "utf8");
111
+ // ── report ──
112
+ console.log(section(`Upgraded ${slug}: v${installed} → v${latest.version}`));
113
+ if (log.changelog.breaking.length > 0) {
114
+ console.log(body(`Breaking changes (${log.changelog.breaking.length}):`));
115
+ console.log("");
116
+ console.log(snippet(log.changelog.breaking.map((item) => `- ${item}`)));
117
+ }
118
+ else {
119
+ console.log(body("No breaking changes detected."));
120
+ }
121
+ if (regenerated.length > 0) {
122
+ console.log("");
123
+ console.log(body(`Regenerated ${regenerated.length} materialized component(s): ${regenerated.join(", ")}`));
124
+ }
125
+ if (failed.length > 0) {
126
+ console.log("");
127
+ console.log(body(`⚠ Could not regenerate: ${failed.join(", ")} (removed/renamed in v${latest.version}?)`));
128
+ }
129
+ console.log(section("Migrate the app"));
130
+ console.log(body(`The migration brief is at _synthesisui/ds/${slug}/UPGRADE.md`));
131
+ console.log("");
132
+ console.log(body("Ask your agent:"));
133
+ console.log(snippet([
134
+ `"Read _synthesisui/ds/${slug}/UPGRADE.md and migrate this app to ${slug} v${latest.version} -`,
135
+ ` fix the breaking changes first, then review the changed components."`,
136
+ ]));
137
+ console.log("");
138
+ console.log(body(`(rollback: synthesisui add ${slug} --version ${installed})`));
139
+ console.log("");
140
+ }
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { init } from "./commands/init.js";
7
7
  import { list } from "./commands/list.js";
8
8
  import { login } from "./commands/login.js";
9
9
  import { template } from "./commands/template.js";
10
+ import { upgrade } from "./commands/upgrade.js";
10
11
  import { use } from "./commands/use.js";
11
12
  import { RegistryError } from "./registry.js";
12
13
  const HELP = `synthesisui - bring SynthesisUI design systems into your project
@@ -18,6 +19,7 @@ Usage:
18
19
  synthesisui add <slug> [options] materialize a DS into _synthesisui/ds/<slug>/
19
20
  synthesisui template <slug> <name> materialize a whole page from a DS template
20
21
  synthesisui component <slug> <name> bring one component in - artifacts + YOUR <Pascal>.tsx in componentsDir
22
+ synthesisui upgrade <slug> update an installed DS + regenerate your components + migration brief
21
23
  synthesisui use <slug> "<intent>" print a ready-to-paste agent prompt to build/modify on-system
22
24
  synthesisui advise "<value prop>" engagement-pattern proposals for this project (login required)
23
25
  synthesisui generate "<desc>" generate a token-only component recipe for your DS (login required)
@@ -192,6 +194,16 @@ async function main() {
192
194
  });
193
195
  break;
194
196
  }
197
+ case "upgrade": {
198
+ const slug = args[0];
199
+ if (!slug) {
200
+ console.error("error: provide the slug - `synthesisui upgrade <slug>`");
201
+ process.exitCode = 1;
202
+ return;
203
+ }
204
+ await upgrade(slug, { registry, dir });
205
+ break;
206
+ }
195
207
  case "use": {
196
208
  const slug = args[0];
197
209
  if (!slug) {
package/dist/registry.js CHANGED
@@ -136,3 +136,17 @@ export async function postGenerate(base, payload) {
136
136
  }
137
137
  return (await res.json());
138
138
  }
139
+ /** Changelog determinístico entre duas versões (Marco B) - `?changelog&from=N`. */
140
+ export async function fetchChangelog(base, slug, from, to) {
141
+ const url = new URL(`${base}/api/registry/ds/${encodeURIComponent(slug)}`);
142
+ url.searchParams.set("changelog", "");
143
+ url.searchParams.set("from", String(from));
144
+ if (to != null)
145
+ url.searchParams.set("to", String(to));
146
+ const res = await request(url.toString());
147
+ if (!res.ok) {
148
+ const body = (await res.json().catch(() => ({})));
149
+ throw new RegistryError(body.message ?? `Registry responded ${res.status} for the changelog.`);
150
+ }
151
+ return (await res.json());
152
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "synthesisui",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Traz design systems do SynthesisUI para qualquer projeto (materializa em _local/ds/).",
5
5
  "type": "module",
6
6
  "bin": {