@intelligo-dev/cli 1.0.0-beta.13 → 1.0.0-beta.15
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/README.md +65 -2
- package/dist/args.d.ts +10 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +20 -0
- package/dist/args.js.map +1 -0
- package/dist/bin.js +103 -22
- package/dist/bin.js.map +1 -1
- package/dist/commands/add.d.ts +4 -0
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +28 -2
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/create-flow.d.ts +8 -1
- package/dist/commands/create-flow.d.ts.map +1 -1
- package/dist/commands/create-flow.js +101 -34
- package/dist/commands/create-flow.js.map +1 -1
- package/dist/commands/create.d.ts +24 -4
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +57 -14
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +123 -35
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/migrate-check.d.ts +20 -1
- package/dist/commands/migrate-check.d.ts.map +1 -1
- package/dist/commands/migrate-check.js +35 -6
- package/dist/commands/migrate-check.js.map +1 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +2 -8
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/sync-messages.d.ts +37 -0
- package/dist/commands/sync-messages.d.ts.map +1 -0
- package/dist/commands/sync-messages.js +88 -0
- package/dist/commands/sync-messages.js.map +1 -0
- package/dist/commands/sync-scaffold.d.ts +36 -0
- package/dist/commands/sync-scaffold.d.ts.map +1 -0
- package/dist/commands/sync-scaffold.js +53 -0
- package/dist/commands/sync-scaffold.js.map +1 -0
- package/dist/commands/sync.d.ts +109 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +392 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/upgrade-check.d.ts.map +1 -1
- package/dist/commands/upgrade-check.js +4 -1
- package/dist/commands/upgrade-check.js.map +1 -1
- package/dist/env-files.d.ts +11 -0
- package/dist/env-files.d.ts.map +1 -1
- package/dist/env-files.js +28 -9
- package/dist/env-files.js.map +1 -1
- package/dist/manifest.d.ts +27 -0
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +30 -3
- package/dist/manifest.js.map +1 -1
- package/dist/module-exports.d.ts +63 -0
- package/dist/module-exports.d.ts.map +1 -0
- package/dist/module-exports.js +231 -0
- package/dist/module-exports.js.map +1 -0
- package/dist/registry-bundle.d.ts +43 -0
- package/dist/registry-bundle.d.ts.map +1 -0
- package/dist/registry-bundle.js +74 -0
- package/dist/registry-bundle.js.map +1 -0
- package/dist/registry-items.d.ts +41 -13
- package/dist/registry-items.d.ts.map +1 -1
- package/dist/registry-items.js +117 -33
- package/dist/registry-items.js.map +1 -1
- package/package.json +1 -1
- package/src/args.ts +25 -0
- package/src/bin.ts +124 -22
- package/src/commands/add.ts +39 -12
- package/src/commands/create-flow.ts +119 -29
- package/src/commands/create.ts +82 -14
- package/src/commands/doctor.ts +156 -47
- package/src/commands/migrate-check.ts +51 -10
- package/src/commands/migrate.ts +2 -8
- package/src/commands/sync-messages.ts +114 -0
- package/src/commands/sync-scaffold.ts +83 -0
- package/src/commands/sync.ts +574 -0
- package/src/commands/upgrade-check.ts +4 -1
- package/src/env-files.ts +28 -7
- package/src/manifest.ts +57 -3
- package/src/module-exports.ts +266 -0
- package/src/registry-bundle.ts +103 -0
- package/src/registry-items.ts +141 -36
- package/templates/admin-page/admin-page.tsx.tpl +96 -24
- package/templates/app-scaffold/gitignore.tpl +25 -0
- package/templates/app-scaffold/intelligo.ts.tpl +6 -47
- package/templates/app-scaffold/next.config.mjs.tpl +31 -2
- package/templates/app-scaffold/package.json.tpl +2 -2
- package/templates/manifest.json +40 -3
- package/templates/pnpm-standalone/npmrc.tpl +6 -0
- package/templates/pnpm-standalone/pnpm-workspace.yaml.tpl +10 -0
- package/templates/registry/ai-agent-activity.json +23 -0
- package/templates/registry/ai-agent-progress.json +21 -0
- package/templates/registry/ai-approval-card.json +27 -0
- package/templates/registry/ai-artifact.json +22 -0
- package/templates/registry/ai-branch.json +21 -0
- package/templates/registry/ai-citations.json +24 -0
- package/templates/registry/ai-code-block.json +23 -0
- package/templates/registry/ai-composer-menu.json +19 -0
- package/templates/registry/ai-file-diff.json +25 -0
- package/templates/registry/ai-image-generation.json +23 -0
- package/templates/registry/ai-markdown.json +23 -0
- package/templates/registry/ai-message-bubble.json +23 -0
- package/templates/registry/ai-message-scroller.json +22 -0
- package/templates/registry/ai-message.json +21 -0
- package/templates/registry/ai-motion.json +19 -0
- package/templates/registry/ai-prompt-input.json +28 -0
- package/templates/registry/ai-reasoning-text.json +22 -0
- package/templates/registry/ai-reasoning.json +22 -0
- package/templates/registry/ai-shimmer-text.json +19 -0
- package/templates/registry/ai-sidebar.json +25 -0
- package/templates/registry/ai-speech-input.json +21 -0
- package/templates/registry/ai-streaming-response.json +24 -0
- package/templates/registry/ai-suggestion.json +19 -0
- package/templates/registry/ai-todo-list.json +22 -0
- package/templates/registry/ai-tool-approval.json +26 -0
- package/templates/registry/ai-tool-result.json +25 -0
- package/templates/registry/alert-dialog.json +23 -0
- package/templates/registry/animated-list.json +21 -0
- package/templates/registry/app-shell.json +93 -0
- package/templates/registry/artifacts.json +82 -0
- package/templates/registry/attachment.json +22 -0
- package/templates/registry/auth-email-verification.json +39 -0
- package/templates/registry/auth-login.json +72 -0
- package/templates/registry/auth-password-reset.json +53 -0
- package/templates/registry/auth-signup.json +41 -0
- package/templates/registry/billing-settings.json +66 -0
- package/templates/registry/button.json +22 -0
- package/templates/registry/chat-eve.json +19 -0
- package/templates/registry/chat-panel.json +30 -0
- package/templates/registry/chat-share.json +42 -0
- package/templates/registry/chat-widget.json +34 -0
- package/templates/registry/chat.json +326 -0
- package/templates/registry/checkbox.json +22 -0
- package/templates/registry/checkout.json +40 -0
- package/templates/registry/collapsible.json +19 -0
- package/templates/registry/command.json +23 -0
- package/templates/registry/copy-button.json +21 -0
- package/templates/registry/dashboard.json +69 -0
- package/templates/registry/dialog.json +24 -0
- package/templates/registry/document-viewer.json +22 -0
- package/templates/registry/dropdown-menu.json +23 -0
- package/templates/registry/expandable-tabs.json +22 -0
- package/templates/registry/feature-gating.json +73 -0
- package/templates/registry/file-upload.json +24 -0
- package/templates/registry/hold-action-button.json +22 -0
- package/templates/registry/input-group.json +23 -0
- package/templates/registry/input.json +19 -0
- package/templates/registry/intelligo.json +187 -0
- package/templates/registry/invitation-accept.json +64 -0
- package/templates/registry/language-switcher.json +29 -0
- package/templates/registry/morphing-modal.json +24 -0
- package/templates/registry/notification-stack.json +24 -0
- package/templates/registry/notifications.json +87 -0
- package/templates/registry/onboarding.json +83 -0
- package/templates/registry/otp-input.json +22 -0
- package/templates/registry/page-header.json +15 -0
- package/templates/registry/payment-poll.json +58 -0
- package/templates/registry/popover-morph.json +22 -0
- package/templates/registry/popover.json +22 -0
- package/templates/registry/pricing.json +117 -0
- package/templates/registry/privacy-settings.json +65 -0
- package/templates/registry/profile-settings.json +68 -0
- package/templates/registry/progress.json +19 -0
- package/templates/registry/radio-group.json +22 -0
- package/templates/registry/registry.json +2960 -0
- package/templates/registry/route-error.json +65 -0
- package/templates/registry/select-morph.json +23 -0
- package/templates/registry/select.json +23 -0
- package/templates/registry/settings-shell.json +47 -0
- package/templates/registry/sheet.json +24 -0
- package/templates/registry/sidebar.json +28 -0
- package/templates/registry/smoke.json +34 -0
- package/templates/registry/spinner.json +16 -0
- package/templates/registry/stat-card.json +18 -0
- package/templates/registry/status-badge.json +18 -0
- package/templates/registry/switch.json +20 -0
- package/templates/registry/tabs.json +23 -0
- package/templates/registry/team-settings.json +97 -0
- package/templates/registry/textarea.json +16 -0
- package/templates/registry/tooltip.json +22 -0
- package/templates/registry/trial-banner.json +43 -0
- package/templates/registry/usage.json +84 -0
- package/templates/registry/workspace-settings.json +71 -0
- package/templates/registry-items.json +3 -3
- package/templates/registry-requires.json +30 -4
- package/templates/vitest/server-only.ts.tpl +7 -0
- package/templates/vitest/vitest.config.ts.tpl +37 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `intelligo sync [items…] [--check] [--force]`
|
|
3
|
+
*
|
|
4
|
+
* Keeps an app's installed registry pages exactly what the framework
|
|
5
|
+
* ships. Installing stays the shadcn CLI's job — every item goes in with
|
|
6
|
+
* `shadcn add <item> --yes --overwrite` — and this command adds what
|
|
7
|
+
* shadcn cannot know:
|
|
8
|
+
*
|
|
9
|
+
* - the version: items come from the registry bundled with this CLI, so
|
|
10
|
+
* they match the `@intelligo-dev/*` packages of the same release;
|
|
11
|
+
* - the order: an item that imports a sibling's files lands after it
|
|
12
|
+
* (requires.json `items`);
|
|
13
|
+
* - the seams: files an item ships once for the deployment to own
|
|
14
|
+
* (requires.json `seams`) are put back after the install, and message
|
|
15
|
+
* files are merged key by key, the app's copy winning;
|
|
16
|
+
* - the record: intelligo.manifest.json keeps each installed file's
|
|
17
|
+
* hash, so `--check` can tell a file edited by hand from one a newer
|
|
18
|
+
* registry replaced. Scaffold files an install replaces (globals.css,
|
|
19
|
+
* the theme provider) leave the `app-scaffold` record for this one,
|
|
20
|
+
* so `upgrade --check` stops calling them customized.
|
|
21
|
+
*
|
|
22
|
+
* `--check` installs nothing and exits 1 when any installed file is
|
|
23
|
+
* missing, edited or behind the registry — the gate CI runs.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { spawn } from "node:child_process";
|
|
27
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
28
|
+
import { createServer, type Server } from "node:http";
|
|
29
|
+
import type { AddressInfo } from "node:net";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
|
|
32
|
+
import type { RegistryRequires } from "./doctor.js";
|
|
33
|
+
import {
|
|
34
|
+
emptyManifest,
|
|
35
|
+
handOver,
|
|
36
|
+
hashContents,
|
|
37
|
+
readManifest,
|
|
38
|
+
writeManifest,
|
|
39
|
+
type Manifest,
|
|
40
|
+
} from "../manifest.js";
|
|
41
|
+
import {
|
|
42
|
+
asInstalled,
|
|
43
|
+
hasRegistryItem,
|
|
44
|
+
installedPath,
|
|
45
|
+
readRegistryItem,
|
|
46
|
+
registryClosure,
|
|
47
|
+
} from "../registry-bundle.js";
|
|
48
|
+
import { withDependencies } from "../registry-items.js";
|
|
49
|
+
import {
|
|
50
|
+
isMessages,
|
|
51
|
+
localeEntries,
|
|
52
|
+
mergeMessages,
|
|
53
|
+
missingMessageKeys,
|
|
54
|
+
type Json,
|
|
55
|
+
} from "./sync-messages.js";
|
|
56
|
+
import { SCAFFOLD_FEATURE, snapshotScaffold } from "./sync-scaffold.js";
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
appLocales,
|
|
60
|
+
mergeMessages,
|
|
61
|
+
missingMessageKeys,
|
|
62
|
+
} from "./sync-messages.js";
|
|
63
|
+
export { SCAFFOLD_FEATURE, scaffoldHandover } from "./sync-scaffold.js";
|
|
64
|
+
|
|
65
|
+
/** The design-system base: no marker file, installed before any page. */
|
|
66
|
+
export const BASE_ITEM = "intelligo";
|
|
67
|
+
|
|
68
|
+
export type SyncFileState =
|
|
69
|
+
/** identical to the registry */
|
|
70
|
+
| "current"
|
|
71
|
+
/** untouched since the last sync; the registry has a newer version */
|
|
72
|
+
| "outdated"
|
|
73
|
+
/** changed by hand since it was installed */
|
|
74
|
+
| "edited"
|
|
75
|
+
/** differs from the registry, and no sync ever recorded it */
|
|
76
|
+
| "differs"
|
|
77
|
+
/** the registry ships it and the app does not have it */
|
|
78
|
+
| "missing"
|
|
79
|
+
/** a seam: the app's own from the first install on */
|
|
80
|
+
| "seam"
|
|
81
|
+
/** a message file that lacks keys the registry's has */
|
|
82
|
+
| "messages-behind"
|
|
83
|
+
/** another locale's copy of a shipped namespace lacks keys the app's English has */
|
|
84
|
+
| "locale-behind";
|
|
85
|
+
|
|
86
|
+
export type SyncEntry = {
|
|
87
|
+
item: string;
|
|
88
|
+
path: string;
|
|
89
|
+
state: SyncFileState;
|
|
90
|
+
/** For `messages-behind` / `locale-behind`: the dotted keys the copy lacks. */
|
|
91
|
+
missingKeys?: string[];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type SyncReport = {
|
|
95
|
+
/** The framework version of the bundled registry. */
|
|
96
|
+
version: string;
|
|
97
|
+
/** The items checked, in install order (Intelligo components included). */
|
|
98
|
+
items: string[];
|
|
99
|
+
entries: SyncEntry[];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type SyncSelection =
|
|
103
|
+
{ ok: true; items: string[] } | { ok: false; message: string };
|
|
104
|
+
|
|
105
|
+
export type SyncContext = {
|
|
106
|
+
appRoot: string;
|
|
107
|
+
registryDir: string;
|
|
108
|
+
requires: RegistryRequires & { seams?: Record<string, string> };
|
|
109
|
+
frameworkVersion: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const FAILING: ReadonlySet<SyncFileState> = new Set([
|
|
113
|
+
"outdated",
|
|
114
|
+
"edited",
|
|
115
|
+
"differs",
|
|
116
|
+
"missing",
|
|
117
|
+
"messages-behind",
|
|
118
|
+
"locale-behind",
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The items to sync: the ones named, else the ones the manifest
|
|
123
|
+
* recorded. With neither, nothing is guessed — a page at an item's
|
|
124
|
+
* marker path may be the product's own (a custom dashboard), and a sync
|
|
125
|
+
* would replace it — so the message lists what looks installed and asks
|
|
126
|
+
* for names.
|
|
127
|
+
*/
|
|
128
|
+
export function selectItems(
|
|
129
|
+
names: readonly string[],
|
|
130
|
+
context: SyncContext
|
|
131
|
+
): SyncSelection {
|
|
132
|
+
const unknown = names.filter(
|
|
133
|
+
(n) => n === "registry" || !hasRegistryItem(context.registryDir, n)
|
|
134
|
+
);
|
|
135
|
+
if (unknown.length > 0) {
|
|
136
|
+
return {
|
|
137
|
+
ok: false,
|
|
138
|
+
message: `Unknown registry item(s): ${unknown.join(", ")}. Available: ${[
|
|
139
|
+
BASE_ITEM,
|
|
140
|
+
...Object.keys(context.requires.items),
|
|
141
|
+
].join(", ")}`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (names.length > 0) return { ok: true, items: [...names] };
|
|
145
|
+
|
|
146
|
+
const recorded = readManifest(context.appRoot)?.registry?.items;
|
|
147
|
+
if (recorded && recorded.length > 0) return { ok: true, items: recorded };
|
|
148
|
+
|
|
149
|
+
const looksInstalled = Object.entries(context.requires.items)
|
|
150
|
+
.filter(([, item]) => existsSync(path.join(context.appRoot, item.marker)))
|
|
151
|
+
.map(([name]) => name);
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
message: [
|
|
155
|
+
"No synced items are recorded in intelligo.manifest.json yet.",
|
|
156
|
+
"Name the items this app installs from the registry, once:",
|
|
157
|
+
"",
|
|
158
|
+
` intelligo sync ${[BASE_ITEM, ...looksInstalled].join(" ")}`,
|
|
159
|
+
"",
|
|
160
|
+
"(these are the items whose files are present — leave out any whose",
|
|
161
|
+
"path your product uses for a page of its own)",
|
|
162
|
+
].join("\n"),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Blocks in requires.json order, the design-system base first. */
|
|
167
|
+
export function installOrder(
|
|
168
|
+
items: readonly string[],
|
|
169
|
+
requires: RegistryRequires
|
|
170
|
+
): string[] {
|
|
171
|
+
const blocks = items.filter((n) => n in requires.items);
|
|
172
|
+
const others = items.filter((n) => !(n in requires.items));
|
|
173
|
+
const ordered = withDependencies(blocks, requires);
|
|
174
|
+
return [
|
|
175
|
+
...others.filter((n) => n === BASE_ITEM),
|
|
176
|
+
...others.filter((n) => n !== BASE_ITEM),
|
|
177
|
+
...ordered,
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type ShippedFile = { item: string; target: string; content: string };
|
|
182
|
+
|
|
183
|
+
function shippedFiles(
|
|
184
|
+
context: SyncContext,
|
|
185
|
+
items: readonly string[]
|
|
186
|
+
): {
|
|
187
|
+
closure: string[];
|
|
188
|
+
files: ShippedFile[];
|
|
189
|
+
} {
|
|
190
|
+
const closure = registryClosure(context.registryDir, items);
|
|
191
|
+
const byTarget = new Map<string, ShippedFile>();
|
|
192
|
+
for (const name of closure) {
|
|
193
|
+
const item = readRegistryItem(context.registryDir, name);
|
|
194
|
+
for (const file of item.files ?? []) {
|
|
195
|
+
const target = installedPath(item, file);
|
|
196
|
+
if (!target || file.content === undefined) continue;
|
|
197
|
+
byTarget.set(target, { item: name, target, content: file.content });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { closure, files: [...byTarget.values()] };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Compare the app against the bundled registry; writes nothing. */
|
|
204
|
+
export function syncCheck(
|
|
205
|
+
items: readonly string[],
|
|
206
|
+
context: SyncContext
|
|
207
|
+
): SyncReport {
|
|
208
|
+
const { closure, files } = shippedFiles(context, items);
|
|
209
|
+
const seams = context.requires.seams ?? {};
|
|
210
|
+
const manifest = readManifest(context.appRoot);
|
|
211
|
+
const recorded = manifest?.registry?.files ?? {};
|
|
212
|
+
// What the scaffold wrote, by hash: a file it wrote and nobody edited
|
|
213
|
+
// is the registry's to replace, not someone's work.
|
|
214
|
+
const scaffolded = new Map(
|
|
215
|
+
(manifest?.features[SCAFFOLD_FEATURE]?.files ?? []).map((f) => [
|
|
216
|
+
f.path,
|
|
217
|
+
f.hash,
|
|
218
|
+
])
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
const entries: SyncEntry[] = files.map(({ item, target, content }) => {
|
|
222
|
+
const abs = path.join(context.appRoot, target);
|
|
223
|
+
if (!existsSync(abs)) return { item, path: target, state: "missing" };
|
|
224
|
+
if (target in seams) return { item, path: target, state: "seam" };
|
|
225
|
+
const local = readFileSync(abs, "utf8");
|
|
226
|
+
|
|
227
|
+
if (isMessages(target)) {
|
|
228
|
+
const missingKeys = missingMessageKeys(
|
|
229
|
+
JSON.parse(content) as Json,
|
|
230
|
+
JSON.parse(local) as Json
|
|
231
|
+
);
|
|
232
|
+
return missingKeys.length > 0
|
|
233
|
+
? { item, path: target, state: "messages-behind", missingKeys }
|
|
234
|
+
: { item, path: target, state: "current" };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (asInstalled(local) === asInstalled(content)) {
|
|
238
|
+
return { item, path: target, state: "current" };
|
|
239
|
+
}
|
|
240
|
+
const hash = recorded[target];
|
|
241
|
+
if (hash === undefined) {
|
|
242
|
+
return {
|
|
243
|
+
item,
|
|
244
|
+
path: target,
|
|
245
|
+
state:
|
|
246
|
+
scaffolded.get(target) === hashContents(local)
|
|
247
|
+
? "outdated"
|
|
248
|
+
: "differs",
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
item,
|
|
253
|
+
path: target,
|
|
254
|
+
state: hashContents(asInstalled(local)) === hash ? "outdated" : "edited",
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
entries.push(...localeEntries(context.appRoot, files));
|
|
259
|
+
return { version: context.frameworkVersion, items: closure, entries };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function syncCheckExitCode(report: SyncReport): number {
|
|
263
|
+
return report.entries.some((e) => FAILING.has(e.state)) ? 1 : 0;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function formatSyncReport(report: SyncReport): string {
|
|
267
|
+
const counts = new Map<SyncFileState, number>();
|
|
268
|
+
for (const e of report.entries) {
|
|
269
|
+
counts.set(e.state, (counts.get(e.state) ?? 0) + 1);
|
|
270
|
+
}
|
|
271
|
+
const lines = [
|
|
272
|
+
`Registry ${report.version}: ${report.items.length} item(s), ${report.entries.length} file(s) — ` +
|
|
273
|
+
[...counts].map(([state, n]) => `${n} ${state}`).join(", "),
|
|
274
|
+
];
|
|
275
|
+
const HINT: Partial<Record<SyncFileState, string>> = {
|
|
276
|
+
outdated: "a newer registry version — `intelligo sync` replaces it",
|
|
277
|
+
edited:
|
|
278
|
+
"edited by hand — move the change into a seam, or ask for one upstream",
|
|
279
|
+
differs: "not what the registry ships, and never synced",
|
|
280
|
+
missing: "not installed",
|
|
281
|
+
"messages-behind": "lacks registry keys — `intelligo sync` adds them",
|
|
282
|
+
"locale-behind":
|
|
283
|
+
"lacks keys the app's English copy has — translate them; sync never writes another locale",
|
|
284
|
+
};
|
|
285
|
+
for (const state of FAILING) {
|
|
286
|
+
const group = report.entries.filter((e) => e.state === state);
|
|
287
|
+
if (group.length === 0) continue;
|
|
288
|
+
lines.push("", `${state} (${HINT[state]}):`);
|
|
289
|
+
for (const e of group) {
|
|
290
|
+
const keys = e.missingKeys
|
|
291
|
+
? ` — ${e.missingKeys.slice(0, 5).join(", ")}${e.missingKeys.length > 5 ? `, +${e.missingKeys.length - 5}` : ""}`
|
|
292
|
+
: "";
|
|
293
|
+
lines.push(` ${e.path} [${e.item}]${keys}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (!report.entries.some((e) => FAILING.has(e.state))) {
|
|
297
|
+
lines.push("✓ every installed file is the registry's, seams aside");
|
|
298
|
+
}
|
|
299
|
+
return lines.join("\n");
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** The package version the app resolves for `@intelligo-dev/core`, if any. */
|
|
303
|
+
export function installedFrameworkVersion(appRoot: string): string | null {
|
|
304
|
+
const manifest = path.join(
|
|
305
|
+
appRoot,
|
|
306
|
+
"node_modules",
|
|
307
|
+
"@intelligo-dev",
|
|
308
|
+
"core",
|
|
309
|
+
"package.json"
|
|
310
|
+
);
|
|
311
|
+
if (!existsSync(manifest)) return null;
|
|
312
|
+
return (JSON.parse(readFileSync(manifest, "utf8")) as { version: string })
|
|
313
|
+
.version;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function serveRegistry(dir: string): Promise<{ server: Server; url: string }> {
|
|
317
|
+
return new Promise((resolve, reject) => {
|
|
318
|
+
const server = createServer((req, res) => {
|
|
319
|
+
const name = decodeURIComponent((req.url ?? "").split("?")[0]!).replace(
|
|
320
|
+
/^\//,
|
|
321
|
+
""
|
|
322
|
+
);
|
|
323
|
+
const file = path.join(dir, name);
|
|
324
|
+
if (!/^[a-z0-9-]+\.json$/.test(name) || !existsSync(file)) {
|
|
325
|
+
res.writeHead(404);
|
|
326
|
+
res.end();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
330
|
+
res.end(readFileSync(file));
|
|
331
|
+
});
|
|
332
|
+
server.once("error", reject);
|
|
333
|
+
server.listen(0, "127.0.0.1", () => {
|
|
334
|
+
const { port } = server.address() as AddressInfo;
|
|
335
|
+
resolve({ server, url: `http://127.0.0.1:${port}` });
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function run(
|
|
341
|
+
command: string,
|
|
342
|
+
args: string[],
|
|
343
|
+
cwd: string
|
|
344
|
+
): Promise<{ code: number; output: string }> {
|
|
345
|
+
return new Promise((resolve) => {
|
|
346
|
+
const child = spawn(command, args, {
|
|
347
|
+
cwd,
|
|
348
|
+
// pnpm, npx and friends are .cmd shims on Windows.
|
|
349
|
+
shell: process.platform === "win32",
|
|
350
|
+
env: process.env,
|
|
351
|
+
});
|
|
352
|
+
let output = "";
|
|
353
|
+
child.stdout.on("data", (d) => (output += String(d)));
|
|
354
|
+
child.stderr.on("data", (d) => (output += String(d)));
|
|
355
|
+
child.on("close", (code) => resolve({ code: code ?? 1, output }));
|
|
356
|
+
child.on("error", (error) =>
|
|
357
|
+
resolve({ code: 1, output: `${output}${error.message}` })
|
|
358
|
+
);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Put the kept seams back, and merge kept messages over the registry's. */
|
|
363
|
+
function restoreKept(
|
|
364
|
+
appRoot: string,
|
|
365
|
+
kept: ReadonlyMap<string, string>,
|
|
366
|
+
shipped: ReadonlyMap<string, string>
|
|
367
|
+
): void {
|
|
368
|
+
for (const [target, content] of kept) {
|
|
369
|
+
const abs = path.join(appRoot, target);
|
|
370
|
+
mkdirSync(path.dirname(abs), { recursive: true });
|
|
371
|
+
if (isMessages(target) && shipped.has(target)) {
|
|
372
|
+
const merged = mergeMessages(
|
|
373
|
+
JSON.parse(shipped.get(target)!) as Json,
|
|
374
|
+
JSON.parse(content) as Json
|
|
375
|
+
);
|
|
376
|
+
writeFileSync(abs, `${JSON.stringify(merged, null, 2)}\n`);
|
|
377
|
+
} else {
|
|
378
|
+
writeFileSync(abs, content);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Write the synced items and each installed file's hash (seams and
|
|
385
|
+
* message files aside) into the manifest.
|
|
386
|
+
*/
|
|
387
|
+
function recordSync(
|
|
388
|
+
context: SyncContext,
|
|
389
|
+
names: readonly string[],
|
|
390
|
+
after: SyncReport,
|
|
391
|
+
{ manifest }: { manifest: Manifest }
|
|
392
|
+
): void {
|
|
393
|
+
const files: Record<string, string> = {};
|
|
394
|
+
for (const e of after.entries) {
|
|
395
|
+
if (e.state === "seam" || e.state === "missing" || isMessages(e.path)) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
files[e.path] = hashContents(
|
|
399
|
+
asInstalled(readFileSync(path.join(context.appRoot, e.path), "utf8"))
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
const recordedItems = new Set([
|
|
403
|
+
...(manifest.registry?.items ?? []),
|
|
404
|
+
...names,
|
|
405
|
+
]);
|
|
406
|
+
writeManifest(context.appRoot, {
|
|
407
|
+
...manifest,
|
|
408
|
+
registry: {
|
|
409
|
+
version: context.frameworkVersion,
|
|
410
|
+
items: installOrder([...recordedItems], context.requires),
|
|
411
|
+
files: { ...manifest.registry?.files, ...files },
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Record `names` as items this app keeps in sync before any is
|
|
418
|
+
* installed, so a bare `intelligo sync` installs them after an install
|
|
419
|
+
* that did not run or did not finish.
|
|
420
|
+
*/
|
|
421
|
+
export function recordItems(
|
|
422
|
+
names: readonly string[],
|
|
423
|
+
context: Pick<SyncContext, "appRoot" | "requires" | "frameworkVersion">
|
|
424
|
+
): void {
|
|
425
|
+
const manifest =
|
|
426
|
+
readManifest(context.appRoot) ?? emptyManifest(context.frameworkVersion);
|
|
427
|
+
const items = new Set([...(manifest.registry?.items ?? []), ...names]);
|
|
428
|
+
writeManifest(context.appRoot, {
|
|
429
|
+
...manifest,
|
|
430
|
+
registry: {
|
|
431
|
+
version: manifest.registry?.version ?? context.frameworkVersion,
|
|
432
|
+
items: installOrder([...items], context.requires),
|
|
433
|
+
files: manifest.registry?.files ?? {},
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export type SyncApplyOptions = {
|
|
439
|
+
force?: boolean;
|
|
440
|
+
log?: (line: string) => void;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Install `items` from the bundled registry, keep the seams, merge the
|
|
445
|
+
* messages and record what was written. Refuses to overwrite a file
|
|
446
|
+
* edited by hand unless `force` — the edit belongs in a seam, and the
|
|
447
|
+
* refusal says which files.
|
|
448
|
+
*/
|
|
449
|
+
export async function syncApply(
|
|
450
|
+
names: readonly string[],
|
|
451
|
+
context: SyncContext,
|
|
452
|
+
options: SyncApplyOptions = {}
|
|
453
|
+
): Promise<number> {
|
|
454
|
+
const log = options.log ?? console.log;
|
|
455
|
+
const { appRoot } = context;
|
|
456
|
+
const shadcn = path.join(appRoot, "node_modules", ".bin", "shadcn");
|
|
457
|
+
if (!existsSync(shadcn)) {
|
|
458
|
+
log(
|
|
459
|
+
"shadcn is not installed in this app — add it as a devDependency (the scaffold declares it) and install."
|
|
460
|
+
);
|
|
461
|
+
return 1;
|
|
462
|
+
}
|
|
463
|
+
const componentsPath = path.join(appRoot, "components.json");
|
|
464
|
+
if (!existsSync(componentsPath)) {
|
|
465
|
+
log("No components.json — run from the app's root.");
|
|
466
|
+
return 1;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const items = installOrder(names, context.requires);
|
|
470
|
+
const before = syncCheck(items, context);
|
|
471
|
+
const shippedTargets = new Set(
|
|
472
|
+
shippedFiles(context, items).files.map((f) => f.target)
|
|
473
|
+
);
|
|
474
|
+
const edited = before.entries.filter(
|
|
475
|
+
(e) => e.state === "edited" || e.state === "differs"
|
|
476
|
+
);
|
|
477
|
+
if (edited.length > 0 && !options.force) {
|
|
478
|
+
log(
|
|
479
|
+
[
|
|
480
|
+
`${edited.length} installed file(s) differ from the registry and would be overwritten:`,
|
|
481
|
+
...edited.map((e) => ` ${e.path} [${e.item}]`),
|
|
482
|
+
"",
|
|
483
|
+
"Move what the change does into a seam (lib/*-config, messages/), then re-run",
|
|
484
|
+
"with --force to replace these files with the registry's.",
|
|
485
|
+
].join("\n")
|
|
486
|
+
);
|
|
487
|
+
return 1;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// What the install must not lose: the app's seams and message files.
|
|
491
|
+
const seams = context.requires.seams ?? {};
|
|
492
|
+
const kept = new Map<string, string>();
|
|
493
|
+
for (const e of before.entries) {
|
|
494
|
+
if (e.state === "missing" || !shippedTargets.has(e.path)) continue;
|
|
495
|
+
if (e.path in seams || isMessages(e.path)) {
|
|
496
|
+
kept.set(e.path, readFileSync(path.join(appRoot, e.path), "utf8"));
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const componentsBefore = JSON.parse(readFileSync(componentsPath, "utf8")) as {
|
|
501
|
+
registries?: Record<string, string>;
|
|
502
|
+
tailwind?: { css?: string };
|
|
503
|
+
};
|
|
504
|
+
// The scaffold's files as they are now, to see which the install replaces.
|
|
505
|
+
const scaffold = snapshotScaffold(appRoot);
|
|
506
|
+
const originalRegistry = componentsBefore.registries?.["@intelligo"];
|
|
507
|
+
const { server, url } = await serveRegistry(context.registryDir);
|
|
508
|
+
|
|
509
|
+
const setRegistry = (value: string | undefined) => {
|
|
510
|
+
// Read fresh: the base item rewrites components.json's style fields,
|
|
511
|
+
// and those changes are the point — only the registry URL is ours.
|
|
512
|
+
const current = JSON.parse(readFileSync(componentsPath, "utf8")) as {
|
|
513
|
+
registries?: Record<string, string>;
|
|
514
|
+
};
|
|
515
|
+
const registries = { ...current.registries };
|
|
516
|
+
if (value === undefined) delete registries["@intelligo"];
|
|
517
|
+
else registries["@intelligo"] = value;
|
|
518
|
+
const next: typeof current = { ...current, registries };
|
|
519
|
+
if (Object.keys(registries).length === 0) delete next.registries;
|
|
520
|
+
writeFileSync(componentsPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
let failed: { item: string; output: string } | null = null;
|
|
524
|
+
try {
|
|
525
|
+
setRegistry(`${url}/{name}.json`);
|
|
526
|
+
for (const item of items) {
|
|
527
|
+
log(`› shadcn add ${item}`);
|
|
528
|
+
const result = await run(
|
|
529
|
+
shadcn,
|
|
530
|
+
["add", `${url}/${item}.json`, "--yes", "--overwrite"],
|
|
531
|
+
appRoot
|
|
532
|
+
);
|
|
533
|
+
if (result.code !== 0) {
|
|
534
|
+
failed = { item, output: result.output };
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
} finally {
|
|
539
|
+
setRegistry(originalRegistry);
|
|
540
|
+
server.close();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// Seams back as they were; messages merged over the registry's.
|
|
544
|
+
const shipped = new Map(
|
|
545
|
+
shippedFiles(context, items).files.map((f) => [f.target, f.content])
|
|
546
|
+
);
|
|
547
|
+
restoreKept(appRoot, kept, shipped);
|
|
548
|
+
|
|
549
|
+
if (failed) {
|
|
550
|
+
log(
|
|
551
|
+
`shadcn add ${failed.item} failed:\n${failed.output.trim().split("\n").slice(-20).join("\n")}`
|
|
552
|
+
);
|
|
553
|
+
return 1;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Record what is on disk now, so the next check can tell an edit.
|
|
557
|
+
const after = syncCheck(items, context);
|
|
558
|
+
recordSync(context, names, after, {
|
|
559
|
+
manifest: handOver(
|
|
560
|
+
readManifest(appRoot) ?? emptyManifest(context.frameworkVersion),
|
|
561
|
+
SCAFFOLD_FEATURE,
|
|
562
|
+
scaffold.handedOver({
|
|
563
|
+
shipped: new Set(shipped.keys()),
|
|
564
|
+
seams,
|
|
565
|
+
css: items.includes(BASE_ITEM)
|
|
566
|
+
? (componentsBefore.tailwind?.css ?? null)
|
|
567
|
+
: null,
|
|
568
|
+
})
|
|
569
|
+
),
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
log(formatSyncReport(after));
|
|
573
|
+
return syncCheckExitCode(after);
|
|
574
|
+
}
|
|
@@ -61,7 +61,10 @@ export function upgradeCheck(options: UpgradeCheckOptions): UpgradeReport {
|
|
|
61
61
|
(spec?.files ?? []).map((f) => [f.target, f.template])
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
for (const target of newFiles(spec,
|
|
64
|
+
for (const target of newFiles(spec, [
|
|
65
|
+
...entry.files,
|
|
66
|
+
...(entry.handedOver ?? []).map((handed) => ({ path: handed })),
|
|
67
|
+
])) {
|
|
65
68
|
report.items.push({ feature, path: target, state: "new" });
|
|
66
69
|
}
|
|
67
70
|
|
package/src/env-files.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parseEnv } from "node:util";
|
|
4
4
|
|
|
5
|
+
import { findWorkspaceRoot } from "./registry-items.js";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* The env files a Next.js app reads, in the order it reads them: an
|
|
7
9
|
* earlier file wins, and a variable already set in the shell wins over
|
|
@@ -13,19 +15,38 @@ import { parseEnv } from "node:util";
|
|
|
13
15
|
*/
|
|
14
16
|
export const ENV_FILES = [".env.local", ".env"] as const;
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Loads the app's env files into `env`, then — when the app is a member
|
|
20
|
+
* of a pnpm workspace — the workspace root's, for an app whose
|
|
21
|
+
* `next.config` falls back to the repository root's `.env`. Precedence,
|
|
22
|
+
* highest first: the shell, the app's `.env.local`, the app's `.env`,
|
|
23
|
+
* the root's `.env.local`, the root's `.env`. A variable already set is
|
|
24
|
+
* never overridden.
|
|
25
|
+
*
|
|
26
|
+
* Returns the files it read, relative to `root` (`.env.local`,
|
|
27
|
+
* `../../.env`).
|
|
28
|
+
*/
|
|
16
29
|
export function loadAppEnv(
|
|
17
30
|
root: string,
|
|
18
31
|
env: NodeJS.ProcessEnv = process.env
|
|
19
32
|
): string[] {
|
|
33
|
+
const dirs = [root];
|
|
34
|
+
const workspaceRoot = findWorkspaceRoot(root);
|
|
35
|
+
if (workspaceRoot && path.resolve(workspaceRoot) !== path.resolve(root)) {
|
|
36
|
+
dirs.push(workspaceRoot);
|
|
37
|
+
}
|
|
38
|
+
|
|
20
39
|
const loaded: string[] = [];
|
|
21
|
-
for (const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
for (const dir of dirs) {
|
|
41
|
+
for (const name of ENV_FILES) {
|
|
42
|
+
const file = path.join(dir, name);
|
|
43
|
+
if (!existsSync(file)) continue;
|
|
44
|
+
const values = parseEnv(readFileSync(file, "utf8"));
|
|
45
|
+
for (const [key, value] of Object.entries(values)) {
|
|
46
|
+
if (env[key] === undefined) env[key] = value;
|
|
47
|
+
}
|
|
48
|
+
loaded.push(path.relative(root, file));
|
|
27
49
|
}
|
|
28
|
-
loaded.push(name);
|
|
29
50
|
}
|
|
30
51
|
return loaded;
|
|
31
52
|
}
|