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,113 +0,0 @@
1
- import { isAbsolute, resolve, sep } from "node:path";
2
- import type { UiConfig } from "../../../config/schema.ts";
3
- import type { ComponentFile } from "../../../ui/types.ts";
4
-
5
- // Resolved, absolute destinations for the add pipeline. Replaces the three
6
- // hard-coded paths that used to live in stamper/internal/tokens.
7
- export interface UiPaths {
8
- componentsDir: string;
9
- internalDir: string;
10
- tokensFile: string;
11
- // The `@/` alias root (config.appDir). Anchors `root: "app"` files.
12
- appDir: string;
13
- projectRoot: string;
14
- }
15
-
16
- const DEFAULT_COMPONENTS_DIR = "app/components/ui";
17
- const DEFAULT_TOKENS_FILE = "app/styles/tokens.css";
18
- const INTERNAL_SUBDIR = "_internal";
19
-
20
- // Thrown when a configured/passed path is absolute or escapes the project root.
21
- // Callers map this to EXIT.USAGE with a one-line message.
22
- export class UiPathError extends Error {
23
- constructor(message: string) {
24
- super(message);
25
- this.name = "UiPathError";
26
- }
27
- }
28
-
29
- // Reject absolute paths and any path that resolves outside `cwd`. Returns the
30
- // resolved absolute path on success.
31
- export function assertInsideProject(cwd: string, rel: string): string {
32
- if (isAbsolute(rel)) {
33
- throw new UiPathError(`path must be relative to the project root: ${rel}`);
34
- }
35
- const abs = resolve(cwd, rel);
36
- if (abs !== cwd && !abs.startsWith(cwd + sep)) {
37
- throw new UiPathError(`path escapes the project root: ${rel}`);
38
- }
39
- return abs;
40
- }
41
-
42
- // Resolve effective UI paths. Precedence (first wins):
43
- // componentsDir: --path > config.ui.componentsDir > convention
44
- // internalDir: <--path>/_internal > config.ui.internalDir > <componentsDir>/_internal
45
- // tokensFile: config.ui.tokensFile > convention (never affected by --path)
46
- export function resolveUiPaths(args: {
47
- cwd: string;
48
- ui?: Partial<UiConfig>;
49
- pathOverride?: string;
50
- appDir?: string;
51
- }): UiPaths {
52
- const { cwd, ui, pathOverride } = args;
53
-
54
- const componentsRel =
55
- pathOverride ?? ui?.componentsDir ?? DEFAULT_COMPONENTS_DIR;
56
- const componentsDir = assertInsideProject(cwd, componentsRel);
57
-
58
- // --path retargets helpers alongside the components; otherwise honor an
59
- // explicit config.ui.internalDir, else co-locate under componentsDir.
60
- let internalDir: string;
61
- if (pathOverride !== undefined) {
62
- internalDir = resolve(componentsDir, INTERNAL_SUBDIR);
63
- } else if (ui?.internalDir !== undefined) {
64
- internalDir = assertInsideProject(cwd, ui.internalDir);
65
- } else {
66
- internalDir = resolve(componentsDir, INTERNAL_SUBDIR);
67
- }
68
-
69
- const tokensRel = ui?.tokensFile ?? DEFAULT_TOKENS_FILE;
70
- const tokensFile = assertInsideProject(cwd, tokensRel);
71
-
72
- // loadConfig already absolutizes config.appDir; a relative value comes from
73
- // callers passing the convention.
74
- const appRel = args.appDir ?? "app";
75
- const appDir = isAbsolute(appRel) ? appRel : assertInsideProject(cwd, appRel);
76
-
77
- return { componentsDir, internalDir, tokensFile, appDir, projectRoot: cwd };
78
- }
79
-
80
- // The directory a component file's `to` is relative to.
81
- export function fileRootDir(uiPaths: UiPaths, file: ComponentFile): string {
82
- switch (file.root ?? "components") {
83
- case "components":
84
- return uiPaths.componentsDir;
85
- case "app":
86
- return uiPaths.appDir;
87
- }
88
- }
89
-
90
- // Subdirs of the app dir a registry file may land in (`root: "app"`).
91
- export const APP_FILE_DIRS = ["components", "hooks", "lib"] as const;
92
-
93
- // Throws unless an app-rooted file stays in APP_FILE_DIRS with no dot-segments,
94
- // so an untrusted payload can't drop routes, middleware, or `.env`-style files.
95
- export function assertAppFileAllowed(file: ComponentFile): void {
96
- if ((file.root ?? "components") !== "app") return;
97
- const segs = file.to.split("/");
98
- const top = segs[0] ?? "";
99
- if (
100
- segs.length < 2 ||
101
- !(APP_FILE_DIRS as readonly string[]).includes(top) ||
102
- segs.some((s) => s.startsWith("."))
103
- ) {
104
- throw new Error(
105
- `refusing to stamp ${file.to} into the app dir: only ${APP_FILE_DIRS.map((d) => `${d}/`).join(", ")} are allowed`,
106
- );
107
- }
108
- }
109
-
110
- // Absolute stamp destination for a component file.
111
- export function fileDest(uiPaths: UiPaths, file: ComponentFile): string {
112
- return resolve(fileRootDir(uiPaths, file), file.to);
113
- }
@@ -1,427 +0,0 @@
1
- import { join } from "node:path";
2
- import { loadConfigOrUsage } from "../../config/load.ts";
3
- import type { ComponentEntry } from "../../ui/types.ts";
4
- import type { CliContext } from "../index.ts";
5
- import { confirm, EXIT, isTTY, log } from "../log.ts";
6
- import { applyComponent } from "./add/apply.ts";
7
- import {
8
- diffComponentItems,
9
- listStampedComponents,
10
- } from "./add/component-diff.ts";
11
- import { type Catalog, loadCatalog } from "./add/load-catalog.ts";
12
- import { planDeps } from "./add/peer-deps.ts";
13
- import {
14
- cleanupSources,
15
- type ResolvedSource,
16
- resolveSources,
17
- } from "./add/source.ts";
18
- import { planStamp } from "./add/stamper.ts";
19
- import { themeExists } from "./add/tokens.ts";
20
- import { resolveUiPaths, UiPathError, type UiPaths } from "./add/ui-paths.ts";
21
- import { writeComponentView } from "./ui/view.ts";
22
-
23
- interface AddArgs {
24
- names: string[];
25
- list: boolean;
26
- all: boolean;
27
- dryRun: boolean;
28
- force: boolean;
29
- help: boolean;
30
- path?: string;
31
- pathMissing: boolean;
32
- view: boolean;
33
- diff: boolean;
34
- check: boolean;
35
- theme?: string;
36
- themeMissing: boolean;
37
- yes: boolean;
38
- allowInsecure: boolean;
39
- }
40
-
41
- const PROD_MSG =
42
- "sordo add is a dev-only tool; refusing to run with NODE_ENV=production.";
43
-
44
- export async function runAdd(argv: string[], ctx: CliContext): Promise<number> {
45
- const args = parseArgs(argv);
46
-
47
- if (args.help) {
48
- printHelp();
49
- return EXIT.OK;
50
- }
51
-
52
- if (process.env.NODE_ENV === "production") {
53
- log.error(PROD_MSG);
54
- return EXIT.USAGE;
55
- }
56
-
57
- if (args.pathMissing) {
58
- log.error("--path requires a directory value.");
59
- return EXIT.USAGE;
60
- }
61
-
62
- if (args.themeMissing) {
63
- log.error("--theme requires a preset name.");
64
- return EXIT.USAGE;
65
- }
66
-
67
- if (!(await Bun.file(join(ctx.cwd, "package.json")).exists())) {
68
- log.error(`not a Sordo project (no package.json found at ${ctx.cwd})`);
69
- return EXIT.USAGE;
70
- }
71
-
72
- const catalog = await loadCatalog(ctx.cwd);
73
-
74
- if (args.list) {
75
- printList(catalog);
76
- return EXIT.OK;
77
- }
78
-
79
- const loaded = await loadConfigOrUsage({
80
- cwd: ctx.cwd,
81
- configPath: ctx.configPath,
82
- });
83
- if ("error" in loaded) {
84
- log.error(loaded.error);
85
- return EXIT.USAGE;
86
- }
87
- const registries = loaded.config.ui?.registries ?? {};
88
-
89
- if (args.view) {
90
- if (args.names.length === 0) {
91
- log.error("no components selected. Pass a component name.");
92
- return EXIT.USAGE;
93
- }
94
- const sources = await resolveSources(args.names, {
95
- catalog,
96
- registries,
97
- cwd: ctx.cwd,
98
- allowInsecure: args.allowInsecure,
99
- });
100
- if (sources === null) return EXIT.USAGE;
101
- try {
102
- for (const s of sources) {
103
- await writeComponentView(s.entry, s.templatesDir);
104
- }
105
- } finally {
106
- await cleanupSources(sources);
107
- }
108
- return EXIT.OK;
109
- }
110
-
111
- let uiPaths: UiPaths;
112
- try {
113
- uiPaths = resolveUiPaths({
114
- cwd: ctx.cwd,
115
- ui: loaded.config.ui,
116
- pathOverride: args.path,
117
- appDir: loaded.config.appDir,
118
- });
119
- } catch (err) {
120
- if (err instanceof UiPathError) {
121
- log.error(err.message);
122
- return EXIT.USAGE;
123
- }
124
- throw err;
125
- }
126
-
127
- if (args.diff) {
128
- return runDiff(catalog, uiPaths, args, registries, ctx.cwd);
129
- }
130
-
131
- if (args.theme && !(await themeExists(catalog.templatesDir, args.theme))) {
132
- log.error(`unknown theme preset: ${args.theme}`);
133
- return EXIT.USAGE;
134
- }
135
-
136
- const sources = args.all
137
- ? catalog.components
138
- .filter((c) => c.status === "completed")
139
- .map(
140
- (entry): ResolvedSource => ({
141
- entry,
142
- templatesDir: catalog.templatesDir,
143
- fromCatalog: true,
144
- }),
145
- )
146
- : await resolveSources(args.names, {
147
- catalog,
148
- registries,
149
- cwd: ctx.cwd,
150
- allowInsecure: args.allowInsecure,
151
- });
152
- if (sources === null) return EXIT.USAGE;
153
- if (sources.length === 0) {
154
- log.error("no components selected. Pass a name or --all.");
155
- printHelp();
156
- return EXIT.USAGE;
157
- }
158
-
159
- try {
160
- for (const source of sources) {
161
- if (!source.fromCatalog && !args.dryRun) {
162
- const ok = await confirmSource(source, args.yes);
163
- if (ok === "abort") return EXIT.USAGE;
164
- if (ok === "skip") continue;
165
- }
166
- const rc = await stampOne(
167
- source.entry,
168
- ctx.cwd,
169
- uiPaths,
170
- source.templatesDir,
171
- args,
172
- );
173
- if (rc !== EXIT.OK) return rc;
174
- }
175
- } finally {
176
- await cleanupSources(sources);
177
- }
178
-
179
- if (args.dryRun) {
180
- log.dim("dry-run: no files written.");
181
- } else {
182
- log.dim("done. Run `bun install` to fetch any new peer dependencies.");
183
- }
184
- return EXIT.OK;
185
- }
186
-
187
- // Show untrusted (non-catalog) source before stamping, then require confirmation
188
- // unless --yes. Refuses in a non-interactive shell without --yes so fetched code
189
- // is never stamped silently (cli/15).
190
- async function confirmSource(
191
- source: ResolvedSource,
192
- yes: boolean,
193
- ): Promise<"ok" | "skip" | "abort"> {
194
- await writeComponentView(source.entry, source.templatesDir);
195
- if (yes) return "ok";
196
- if (!process.stdin.isTTY) {
197
- log.error(
198
- `refusing to stamp ${source.entry.name} from an external source without --yes (no TTY to confirm).`,
199
- );
200
- return "abort";
201
- }
202
- const ok = await confirm(`Stamp ${source.entry.name} from the source above?`);
203
- if (!ok) {
204
- log.dim(` skipped ${source.entry.name}`);
205
- return "skip";
206
- }
207
- return "ok";
208
- }
209
-
210
- async function runDiff(
211
- catalog: Catalog,
212
- uiPaths: UiPaths,
213
- args: AddArgs,
214
- registries: Record<string, string>,
215
- cwd: string,
216
- ): Promise<number> {
217
- const color = isTTY(process.stdout) && !process.env.NO_COLOR;
218
- const sources =
219
- args.names.length > 0
220
- ? await resolveSources(args.names, {
221
- catalog,
222
- registries,
223
- cwd,
224
- allowInsecure: args.allowInsecure,
225
- })
226
- : (await listStampedComponents(catalog, uiPaths)).map(
227
- (entry): ResolvedSource => ({
228
- entry,
229
- templatesDir: catalog.templatesDir,
230
- fromCatalog: true,
231
- }),
232
- );
233
- if (sources === null) return EXIT.USAGE;
234
-
235
- let drift = false;
236
- try {
237
- for (const source of sources) {
238
- const items = await diffComponentItems(
239
- source.entry,
240
- uiPaths,
241
- source.templatesDir,
242
- color,
243
- );
244
- log.info(source.entry.name);
245
- for (const item of items) {
246
- if (item.status === "drift") {
247
- drift = true;
248
- log.info(` drift ${item.label}`);
249
- process.stdout.write(`${item.body}\n`);
250
- } else if (item.status === "not-stamped") {
251
- log.dim(` not stamped ${item.label}`);
252
- } else {
253
- log.dim(` up to date ${item.label}`);
254
- }
255
- }
256
- }
257
- } finally {
258
- await cleanupSources(sources);
259
- }
260
-
261
- if (args.check) return drift ? EXIT.ERROR : EXIT.OK;
262
- return EXIT.OK;
263
- }
264
-
265
- export function resolveNames(
266
- catalog: Catalog,
267
- names: string[],
268
- ): ComponentEntry[] | null {
269
- const out: ComponentEntry[] = [];
270
- for (const name of names) {
271
- const entry = catalog.components.find((c) => c.name === name);
272
- if (!entry) {
273
- log.error(`unknown component: ${name}`);
274
- return null;
275
- }
276
- out.push(entry);
277
- }
278
- return out;
279
- }
280
-
281
- async function stampOne(
282
- entry: ComponentEntry,
283
- cwd: string,
284
- uiPaths: UiPaths,
285
- templatesDir: string,
286
- args: AddArgs,
287
- ): Promise<number> {
288
- log.info(
289
- `${entry.name} (phase ${entry.phase}, island=${entry.island}, ${entry.status})`,
290
- );
291
-
292
- if (args.dryRun) {
293
- const plan = await planStamp(entry, uiPaths, templatesDir);
294
- const depPlan = await planDeps(entry.peerDeps, cwd);
295
- for (const p of plan) {
296
- const marker = p.exists ? "exists" : "new";
297
- log.dim(` [${marker}] ${p.to}`);
298
- }
299
- for (const [name, range] of Object.entries(depPlan.added)) {
300
- log.dim(` + ${name}@${range}`);
301
- }
302
- for (const c of depPlan.conflicted) {
303
- log.dim(` ! ${c.name}: user ${c.user} vs requested ${c.requested}`);
304
- }
305
- for (const g of entry.tokens ?? []) log.dim(` tokens: ${g}`);
306
- for (const h of entry.internalHelpers) {
307
- log.dim(` helper: _internal/${h}.ts`);
308
- }
309
- return EXIT.OK;
310
- }
311
-
312
- try {
313
- await applyComponent(entry, cwd, uiPaths, templatesDir, {
314
- force: args.force,
315
- themeName: args.theme,
316
- });
317
- } catch (err) {
318
- log.error(err instanceof Error ? err.message : String(err));
319
- return EXIT.ERROR;
320
- }
321
- return EXIT.OK;
322
- }
323
-
324
- function printList(catalog: Catalog): void {
325
- const rows = catalog.components;
326
- const widths = {
327
- name: Math.max(4, ...rows.map((r) => r.name.length)),
328
- phase: 5,
329
- island: Math.max(6, ...rows.map((r) => r.island.length)),
330
- status: Math.max(6, ...rows.map((r) => r.status.length)),
331
- };
332
- const header = `${pad("name", widths.name)} ${pad("phase", widths.phase)} ${pad("island", widths.island)} ${pad("status", widths.status)}`;
333
- log.info(header);
334
- log.dim("-".repeat(header.length));
335
- for (const r of rows) {
336
- log.info(
337
- `${pad(r.name, widths.name)} ${pad(String(r.phase), widths.phase)} ${pad(r.island, widths.island)} ${pad(r.status, widths.status)}`,
338
- );
339
- }
340
- }
341
-
342
- function pad(s: string, n: number): string {
343
- return s.length >= n ? s : s + " ".repeat(n - s.length);
344
- }
345
-
346
- function parseArgs(argv: string[]): AddArgs {
347
- const out: AddArgs = {
348
- names: [],
349
- list: false,
350
- all: false,
351
- dryRun: false,
352
- force: false,
353
- help: false,
354
- pathMissing: false,
355
- view: false,
356
- diff: false,
357
- check: false,
358
- themeMissing: false,
359
- yes: false,
360
- allowInsecure: false,
361
- };
362
- for (let i = 0; i < argv.length; i++) {
363
- const a = argv[i];
364
- if (a === undefined) continue;
365
- if (a === "--list") out.list = true;
366
- else if (a === "--all") out.all = true;
367
- else if (a === "--dry-run") out.dryRun = true;
368
- else if (a === "--force") out.force = true;
369
- else if (a === "--view") out.view = true;
370
- else if (a === "--diff") out.diff = true;
371
- else if (a === "--check") out.check = true;
372
- else if (a === "--yes" || a === "-y") out.yes = true;
373
- else if (a === "--allow-insecure") out.allowInsecure = true;
374
- else if (a === "--help" || a === "-h") out.help = true;
375
- else if (a === "--path") {
376
- const v = argv[++i];
377
- if (v === undefined) out.pathMissing = true;
378
- else out.path = v;
379
- } else if (a.startsWith("--path=")) {
380
- out.path = a.slice("--path=".length);
381
- } else if (a === "--theme") {
382
- const v = argv[++i];
383
- if (v === undefined) out.themeMissing = true;
384
- else out.theme = v;
385
- } else if (a.startsWith("--theme=")) {
386
- out.theme = a.slice("--theme=".length);
387
- } else out.names.push(a);
388
- }
389
- return out;
390
- }
391
-
392
- function printHelp(): void {
393
- process.stdout.write(`sordo add — stamp UI components into your project
394
-
395
- Usage:
396
- sordo add <component> [...components]
397
- sordo add ./path/to/component.tsx
398
- sordo add @namespace/component
399
- sordo add https://registry.example/component.json
400
- sordo add --all
401
- sordo add --list
402
- sordo add --dry-run <component>
403
-
404
- Sources:
405
- <name> A component from the built-in catalog (none ship by default;
406
- use @shadcn/<name> for upstream shadcn/ui).
407
- <local-path> A local component file or a built registry payload (.json).
408
- @ns/<name> A namespaced registry from config.ui.registries.
409
- @shadcn/<name> Upstream shadcn/ui, stamped verbatim (built in; override the
410
- base via config.ui.registries["@shadcn"]). Use it on pages
411
- that export \`hydrate = true\`; run \`sordo ui init --shadcn\` once.
412
- <url> An https URL to a built payload or shadcn registry item.
413
-
414
- Flags:
415
- --all Stamp every catalog component whose status is completed.
416
- --list Print every component with phase, island flag, and status.
417
- --dry-run Print the file/dep diff without writing.
418
- --force Overwrite existing files.
419
- --view Print the component's source instead of stamping.
420
- --diff Show how stamped files drift from the catalog (read-only).
421
- --check With --diff, exit non-zero if any component has drifted.
422
- --path <dir> Stamp into <dir> for this invocation (overrides config.ui).
423
- --theme <name> Merge a base-color preset's tokens (neutral|slate|stone|zinc).
424
- --yes, -y Skip the source-preview confirmation for external sources.
425
- --allow-insecure Permit http:// registry fetches (https is required otherwise).
426
- `);
427
- }
@@ -1,143 +0,0 @@
1
- import { loadConfig } from "../../config/load.ts";
2
- import {
3
- type DeployPlugin,
4
- isDeployPlugin,
5
- type Plugin,
6
- type PluginLogger,
7
- } from "../../plugin/index.ts";
8
- import { runBuild } from "../build.ts";
9
- import type { CliContext } from "../index.ts";
10
- import { EXIT, log } from "../log.ts";
11
-
12
- interface DeployArgs {
13
- target?: "bun" | "edge";
14
- env?: string;
15
- skipBuild: boolean;
16
- }
17
-
18
- const NO_PLUGIN_HINT = (
19
- target: string,
20
- ): string => `No deploy plugin installed for target "${target}".
21
- Install one of:
22
- bun add @sordo/deploy-cloudflare
23
- bun add @sordo/deploy-vercel
24
- bun add @sordo/deploy-deno
25
- bun add @sordo/deploy-netlify
26
- Or write your own — see framework spec 09-plugins.`;
27
-
28
- const pluginLogger: PluginLogger = {
29
- info: (m, ...rest) =>
30
- log.info(`${m}${rest.length ? ` ${rest.join(" ")}` : ""}`),
31
- warn: (m, ...rest) =>
32
- log.warn(`${m}${rest.length ? ` ${rest.join(" ")}` : ""}`),
33
- error: (m, ...rest) =>
34
- log.error(`${m}${rest.length ? ` ${rest.join(" ")}` : ""}`),
35
- };
36
-
37
- export async function runDeploy(
38
- argv: string[],
39
- ctx: CliContext,
40
- ): Promise<number> {
41
- const args = parseArgs(argv);
42
-
43
- let loaded: Awaited<ReturnType<typeof loadConfig>>;
44
- try {
45
- loaded = await loadConfig({
46
- cwd: ctx.cwd,
47
- configPath: ctx.configPath,
48
- overrides: args.target ? { target: args.target } : undefined,
49
- });
50
- } catch (err) {
51
- log.error((err as Error)?.message ?? String(err));
52
- return EXIT.ERROR;
53
- }
54
- const { config } = loaded;
55
- const target = config.target;
56
-
57
- if (!args.skipBuild) {
58
- const passthrough: string[] = ["--target", target];
59
- const code = await runBuild(passthrough, ctx);
60
- if (code !== EXIT.OK) return code;
61
- } else {
62
- const serverEntry = `${config.outDir}/server/server-entry.js`;
63
- if (!(await Bun.file(serverEntry).exists())) {
64
- log.error(
65
- `--skip-build set but no prior build found at ${config.outDir}. Run 'sordo build' first.`,
66
- );
67
- return EXIT.ERROR;
68
- }
69
- }
70
-
71
- const plugins = (config.plugins ?? []) as Plugin[];
72
- const candidates = plugins
73
- .filter(isDeployPlugin)
74
- .filter((p) => p.deployTarget === target);
75
-
76
- if (candidates.length === 0) {
77
- if (target === "bun") {
78
- log.info(
79
- `No deploy plugin installed. To run: bun ${config.outDir}/server/server-entry.js`,
80
- );
81
- return EXIT.OK;
82
- }
83
- log.error(NO_PLUGIN_HINT(target));
84
- return EXIT.USAGE;
85
- }
86
-
87
- let plugin: DeployPlugin | undefined;
88
- if (args.env) {
89
- plugin = candidates.find((p) => p.name === args.env);
90
- if (!plugin) {
91
- log.error(
92
- `no deploy plugin matches --env "${args.env}" for target "${target}"`,
93
- );
94
- return EXIT.USAGE;
95
- }
96
- } else {
97
- plugin = candidates[0];
98
- if (candidates.length > 1) {
99
- log.warn(
100
- `multiple deploy plugins for "${target}"; using "${plugin?.name}". Pass --env <name> to select.`,
101
- );
102
- }
103
- }
104
-
105
- if (!plugin) return EXIT.ERROR;
106
-
107
- const serverEntry = `${config.outDir}/server/server-entry.js`;
108
- log.success(`built (target ${target})`);
109
- log.info(`deploying via ${plugin.name}…`);
110
-
111
- try {
112
- const url = await plugin.deploy(
113
- { outDir: config.outDir, serverEntry },
114
- { env: args.env, cwd: ctx.cwd, logger: pluginLogger },
115
- );
116
- if (typeof url === "string" && url.length > 0) {
117
- log.success(`live at ${url}`);
118
- } else {
119
- log.success(`deploy complete (${plugin.name})`);
120
- }
121
- return EXIT.OK;
122
- } catch (err) {
123
- log.error(
124
- `[plugin ${plugin.name}] deploy failed: ${(err as Error)?.message ?? String(err)}`,
125
- );
126
- return EXIT.ERROR;
127
- }
128
- }
129
-
130
- function parseArgs(argv: string[]): DeployArgs {
131
- const out: DeployArgs = { skipBuild: false };
132
- for (let i = 0; i < argv.length; i++) {
133
- const a = argv[i];
134
- if (a === undefined) continue;
135
- if (a === "--target") out.target = String(argv[++i]) as "bun" | "edge";
136
- else if (a.startsWith("--target="))
137
- out.target = a.slice(9) as "bun" | "edge";
138
- else if (a === "--env") out.env = String(argv[++i]);
139
- else if (a.startsWith("--env=")) out.env = a.slice(6);
140
- else if (a === "--skip-build") out.skipBuild = true;
141
- }
142
- return out;
143
- }