create-sordo 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/README.md +52 -2
- package/bin/create-sordo.ts +11 -0
- package/package.json +36 -5
- package/src/index.ts +675 -0
- package/src/probes.ts +28 -0
- package/src/prompts.ts +141 -0
- package/src/readme.ts +74 -0
- package/src/ui.ts +207 -0
- package/src/versions.ts +3 -0
- package/templates/_backend/app/routes/api/todos.ts +27 -0
- package/templates/_claude/.claude/commands/sordo-init.md +64 -0
- package/templates/_claude/.claude/hooks/biome-check.sh +17 -0
- package/templates/_claude/.claude/rules/build-time-discovery.md +17 -0
- package/templates/_claude/.claude/rules/bun-native.md +28 -0
- package/templates/_claude/.claude/rules/filesystem-routing.md +31 -0
- package/templates/_claude/.claude/rules/islands.md +46 -0
- package/templates/_claude/.claude/rules/optional-ai.md +16 -0
- package/templates/_claude/.claude/rules/web-standards-boundary.md +25 -0
- package/templates/_claude/.claude/settings.json +22 -0
- package/templates/_claude/.claude/skills/sordo/SKILL.md +121 -0
- package/templates/_claude/.claude/skills/sordo-cli/SKILL.md +112 -0
- package/templates/_claude/CLAUDE.md +28 -0
- package/templates/_codex/.codex/README.md +10 -0
- package/templates/_codex/.codex/rules/build-time-discovery.md +17 -0
- package/templates/_codex/.codex/rules/bun-native.md +28 -0
- package/templates/_codex/.codex/rules/filesystem-routing.md +31 -0
- package/templates/_codex/.codex/rules/islands.md +46 -0
- package/templates/_codex/.codex/rules/optional-ai.md +15 -0
- package/templates/_codex/.codex/rules/sordo-cli.md +108 -0
- package/templates/_codex/.codex/rules/sordo-patterns.md +122 -0
- package/templates/_codex/.codex/rules/web-standards-boundary.md +25 -0
- package/templates/_codex/AGENTS.md +27 -0
- package/templates/_container/.dockerignore +7 -0
- package/templates/_container/Dockerfile +27 -0
- package/templates/_monorepo/packages/README.md +18 -0
- package/templates/_shared/sordo-patterns.md +122 -0
- package/templates/default/README-template.md +181 -0
- package/templates/default/app/islands/TodoApp.tsx +83 -0
- package/templates/default/app/routes/api/health.ts +8 -0
- package/templates/default/app/routes/index.tsx +29 -0
- package/templates/default/app/server.ts +28 -0
- package/templates/default/gitignore +9 -0
- package/templates/default/sordo.config.ts +5 -0
- package/templates/default/tsconfig.json +14 -0
- package/templates/ui-shadcn/components/button.tsx +63 -0
- package/templates/ui-shadcn/components/dialog.tsx +158 -0
- package/templates/ui-shadcn/demo/index.tsx +62 -0
- package/templates/ui-starter/_internal/cn.ts +6 -0
- package/templates/ui-starter/_internal/slot.ts +50 -0
- package/templates/ui-starter/_internal/variants.ts +1 -0
- package/templates/ui-starter/button.tsx +60 -0
- package/templates/ui-starter/card.tsx +92 -0
- package/templates/ui-starter/demo/TodoApp.tsx +86 -0
- package/templates/ui-starter/demo/index.tsx +45 -0
- package/templates/ui-starter/input.tsx +20 -0
- package/templates/ui-starter/label.tsx +18 -0
- package/templates/ui-starter/themes/neutral/tokens.css +46 -0
- package/templates/ui-starter/themes/slate/tokens.css +46 -0
- package/templates/ui-starter/themes/stone/tokens.css +46 -0
- package/templates/ui-starter/themes/zinc/tokens.css +46 -0
- package/templates/ui-starter/tokens.css +46 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
import { existsSync, readdirSync, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { hasGit, probeTools } from "./probes.ts";
|
|
4
|
+
import {
|
|
5
|
+
type AgentTemplate,
|
|
6
|
+
type Deploy,
|
|
7
|
+
isInteractive,
|
|
8
|
+
type ProjectType,
|
|
9
|
+
promptAgent,
|
|
10
|
+
promptDeploy,
|
|
11
|
+
promptMonorepo,
|
|
12
|
+
promptName,
|
|
13
|
+
promptTarget,
|
|
14
|
+
promptType,
|
|
15
|
+
promptUi,
|
|
16
|
+
type Target,
|
|
17
|
+
type Theme,
|
|
18
|
+
} from "./prompts.ts";
|
|
19
|
+
import { renderTemplatesInTree } from "./readme.ts";
|
|
20
|
+
import {
|
|
21
|
+
applyShadcnStarter,
|
|
22
|
+
applyUiStarter,
|
|
23
|
+
UI_DEPS,
|
|
24
|
+
UI_DEV_DEPS,
|
|
25
|
+
UI_SHADCN_DEPS,
|
|
26
|
+
} from "./ui.ts";
|
|
27
|
+
import { SORDO_VERSION } from "./versions.ts";
|
|
28
|
+
|
|
29
|
+
// Step logger — visible progress so the user can see what scaffolding does.
|
|
30
|
+
// Honors NO_COLOR; degrades gracefully on non-TTY streams.
|
|
31
|
+
function colorOn(): boolean {
|
|
32
|
+
if (process.env.NO_COLOR) return false;
|
|
33
|
+
return Boolean((process.stdout as NodeJS.WriteStream).isTTY);
|
|
34
|
+
}
|
|
35
|
+
const COL = colorOn();
|
|
36
|
+
const c = {
|
|
37
|
+
dim: (s: string) => (COL ? `\x1b[2m${s}\x1b[0m` : s),
|
|
38
|
+
green: (s: string) => (COL ? `\x1b[32m${s}\x1b[0m` : s),
|
|
39
|
+
cyan: (s: string) => (COL ? `\x1b[36m${s}\x1b[0m` : s),
|
|
40
|
+
bold: (s: string) => (COL ? `\x1b[1m${s}\x1b[0m` : s),
|
|
41
|
+
};
|
|
42
|
+
function step(msg: string): void {
|
|
43
|
+
process.stdout.write(` ${c.green("✓")} ${msg}\n`);
|
|
44
|
+
}
|
|
45
|
+
function pending(msg: string): void {
|
|
46
|
+
process.stdout.write(` ${c.dim("…")} ${msg}\n`);
|
|
47
|
+
}
|
|
48
|
+
function header(msg: string): void {
|
|
49
|
+
process.stdout.write(`\n${c.bold(c.cyan("▲"))} ${msg}\n\n`);
|
|
50
|
+
}
|
|
51
|
+
function fmtMs(ms: number): string {
|
|
52
|
+
return ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(1)}s`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface Args {
|
|
56
|
+
name?: string;
|
|
57
|
+
template: AgentTemplate;
|
|
58
|
+
templateExplicit: boolean;
|
|
59
|
+
type: ProjectType;
|
|
60
|
+
typeExplicit: boolean;
|
|
61
|
+
ui: boolean;
|
|
62
|
+
uiExplicit: boolean;
|
|
63
|
+
// "sordo" stamps the vendored starter; "shadcn" vendors upstream
|
|
64
|
+
// shadcn/ui on a whole-tree hydrated demo page.
|
|
65
|
+
uiKind: UiKind;
|
|
66
|
+
monorepo: boolean;
|
|
67
|
+
monorepoExplicit: boolean;
|
|
68
|
+
target: Target;
|
|
69
|
+
targetExplicit: boolean;
|
|
70
|
+
theme: Theme;
|
|
71
|
+
deploy: Deploy;
|
|
72
|
+
deployExplicit: boolean;
|
|
73
|
+
install: boolean;
|
|
74
|
+
git: boolean;
|
|
75
|
+
yes: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const TEMPLATES_ROOT = resolve(dirname(import.meta.dir), "templates");
|
|
79
|
+
const BASE_TEMPLATE = "default";
|
|
80
|
+
const VALID_TEMPLATES: AgentTemplate[] = ["claude", "codex", "none"];
|
|
81
|
+
const VALID_TYPES: ProjectType[] = ["frontend", "backend", "fullstack"];
|
|
82
|
+
const VALID_THEMES: Theme[] = ["neutral", "slate", "stone", "zinc"];
|
|
83
|
+
type UiKind = "sordo" | "shadcn";
|
|
84
|
+
const UI_KINDS: UiKind[] = ["sordo", "shadcn"];
|
|
85
|
+
|
|
86
|
+
export async function run(argv: string[]): Promise<number> {
|
|
87
|
+
const args = parseArgs(argv);
|
|
88
|
+
const interactive = !args.yes && isInteractive();
|
|
89
|
+
|
|
90
|
+
if (!args.name) {
|
|
91
|
+
if (interactive) {
|
|
92
|
+
args.name = promptName(undefined, isValidName);
|
|
93
|
+
if (!args.name) {
|
|
94
|
+
stderr("✗ failed to read a valid project name");
|
|
95
|
+
return 2;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
printUsage();
|
|
99
|
+
return 2;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!isValidName(args.name)) {
|
|
104
|
+
stderr(`✗ invalid project name: "${args.name}"`);
|
|
105
|
+
return 2;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (interactive) {
|
|
109
|
+
if (!args.templateExplicit) args.template = promptAgent();
|
|
110
|
+
if (!args.typeExplicit) args.type = promptType();
|
|
111
|
+
if (
|
|
112
|
+
(args.type === "frontend" || args.type === "fullstack") &&
|
|
113
|
+
!args.uiExplicit
|
|
114
|
+
) {
|
|
115
|
+
args.ui = promptUi();
|
|
116
|
+
}
|
|
117
|
+
if (args.type === "fullstack" && !args.monorepoExplicit) {
|
|
118
|
+
args.monorepo = promptMonorepo();
|
|
119
|
+
}
|
|
120
|
+
if (!args.targetExplicit) args.target = promptTarget(args.type);
|
|
121
|
+
if (args.target === "edge" && !args.deployExplicit) {
|
|
122
|
+
args.deploy = promptDeploy();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!VALID_TEMPLATES.includes(args.template)) {
|
|
127
|
+
stderr(
|
|
128
|
+
`✗ unknown --agent "${args.template}" (expected: ${VALID_TEMPLATES.join(", ")})`,
|
|
129
|
+
);
|
|
130
|
+
return 2;
|
|
131
|
+
}
|
|
132
|
+
if (!UI_KINDS.includes(args.uiKind)) {
|
|
133
|
+
stderr(
|
|
134
|
+
`✗ unknown --ui "${args.uiKind}" (expected: ${UI_KINDS.join(", ")})`,
|
|
135
|
+
);
|
|
136
|
+
return 2;
|
|
137
|
+
}
|
|
138
|
+
if (!VALID_TYPES.includes(args.type)) {
|
|
139
|
+
stderr(
|
|
140
|
+
`✗ unknown --type "${args.type}" (expected: ${VALID_TYPES.join(", ")})`,
|
|
141
|
+
);
|
|
142
|
+
return 2;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Gating (spec 18 §Behavior): backend has no UI surface; only full-stack
|
|
146
|
+
// projects can be a monorepo or use the container target.
|
|
147
|
+
if (args.type === "backend") args.ui = false;
|
|
148
|
+
if (args.type !== "fullstack") {
|
|
149
|
+
args.monorepo = false;
|
|
150
|
+
if (args.target === "container") {
|
|
151
|
+
stderr("✗ --target container is only available for --type fullstack");
|
|
152
|
+
return 2;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const appName = args.name;
|
|
157
|
+
const targetDir = isAbsolute(args.name)
|
|
158
|
+
? args.name
|
|
159
|
+
: resolve(process.cwd(), args.name);
|
|
160
|
+
const appRoot = args.monorepo ? `${targetDir}/apps/${appName}` : targetDir;
|
|
161
|
+
|
|
162
|
+
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
163
|
+
stderr(`✗ directory not empty: ${targetDir}`);
|
|
164
|
+
return 2;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const baseDir = resolve(TEMPLATES_ROOT, BASE_TEMPLATE);
|
|
168
|
+
if (!existsSync(baseDir)) {
|
|
169
|
+
stderr(`✗ base template missing: ${baseDir}`);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
probeTools();
|
|
174
|
+
|
|
175
|
+
header(`create-sordo — scaffolding ${c.bold(args.name)}`);
|
|
176
|
+
|
|
177
|
+
await Bun.$`mkdir -p ${appRoot}`.quiet();
|
|
178
|
+
await Bun.$`cp -R ${baseDir}/. ${appRoot}`.quiet();
|
|
179
|
+
step(`copied base template ${c.dim(`(${args.type})`)}`);
|
|
180
|
+
|
|
181
|
+
// README + .gitignore live at the project root; in a monorepo that's above
|
|
182
|
+
// the app dir, so lift them out before renaming.
|
|
183
|
+
if (args.monorepo) {
|
|
184
|
+
for (const f of ["README-template.md", "gitignore"]) {
|
|
185
|
+
if (existsSync(`${appRoot}/${f}`)) {
|
|
186
|
+
await Bun.$`mv ${appRoot}/${f} ${targetDir}/${f}`.quiet();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
await renameTemplateFiles(targetDir);
|
|
191
|
+
|
|
192
|
+
await applyProjectType(appRoot, args.type);
|
|
193
|
+
step(`applied project type ${c.dim(`(${args.type})`)}`);
|
|
194
|
+
|
|
195
|
+
await writeAppPackageJson(appRoot, appName, args);
|
|
196
|
+
await patchSordoConfig(appRoot, args);
|
|
197
|
+
step(
|
|
198
|
+
`wrote package.json + sordo.config.ts ${c.dim(`(target: ${args.target})`)}`,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
if (args.template !== "none") {
|
|
202
|
+
const overlay = resolve(TEMPLATES_ROOT, `_${args.template}`);
|
|
203
|
+
if (existsSync(overlay)) {
|
|
204
|
+
await Bun.$`cp -R ${overlay}/. ${targetDir}`.quiet();
|
|
205
|
+
step(`applied agent overlay ${c.dim(`(${args.template})`)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (args.monorepo) {
|
|
210
|
+
await setupMonorepoRoot(targetDir, appName);
|
|
211
|
+
step(`set up Bun workspace ${c.dim(`(apps/${appName})`)}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (args.ui && args.uiKind === "shadcn") {
|
|
215
|
+
await applyShadcnStarter(
|
|
216
|
+
appRoot,
|
|
217
|
+
args.theme,
|
|
218
|
+
resolve(TEMPLATES_ROOT, "ui-starter"),
|
|
219
|
+
resolve(TEMPLATES_ROOT, "ui-shadcn"),
|
|
220
|
+
);
|
|
221
|
+
step(`added shadcn/ui starter ${c.dim("(hydrated demo page)")}`);
|
|
222
|
+
} else if (args.ui) {
|
|
223
|
+
await applyUiStarter(
|
|
224
|
+
appRoot,
|
|
225
|
+
args.theme,
|
|
226
|
+
resolve(TEMPLATES_ROOT, "ui-starter"),
|
|
227
|
+
);
|
|
228
|
+
step(`stamped UI starter ${c.dim(`(theme: ${args.theme})`)}`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (args.target === "container") {
|
|
232
|
+
await applyContainer(appRoot, args.name);
|
|
233
|
+
step("emitted Dockerfile + .dockerignore");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
await renderTemplatesInTree(targetDir, {
|
|
237
|
+
name: args.name,
|
|
238
|
+
agent: args.template,
|
|
239
|
+
type: args.type,
|
|
240
|
+
ui: args.ui ? "yes" : "no",
|
|
241
|
+
monorepo: args.monorepo ? "yes" : "no",
|
|
242
|
+
target: args.target,
|
|
243
|
+
deploy: args.deploy,
|
|
244
|
+
app_name: appName,
|
|
245
|
+
});
|
|
246
|
+
step("rendered template variables (README, app files, …)");
|
|
247
|
+
|
|
248
|
+
if (args.install) {
|
|
249
|
+
pending("installing dependencies (bun install)…");
|
|
250
|
+
const t0 = performance.now();
|
|
251
|
+
const proc = await Bun.$`bun install`.cwd(targetDir).quiet().nothrow();
|
|
252
|
+
const dt = performance.now() - t0;
|
|
253
|
+
if (proc.exitCode === 0) {
|
|
254
|
+
step(`installed dependencies ${c.dim(`(${fmtMs(dt)})`)}`);
|
|
255
|
+
} else {
|
|
256
|
+
step(
|
|
257
|
+
`bun install exited with code ${proc.exitCode} — you may need to retry it manually`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
step(`skipped ${c.dim("`bun install`")} (--no-install)`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const gitSkippedReason = args.git ? await initGit(targetDir) : undefined;
|
|
265
|
+
if (args.git && !gitSkippedReason) step("initialized git and committed");
|
|
266
|
+
|
|
267
|
+
printNextSteps(args, appName);
|
|
268
|
+
if (gitSkippedReason === "git-missing") {
|
|
269
|
+
stderr("create-sordo: `git` not found — skipping `git init`.");
|
|
270
|
+
}
|
|
271
|
+
if (gitSkippedReason === "git-init-failed") {
|
|
272
|
+
stderr("create-sordo: `git init` failed — skipping the initial commit.");
|
|
273
|
+
}
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function parseArgs(argv: string[]): Args {
|
|
278
|
+
const out: Args = {
|
|
279
|
+
template: "claude",
|
|
280
|
+
templateExplicit: false,
|
|
281
|
+
type: "fullstack",
|
|
282
|
+
typeExplicit: false,
|
|
283
|
+
ui: true,
|
|
284
|
+
uiExplicit: false,
|
|
285
|
+
uiKind: "sordo",
|
|
286
|
+
monorepo: false,
|
|
287
|
+
monorepoExplicit: false,
|
|
288
|
+
target: "bun",
|
|
289
|
+
targetExplicit: false,
|
|
290
|
+
theme: "neutral",
|
|
291
|
+
deploy: "none",
|
|
292
|
+
deployExplicit: false,
|
|
293
|
+
install: true,
|
|
294
|
+
git: false,
|
|
295
|
+
yes: false,
|
|
296
|
+
};
|
|
297
|
+
const setTemplate = (raw: string) => {
|
|
298
|
+
out.template = aliasTemplate(raw);
|
|
299
|
+
out.templateExplicit = true;
|
|
300
|
+
};
|
|
301
|
+
const setType = (raw: string) => {
|
|
302
|
+
out.type = raw as ProjectType;
|
|
303
|
+
out.typeExplicit = true;
|
|
304
|
+
};
|
|
305
|
+
const setTarget = (raw: string) => {
|
|
306
|
+
out.target = raw as Target;
|
|
307
|
+
out.targetExplicit = true;
|
|
308
|
+
};
|
|
309
|
+
const setDeploy = (raw: string) => {
|
|
310
|
+
out.deploy = raw as Deploy;
|
|
311
|
+
out.deployExplicit = true;
|
|
312
|
+
};
|
|
313
|
+
for (let i = 0; i < argv.length; i++) {
|
|
314
|
+
const a = argv[i];
|
|
315
|
+
if (a === undefined) continue;
|
|
316
|
+
// --agent is the spec-18 name; --template is the spec-05/09 alias.
|
|
317
|
+
if (a === "--template" || a === "--agent") setTemplate(next(argv, ++i));
|
|
318
|
+
else if (a.startsWith("--template=")) setTemplate(a.slice(11));
|
|
319
|
+
else if (a.startsWith("--agent=")) setTemplate(a.slice(8));
|
|
320
|
+
else if (a === "--type") setType(next(argv, ++i));
|
|
321
|
+
else if (a.startsWith("--type=")) setType(a.slice(7));
|
|
322
|
+
else if (a === "--ui") {
|
|
323
|
+
out.ui = true;
|
|
324
|
+
out.uiExplicit = true;
|
|
325
|
+
// Optional value: `--ui shadcn`. Anything else is left for the name.
|
|
326
|
+
const v = argv[i + 1];
|
|
327
|
+
if (v && UI_KINDS.includes(v as UiKind)) {
|
|
328
|
+
out.uiKind = v as UiKind;
|
|
329
|
+
i++;
|
|
330
|
+
}
|
|
331
|
+
} else if (a.startsWith("--ui=")) {
|
|
332
|
+
out.ui = true;
|
|
333
|
+
out.uiExplicit = true;
|
|
334
|
+
out.uiKind = a.slice(5) as UiKind;
|
|
335
|
+
} else if (a === "--no-ui") {
|
|
336
|
+
out.ui = false;
|
|
337
|
+
out.uiExplicit = true;
|
|
338
|
+
} else if (a === "--monorepo") {
|
|
339
|
+
out.monorepo = true;
|
|
340
|
+
out.monorepoExplicit = true;
|
|
341
|
+
} else if (a === "--no-monorepo") {
|
|
342
|
+
out.monorepo = false;
|
|
343
|
+
out.monorepoExplicit = true;
|
|
344
|
+
} else if (a === "--target") setTarget(next(argv, ++i));
|
|
345
|
+
else if (a.startsWith("--target=")) setTarget(a.slice(9));
|
|
346
|
+
else if (a === "--theme") out.theme = aliasTheme(next(argv, ++i));
|
|
347
|
+
else if (a.startsWith("--theme=")) out.theme = aliasTheme(a.slice(8));
|
|
348
|
+
else if (a === "--deploy") setDeploy(next(argv, ++i));
|
|
349
|
+
else if (a.startsWith("--deploy=")) setDeploy(a.slice(9));
|
|
350
|
+
else if (a === "--no-install") out.install = false;
|
|
351
|
+
else if (a === "--git") out.git = true;
|
|
352
|
+
// --no-git: kept as a no-op for back-compat. Git is opt-in (default off).
|
|
353
|
+
else if (a === "--no-git") out.git = false;
|
|
354
|
+
else if (a === "--yes" || a === "-y") out.yes = true;
|
|
355
|
+
// --blank / --demo: spec-09 scaffold flags, superseded by --type. Accepted
|
|
356
|
+
// as no-ops so old invocations don't error.
|
|
357
|
+
else if (a === "--blank" || a === "--empty" || a === "--demo") continue;
|
|
358
|
+
else if (!out.name && !a.startsWith("-")) out.name = a;
|
|
359
|
+
}
|
|
360
|
+
return out;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Translate spec-05 --agent values (claude-code/none) and current --agent
|
|
364
|
+
// values (claude/codex/none) into the unified AgentTemplate type.
|
|
365
|
+
function aliasTemplate(raw: string): AgentTemplate {
|
|
366
|
+
if (raw === "claude-code") return "claude";
|
|
367
|
+
if (raw === "claude" || raw === "codex" || raw === "none") return raw;
|
|
368
|
+
return raw as AgentTemplate;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function aliasTheme(raw: string): Theme {
|
|
372
|
+
return (VALID_THEMES as string[]).includes(raw) ? (raw as Theme) : "neutral";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function next(argv: string[], i: number): string {
|
|
376
|
+
return argv[i] ?? "";
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function isValidName(name: string): boolean {
|
|
380
|
+
if (!name) return false;
|
|
381
|
+
if (name.includes("/") || name.includes("\\")) return false;
|
|
382
|
+
if (name.startsWith(".")) return false;
|
|
383
|
+
return /^[a-z0-9][a-z0-9_-]*$/.test(name);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function renameTemplateFiles(dir: string): Promise<void> {
|
|
387
|
+
const renames: Array<[string, string]> = [
|
|
388
|
+
["gitignore", ".gitignore"],
|
|
389
|
+
["README-template.md", "README.md"],
|
|
390
|
+
];
|
|
391
|
+
for (const [from, to] of renames) {
|
|
392
|
+
const src = `${dir}/${from}`;
|
|
393
|
+
if (await Bun.file(src).exists()) {
|
|
394
|
+
await Bun.$`mv ${src} ${dir}/${to}`.quiet();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Shape the base (full-stack) template for the chosen project type. We prune
|
|
400
|
+
// from one source rather than keep three near-identical trees.
|
|
401
|
+
async function applyProjectType(
|
|
402
|
+
appRoot: string,
|
|
403
|
+
type: ProjectType,
|
|
404
|
+
): Promise<void> {
|
|
405
|
+
if (type === "frontend") {
|
|
406
|
+
// No API surface.
|
|
407
|
+
await Bun.$`rm -rf ${appRoot}/app/routes/api`.quiet();
|
|
408
|
+
} else if (type === "backend") {
|
|
409
|
+
// API only — drop the page + island, add a sample resource.
|
|
410
|
+
await Bun.$`rm -rf ${appRoot}/app/islands`.quiet();
|
|
411
|
+
await Bun.$`rm -f ${appRoot}/app/routes/index.tsx`.quiet();
|
|
412
|
+
const overlay = resolve(TEMPLATES_ROOT, "_backend");
|
|
413
|
+
if (existsSync(overlay)) {
|
|
414
|
+
await Bun.$`cp -R ${overlay}/. ${appRoot}`.quiet();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function pkgScripts(ui: boolean): Record<string, string> {
|
|
420
|
+
if (!ui) {
|
|
421
|
+
return {
|
|
422
|
+
dev: "sordo dev",
|
|
423
|
+
build: "sordo build",
|
|
424
|
+
start: "sordo start",
|
|
425
|
+
typecheck: "tsc --noEmit",
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
// UI projects compile Tailwind themselves (Sordo bundles no CSS). `css`
|
|
429
|
+
// emits the sheet the styles route serves; `dev`/`build` run it first so the
|
|
430
|
+
// app is styled on boot. `css:watch` rebuilds on className changes in dev.
|
|
431
|
+
const css =
|
|
432
|
+
"tailwindcss -i app/styles/app.css -o app/styles/app.generated.css";
|
|
433
|
+
return {
|
|
434
|
+
dev: "bun run css && sordo dev",
|
|
435
|
+
build: "bun run css && sordo build",
|
|
436
|
+
start: "sordo start",
|
|
437
|
+
typecheck: "tsc --noEmit",
|
|
438
|
+
css,
|
|
439
|
+
"css:watch": `${css} --watch`,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function writeAppPackageJson(
|
|
444
|
+
dir: string,
|
|
445
|
+
name: string,
|
|
446
|
+
args: Args,
|
|
447
|
+
): Promise<void> {
|
|
448
|
+
const dependencies: Record<string, string> = {
|
|
449
|
+
// Pinned to the release this scaffolder shipped with, so new apps don't
|
|
450
|
+
// float on every install.
|
|
451
|
+
sordo: `^${SORDO_VERSION}`,
|
|
452
|
+
react: "^19.0.0",
|
|
453
|
+
"react-dom": "^19.0.0",
|
|
454
|
+
};
|
|
455
|
+
const devDependencies: Record<string, string> = {
|
|
456
|
+
"@types/react": "^19.0.0",
|
|
457
|
+
"@types/react-dom": "^19.0.0",
|
|
458
|
+
"bun-types": "^1.3.0",
|
|
459
|
+
typescript: "^5.5.0",
|
|
460
|
+
};
|
|
461
|
+
if (args.ui) {
|
|
462
|
+
Object.assign(
|
|
463
|
+
dependencies,
|
|
464
|
+
args.uiKind === "shadcn" ? UI_SHADCN_DEPS : UI_DEPS,
|
|
465
|
+
);
|
|
466
|
+
Object.assign(devDependencies, UI_DEV_DEPS);
|
|
467
|
+
}
|
|
468
|
+
const pkg = {
|
|
469
|
+
name,
|
|
470
|
+
version: "0.1.0",
|
|
471
|
+
private: true,
|
|
472
|
+
type: "module",
|
|
473
|
+
scripts: pkgScripts(args.ui),
|
|
474
|
+
dependencies: sorted(dependencies),
|
|
475
|
+
devDependencies: sorted(devDependencies),
|
|
476
|
+
engines: { bun: ">=1.3.0" },
|
|
477
|
+
};
|
|
478
|
+
await Bun.write(`${dir}/package.json`, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Root workspace manifest + skeleton (spec 18 §Monorepo layout).
|
|
482
|
+
async function setupMonorepoRoot(
|
|
483
|
+
targetDir: string,
|
|
484
|
+
appName: string,
|
|
485
|
+
): Promise<void> {
|
|
486
|
+
const root = {
|
|
487
|
+
name: `${appName}-monorepo`,
|
|
488
|
+
version: "0.1.0",
|
|
489
|
+
private: true,
|
|
490
|
+
type: "module",
|
|
491
|
+
workspaces: ["apps/*", "packages/*"],
|
|
492
|
+
engines: { bun: ">=1.3.0" },
|
|
493
|
+
};
|
|
494
|
+
await Bun.write(
|
|
495
|
+
`${targetDir}/package.json`,
|
|
496
|
+
`${JSON.stringify(root, null, 2)}\n`,
|
|
497
|
+
);
|
|
498
|
+
// biome.json is written here rather than shipped as a template file: a
|
|
499
|
+
// committed nested biome.json would be discovered as a conflicting root
|
|
500
|
+
// config by this repo's own Biome.
|
|
501
|
+
await Bun.write(`${targetDir}/biome.json`, `${MONOREPO_BIOME}\n`);
|
|
502
|
+
const skeleton = resolve(TEMPLATES_ROOT, "_monorepo");
|
|
503
|
+
if (existsSync(skeleton)) {
|
|
504
|
+
await Bun.$`cp -R ${skeleton}/. ${targetDir}`.quiet();
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const MONOREPO_BIOME = JSON.stringify(
|
|
509
|
+
{
|
|
510
|
+
$schema: "https://biomejs.dev/schemas/2.4.15/schema.json",
|
|
511
|
+
vcs: { enabled: true, clientKind: "git", useIgnoreFile: true },
|
|
512
|
+
formatter: { enabled: true, indentStyle: "tab" },
|
|
513
|
+
linter: { enabled: true, rules: { recommended: true } },
|
|
514
|
+
javascript: { formatter: { quoteStyle: "double" } },
|
|
515
|
+
assist: {
|
|
516
|
+
enabled: true,
|
|
517
|
+
actions: { source: { organizeImports: "on" } },
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
null,
|
|
521
|
+
2,
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
async function applyContainer(appRoot: string, name: string): Promise<void> {
|
|
525
|
+
const overlay = resolve(TEMPLATES_ROOT, "_container");
|
|
526
|
+
if (!existsSync(overlay)) return;
|
|
527
|
+
await Bun.$`cp -R ${overlay}/. ${appRoot}`.quiet();
|
|
528
|
+
// Dockerfile has no rendered extension, so interpolate {{name}} here.
|
|
529
|
+
const dockerfile = `${appRoot}/Dockerfile`;
|
|
530
|
+
if (await Bun.file(dockerfile).exists()) {
|
|
531
|
+
const text = await Bun.file(dockerfile).text();
|
|
532
|
+
await Bun.write(dockerfile, text.replaceAll("{{name}}", name));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function sorted(deps: Record<string, string>): Record<string, string> {
|
|
537
|
+
const out: Record<string, string> = {};
|
|
538
|
+
for (const k of Object.keys(deps).sort()) out[k] = deps[k] as string;
|
|
539
|
+
return out;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// container packages the bun adapter, so sordo.config keeps target "bun".
|
|
543
|
+
function configTarget(target: Target): "bun" | "edge" {
|
|
544
|
+
return target === "edge" ? "edge" : "bun";
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
async function patchSordoConfig(dir: string, args: Args): Promise<void> {
|
|
548
|
+
const path = `${dir}/sordo.config.ts`;
|
|
549
|
+
if (!(await Bun.file(path).exists())) return;
|
|
550
|
+
const current = await Bun.file(path).text();
|
|
551
|
+
let nextText = current.replace(
|
|
552
|
+
/target:\s*"(bun|edge)"/,
|
|
553
|
+
`target: "${configTarget(args.target)}"`,
|
|
554
|
+
);
|
|
555
|
+
// Point the agent manifest at the file the chosen agent already reads.
|
|
556
|
+
// Default (claude / none) leaves the framework default ("CLAUDE.md").
|
|
557
|
+
if (args.template === "codex" && !/agentsMd:/.test(nextText)) {
|
|
558
|
+
nextText = nextText.replace(
|
|
559
|
+
/target:\s*"(bun|edge)",?\n/,
|
|
560
|
+
(m) => `${m.replace(/,?\n$/, ",\n")}\tagentsMd: { path: "AGENTS.md" },\n`,
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
if (nextText !== current) await Bun.write(path, nextText);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
async function initGit(targetDir: string): Promise<string | undefined> {
|
|
567
|
+
if (!hasGit()) return "git-missing";
|
|
568
|
+
// Strip git hook env vars so these commands resolve relative to targetDir
|
|
569
|
+
// rather than inheriting GIT_DIR/GIT_INDEX_FILE from a running commit hook.
|
|
570
|
+
const gitEnv: NodeJS.ProcessEnv = { ...process.env };
|
|
571
|
+
for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE"]) {
|
|
572
|
+
delete gitEnv[key];
|
|
573
|
+
}
|
|
574
|
+
const init = await Bun.$`git init`
|
|
575
|
+
.cwd(targetDir)
|
|
576
|
+
.env(gitEnv)
|
|
577
|
+
.quiet()
|
|
578
|
+
.nothrow();
|
|
579
|
+
// Only stage/commit once `targetDir` is itself the git top-level. If
|
|
580
|
+
// `git init` failed, or the scaffold landed inside an existing repo (e.g.
|
|
581
|
+
// a git worktree), git resolves `.git` to a parent and `git add`/`commit`
|
|
582
|
+
// would clobber that outer repo. Compare the resolved top-level to be sure.
|
|
583
|
+
const top = await Bun.$`git rev-parse --show-toplevel`
|
|
584
|
+
.cwd(targetDir)
|
|
585
|
+
.env(gitEnv)
|
|
586
|
+
.quiet()
|
|
587
|
+
.nothrow();
|
|
588
|
+
// `git rev-parse` reports a symlink-resolved path; resolve `targetDir` the
|
|
589
|
+
// same way so the comparison holds on macOS (/var → /private/var).
|
|
590
|
+
const ownsRepo =
|
|
591
|
+
init.exitCode === 0 &&
|
|
592
|
+
top.exitCode === 0 &&
|
|
593
|
+
top.stdout.toString().trim() === realpathSync(targetDir);
|
|
594
|
+
if (!ownsRepo) return "git-init-failed";
|
|
595
|
+
await Bun.$`git add -A`.cwd(targetDir).env(gitEnv).quiet().nothrow();
|
|
596
|
+
await Bun.$`git commit -m ${"chore: initial commit from create-sordo"}`
|
|
597
|
+
.cwd(targetDir)
|
|
598
|
+
.env(gitEnv)
|
|
599
|
+
.quiet()
|
|
600
|
+
.nothrow();
|
|
601
|
+
return undefined;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function printNextSteps(args: Args, appName: string): void {
|
|
605
|
+
const out = (s: string) => process.stdout.write(s);
|
|
606
|
+
const devCmd = args.monorepo
|
|
607
|
+
? `bun --filter ${appName} dev`
|
|
608
|
+
: "bunx sordo dev";
|
|
609
|
+
out(`\n✓ created ${args.name}\n\n`);
|
|
610
|
+
out(` cd ${args.name}\n`);
|
|
611
|
+
if (!args.install) out(" bun install\n");
|
|
612
|
+
out(
|
|
613
|
+
` ${devCmd} → http://localhost:3000 (start the dev server)\n`,
|
|
614
|
+
);
|
|
615
|
+
if (args.ui && args.uiKind === "shadcn") {
|
|
616
|
+
out(
|
|
617
|
+
"\nshadcn/ui is set up on a hydrated page — add more with `bunx sordo add @shadcn/<name>`.\n",
|
|
618
|
+
);
|
|
619
|
+
} else if (args.ui) {
|
|
620
|
+
out("\nUI starter is set up — components live in app/components/ui/.\n");
|
|
621
|
+
}
|
|
622
|
+
if (args.template === "claude") {
|
|
623
|
+
out(
|
|
624
|
+
"\nWant to scaffold features (auth, CRM, task board, dashboard, …)?\n" +
|
|
625
|
+
"Open a NEW terminal in this project and run:\n\n" +
|
|
626
|
+
' claude --permission-mode plan "/sordo-init"\n\n' +
|
|
627
|
+
"That starts an interactive, plan-mode session that designs and\n" +
|
|
628
|
+
"scaffolds your project with you before writing any files.\n",
|
|
629
|
+
);
|
|
630
|
+
} else if (args.template === "codex") {
|
|
631
|
+
out(
|
|
632
|
+
"\nWant to scaffold features (auth, CRM, task board, dashboard, …)?\n" +
|
|
633
|
+
"Open Codex in this project and ask it to scaffold a pattern — it reads\n" +
|
|
634
|
+
".codex/rules/sordo-patterns.md for the recipes.\n",
|
|
635
|
+
);
|
|
636
|
+
} else {
|
|
637
|
+
out(
|
|
638
|
+
"\nAdd UI components with `sordo add <component>`. Feature patterns are\n" +
|
|
639
|
+
"agent-driven — re-scaffold with --agent claude or codex to get /sordo.\n",
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function stderr(msg: string): void {
|
|
645
|
+
process.stderr.write(`${msg}\n`);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function printUsage(): void {
|
|
649
|
+
process.stdout.write(`create-sordo — scaffold a new Sordo project
|
|
650
|
+
|
|
651
|
+
Usage:
|
|
652
|
+
bunx create-sordo@latest <name> [options]
|
|
653
|
+
|
|
654
|
+
Options:
|
|
655
|
+
--agent claude | codex | none (default claude)
|
|
656
|
+
--type frontend | backend | fullstack (default fullstack)
|
|
657
|
+
--ui [shadcn] | --no-ui (frontend/fullstack; default yes)
|
|
658
|
+
--ui shadcn: upstream shadcn/ui on a hydrated page
|
|
659
|
+
--monorepo | --no-monorepo (fullstack only; default no)
|
|
660
|
+
--target bun | edge | container (container = fullstack only; default bun)
|
|
661
|
+
--deploy cloudflare | vercel | deno | netlify | none (edge only)
|
|
662
|
+
--theme neutral | slate | stone | zinc (ui only, default neutral)
|
|
663
|
+
--yes, -y (accept all defaults)
|
|
664
|
+
--no-install (skip 'bun install')
|
|
665
|
+
--git (run 'git init' + initial commit)
|
|
666
|
+
|
|
667
|
+
Examples:
|
|
668
|
+
bunx create-sordo@latest my-app
|
|
669
|
+
bunx create-sordo@latest my-app --type backend
|
|
670
|
+
bunx create-sordo@latest my-app --type fullstack --monorepo --ui --theme slate
|
|
671
|
+
bunx create-sordo@latest my-app --ui shadcn
|
|
672
|
+
bunx create-sordo@latest my-app --agent codex
|
|
673
|
+
bunx create-sordo@latest my-app --agent none
|
|
674
|
+
`);
|
|
675
|
+
}
|
package/src/probes.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Tool probes for the scaffolder. See spec cli/10-scaffold-probes.
|
|
2
|
+
//
|
|
3
|
+
// `bun` is required to run the resulting project — if it is missing from PATH
|
|
4
|
+
// at scaffold time, fail before any FS writes so the user does not end up with
|
|
5
|
+
// half a project on disk.
|
|
6
|
+
// `git` is optional — if it is missing, skip the `git init` step and warn at
|
|
7
|
+
// the end of the scaffold rather than letting git fail mid-pipeline.
|
|
8
|
+
|
|
9
|
+
export interface ProbeIO {
|
|
10
|
+
stderr?: (msg: string) => void;
|
|
11
|
+
exit?: (code: number) => never;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function probeTools(io: ProbeIO = {}): void {
|
|
15
|
+
const stderr = io.stderr ?? ((m: string) => process.stderr.write(`${m}\n`));
|
|
16
|
+
const exit = io.exit ?? ((c: number) => process.exit(c) as never);
|
|
17
|
+
|
|
18
|
+
if (!Bun.which("bun")) {
|
|
19
|
+
stderr(
|
|
20
|
+
"create-sordo: `bun` not found in PATH. Install Bun from https://bun.sh and re-run.",
|
|
21
|
+
);
|
|
22
|
+
exit(1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function hasGit(): boolean {
|
|
27
|
+
return Bun.which("git") !== null;
|
|
28
|
+
}
|