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,19 +0,0 @@
1
- // Working-tree state, used to refuse codemods on a dirty tree (so the rewrite
2
- // is its own reviewable diff). Outside a git repo, `git status` errors → not a
3
- // repo, and the caller requires --force.
4
- export async function gitTreeState(
5
- cwd: string,
6
- ): Promise<{ isRepo: boolean; clean: boolean }> {
7
- // Strip git hook env vars so that `git status` resolves the repo from `cwd`
8
- // rather than inheriting GIT_DIR/GIT_INDEX_FILE from a running commit hook.
9
- const env = { ...process.env };
10
- for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE"]) {
11
- delete env[key];
12
- }
13
- try {
14
- const res = await Bun.$`git status --porcelain`.cwd(cwd).env(env).quiet();
15
- return { isRepo: true, clean: res.stdout.toString().trim().length === 0 };
16
- } catch {
17
- return { isRepo: false, clean: false };
18
- }
19
- }
@@ -1,67 +0,0 @@
1
- // Rewrite scattered `@radix-ui/react-*` imports to the unified `radix-ui`
2
- // namespace import. Detection uses Bun's transpiler; the surgical edit is a
3
- // scoped regex on import statements so user formatting/comments survive (a full
4
- // Bun.Transpiler transform would reprint and destroy them).
5
-
6
- export interface RewriteResult {
7
- output: string;
8
- changed: boolean;
9
- reports: string[];
10
- }
11
-
12
- const NS_IMPORT =
13
- /^[ \t]*import\s+\*\s+as\s+(\w+)\s+from\s+["']@radix-ui\/react-([\w-]+)["'];?[ \t]*\n?/gm;
14
-
15
- const NAMED_IMPORT =
16
- /^[ \t]*import\s*\{[^}]*\}\s*from\s*["']@radix-ui\/react-[\w-]+["'];?[ \t]*$/gm;
17
-
18
- function kebabToPascal(s: string): string {
19
- return s
20
- .split("-")
21
- .map((p) => (p ? p[0]?.toUpperCase() + p.slice(1) : ""))
22
- .join("");
23
- }
24
-
25
- // True if the file imports any scattered @radix-ui/react-* package.
26
- export function hasScatteredRadix(source: string): boolean {
27
- return /["']@radix-ui\/react-[\w-]+["']/.test(source);
28
- }
29
-
30
- export function rewriteRadix(source: string): RewriteResult {
31
- if (!hasScatteredRadix(source)) {
32
- return { output: source, changed: false, reports: [] };
33
- }
34
-
35
- const reports: string[] = [];
36
- const specifiers: string[] = [];
37
-
38
- NS_IMPORT.lastIndex = 0;
39
- for (const m of source.matchAll(NS_IMPORT)) {
40
- const local = m[1] ?? "";
41
- const ns = kebabToPascal(m[2] ?? "");
42
- specifiers.push(ns === local ? ns : `${ns} as ${local}`);
43
- }
44
-
45
- // Named imports from a radix package have no 1:1 unified equivalent; report.
46
- NAMED_IMPORT.lastIndex = 0;
47
- for (const m of source.matchAll(NAMED_IMPORT)) {
48
- reports.push(`named import has no unified equivalent: ${m[0].trim()}`);
49
- }
50
-
51
- if (specifiers.length === 0) {
52
- // Only un-convertible forms present; nothing rewritten.
53
- return { output: source, changed: false, reports };
54
- }
55
-
56
- // Replace the first scattered import with the merged unified import and drop
57
- // the rest. Doing it in one pass keeps the merged import where the first one
58
- // was (offset-safe — no manual slicing of a mutated string).
59
- const merged = `import { ${specifiers.join(", ")} } from "radix-ui";\n`;
60
- let seen = 0;
61
- NS_IMPORT.lastIndex = 0;
62
- const finalOut = source.replace(NS_IMPORT, () =>
63
- seen++ === 0 ? merged : "",
64
- );
65
-
66
- return { output: finalOut, changed: finalOut !== source, reports };
67
- }
@@ -1,148 +0,0 @@
1
- // Rewrite physical → logical properties. Scoped to className string literals,
2
- // cn()/clsx() string arguments, and style-object keys (in .tsx/.ts), or CSS
3
- // property names (in .css). Never rewrites bare identifiers; ambiguous dynamic
4
- // class construction is reported, not guessed.
5
-
6
- export interface RewriteResult {
7
- output: string;
8
- changed: boolean;
9
- reports: string[];
10
- }
11
-
12
- const EXACT: Record<string, string> = {
13
- "text-left": "text-start",
14
- "text-right": "text-end",
15
- "float-left": "float-start",
16
- "float-right": "float-end",
17
- "clear-left": "clear-start",
18
- "clear-right": "clear-end",
19
- };
20
-
21
- const PREFIX: Array<[string, string]> = [
22
- ["ml-", "ms-"],
23
- ["mr-", "me-"],
24
- ["pl-", "ps-"],
25
- ["pr-", "pe-"],
26
- ["left-", "start-"],
27
- ["right-", "end-"],
28
- ["border-l-", "border-s-"],
29
- ["border-r-", "border-e-"],
30
- ["rounded-tl-", "rounded-ss-"],
31
- ["rounded-tr-", "rounded-se-"],
32
- ["rounded-bl-", "rounded-es-"],
33
- ["rounded-br-", "rounded-ee-"],
34
- ["rounded-l-", "rounded-s-"],
35
- ["rounded-r-", "rounded-e-"],
36
- ];
37
-
38
- const BARE: Record<string, string> = {
39
- "border-l": "border-s",
40
- "border-r": "border-e",
41
- "rounded-l": "rounded-s",
42
- "rounded-r": "rounded-e",
43
- "rounded-tl": "rounded-ss",
44
- "rounded-tr": "rounded-se",
45
- "rounded-bl": "rounded-es",
46
- "rounded-br": "rounded-ee",
47
- };
48
-
49
- const STYLE_KEYS: Record<string, string> = {
50
- marginLeft: "marginInlineStart",
51
- marginRight: "marginInlineEnd",
52
- paddingLeft: "paddingInlineStart",
53
- paddingRight: "paddingInlineEnd",
54
- borderLeft: "borderInlineStart",
55
- borderRight: "borderInlineEnd",
56
- };
57
-
58
- const CSS_PROPS: Array<[RegExp, string]> = [
59
- [/margin-left/g, "margin-inline-start"],
60
- [/margin-right/g, "margin-inline-end"],
61
- [/padding-left/g, "padding-inline-start"],
62
- [/padding-right/g, "padding-inline-end"],
63
- [/border-left/g, "border-inline-start"],
64
- [/border-right/g, "border-inline-end"],
65
- ];
66
-
67
- function mapCore(core: string): string {
68
- const exact = EXACT[core];
69
- if (exact) return exact;
70
- for (const [from, to] of PREFIX) {
71
- if (core.startsWith(from)) return to + core.slice(from.length);
72
- }
73
- const bare = BARE[core];
74
- if (bare) return bare;
75
- return core;
76
- }
77
-
78
- // Map a single Tailwind class token, preserving variant prefixes (`md:`,
79
- // `hover:`) and a leading negative sign.
80
- function mapToken(token: string): string {
81
- if (token === "") return token;
82
- const colon = token.lastIndexOf(":");
83
- const variant = colon >= 0 ? token.slice(0, colon + 1) : "";
84
- let core = colon >= 0 ? token.slice(colon + 1) : token;
85
- const neg = core.startsWith("-") ? "-" : "";
86
- if (neg) core = core.slice(1);
87
- return variant + neg + mapCore(core);
88
- }
89
-
90
- function mapClassString(s: string): string {
91
- return s
92
- .split(/(\s+)/)
93
- .map((part) => (/^\s+$/.test(part) ? part : mapToken(part)))
94
- .join("");
95
- }
96
-
97
- const CLASSNAME_DQ = /className=(")([^"]*)"/g;
98
- const CLASSNAME_SQ = /className=(')([^']*)'/g;
99
- const CLASSNAME_TPL = /className=\{`([^`]*)`\}/g;
100
- const CN_CALL = /\b(cn|clsx)\(([^)]*)\)/g;
101
- const STRING_LIT = /(["'])((?:(?!\1).)*)\1/g;
102
-
103
- export function rewriteRtl(source: string, isCss: boolean): RewriteResult {
104
- if (isCss) {
105
- let out = source;
106
- for (const [re, to] of CSS_PROPS) out = out.replace(re, to);
107
- return { output: out, changed: out !== source, reports: [] };
108
- }
109
-
110
- const reports: string[] = [];
111
- let out = source;
112
-
113
- out = out.replace(
114
- CLASSNAME_DQ,
115
- (_m, _q, body: string) => `className="${mapClassString(body)}"`,
116
- );
117
- out = out.replace(
118
- CLASSNAME_SQ,
119
- (_m, _q, body: string) => `className='${mapClassString(body)}'`,
120
- );
121
- out = out.replace(CLASSNAME_TPL, (m, body: string) => {
122
- if (body.includes("${")) {
123
- reports.push(`dynamic className template — review manually: ${m.trim()}`);
124
- return m;
125
- }
126
- return `className={\`${mapClassString(body)}\`}`;
127
- });
128
-
129
- // cn()/clsx() string-literal arguments.
130
- out = out.replace(CN_CALL, (_m, fn: string, args: string) => {
131
- const mapped = args.replace(
132
- STRING_LIT,
133
- (_s, q: string, body: string) => `${q}${mapClassString(body)}${q}`,
134
- );
135
- return `${fn}(${mapped})`;
136
- });
137
-
138
- // style={{ ... }} object keys.
139
- out = out.replace(/style=\{\{([^}]*)\}\}/g, (_m, body: string) => {
140
- let inner = body;
141
- for (const [k, v] of Object.entries(STYLE_KEYS)) {
142
- inner = inner.replace(new RegExp(`\\b${k}\\b`, "g"), v);
143
- }
144
- return `style={{${inner}}}`;
145
- });
146
-
147
- return { output: out, changed: out !== source, reports };
148
- }
@@ -1,82 +0,0 @@
1
- import { dirname, join, relative } from "node:path";
2
- import { log } from "../../log.ts";
3
- import { INTERNAL_FILES } from "../add/internal.ts";
4
- import type { UiPaths } from "../add/ui-paths.ts";
5
-
6
- // `sordo ui init --shadcn`: the project wiring upstream shadcn/ui source
7
- // expects, so `sordo add @shadcn/<name>` stamps files that build unchanged.
8
- // - tsconfig `paths`: `@/*` → the app dir (`@/components/ui/button`, …)
9
- // - `@/lib/utils`: re-export of the catalog's `cn` helper
10
-
11
- const ALIAS = "@/*";
12
-
13
- interface TsConfig {
14
- compilerOptions?: { paths?: Record<string, string[]> };
15
- [key: string]: unknown;
16
- }
17
-
18
- export async function applyShadcnInit(
19
- uiPaths: UiPaths,
20
- opts: { dryRun: boolean; force: boolean },
21
- ): Promise<void> {
22
- await ensureAlias(uiPaths, opts);
23
- await ensureUtils(uiPaths, opts);
24
- }
25
-
26
- async function ensureAlias(
27
- uiPaths: UiPaths,
28
- opts: { dryRun: boolean },
29
- ): Promise<void> {
30
- const path = join(uiPaths.projectRoot, "tsconfig.json");
31
- const target = `./${relative(uiPaths.projectRoot, uiPaths.appDir) || "."}/*`;
32
- const file = Bun.file(path);
33
- const text = (await file.exists()) ? await file.text() : "{}";
34
-
35
- let config: TsConfig;
36
- let strictJson = true;
37
- try {
38
- config = JSON.parse(text) as TsConfig;
39
- } catch {
40
- strictJson = false;
41
- config = Bun.JSONC.parse(text) as TsConfig;
42
- }
43
- const existing = config.compilerOptions?.paths?.[ALIAS];
44
- if (existing) {
45
- log.dim(` alias ${ALIAS} present (${existing.join(", ")})`);
46
- return;
47
- }
48
- // Rewriting would drop the user's comments; print the edit instead.
49
- if (!strictJson) {
50
- log.warn(
51
- ` tsconfig.json has comments; add "paths": { "${ALIAS}": ["${target}"] } to compilerOptions yourself.`,
52
- );
53
- return;
54
- }
55
- config.compilerOptions = {
56
- ...(config.compilerOptions ?? {}),
57
- paths: { ...(config.compilerOptions?.paths ?? {}), [ALIAS]: [target] },
58
- };
59
- if (!opts.dryRun) {
60
- await Bun.write(path, `${JSON.stringify(config, null, "\t")}\n`);
61
- }
62
- log.success(` alias ${ALIAS} -> ${target} (tsconfig.json)`);
63
- }
64
-
65
- async function ensureUtils(
66
- uiPaths: UiPaths,
67
- opts: { dryRun: boolean; force: boolean },
68
- ): Promise<void> {
69
- const path = join(uiPaths.appDir, "lib", "utils.ts");
70
- if ((await Bun.file(path).exists()) && !opts.force) {
71
- log.dim(` ${path} present`);
72
- return;
73
- }
74
- const cnFile = join(uiPaths.internalDir, INTERNAL_FILES.cn);
75
- let spec = relative(dirname(path), cnFile).replace(/\\/g, "/");
76
- if (!spec.startsWith(".")) spec = `./${spec}`;
77
- if (!opts.dryRun) {
78
- await Bun.$`mkdir -p ${dirname(path)}`.quiet();
79
- await Bun.write(path, `export { cn } from ${JSON.stringify(spec)};\n`);
80
- }
81
- log.success(` wrote ${path}`);
82
- }
@@ -1,63 +0,0 @@
1
- import { join } from "node:path";
2
- import type { ComponentEntry } from "../../../ui/types.ts";
3
- import { isTTY } from "../../log.ts";
4
-
5
- export interface RenderedView {
6
- // Metadata block — written to stderr so stdout stays pipeable.
7
- header: string;
8
- // Concatenated template source(s) — written to stdout, valid .tsx.
9
- source: string;
10
- }
11
-
12
- const DIM = "\x1b[2m";
13
- const CYAN = "\x1b[36m";
14
- const RESET = "\x1b[0m";
15
-
16
- // Render a component's metadata + the full source of every file it would stamp.
17
- // Pure (no writes) so both `sordo view` and `sordo add --view` can reuse it.
18
- export async function renderComponentSource(
19
- entry: ComponentEntry,
20
- templatesDir: string,
21
- opts: { color: boolean },
22
- ): Promise<RenderedView> {
23
- const c = opts.color;
24
- const label = (s: string) => (c ? `${DIM}${s}${RESET}` : s);
25
- const name = (s: string) => (c ? `${CYAN}${s}${RESET}` : s);
26
-
27
- const deps = Object.entries(entry.peerDeps)
28
- .map(([n, r]) => `${n}@${r}`)
29
- .join(", ");
30
- const headerLines = [
31
- `${name(entry.name)}`,
32
- `${label("phase")} ${entry.phase}`,
33
- `${label("kind")} ${entry.kind}`,
34
- `${label("island")} ${entry.island}`,
35
- `${label("status")} ${entry.status}`,
36
- `${label("peerDeps")} ${deps || "—"}`,
37
- `${label("helpers")} ${entry.internalHelpers.join(", ") || "—"}`,
38
- `${label("tokens")} ${(entry.tokens ?? []).join(", ") || "—"}`,
39
- ];
40
-
41
- const parts: string[] = [];
42
- for (const f of entry.files) {
43
- const src = await Bun.file(join(templatesDir, f.from)).text();
44
- const fence = `// ──── ${f.to} ────`;
45
- parts.push(`${c ? `${DIM}${fence}${RESET}` : fence}\n${src}`);
46
- }
47
-
48
- return {
49
- header: headerLines.join("\n"),
50
- source: parts.join("\n"),
51
- };
52
- }
53
-
54
- // Render and emit: metadata → stderr, source → stdout (pipeable escape hatch).
55
- export async function writeComponentView(
56
- entry: ComponentEntry,
57
- templatesDir: string,
58
- ): Promise<void> {
59
- const color = isTTY(process.stdout) && !process.env.NO_COLOR;
60
- const r = await renderComponentSource(entry, templatesDir, { color });
61
- process.stderr.write(`${r.header}\n\n`);
62
- process.stdout.write(`${r.source}\n`);
63
- }
@@ -1,86 +0,0 @@
1
- import type { CliContext } from "../index.ts";
2
- import { EXIT } from "../log.ts";
3
- import { runUiBuild, type UiBuildArgs } from "./ui/build.ts";
4
- import { runUiInit, type UiInitArgs } from "./ui/init.ts";
5
-
6
- // `sordo ui <sub>` subcommand group: `init` (scaffold) and `build` (compile a
7
- // fetchable registry for third-party authors, cli/15).
8
- export async function runUi(argv: string[], ctx: CliContext): Promise<number> {
9
- const [sub, ...rest] = argv;
10
-
11
- if (sub === undefined || sub === "help" || sub === "--help" || sub === "-h") {
12
- printHelp();
13
- return EXIT.OK;
14
- }
15
-
16
- switch (sub) {
17
- case "init":
18
- return runUiInit(parseInitArgs(rest), ctx);
19
- case "build":
20
- return runUiBuild(parseBuildArgs(rest), ctx);
21
- default:
22
- printHelp();
23
- return EXIT.USAGE;
24
- }
25
- }
26
-
27
- function parseInitArgs(argv: string[]): UiInitArgs {
28
- const out: UiInitArgs = { dryRun: false, force: false };
29
- for (let i = 0; i < argv.length; i++) {
30
- const a = argv[i];
31
- if (a === undefined) continue;
32
- if (a === "--dry-run") out.dryRun = true;
33
- else if (a === "--force") out.force = true;
34
- else if (a === "--shadcn") out.shadcn = true;
35
- else if (a === "--theme") {
36
- const v = argv[++i];
37
- if (v === undefined) out.themeMissing = true;
38
- else out.theme = v;
39
- } else if (a.startsWith("--theme=")) {
40
- out.theme = a.slice("--theme=".length);
41
- }
42
- }
43
- return out;
44
- }
45
-
46
- function parseBuildArgs(argv: string[]): UiBuildArgs {
47
- const out: UiBuildArgs = { outMissing: false, help: false };
48
- for (let i = 0; i < argv.length; i++) {
49
- const a = argv[i];
50
- if (a === undefined) continue;
51
- if (a === "--help" || a === "-h") out.help = true;
52
- else if (a === "--out") {
53
- const v = argv[++i];
54
- if (v === undefined) out.outMissing = true;
55
- else out.out = v;
56
- } else if (a.startsWith("--out=")) {
57
- out.out = a.slice("--out=".length);
58
- } else if (a === "--registry") {
59
- const v = argv[++i];
60
- if (v !== undefined) out.registry = v;
61
- } else if (a.startsWith("--registry=")) {
62
- out.registry = a.slice("--registry=".length);
63
- } else if (a === "--templates") {
64
- const v = argv[++i];
65
- if (v !== undefined) out.templates = v;
66
- } else if (a.startsWith("--templates=")) {
67
- out.templates = a.slice("--templates=".length);
68
- }
69
- }
70
- return out;
71
- }
72
-
73
- function printHelp(): void {
74
- process.stdout.write(`sordo ui — UI catalog setup
75
-
76
- Usage:
77
- sordo ui init [--dry-run] [--force] [--theme <name>] [--shadcn]
78
- sordo ui build --out <dir> [--registry <path>] [--templates <dir>]
79
-
80
- Subcommands:
81
- init Lay down tokens, the cn helper, and Tailwind wiring before stamping.
82
- --shadcn also adds the @/* tsconfig alias and @/lib/utils that
83
- upstream shadcn/ui source imports (for \`sordo add @shadcn/<name>\`).
84
- build Compile a fetchable registry.json + per-component JSON (for authors).
85
- `);
86
- }
@@ -1,134 +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 { 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 { resolveUiPaths, UiPathError, type UiPaths } from "./add/ui-paths.ts";
13
- import { resolveNames } from "./add.ts";
14
-
15
- interface UpdateArgs {
16
- names: string[];
17
- all: boolean;
18
- dryRun: boolean;
19
- }
20
-
21
- const PROD_MSG =
22
- "sordo update is a dev-only tool; refusing to run with NODE_ENV=production.";
23
-
24
- // `sordo update [<component>|--all]` — re-stamp stamped components from the
25
- // catalog, after showing the drift. Overwrites local edits (the shown diff is
26
- // the safeguard; commit before updating).
27
- export async function runUpdate(
28
- argv: string[],
29
- ctx: CliContext,
30
- ): Promise<number> {
31
- const args = parseArgs(argv);
32
-
33
- if (process.env.NODE_ENV === "production") {
34
- log.error(PROD_MSG);
35
- return EXIT.USAGE;
36
- }
37
-
38
- if (!(await Bun.file(join(ctx.cwd, "package.json")).exists())) {
39
- log.error(`not a Sordo project (no package.json found at ${ctx.cwd})`);
40
- return EXIT.USAGE;
41
- }
42
-
43
- const catalog = await loadCatalog(ctx.cwd);
44
-
45
- const loaded = await loadConfigOrUsage({
46
- cwd: ctx.cwd,
47
- configPath: ctx.configPath,
48
- });
49
- if ("error" in loaded) {
50
- log.error(loaded.error);
51
- return EXIT.USAGE;
52
- }
53
-
54
- let uiPaths: UiPaths;
55
- try {
56
- uiPaths = resolveUiPaths({
57
- cwd: ctx.cwd,
58
- ui: loaded.config.ui,
59
- appDir: loaded.config.appDir,
60
- });
61
- } catch (err) {
62
- if (err instanceof UiPathError) {
63
- log.error(err.message);
64
- return EXIT.USAGE;
65
- }
66
- throw err;
67
- }
68
-
69
- const entries = await selectEntries(catalog, uiPaths, args);
70
- if (entries === null) return EXIT.USAGE;
71
- if (entries.length === 0) {
72
- log.error("no components selected. Pass a name or --all.");
73
- return EXIT.USAGE;
74
- }
75
-
76
- const color = isTTY(process.stdout) && !process.env.NO_COLOR;
77
- for (const entry of entries) {
78
- log.info(entry.name);
79
- const items = await diffComponentItems(
80
- entry,
81
- uiPaths,
82
- catalog.templatesDir,
83
- color,
84
- );
85
- let drifted = false;
86
- for (const item of items) {
87
- if (item.status === "drift") {
88
- drifted = true;
89
- log.info(` drift ${item.label}`);
90
- process.stdout.write(`${item.body}\n`);
91
- }
92
- }
93
- if (!drifted) {
94
- log.dim(" up to date");
95
- continue;
96
- }
97
- if (args.dryRun) continue;
98
- try {
99
- await applyComponent(entry, ctx.cwd, uiPaths, catalog.templatesDir, {
100
- force: true,
101
- });
102
- } catch (err) {
103
- log.error(err instanceof Error ? err.message : String(err));
104
- return EXIT.ERROR;
105
- }
106
- }
107
-
108
- if (args.dryRun) {
109
- log.dim("dry-run: no files written.");
110
- } else {
111
- log.dim("done. Run `bun install` to fetch any new peer dependencies.");
112
- }
113
- return EXIT.OK;
114
- }
115
-
116
- async function selectEntries(
117
- catalog: Catalog,
118
- uiPaths: UiPaths,
119
- args: UpdateArgs,
120
- ): Promise<ComponentEntry[] | null> {
121
- if (args.names.length > 0) return resolveNames(catalog, args.names);
122
- if (args.all) return listStampedComponents(catalog, uiPaths);
123
- return [];
124
- }
125
-
126
- function parseArgs(argv: string[]): UpdateArgs {
127
- const out: UpdateArgs = { names: [], all: false, dryRun: false };
128
- for (const a of argv) {
129
- if (a === "--all") out.all = true;
130
- else if (a === "--dry-run") out.dryRun = true;
131
- else if (!a.startsWith("-")) out.names.push(a);
132
- }
133
- return out;
134
- }
@@ -1,53 +0,0 @@
1
- import { join } from "node:path";
2
- import pkg from "../../../package.json" with { type: "json" };
3
- import type { CliContext } from "../index.ts";
4
- import { EXIT, log } from "../log.ts";
5
-
6
- const FRAMEWORK_VERSION = (pkg as { version: string }).version;
7
-
8
- // Mirror update-check's channel detection so an upgrade stays on the same line:
9
- // a prerelease install upgrades to the newest prerelease, stable to `latest`.
10
- function channelTag(version: string): string {
11
- const dash = version.indexOf("-");
12
- if (dash === -1) return "latest";
13
- return version.slice(dash + 1).split(".")[0] || "latest";
14
- }
15
-
16
- // `sordo upgrade [--dry-run]` — bump the project's `sordo` dependency to the
17
- // newest version on its channel via `bun add`. This is the one place the CLI is
18
- // allowed to invoke an install, because the user asked for it explicitly.
19
- export async function runUpgrade(
20
- argv: string[],
21
- ctx: CliContext,
22
- ): Promise<number> {
23
- if (process.env.NODE_ENV === "production") {
24
- log.error("sordo upgrade is a dev-time command; not for production.");
25
- return EXIT.USAGE;
26
- }
27
-
28
- if (!(await Bun.file(join(ctx.cwd, "package.json")).exists())) {
29
- log.error(`not a Sordo project (no package.json found at ${ctx.cwd})`);
30
- return EXIT.USAGE;
31
- }
32
-
33
- const spec = `sordo@${channelTag(FRAMEWORK_VERSION)}`;
34
-
35
- if (argv.includes("--dry-run")) {
36
- log.dim(`(dry run) would run: bun add ${spec}`);
37
- return EXIT.OK;
38
- }
39
-
40
- log.info(`Upgrading ${spec} in ${ctx.cwd} …`);
41
- const proc = Bun.spawn(["bun", "add", spec], {
42
- cwd: ctx.cwd,
43
- stdout: "inherit",
44
- stderr: "inherit",
45
- });
46
- const code = await proc.exited;
47
- if (code !== 0) {
48
- log.error(`bun add ${spec} failed (exit ${code})`);
49
- return EXIT.ERROR;
50
- }
51
- log.success(`sordo upgraded (${spec}).`);
52
- return EXIT.OK;
53
- }
@@ -1,34 +0,0 @@
1
- import { join } from "node:path";
2
- import type { CliContext } from "../index.ts";
3
- import { EXIT, log } from "../log.ts";
4
- import { loadCatalog } from "./add/load-catalog.ts";
5
- import { writeComponentView } from "./ui/view.ts";
6
-
7
- // `sordo view <component>` — alias for `sordo add --view`. Read-only.
8
- export async function runView(
9
- argv: string[],
10
- ctx: CliContext,
11
- ): Promise<number> {
12
- const names = argv.filter((a) => !a.startsWith("-"));
13
- if (names.length === 0) {
14
- log.error("usage: sordo view <component>");
15
- return EXIT.USAGE;
16
- }
17
-
18
- if (!(await Bun.file(join(ctx.cwd, "package.json")).exists())) {
19
- log.error(`not a Sordo project (no package.json found at ${ctx.cwd})`);
20
- return EXIT.USAGE;
21
- }
22
-
23
- const catalog = await loadCatalog(ctx.cwd);
24
-
25
- for (const name of names) {
26
- const entry = catalog.components.find((c) => c.name === name);
27
- if (!entry) {
28
- log.error(`unknown component: ${name}`);
29
- return EXIT.USAGE;
30
- }
31
- await writeComponentView(entry, catalog.templatesDir);
32
- }
33
- return EXIT.OK;
34
- }