sordo 0.4.0 → 1.0.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.
Files changed (152) hide show
  1. package/CHANGELOG.md +6 -116
  2. package/README.md +8 -175
  3. package/bin/sordo.ts +1 -4
  4. package/package.json +17 -41
  5. package/src/agents-md.ts +1 -0
  6. package/src/ai.ts +1 -0
  7. package/src/build.ts +1 -0
  8. package/src/client.ts +1 -0
  9. package/src/config.ts +1 -0
  10. package/src/dev.ts +1 -0
  11. package/src/index.ts +1 -55
  12. package/src/middleware.ts +1 -0
  13. package/src/plugin.ts +1 -0
  14. package/src/render.ts +1 -0
  15. package/src/router.ts +1 -0
  16. package/src/server.ts +1 -0
  17. package/CLAUDE.md +0 -124
  18. package/src/adapters/bun.ts +0 -59
  19. package/src/adapters/edge.ts +0 -75
  20. package/src/adapters/types.ts +0 -43
  21. package/src/agents-md/collect.ts +0 -113
  22. package/src/agents-md/generate.ts +0 -44
  23. package/src/agents-md/index.ts +0 -9
  24. package/src/agents-md/render.ts +0 -150
  25. package/src/agents-md/subprocess-entry.ts +0 -92
  26. package/src/agents-md/subprocess-runner.ts +0 -111
  27. package/src/agents-md/write.ts +0 -38
  28. package/src/agents-md/zod-to-json-schema.ts +0 -18
  29. package/src/ai/context.ts +0 -72
  30. package/src/ai/define.ts +0 -15
  31. package/src/ai/errors.ts +0 -51
  32. package/src/ai/index.ts +0 -36
  33. package/src/ai/middleware.ts +0 -21
  34. package/src/ai/registry.ts +0 -96
  35. package/src/ai/run.ts +0 -185
  36. package/src/ai/scan.ts +0 -42
  37. package/src/ai/stream.ts +0 -71
  38. package/src/ai/triggers.ts +0 -124
  39. package/src/ai/types.ts +0 -67
  40. package/src/ai/validate.ts +0 -82
  41. package/src/build/assets.ts +0 -48
  42. package/src/build/client-entry.ts +0 -43
  43. package/src/build/css.ts +0 -102
  44. package/src/build/embedded.ts +0 -66
  45. package/src/build/hash.ts +0 -21
  46. package/src/build/index.ts +0 -480
  47. package/src/build/macros/agents-hash.macro.ts +0 -9
  48. package/src/build/macros/agents.macro.ts +0 -21
  49. package/src/build/macros/env.macro.ts +0 -25
  50. package/src/build/macros/inline-assets.macro.ts +0 -28
  51. package/src/build/macros/manifest.macro.ts +0 -8
  52. package/src/build/macros/routes.macro.ts +0 -10
  53. package/src/build/page-entry.ts +0 -136
  54. package/src/build/scan-islands.ts +0 -39
  55. package/src/build/server-entry.ts +0 -256
  56. package/src/cli/ansi.ts +0 -41
  57. package/src/cli/build.ts +0 -195
  58. package/src/cli/commands/add/apply.ts +0 -31
  59. package/src/cli/commands/add/component-diff.ts +0 -116
  60. package/src/cli/commands/add/diff.ts +0 -153
  61. package/src/cli/commands/add/internal.ts +0 -41
  62. package/src/cli/commands/add/load-catalog.ts +0 -22
  63. package/src/cli/commands/add/peer-deps.ts +0 -115
  64. package/src/cli/commands/add/registry-fetch.ts +0 -122
  65. package/src/cli/commands/add/shadcn.ts +0 -285
  66. package/src/cli/commands/add/source.ts +0 -273
  67. package/src/cli/commands/add/stamper.ts +0 -73
  68. package/src/cli/commands/add/tokens.ts +0 -81
  69. package/src/cli/commands/add/ui-paths.ts +0 -113
  70. package/src/cli/commands/add.ts +0 -427
  71. package/src/cli/commands/deploy.ts +0 -143
  72. package/src/cli/commands/migrate.ts +0 -149
  73. package/src/cli/commands/secret.ts +0 -316
  74. package/src/cli/commands/ui/build.ts +0 -111
  75. package/src/cli/commands/ui/init.ts +0 -135
  76. package/src/cli/commands/ui/migrate/git-guard.ts +0 -19
  77. package/src/cli/commands/ui/migrate/radix.ts +0 -67
  78. package/src/cli/commands/ui/migrate/rtl.ts +0 -148
  79. package/src/cli/commands/ui/shadcn.ts +0 -82
  80. package/src/cli/commands/ui/view.ts +0 -63
  81. package/src/cli/commands/ui.ts +0 -86
  82. package/src/cli/commands/update.ts +0 -134
  83. package/src/cli/commands/upgrade.ts +0 -53
  84. package/src/cli/commands/view.ts +0 -34
  85. package/src/cli/dev.ts +0 -393
  86. package/src/cli/doctor/config-checks.ts +0 -63
  87. package/src/cli/doctor/deps.ts +0 -295
  88. package/src/cli/doctor/hydrate.ts +0 -65
  89. package/src/cli/doctor/monorepo.ts +0 -158
  90. package/src/cli/doctor/probes.ts +0 -16
  91. package/src/cli/doctor/report.ts +0 -72
  92. package/src/cli/doctor/toolchain.ts +0 -95
  93. package/src/cli/doctor/types.ts +0 -36
  94. package/src/cli/doctor.ts +0 -127
  95. package/src/cli/index.ts +0 -168
  96. package/src/cli/log.ts +0 -135
  97. package/src/cli/run/affected.ts +0 -79
  98. package/src/cli/run/cache-key.ts +0 -177
  99. package/src/cli/run/cache-store.ts +0 -0
  100. package/src/cli/run/files.ts +0 -96
  101. package/src/cli/run/git.ts +0 -13
  102. package/src/cli/run/runner.ts +0 -189
  103. package/src/cli/run/workspace.ts +0 -216
  104. package/src/cli/run.ts +0 -184
  105. package/src/cli/start.ts +0 -99
  106. package/src/cli/update-check.ts +0 -157
  107. package/src/client/index.ts +0 -65
  108. package/src/client/link.tsx +0 -61
  109. package/src/client/page.ts +0 -250
  110. package/src/config/define.ts +0 -5
  111. package/src/config/env.ts +0 -36
  112. package/src/config/load.ts +0 -152
  113. package/src/config/schema.ts +0 -135
  114. package/src/config/secrets.ts +0 -108
  115. package/src/dev/client.ts +0 -112
  116. package/src/dev/hot.ts +0 -24
  117. package/src/dev/index.ts +0 -4
  118. package/src/dev/tree.ts +0 -95
  119. package/src/dev/watcher.ts +0 -95
  120. package/src/internal/hmr-client.ts +0 -52
  121. package/src/internal/open-in-editor.ts +0 -23
  122. package/src/internal/runtime.ts +0 -30
  123. package/src/middleware/cookie-jar.ts +0 -135
  124. package/src/middleware/cookies.ts +0 -60
  125. package/src/middleware/index.ts +0 -127
  126. package/src/middleware/request-id.ts +0 -22
  127. package/src/middleware/response-helpers.ts +0 -25
  128. package/src/plugin/index.ts +0 -109
  129. package/src/render/bootstrap.ts +0 -44
  130. package/src/render/dev-error.tsx +0 -73
  131. package/src/render/index.tsx +0 -261
  132. package/src/render/island.tsx +0 -33
  133. package/src/render/meta.tsx +0 -48
  134. package/src/render/shell.tsx +0 -41
  135. package/src/router/conflict.ts +0 -20
  136. package/src/router/filesystem.ts +0 -37
  137. package/src/router/index.ts +0 -247
  138. package/src/router/match.ts +0 -91
  139. package/src/router/pattern.ts +0 -88
  140. package/src/server/index.ts +0 -250
  141. package/src/server/inline-assets.ts +0 -39
  142. package/src/types.ts +0 -53
  143. package/src/ui/schema.ts +0 -68
  144. package/src/ui/types.ts +0 -10
  145. package/templates/_internal/cn.ts +0 -6
  146. package/templates/_internal/slot.ts +0 -50
  147. package/templates/_internal/variants.ts +0 -1
  148. package/templates/themes/neutral/tokens.css +0 -46
  149. package/templates/themes/slate/tokens.css +0 -46
  150. package/templates/themes/stone/tokens.css +0 -46
  151. package/templates/themes/zinc/tokens.css +0 -46
  152. package/templates/tokens.css +0 -46
@@ -1,149 +0,0 @@
1
- import { join } from "node:path";
2
- import { loadConfigOrUsage } from "../../config/load.ts";
3
- import type { CliContext } from "../index.ts";
4
- import { EXIT, log } from "../log.ts";
5
- import { resolveUiPaths, UiPathError } from "./add/ui-paths.ts";
6
- import { gitTreeState } from "./ui/migrate/git-guard.ts";
7
- import { rewriteRadix } from "./ui/migrate/radix.ts";
8
- import { rewriteRtl } from "./ui/migrate/rtl.ts";
9
-
10
- interface MigrateArgs {
11
- kind?: "radix" | "rtl";
12
- glob?: string;
13
- dryRun: boolean;
14
- force: boolean;
15
- }
16
-
17
- const PROD_MSG =
18
- "sordo migrate is a dev-only tool; refusing to run with NODE_ENV=production.";
19
-
20
- export async function runMigrate(
21
- argv: string[],
22
- ctx: CliContext,
23
- ): Promise<number> {
24
- const args = parseArgs(argv);
25
-
26
- if (args.kind === undefined) {
27
- printHelp();
28
- return EXIT.USAGE;
29
- }
30
-
31
- if (process.env.NODE_ENV === "production") {
32
- log.error(PROD_MSG);
33
- return EXIT.USAGE;
34
- }
35
-
36
- // Default glob: the resolved componentsDir.
37
- let glob = args.glob;
38
- if (glob === undefined) {
39
- const loaded = await loadConfigOrUsage({
40
- cwd: ctx.cwd,
41
- configPath: ctx.configPath,
42
- });
43
- if ("error" in loaded) {
44
- log.error(loaded.error);
45
- return EXIT.USAGE;
46
- }
47
- try {
48
- glob = resolveUiPaths({
49
- cwd: ctx.cwd,
50
- ui: loaded.config.ui,
51
- }).componentsDir;
52
- } catch (err) {
53
- if (err instanceof UiPathError) {
54
- log.error(err.message);
55
- return EXIT.USAGE;
56
- }
57
- throw err;
58
- }
59
- }
60
-
61
- if (!args.force) {
62
- const tree = await gitTreeState(ctx.cwd);
63
- if (!tree.isRepo) {
64
- log.error(
65
- "not a git repo — re-run with --force to apply the codemod anyway.",
66
- );
67
- return EXIT.USAGE;
68
- }
69
- if (!tree.clean) {
70
- log.error(
71
- "working tree is dirty — commit first, or re-run with --force.",
72
- );
73
- return EXIT.USAGE;
74
- }
75
- }
76
-
77
- const files = await collectFiles(ctx.cwd, glob, args.kind);
78
- if (files.length === 0) {
79
- log.warn(`no files matched: ${glob}`);
80
- return EXIT.OK;
81
- }
82
-
83
- let changedCount = 0;
84
- for (const file of files) {
85
- const source = await Bun.file(file).text();
86
- const result =
87
- args.kind === "radix"
88
- ? rewriteRadix(source)
89
- : rewriteRtl(source, file.endsWith(".css"));
90
-
91
- for (const r of result.reports) log.warn(` ${file}: ${r}`);
92
-
93
- if (!result.changed) continue;
94
- changedCount++;
95
- log.success(` ${args.dryRun ? "would rewrite" : "rewrote"} ${file}`);
96
- if (!args.dryRun) await Bun.write(file, result.output);
97
- }
98
-
99
- if (args.dryRun) {
100
- log.dim(`dry-run: ${changedCount} file(s) would change. Nothing written.`);
101
- } else {
102
- log.dim(
103
- `done. ${changedCount} file(s) changed. Review the diff before commit.`,
104
- );
105
- }
106
- return EXIT.OK;
107
- }
108
-
109
- async function collectFiles(
110
- cwd: string,
111
- glob: string,
112
- kind: "radix" | "rtl",
113
- ): Promise<string[]> {
114
- // radix only touches TS/TSX; rtl also touches CSS.
115
- const pattern = kind === "rtl" ? "**/*.{ts,tsx,css}" : "**/*.{ts,tsx}";
116
- const root = join(cwd, glob);
117
- const out: string[] = [];
118
- const scanner = new Bun.Glob(pattern);
119
- for await (const rel of scanner.scan({ cwd: root, onlyFiles: true })) {
120
- out.push(join(root, rel));
121
- }
122
- return out;
123
- }
124
-
125
- function parseArgs(argv: string[]): MigrateArgs {
126
- const out: MigrateArgs = { dryRun: false, force: false };
127
- for (const a of argv) {
128
- if (a === "--dry-run") out.dryRun = true;
129
- else if (a === "--force") out.force = true;
130
- else if (a === "radix" || a === "rtl") out.kind = a;
131
- else if (!a.startsWith("-")) out.glob = a;
132
- }
133
- return out;
134
- }
135
-
136
- function printHelp(): void {
137
- process.stdout.write(`sordo migrate — codemods for older shadcn-era source
138
-
139
- Usage:
140
- sordo migrate radix [<glob>] [--dry-run] [--force]
141
- sordo migrate rtl [<glob>] [--dry-run] [--force]
142
-
143
- radix Rewrite @radix-ui/react-* imports to the unified radix-ui import.
144
- rtl Rewrite physical CSS/Tailwind props to logical (ml-* -> ms-*, etc.).
145
-
146
- Refuses to run on a dirty git tree without --force. Default glob: the resolved
147
- components dir. Commit before applying.
148
- `);
149
- }
@@ -1,316 +0,0 @@
1
- import { loadConfig } from "../../config/load.ts";
2
- import {
3
- getSecretsApi,
4
- isLibsecretError,
5
- isProductionEnv,
6
- resolveServiceName,
7
- } from "../../config/secrets.ts";
8
- import type { CliContext } from "../index.ts";
9
- import { EXIT, log } from "../log.ts";
10
-
11
- interface SecretArgs {
12
- sub: "set" | "get" | "list" | "rm" | "doctor" | "help" | undefined;
13
- key?: string;
14
- value?: string;
15
- force: boolean;
16
- }
17
-
18
- const PROD_MSG =
19
- "sordo secret is a dev-only tool. In production, set values via your host's secrets surface.";
20
-
21
- const LIBSECRET_HINT =
22
- "OS keychain backend unavailable. On Debian/Ubuntu: sudo apt install libsecret-1-dev";
23
-
24
- export async function runSecret(
25
- argv: string[],
26
- ctx: CliContext,
27
- ): Promise<number> {
28
- const args = parseArgs(argv);
29
-
30
- if (!args.sub || args.sub === "help") {
31
- printHelp();
32
- return EXIT.OK;
33
- }
34
-
35
- if (isProductionEnv() && args.sub !== "doctor") {
36
- log.error(PROD_MSG);
37
- return EXIT.USAGE;
38
- }
39
-
40
- if (args.sub === "doctor") {
41
- return runDoctor(ctx);
42
- }
43
-
44
- const api = getSecretsApi();
45
- if (!api) {
46
- log.error(LIBSECRET_HINT);
47
- return EXIT.USAGE;
48
- }
49
-
50
- const service = await resolveServiceName(ctx.cwd);
51
-
52
- switch (args.sub) {
53
- case "set":
54
- return cmdSet(api, service, args);
55
- case "get":
56
- return cmdGet(api, service, args);
57
- case "list":
58
- return cmdList(api, service);
59
- case "rm":
60
- return cmdRm(api, service, args);
61
- default:
62
- printHelp();
63
- return EXIT.USAGE;
64
- }
65
- }
66
-
67
- function parseArgs(argv: string[]): SecretArgs {
68
- const out: SecretArgs = { sub: undefined, force: false };
69
- const positional: string[] = [];
70
- for (const a of argv) {
71
- if (a === "--force") out.force = true;
72
- else positional.push(a);
73
- }
74
- const [sub, key, value] = positional;
75
- if (
76
- sub === "set" ||
77
- sub === "get" ||
78
- sub === "list" ||
79
- sub === "rm" ||
80
- sub === "doctor" ||
81
- sub === "help"
82
- ) {
83
- out.sub = sub;
84
- }
85
- out.key = key;
86
- out.value = value;
87
- return out;
88
- }
89
-
90
- async function cmdSet(
91
- api: ReturnType<typeof getSecretsApi>,
92
- service: string,
93
- args: SecretArgs,
94
- ): Promise<number> {
95
- if (!api?.set) {
96
- log.error(LIBSECRET_HINT);
97
- return EXIT.USAGE;
98
- }
99
- if (!args.key) {
100
- log.error("usage: sordo secret set <key> [value]");
101
- return EXIT.USAGE;
102
- }
103
- let value = args.value;
104
- if (value === undefined) {
105
- value = await readValue();
106
- }
107
- if (value === undefined || value === "") {
108
- log.error("no value provided");
109
- return EXIT.USAGE;
110
- }
111
- try {
112
- await api.set({ service, name: args.key, value });
113
- } catch (err) {
114
- if (isLibsecretError(err)) {
115
- log.error(LIBSECRET_HINT);
116
- return EXIT.USAGE;
117
- }
118
- throw err;
119
- }
120
- log.success(`stored ${args.key} (service: ${service})`);
121
- return EXIT.OK;
122
- }
123
-
124
- async function cmdGet(
125
- api: ReturnType<typeof getSecretsApi>,
126
- service: string,
127
- args: SecretArgs,
128
- ): Promise<number> {
129
- if (!api) return EXIT.USAGE;
130
- if (!args.key) {
131
- log.error("usage: sordo secret get <key>");
132
- return EXIT.USAGE;
133
- }
134
- let value: string | null | undefined;
135
- try {
136
- value = await api.get({ service, name: args.key });
137
- } catch (err) {
138
- if (isLibsecretError(err)) {
139
- log.error(LIBSECRET_HINT);
140
- return EXIT.USAGE;
141
- }
142
- throw err;
143
- }
144
- if (!value) {
145
- log.error(`unset: ${args.key}`);
146
- return EXIT.ERROR;
147
- }
148
- if (!process.stdout.isTTY && !args.force) {
149
- log.error(
150
- "refusing to print secret to non-TTY stdout. Pass --force to override.",
151
- );
152
- return EXIT.USAGE;
153
- }
154
- process.stdout.write(`${value}\n`);
155
- return EXIT.OK;
156
- }
157
-
158
- async function cmdList(
159
- api: ReturnType<typeof getSecretsApi>,
160
- service: string,
161
- ): Promise<number> {
162
- if (!api?.list) {
163
- log.error(LIBSECRET_HINT);
164
- return EXIT.USAGE;
165
- }
166
- let keys: string[] = [];
167
- try {
168
- keys = await api.list({ service });
169
- } catch (err) {
170
- if (isLibsecretError(err)) {
171
- log.error(LIBSECRET_HINT);
172
- return EXIT.USAGE;
173
- }
174
- throw err;
175
- }
176
- if (keys.length === 0) {
177
- log.dim(`(no secrets in service ${service})`);
178
- return EXIT.OK;
179
- }
180
- for (const key of keys) {
181
- let value: string | null | undefined;
182
- try {
183
- value = await api.get({ service, name: key });
184
- } catch {
185
- value = "";
186
- }
187
- log.info(` ${key} ${maskValue(value ?? "")}`);
188
- }
189
- return EXIT.OK;
190
- }
191
-
192
- async function cmdRm(
193
- api: ReturnType<typeof getSecretsApi>,
194
- service: string,
195
- args: SecretArgs,
196
- ): Promise<number> {
197
- if (!api?.delete) {
198
- log.error(LIBSECRET_HINT);
199
- return EXIT.USAGE;
200
- }
201
- if (!args.key) {
202
- log.error("usage: sordo secret rm <key>");
203
- return EXIT.USAGE;
204
- }
205
- try {
206
- await api.delete({ service, name: args.key });
207
- log.success(`removed ${args.key}`);
208
- } catch (err) {
209
- if (isLibsecretError(err)) {
210
- log.error(LIBSECRET_HINT);
211
- return EXIT.USAGE;
212
- }
213
- log.dim(`(no such key: ${args.key})`);
214
- }
215
- return EXIT.OK;
216
- }
217
-
218
- async function runDoctor(ctx: CliContext): Promise<number> {
219
- const { config } = await loadConfig({
220
- cwd: ctx.cwd,
221
- configPath: ctx.configPath,
222
- });
223
- const keys = config.secrets ?? [];
224
- if (keys.length === 0) {
225
- log.dim("(no entries in config.secrets)");
226
- return EXIT.OK;
227
- }
228
- const api = getSecretsApi();
229
- const service = await resolveServiceName(ctx.cwd);
230
- for (const key of keys) {
231
- const source = await classify(api, service, key);
232
- log.info(` ${pad(key, 24)} ${source}`);
233
- }
234
- return EXIT.OK;
235
- }
236
-
237
- async function classify(
238
- api: ReturnType<typeof getSecretsApi>,
239
- service: string,
240
- key: string,
241
- ): Promise<string> {
242
- if (api) {
243
- try {
244
- const v = await api.get({ service, name: key });
245
- if (v) return "keychain";
246
- } catch {
247
- // fall through
248
- }
249
- }
250
- if (process.env[key]) return "Bun.env";
251
- return "missing";
252
- }
253
-
254
- function maskValue(value: string): string {
255
- if (value.length >= 8) return `••••${value.slice(-4)}`;
256
- return "••••";
257
- }
258
-
259
- function pad(s: string, n: number): string {
260
- if (s.length >= n) return s;
261
- return s + " ".repeat(n - s.length);
262
- }
263
-
264
- async function readValue(): Promise<string | undefined> {
265
- if (!process.stdin.isTTY) {
266
- const text = await Bun.stdin.text();
267
- const nl = text.indexOf("\n");
268
- const value = nl === -1 ? text : text.slice(0, nl);
269
- return value || undefined;
270
- }
271
- process.stdout.write("value: ");
272
- const stdin = process.stdin as NodeJS.ReadStream & {
273
- setRawMode?: (mode: boolean) => void;
274
- };
275
- stdin.setRawMode?.(true);
276
- stdin.resume();
277
- return await new Promise<string | undefined>((resolveValue) => {
278
- let buf = "";
279
- const onData = (chunk: Buffer): void => {
280
- const s = chunk.toString("utf8");
281
- for (const ch of s) {
282
- if (ch === "\r" || ch === "\n") {
283
- stdin.setRawMode?.(false);
284
- stdin.pause();
285
- stdin.off("data", onData);
286
- process.stdout.write("\n");
287
- resolveValue(buf || undefined);
288
- return;
289
- }
290
- if (ch === "") {
291
- // Ctrl-C
292
- stdin.setRawMode?.(false);
293
- process.exit(EXIT.INTERRUPTED);
294
- }
295
- if (ch === "") {
296
- buf = buf.slice(0, -1);
297
- } else {
298
- buf += ch;
299
- }
300
- }
301
- };
302
- stdin.on("data", onData);
303
- });
304
- }
305
-
306
- function printHelp(): void {
307
- process.stdout.write(`sordo secret — manage dev-time secrets
308
-
309
- Usage:
310
- sordo secret set <key> [value]
311
- sordo secret get <key> [--force]
312
- sordo secret list
313
- sordo secret rm <key>
314
- sordo secret doctor
315
- `);
316
- }
@@ -1,111 +0,0 @@
1
- import { isAbsolute, join, resolve } from "node:path";
2
- import { ComponentEntrySchema } from "../../../ui/schema.ts";
3
- import type { ComponentEntry } from "../../../ui/types.ts";
4
- import type { CliContext } from "../../index.ts";
5
- import { EXIT, log } from "../../log.ts";
6
- import {
7
- type ComponentPayload,
8
- requiredTemplatePaths,
9
- } from "../add/registry-fetch.ts";
10
-
11
- export interface UiBuildArgs {
12
- out?: string;
13
- outMissing: boolean;
14
- registry?: string;
15
- templates?: string;
16
- help: boolean;
17
- }
18
-
19
- // `sordo ui build` — the inverse of the remote-fetch path: read a hand-
20
- // maintained `registry.ts` + `templates/` and emit a static, fetchable
21
- // `registry.json` plus one `<name>.json` per component with inlined source, so a
22
- // third-party publisher's catalog can be consumed by `sordo add` (cli/15).
23
- // Pure transform: no network, no install.
24
- export async function runUiBuild(
25
- args: UiBuildArgs,
26
- ctx: CliContext,
27
- ): Promise<number> {
28
- if (args.help) {
29
- printHelp();
30
- return EXIT.OK;
31
- }
32
- if (args.outMissing || !args.out) {
33
- log.error("--out <dir> is required.");
34
- return EXIT.USAGE;
35
- }
36
-
37
- const abs = (p: string): string => (isAbsolute(p) ? p : resolve(ctx.cwd, p));
38
- const registryPath = abs(args.registry ?? "registry.ts");
39
- const templatesDir = abs(args.templates ?? "templates");
40
- const outDir = abs(args.out);
41
-
42
- if (!(await Bun.file(registryPath).exists())) {
43
- log.error(`registry not found: ${registryPath}`);
44
- return EXIT.USAGE;
45
- }
46
-
47
- const mod = (await import(registryPath)) as { components?: unknown };
48
- if (!Array.isArray(mod.components)) {
49
- log.error(`${registryPath} does not export a \`components\` array`);
50
- return EXIT.USAGE;
51
- }
52
-
53
- const entries: ComponentEntry[] = [];
54
- for (const raw of mod.components) {
55
- const parsed = ComponentEntrySchema.safeParse(raw);
56
- if (!parsed.success) {
57
- const name = (raw as { name?: unknown })?.name ?? "<unknown>";
58
- log.error(
59
- `entry ${String(name)} failed validation: ${parsed.error.issues
60
- .map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`)
61
- .join("; ")}`,
62
- );
63
- return EXIT.USAGE;
64
- }
65
- entries.push(parsed.data);
66
- }
67
-
68
- for (const entry of entries) {
69
- const templates: Record<string, string> = {};
70
- for (const rel of requiredTemplatePaths(entry)) {
71
- const file = Bun.file(join(templatesDir, rel));
72
- if (!(await file.exists())) {
73
- log.error(
74
- `component ${entry.name}: template not found: ${join(templatesDir, rel)}`,
75
- );
76
- return EXIT.USAGE;
77
- }
78
- templates[rel] = await file.text();
79
- }
80
- const payload: ComponentPayload = { entry, templates };
81
- await Bun.write(
82
- join(outDir, `${entry.name}.json`),
83
- `${JSON.stringify(payload, null, "\t")}\n`,
84
- );
85
- log.success(` ${entry.name}.json`);
86
- }
87
-
88
- await Bun.write(
89
- join(outDir, "registry.json"),
90
- `${JSON.stringify({ components: entries }, null, "\t")}\n`,
91
- );
92
- log.success(` registry.json (${entries.length} components)`);
93
- log.dim(`done. Emitted ${entries.length + 1} files to ${outDir}.`);
94
- return EXIT.OK;
95
- }
96
-
97
- function printHelp(): void {
98
- process.stdout.write(`sordo ui build — compile a fetchable registry
99
-
100
- Usage:
101
- sordo ui build --out <dir> [--registry <path>] [--templates <dir>]
102
-
103
- Reads a registry.ts + templates/ and emits registry.json plus one <name>.json
104
- per component with inlined source. For third-party registry authors.
105
-
106
- Flags:
107
- --out <dir> Output directory (required).
108
- --registry <path> Registry module (default: ./registry.ts).
109
- --templates <dir> Templates directory (default: ./templates).
110
- `);
111
- }
@@ -1,135 +0,0 @@
1
- import { join } from "node:path";
2
- import { loadConfigOrUsage } from "../../../config/load.ts";
3
- import type { CliContext } from "../../index.ts";
4
- import { EXIT, log } from "../../log.ts";
5
- import { stampInternals } from "../add/internal.ts";
6
- import { loadCatalog } from "../add/load-catalog.ts";
7
- import { applyDeps, planDeps } from "../add/peer-deps.ts";
8
- import { mergeTokens, themeExists } from "../add/tokens.ts";
9
- import { resolveUiPaths, UiPathError, type UiPaths } from "../add/ui-paths.ts";
10
- import { applyShadcnInit } from "./shadcn.ts";
11
-
12
- export interface UiInitArgs {
13
- dryRun: boolean;
14
- force: boolean;
15
- theme?: string;
16
- themeMissing?: boolean;
17
- // Also wire the `@/` alias + `@/lib/utils` that upstream shadcn source uses.
18
- shadcn?: boolean;
19
- }
20
-
21
- const PROD_MSG =
22
- "sordo ui init is a dev-only tool; refusing to run with NODE_ENV=production.";
23
-
24
- // Base helper deps for the cn() utility. Kept in sync with the registry's `cn`
25
- // constant; init lays these down before any component is stamped.
26
- const BASE_DEPS: Record<string, string> = {
27
- clsx: "^2.1.0",
28
- "tailwind-merge": "^2.5.0",
29
- };
30
-
31
- export async function runUiInit(
32
- args: UiInitArgs,
33
- ctx: CliContext,
34
- ): Promise<number> {
35
- if (args.themeMissing) {
36
- log.error("--theme requires a preset name.");
37
- return EXIT.USAGE;
38
- }
39
-
40
- if (process.env.NODE_ENV === "production") {
41
- log.error(PROD_MSG);
42
- return EXIT.USAGE;
43
- }
44
-
45
- if (!(await Bun.file(join(ctx.cwd, "package.json")).exists())) {
46
- log.error(`not a Sordo project (no package.json found at ${ctx.cwd})`);
47
- return EXIT.USAGE;
48
- }
49
-
50
- const catalog = await loadCatalog(ctx.cwd);
51
-
52
- const loaded = await loadConfigOrUsage({
53
- cwd: ctx.cwd,
54
- configPath: ctx.configPath,
55
- });
56
- if ("error" in loaded) {
57
- log.error(loaded.error);
58
- return EXIT.USAGE;
59
- }
60
-
61
- let uiPaths: UiPaths;
62
- try {
63
- uiPaths = resolveUiPaths({
64
- cwd: ctx.cwd,
65
- ui: loaded.config.ui,
66
- appDir: loaded.config.appDir,
67
- });
68
- } catch (err) {
69
- if (err instanceof UiPathError) {
70
- log.error(err.message);
71
- return EXIT.USAGE;
72
- }
73
- throw err;
74
- }
75
-
76
- if (args.theme && !(await themeExists(catalog.templatesDir, args.theme))) {
77
- log.error(`unknown theme preset: ${args.theme}`);
78
- return EXIT.USAGE;
79
- }
80
-
81
- try {
82
- await mergeTokens(["base"], uiPaths, catalog.templatesDir, {
83
- dryRun: args.dryRun,
84
- force: args.force,
85
- themeName: args.theme,
86
- });
87
- await stampInternals(["cn"], uiPaths, catalog.templatesDir, {
88
- dryRun: args.dryRun,
89
- force: args.force,
90
- });
91
- if (args.shadcn) {
92
- await applyShadcnInit(uiPaths, {
93
- dryRun: args.dryRun,
94
- force: args.force,
95
- });
96
- }
97
- if (!args.dryRun) {
98
- const depPlan = await planDeps(BASE_DEPS, ctx.cwd);
99
- await applyDeps(depPlan, ctx.cwd);
100
- } else {
101
- for (const [name, range] of Object.entries(BASE_DEPS)) {
102
- log.dim(` + ${name}@${range}`);
103
- }
104
- }
105
- } catch (err) {
106
- log.error(err instanceof Error ? err.message : String(err));
107
- return EXIT.ERROR;
108
- }
109
-
110
- printWiring(uiPaths.tokensFile);
111
-
112
- if (args.dryRun) {
113
- log.dim("dry-run: no files written.");
114
- } else {
115
- log.dim("done. Run `bun install` to fetch the new peer dependencies.");
116
- }
117
- return EXIT.OK;
118
- }
119
-
120
- // sordo never edits the user's stylesheet; it prints the wiring to add once.
121
- function printWiring(tokensFile: string): void {
122
- log.info(" tailwind add to your app.css (sordo never edits it):");
123
- log.dim(` @import "tailwindcss";`);
124
- log.dim(` @import "${relTokensImport(tokensFile)}";`);
125
- log.dim(` @theme inline { /* map --color-* to the tokens */ }`);
126
- log.info(" build have sordo compile and link it:");
127
- log.dim(` css: "app/styles/app.css" (sordo.config.ts)`);
128
- log.dim(" bun add -D bun-plugin-tailwind");
129
- }
130
-
131
- function relTokensImport(tokensFile: string): string {
132
- // Best-effort hint: most projects import tokens relative to app.css.
133
- const base = tokensFile.split("/").slice(-2).join("/");
134
- return `./${base}`;
135
- }