create-macostack 0.6.1 → 0.6.2

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.
@@ -15,7 +15,9 @@ import {
15
15
  mkdirSync,
16
16
  mkdtempSync,
17
17
  readdirSync,
18
+ readFileSync,
18
19
  rmSync,
20
+ writeFileSync,
19
21
  } from "node:fs";
20
22
  import { tmpdir } from "node:os";
21
23
  import { basename, join, resolve } from "node:path";
@@ -80,6 +82,11 @@ const PARTS: Part[] = [
80
82
  },
81
83
  ];
82
84
 
85
+ // The docs system: AGENTS.md + docs/ + slash commands for Claude Code and
86
+ // OpenCode. Lands at the WORKSPACE ROOT (not inside a part) and becomes its own
87
+ // git repo — its .gitignore excludes client/ and server/.
88
+ const DOCS_REPO = Bun.env.MACOSTACK_DOCS_REPO ?? "macostack-docs";
89
+
83
90
  //////////////////////////////////////////////////////////////////
84
91
  // FLAGS
85
92
  //////////////////////////////////////////////////////////////////
@@ -96,8 +103,10 @@ const parsed = parseArgs({
96
103
  ref: { type: "string" },
97
104
  "server-repo": { type: "string" },
98
105
  "client-repo": { type: "string" },
106
+ "docs-repo": { type: "string" },
99
107
  "skip-install": { type: "boolean", default: false },
100
108
  "skip-setup": { type: "boolean", default: false },
109
+ "skip-docs": { type: "boolean", default: false },
101
110
  },
102
111
  });
103
112
  const flags = parsed.values;
@@ -116,8 +125,10 @@ Flags:
116
125
  --ref <ref> branch or tag to pull (default: ${DEFAULT_REF})
117
126
  --server-repo <name> server template repo
118
127
  --client-repo <name> client template repo
128
+ --docs-repo <name> docs system repo (default: ${DOCS_REPO})
119
129
  --skip-install don't run bun install
120
130
  --skip-setup don't run each template's setup wizard
131
+ --skip-docs don't scaffold the docs system (AGENTS.md + docs/)
121
132
 
122
133
  Auth (templates are private):
123
134
  export GITHUB_TOKEN=github_pat_… or gh auth login
@@ -155,6 +166,110 @@ const isEmptyDir = (dir: string) =>
155
166
  !existsSync(dir) ||
156
167
  readdirSync(dir).filter((e) => e !== ".DS_Store").length === 0;
157
168
 
169
+ const ghFetch = (token: string, path: string) =>
170
+ fetch(`https://api.github.com${path}`, {
171
+ headers: {
172
+ Accept: "application/vnd.github+json",
173
+ Authorization: `Bearer ${token}`,
174
+ "User-Agent": "create-macostack",
175
+ "X-GitHub-Api-Version": "2022-11-28",
176
+ },
177
+ });
178
+
179
+ // Download a repo tarball (no git history) and unpack it into dest.
180
+ // Returns an error message, or null on success.
181
+ const downloadInto = async (
182
+ token: string,
183
+ ownerName: string,
184
+ repo: string,
185
+ refName: string,
186
+ dest: string,
187
+ ): Promise<string | null> => {
188
+ const tmp = mkdtempSync(join(tmpdir(), "create-macostack-"));
189
+ try {
190
+ const res = await ghFetch(token, `/repos/${ownerName}/${repo}/tarball/${refName}`);
191
+ if (!res.ok) return `GitHub refused the download (HTTP ${res.status})`;
192
+ const archive = join(tmp, "template.tar.gz");
193
+ await Bun.write(archive, await res.arrayBuffer());
194
+ mkdirSync(dest, { recursive: true });
195
+ const tar = Bun.spawnSync(
196
+ ["tar", "-xzf", archive, "-C", dest, "--strip-components=1"],
197
+ { stdout: "pipe", stderr: "pipe" },
198
+ );
199
+ if (tar.exitCode !== 0) return `couldn't unpack: ${tar.stderr.toString().slice(0, 200)}`;
200
+ return null;
201
+ } finally {
202
+ rmSync(tmp, { recursive: true, force: true });
203
+ }
204
+ };
205
+
206
+ // Bring the docs system into the workspace root: AGENTS.md, docs/, and the
207
+ // /spec /design /tasks /implement /review commands for BOTH agents. Stamps the
208
+ // placeholders and turns the root into its own git repo (its .gitignore
209
+ // excludes client/ and server/ — each part stays an independent repo).
210
+ const scaffoldDocs = async (
211
+ token: string,
212
+ root: string,
213
+ name: string,
214
+ modules: string[] | null,
215
+ ): Promise<boolean> => {
216
+ const docsOwner = flags.owner ?? DEFAULT_OWNER;
217
+ const docsRef = flags.ref ?? DEFAULT_REF;
218
+ const docsRepo = flags["docs-repo"] ?? DOCS_REPO;
219
+ const s = spinner();
220
+ s.start(`Docs — downloading ${docsOwner}/${docsRepo}@${docsRef}`);
221
+ const err = await downloadInto(token, docsOwner, docsRepo, docsRef, root);
222
+ if (err) {
223
+ s.stop("Docs — download failed");
224
+ note(
225
+ `The app itself is fine — only the docs system is missing (${err}).\n` +
226
+ " Add it later by running me again in this folder.",
227
+ "Heads up",
228
+ );
229
+ return false;
230
+ }
231
+
232
+ const stamp = (rel: string, replacements: Record<string, string>) => {
233
+ const p = resolve(root, rel);
234
+ if (!existsSync(p)) return;
235
+ let txt = readFileSync(p, "utf8");
236
+ for (const [k, v] of Object.entries(replacements)) txt = txt.replaceAll(k, v);
237
+ writeFileSync(p, txt);
238
+ };
239
+ const modulesText =
240
+ modules && modules.length > 0
241
+ ? modules.map((m) => `- ${m}`).join("\n")
242
+ : "Configuración por defecto del template.";
243
+ stamp("README.md", { "{{APP_NAME}}": name });
244
+ stamp("docs/PRODUCT.md", { "{{APP_NAME}}": name });
245
+ stamp("docs/ARCHITECTURE.md", { "{{MODULES}}": modulesText });
246
+
247
+ // The workspace root becomes its own repo: docs + orchestration, versioned.
248
+ if (!existsSync(resolve(root, ".git"))) {
249
+ Bun.spawnSync(["git", "init", "-b", "main"], { cwd: root, stdout: "pipe", stderr: "pipe" });
250
+ Bun.spawnSync(["git", "add", "-A"], { cwd: root, stdout: "pipe", stderr: "pipe" });
251
+ Bun.spawnSync(["git", "commit", "-m", "init: docs workspace"], { cwd: root, stdout: "pipe", stderr: "pipe" });
252
+ }
253
+ s.stop("Docs — AGENTS.md + docs/ + slash commands ready (Claude Code & OpenCode)");
254
+ return true;
255
+ };
256
+
257
+ // Scaffold docs/features/<name>/ from the _template folder (SPEC → DESIGN →
258
+ // TASKS). Returns an error message, or null on success.
259
+ const scaffoldFeature = (root: string, feature: string): string | null => {
260
+ const templateDir = resolve(root, "docs", "features", "_template");
261
+ const dest = resolve(root, "docs", "features", feature);
262
+ if (!existsSync(templateDir))
263
+ return "docs/features/_template is missing — add the docs system first.";
264
+ if (existsSync(dest)) return `docs/features/${feature} already exists.`;
265
+ mkdirSync(dest, { recursive: true });
266
+ for (const f of readdirSync(templateDir)) {
267
+ const txt = readFileSync(join(templateDir, f), "utf8").replaceAll("<nombre>", feature);
268
+ writeFileSync(join(dest, f), txt);
269
+ }
270
+ return null;
271
+ };
272
+
158
273
  //////////////////////////////////////////////////////////////////
159
274
  // WIZARD
160
275
  //////////////////////////////////////////////////////////////////
@@ -271,10 +386,16 @@ if (present.length > 0) {
271
386
  bail(`${displayRoot} already has macostack in it — run me without --yes to manage it.`);
272
387
  }
273
388
  const missing = PARTS.filter((p) => !present.includes(p));
274
- const stateLine = PARTS.map((p) => `${p.label}: ${present.includes(p) ? "✓ installed" : "— not yet"}`).join(" ");
389
+ const hasDocs = existsSync(resolve(targetRoot, "AGENTS.md"));
390
+ const stateLine =
391
+ PARTS.map((p) => `${p.label}: ${present.includes(p) ? "✓ installed" : "— not yet"}`).join(" ") +
392
+ ` Docs: ${hasDocs ? "✓ installed" : "— not yet"}`;
275
393
  note(stateLine, "You already have macostack here");
276
394
 
277
395
  const actions = [
396
+ ...(hasDocs
397
+ ? [{ value: "feature", label: "Start a new feature", hint: "SPEC → DESIGN → TASKS in docs/features/" }]
398
+ : [{ value: "docs", label: "Add the docs system", hint: "AGENTS.md + docs/ + /spec /design /tasks commands" }]),
278
399
  ...missing.map((p) => ({ value: `add:${p.id}`, label: `Add the ${p.label.toLowerCase()}`, hint: p.hint })),
279
400
  ...present.map((p) => ({ value: `adjust:${p.id}`, label: `Adjust ${p.label.toLowerCase()} modules`, hint: "turn things on or off" })),
280
401
  { value: "exit", label: "Nothing — just looking", hint: "leaves everything untouched" },
@@ -287,6 +408,44 @@ if (present.length > 0) {
287
408
  outro("All good — nothing was touched. 👋");
288
409
  process.exit(0);
289
410
  }
411
+ if (action === "feature") {
412
+ const feature = answered(
413
+ await text({
414
+ message: "Feature name?",
415
+ placeholder: "member-invites",
416
+ validate: (v) =>
417
+ validName(v ?? "") ? undefined : "lowercase letters, digits and dashes — e.g. member-invites",
418
+ }),
419
+ );
420
+ const err = scaffoldFeature(targetRoot, feature);
421
+ if (err) bail(err);
422
+ note(
423
+ `docs/features/${feature}/ created (SPEC, DESIGN, TASKS).\nNext: open your agent here and run /spec ${feature}`,
424
+ "Feature",
425
+ );
426
+ outro(`${appName} — ready to spec ✨`);
427
+ process.exit(0);
428
+ }
429
+ if (action === "docs") {
430
+ const docsToken = githubToken();
431
+ if (!docsToken) {
432
+ bail(
433
+ "I need GitHub access to download the docs system (the repo is private).\n" +
434
+ " Easiest: gh auth login\n" +
435
+ " Or: export GITHUB_TOKEN=github_pat_… (Contents: Read-only)",
436
+ );
437
+ throw ""; // unreachable
438
+ }
439
+ const ok = await scaffoldDocs(docsToken, targetRoot, appName, null);
440
+ if (ok) {
441
+ note(
442
+ `Open Claude Code or OpenCode in ${displayRoot}/ — it reads AGENTS.md.\nFirst: fill docs/PRODUCT.md, then /spec your-first-feature`,
443
+ "Next",
444
+ );
445
+ }
446
+ outro(`${appName} is up to date ✨`);
447
+ process.exit(0);
448
+ }
290
449
  const [verb, partId] = (action as string).split(":");
291
450
  const part = PARTS.find((p) => p.id === partId)!;
292
451
  if (verb === "adjust") {
@@ -340,15 +499,7 @@ for (const p of selected) {
340
499
 
341
500
  // Preflight every selected template so a typo'd repo or missing access fails
342
501
  // BEFORE any folders exist.
343
- const gh = (path: string) =>
344
- fetch(`https://api.github.com${path}`, {
345
- headers: {
346
- Accept: "application/vnd.github+json",
347
- Authorization: `Bearer ${token}`,
348
- "User-Agent": "create-macostack",
349
- "X-GitHub-Api-Version": "2022-11-28",
350
- },
351
- });
502
+ const gh = (path: string) => ghFetch(token, path);
352
503
  for (const p of selected) {
353
504
  const res = await gh(`/repos/${owner}/${p.repo}`);
354
505
  if (!res.ok) {
@@ -371,26 +522,10 @@ for (const p of selected) {
371
522
  const dest = resolve(targetRoot, p.folder);
372
523
  const s = spinner();
373
524
  s.start(`${p.label} — downloading ${owner}/${p.repo}@${ref}`);
374
- const tmp = mkdtempSync(join(tmpdir(), "create-macostack-"));
375
- try {
376
- const res = await gh(`/repos/${owner}/${p.repo}/tarball/${ref}`);
377
- if (!res.ok) {
378
- s.stop(`${p.label} — download failed`);
379
- bail(`GitHub refused the download (HTTP ${res.status}). Try again, or check --ref ${ref}.`);
380
- }
381
- const archive = join(tmp, "template.tar.gz");
382
- await Bun.write(archive, await res.arrayBuffer());
383
- mkdirSync(dest, { recursive: true });
384
- const tar = Bun.spawnSync(
385
- ["tar", "-xzf", archive, "-C", dest, "--strip-components=1"],
386
- { stdout: "pipe", stderr: "pipe" },
387
- );
388
- if (tar.exitCode !== 0) {
389
- s.stop(`${p.label} — extract failed`);
390
- bail(`Couldn't unpack the template: ${tar.stderr.toString().slice(0, 200)}`);
391
- }
392
- } finally {
393
- rmSync(tmp, { recursive: true, force: true });
525
+ const err = await downloadInto(token, owner, p.repo, ref, dest);
526
+ if (err) {
527
+ s.stop(`${p.label} — download failed`);
528
+ bail(`${err}. Try again, or check --ref ${ref}.`);
394
529
  }
395
530
  s.stop(`${p.label} — downloaded into ${displayRoot}/${p.folder}`);
396
531
 
@@ -568,6 +703,14 @@ for (const s of setups) {
568
703
  ready.push(p);
569
704
  }
570
705
 
706
+ // Phase 4 — the docs system: AGENTS.md + docs/ + slash commands for Claude
707
+ // Code and OpenCode, stamped with this app's choices. The root becomes the
708
+ // workspace repo (docs + orchestration; client/ and server/ stay independent).
709
+ let docsReady = existsSync(resolve(targetRoot, "AGENTS.md"));
710
+ if (!flags["skip-docs"] && !docsReady) {
711
+ docsReady = await scaffoldDocs(token, targetRoot, appName, chosenModules);
712
+ }
713
+
571
714
  //////////////////////////////////////////////////////////////////
572
715
  // DONE
573
716
  //////////////////////////////////////////////////////////////////
@@ -583,6 +726,11 @@ if (server) {
583
726
  if (client) {
584
727
  steps.push(`Start the web app:\n cd ${displayRoot}/client\n bun dev`);
585
728
  }
729
+ if (docsReady) {
730
+ steps.push(
731
+ `Define the product:\n open Claude Code or OpenCode in ${displayRoot}/ — they read AGENTS.md\n first session: fill docs/PRODUCT.md, then /spec <your-first-feature>`,
732
+ );
733
+ }
586
734
  steps.push(
587
735
  `When you're ready to publish (each part is its own repo):\n` +
588
736
  ready
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-macostack",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Scaffold a production-ready full-stack app from the macostack templates: Bun + Hono + Postgres backend and TanStack web app, each as its own git repo.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,6 +38,6 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3.14",
41
- "typescript": "^6.0.3"
41
+ "typescript": "^7.0.2"
42
42
  }
43
43
  }