create-macostack 0.6.0 → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 macobits
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,53 +1,99 @@
1
1
  # create-macostack
2
2
 
3
- Orquestador mínimo para crear ventures macostack desde templates privados.
3
+ Scaffold a production-ready full-stack app from the macostack templates — a Bun + Hono + Postgres backend and a TanStack (React) web app — with a single command.
4
4
 
5
5
  ```bash
6
- export GITHUB_TOKEN="github_pat_..." # fine-grained, Contents: Read-only
7
- bun create macostack mi-tienda
6
+ bun create macostack my-app
8
7
  ```
9
8
 
10
- Salida esperada:
9
+ An interactive wizard walks you through the rest:
11
10
 
12
- ```txt
13
- mi-tienda/
14
- server/ # repo git propio
15
- client/ # repo git propio
11
+ 1. **Pick the parts** your app needs — backend API, web app, or both.
12
+ 2. **Choose a deploy target and feature modules.** Each template declares its own questions; the CLI merges them so every feature is asked exactly once for the whole app.
13
+ 3. **Optionally prefill environment values** — your primary domain (CORS, cookie scope, and the web app's API URL) and a Resend API key for transactional email.
14
+
15
+ The CLI then downloads each template without its git history, installs dependencies, runs each template's own setup (app name, fresh secrets, module wiring), and leaves every part as its own independent git repository, ready to push.
16
+
17
+ ## Requirements
18
+
19
+ - [Bun](https://bun.sh) 1.x
20
+ - GitHub access to the template repositories (they are private by default):
21
+
22
+ ```bash
23
+ gh auth login
24
+ # or
25
+ export GITHUB_TOKEN=github_pat_… # fine-grained token, Contents: Read-only
16
26
  ```
17
27
 
18
- La raíz no se inicializa como git. El CLI descarga tarballs privados, instala con
19
- `bun install`, delega `bun run setup` cuando existe, y asegura un repo git por
20
- mitad si el setup no lo creó.
28
+ Access is verified before anything is written to disk a typo'd repo or missing permission fails cleanly, with no half-created folders.
21
29
 
22
- ## Desarrollo local
30
+ ## Usage
23
31
 
24
32
  ```bash
25
- bun install
26
- bun run dev mi-tienda
33
+ bun create macostack my-app # scaffold into ./my-app
34
+ bun create macostack . # scaffold into the current (empty) directory
27
35
  ```
28
36
 
29
- ## Configuración
37
+ Result:
30
38
 
31
- Defaults:
39
+ ```txt
40
+ my-app/
41
+ ├── server/ # Bun + Hono + Postgres API — its own git repo
42
+ └── client/ # TanStack web app — its own git repo
43
+ ```
32
44
 
33
- - owner: `macobits`
34
- - server repo: `macostack-server`
35
- - client repo: `macostack-client`
36
- - ref: `main`
45
+ The root folder is intentionally **not** a git repository: server and client are designed to live and deploy as separate repos.
37
46
 
38
- Flags útiles:
47
+ ### Managing an existing app
48
+
49
+ Run the CLI again inside an app it created to add the missing part or toggle feature modules on and off — it detects the existing setup and switches to manage mode:
39
50
 
40
51
  ```bash
41
- bun run dev mi-tienda --owner macobits --ref main
42
- bun run dev mi-api --server --skip-setup
43
- bun run dev mi-web --client --skip-install
52
+ cd my-app
53
+ bun create macostack .
44
54
  ```
45
55
 
46
- También puedes usar env vars:
56
+ ### Flags
57
+
58
+ | Flag | Description |
59
+ | --- | --- |
60
+ | `--server` / `--client` | Scaffold only that part (default: interactive) |
61
+ | `--yes` | Non-interactive: both parts, template defaults |
62
+ | `--owner <org>` | GitHub owner of the template repos (default: `macobits`) |
63
+ | `--ref <ref>` | Branch or tag to download (default: `main`) |
64
+ | `--server-repo <name>` | Server template repo (default: `macostack-server`) |
65
+ | `--client-repo <name>` | Client template repo (default: `macostack-client`) |
66
+ | `--skip-install` | Skip `bun install` |
67
+ | `--skip-setup` | Skip each template's setup wizard |
68
+ | `--help` | Print usage |
69
+
70
+ ### Environment variables
71
+
72
+ | Variable | Description |
73
+ | --- | --- |
74
+ | `GITHUB_TOKEN` / `GH_TOKEN` | Token used to download the templates (falls back to `gh auth token`) |
75
+ | `MACOSTACK_GITHUB_OWNER` | Default template owner |
76
+ | `MACOSTACK_SERVER_REPO` | Default server template repo |
77
+ | `MACOSTACK_CLIENT_REPO` | Default client template repo |
78
+ | `MACOSTACK_REF` | Default branch or tag |
79
+
80
+ ## Bring your own templates
81
+
82
+ The orchestrator is deliberately template-agnostic: it never hardcodes which features exist. Point `--owner`, `--server-repo`, and `--client-repo` at your own repositories, and expose a `setup` script in each template's `package.json`:
83
+
84
+ - `bun run setup --questions` prints a JSON spec of the questions the template supports (feature modules, optional deploy target).
85
+ - `bun run setup --yes --name <app> [--modules a,b] [--runtime x] [--domain d]` applies the answers.
86
+
87
+ Anything the template declares, the CLI renders — nothing more.
88
+
89
+ ## Development
47
90
 
48
91
  ```bash
49
- MACOSTACK_GITHUB_OWNER=macobits
50
- MACOSTACK_SERVER_REPO=macostack-server
51
- MACOSTACK_CLIENT_REPO=macostack-client
52
- GITHUB_TOKEN=github_pat_...
92
+ bun install
93
+ bun run dev my-app --skip-install # run the CLI from source
94
+ bun run typecheck
53
95
  ```
96
+
97
+ ## License
98
+
99
+ [MIT](./LICENSE) © macobits
@@ -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
  //////////////////////////////////////////////////////////////////
@@ -187,7 +302,7 @@ if (scaffoldHere) {
187
302
  }
188
303
  } else if (positional) {
189
304
  if (!validName(positional)) {
190
- bail("App names use lowercase letters, digits and dashes — e.g. soccer-app");
305
+ bail("App names use lowercase letters, digits and dashes — e.g. my-app");
191
306
  }
192
307
  appName = positional;
193
308
  } else if (flags.yes) {
@@ -197,9 +312,9 @@ if (scaffoldHere) {
197
312
  appName = answered(
198
313
  await text({
199
314
  message: "What should we call your app?",
200
- placeholder: "soccer-app",
315
+ placeholder: "my-app",
201
316
  validate: (v) =>
202
- validName(v ?? "") ? undefined : "lowercase letters, digits and dashes — e.g. soccer-app",
317
+ validName(v ?? "") ? undefined : "lowercase letters, digits and dashes — e.g. my-app",
203
318
  }),
204
319
  );
205
320
  }
@@ -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,7 +1,22 @@
1
1
  {
2
2
  "name": "create-macostack",
3
- "version": "0.6.0",
4
- "description": "Private macostack scaffold orchestrator for detached server/client repos.",
3
+ "version": "0.6.2",
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
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/macobits/create-macostack.git"
9
+ },
10
+ "keywords": [
11
+ "create",
12
+ "scaffold",
13
+ "template",
14
+ "bun",
15
+ "hono",
16
+ "tanstack",
17
+ "fullstack",
18
+ "macostack"
19
+ ],
5
20
  "type": "module",
6
21
  "bin": {
7
22
  "create-macostack": "./bin/create-macostack.ts"
@@ -23,6 +38,6 @@
23
38
  },
24
39
  "devDependencies": {
25
40
  "@types/bun": "^1.3.14",
26
- "typescript": "^6.0.3"
41
+ "typescript": "^7.0.2"
27
42
  }
28
43
  }