create-apollo-monorepo 0.9.0 → 0.9.1
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/index.mjs +105 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -399,7 +399,13 @@ function writeRootPackageJson(targetDir, dirName) {
|
|
|
399
399
|
"cms-plugin:new": "node scripts/new-cms-plugin.mjs",
|
|
400
400
|
lint: "pnpm -r lint",
|
|
401
401
|
typecheck: "pnpm -r typecheck",
|
|
402
|
-
|
|
402
|
+
// Stash any local changes inside the submodule so the fast-forward
|
|
403
|
+
// merge can't conflict, then update, then run `pnpm install` at the
|
|
404
|
+
// root so workspace deps pick up any package.json changes pulled in
|
|
405
|
+
// from the new apollo-cms commit. The stash is restored if it was
|
|
406
|
+
// created; otherwise this is a no-op.
|
|
407
|
+
"backend:update":
|
|
408
|
+
"node -e \"const {execSync:e}=require('child_process');const r=s=>e(s,{stdio:'inherit'});const has=e('git -C apps/backend status --porcelain',{encoding:'utf8'}).trim().length>0;if(has)r('git -C apps/backend stash push -u -m backend-update-auto');r('git submodule update --remote --merge apps/backend');r('pnpm install');if(has){try{r('git -C apps/backend stash pop');}catch(_){console.error('[backend:update] stash pop had conflicts — resolve manually with: git -C apps/backend stash list');}}\"",
|
|
403
409
|
// `pnpm setup` is pnpm's CLI bootstrap built-in — must use `run` to
|
|
404
410
|
// forward to the workspace's setup script (apollo-cms's db:push + db:seed).
|
|
405
411
|
"backend:setup": "pnpm --filter ./apps/backend run setup",
|
|
@@ -1383,6 +1389,100 @@ module.exports = {
|
|
|
1383
1389
|
writeFileSync(resolve(targetDir, "ecosystem.config.cjs"), config);
|
|
1384
1390
|
}
|
|
1385
1391
|
|
|
1392
|
+
function writeClaudeMd(targetDir, adminPrefix) {
|
|
1393
|
+
const singleOrigin = !!adminPrefix;
|
|
1394
|
+
const prefix = adminPrefix || "/admin";
|
|
1395
|
+
const singleOriginSection = singleOrigin
|
|
1396
|
+
? `## Single-origin routing
|
|
1397
|
+
|
|
1398
|
+
Frontend is the public entry point. It rewrites these paths to the backend (do **not** create matching routes in the frontend):
|
|
1399
|
+
|
|
1400
|
+
- \`/admin/*\`, \`/uploads/*\`
|
|
1401
|
+
- \`/api/auth/*\`, \`/api/v1/*\`, \`/api/email/*\`, \`/api/cron\`, \`/api/health\`, \`/api/mcp\`, \`/api/admin/*\`, \`/api/editing-presence/*\`
|
|
1402
|
+
- \`/_next/static\` under \`APOLLO_ASSET_PREFIX=${prefix}\` (backend chunks)
|
|
1403
|
+
|
|
1404
|
+
Custom frontend APIs must be namespaced (e.g. \`/api/internal/*\`).
|
|
1405
|
+
|
|
1406
|
+
To disable single-origin: remove \`APOLLO_ASSET_PREFIX\` from \`apps/backend/.env.local\` and delete the \`rewrites()\` block in \`apps/frontend/next.config.ts\`.
|
|
1407
|
+
|
|
1408
|
+
Known gotcha: backend's \`/_next/image\` is not rewritten — custom admin code using \`<Image>\` on \`/uploads/*\` will 404. Use plain \`<img>\` or \`unoptimized\`.
|
|
1409
|
+
`
|
|
1410
|
+
: `## Routing model — separate origins
|
|
1411
|
+
|
|
1412
|
+
Frontend and backend run on independent origins. No rewrites; talk to the backend over its public URL.
|
|
1413
|
+
`;
|
|
1414
|
+
|
|
1415
|
+
const content = `# CLAUDE.md
|
|
1416
|
+
|
|
1417
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
1418
|
+
|
|
1419
|
+
## Repo shape
|
|
1420
|
+
|
|
1421
|
+
pnpm workspace monorepo. Three workspaces under \`apps/\`:
|
|
1422
|
+
|
|
1423
|
+
- \`apps/frontend\` — public Next.js site${singleOrigin ? " (the public origin in single-origin mode)" : ""}.
|
|
1424
|
+
- \`apps/backend\` — **git submodule** pointing at \`apollo-cms\`. Treat as read-only; do not edit files in here. Open PRs upstream.
|
|
1425
|
+
- \`apps/cms-plugins/<slug>\` — project-specific Apollo CMS plugins. Loaded by the backend via \`APOLLO_EXTRA_PLUGINS_DIR=../cms-plugins\`. Each plugin is built with esbuild to \`dist/server.mjs\` before the backend builds.
|
|
1426
|
+
- \`apps/proxy/server.mjs\` — zero-dep Node reverse proxy used for single-origin dev and self-hosted deploys.
|
|
1427
|
+
|
|
1428
|
+
Built-in plugins in \`apps/backend/plugins/\` always win on slug collisions with \`apps/cms-plugins/\`.
|
|
1429
|
+
|
|
1430
|
+
${singleOriginSection}
|
|
1431
|
+
## Common commands
|
|
1432
|
+
|
|
1433
|
+
\`\`\`bash
|
|
1434
|
+
pnpm install
|
|
1435
|
+
pnpm backend:setup # first-time: db:push + db:seed
|
|
1436
|
+
pnpm backend:upgrade # release-time: db:push + replay src/upgrades/0.1.*.ts + seed
|
|
1437
|
+
pnpm backend:update # fast-forward the apollo-cms submodule
|
|
1438
|
+
|
|
1439
|
+
pnpm dev # FE + BE + plugin watcher (parallel)
|
|
1440
|
+
pnpm dev:rp # same + reverse proxy on :3030 (single origin, shared cookies)
|
|
1441
|
+
pnpm dev:frontend # FE only
|
|
1442
|
+
pnpm dev:backend # BE only (runs predev:setup to build plugins first)
|
|
1443
|
+
|
|
1444
|
+
pnpm build # cms-plugins → backend plugins → backend → frontend
|
|
1445
|
+
pnpm build:backend
|
|
1446
|
+
pnpm build:frontend
|
|
1447
|
+
|
|
1448
|
+
pnpm start # FE + BE
|
|
1449
|
+
pnpm start:rp # FE + BE + proxy
|
|
1450
|
+
|
|
1451
|
+
pnpm lint # recursive
|
|
1452
|
+
pnpm typecheck # recursive
|
|
1453
|
+
|
|
1454
|
+
pnpm cms-plugin:new <slug> # scaffold a new plugin from example-plugin
|
|
1455
|
+
\`\`\`
|
|
1456
|
+
|
|
1457
|
+
\`pnpm dev\` and \`pnpm build\` both run \`cms-plugins:build\` first (via \`predev:setup\` / build script chain) — plugins must compile to \`dist/server.mjs\` before the backend resolves them in production. In dev under Bun the loader also accepts \`index.ts\` directly.
|
|
1458
|
+
|
|
1459
|
+
Release flow on a server: \`pnpm install && pnpm backend:upgrade && pnpm build && pm2 reload all\`. \`pnpm start\` does **not** run migrations.
|
|
1460
|
+
|
|
1461
|
+
## Ports
|
|
1462
|
+
|
|
1463
|
+
Configured in \`ecosystem.config.cjs\` (PM2) and consumed by \`apps/proxy/server.mjs\` via env:
|
|
1464
|
+
|
|
1465
|
+
| Service | Port |
|
|
1466
|
+
| -------- | ---- |
|
|
1467
|
+
| proxy | 3030 |
|
|
1468
|
+
| backend | 3000 |
|
|
1469
|
+
| frontend | 3001 |
|
|
1470
|
+
|
|
1471
|
+
Proxy reads \`PORT\`, \`BACKEND\`, \`FRONTEND\`, \`ADMIN_PREFIX\` from env. When using the proxy locally, set \`NEXT_PUBLIC_SITE_URL=http://localhost:3030\` so Better Auth / OAuth callbacks land on the unified origin.
|
|
1472
|
+
|
|
1473
|
+
## Deploy
|
|
1474
|
+
|
|
1475
|
+
- Self-hosted: build on a runner, rsync to the server, then \`pm2 startOrReload ecosystem.config.cjs --update-env\`. If the backend submodule is private, the deploy runner needs a token with read access.
|
|
1476
|
+
- Vercel: two projects per repo (\`apps/backend\` and \`apps/frontend\` root dirs). Backend's Build Command must copy \`apps/cms-plugins/*/dist\` into \`apps/backend/plugins/\` before \`next build\` because Turbopack rejects \`outputFileTracingIncludes\` globs above the project root. "Include all submodules" must be ON in both projects.
|
|
1477
|
+
|
|
1478
|
+
## Submodule discipline
|
|
1479
|
+
|
|
1480
|
+
- Do not edit files under \`apps/backend\` — they belong to the upstream \`apollo-cms\` repo.
|
|
1481
|
+
- After \`pnpm backend:update\`, run \`pnpm install\` (in case package.json changed) then \`pnpm backend:upgrade\` (replays data migrations that \`backend:setup\` skips).
|
|
1482
|
+
`;
|
|
1483
|
+
writeFileSync(resolve(targetDir, "CLAUDE.md"), content);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1386
1486
|
function writeReadme(targetDir, dirName, frontendName, adminPrefix) {
|
|
1387
1487
|
const singleOrigin = !!adminPrefix;
|
|
1388
1488
|
|
|
@@ -1511,14 +1611,13 @@ folder + \`plugin.json#name\`.
|
|
|
1511
1611
|
Apollo CMS is tracked as a git submodule. Full upgrade flow:
|
|
1512
1612
|
|
|
1513
1613
|
\`\`\`bash
|
|
1514
|
-
pnpm backend:update # fast-forward apps/backend
|
|
1515
|
-
pnpm install # in case the submodule changed package.json
|
|
1614
|
+
pnpm backend:update # auto-stash, fast-forward apps/backend, run pnpm install
|
|
1516
1615
|
pnpm backend:upgrade # drizzle push + replay version migrations + seed
|
|
1517
1616
|
\`\`\`
|
|
1518
1617
|
|
|
1519
1618
|
| Script | What it does |
|
|
1520
1619
|
| --- | --- |
|
|
1521
|
-
| \`pnpm backend:update\` |
|
|
1620
|
+
| \`pnpm backend:update\` | Auto-stashes local submodule changes, fast-forwards \`apps/backend\`, runs \`pnpm install\` so new backend deps are picked up, then restores the stash. |
|
|
1522
1621
|
| \`pnpm backend:setup\` | First-time bootstrap: \`db:push\` + \`db:seed\` only |
|
|
1523
1622
|
| \`pnpm backend:upgrade\` | Full pipeline: \`db:push\` + replay \`src/upgrades/0.1.*.ts\` data migrations + \`db:seed\`. **Use this** after \`backend:update\` — \`backend:setup\` skips the data-migration phase. |
|
|
1524
1623
|
|
|
@@ -1691,12 +1790,13 @@ async function main() {
|
|
|
1691
1790
|
writeRootGitignore(targetDir);
|
|
1692
1791
|
writeRootEnv(targetDir, { dbUrl, siteUrl, locale, authSecret, cronSecret, adminPrefix, backendInternalUrl });
|
|
1693
1792
|
writeReadme(targetDir, dirName, frontendName, adminPrefix);
|
|
1793
|
+
writeClaudeMd(targetDir, adminPrefix);
|
|
1694
1794
|
if (adminPrefix) writeNginxSample(targetDir, adminPrefix);
|
|
1695
1795
|
writeProxyApp(targetDir, dirName, adminPrefix);
|
|
1696
1796
|
writeCheckEnvScript(targetDir);
|
|
1697
1797
|
writePm2Config(targetDir, dirName, adminPrefix);
|
|
1698
1798
|
success(
|
|
1699
|
-
`package.json, pnpm-workspace.yaml, .gitignore, .env.local, README.md${
|
|
1799
|
+
`package.json, pnpm-workspace.yaml, .gitignore, .env.local, README.md, CLAUDE.md${
|
|
1700
1800
|
adminPrefix ? ", nginx.conf.sample" : ""
|
|
1701
1801
|
}, apps/proxy, ecosystem.config.cjs, scripts/check-env.mjs`,
|
|
1702
1802
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-apollo-monorepo",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Scaffold a monorepo with a frontend app and Apollo CMS as a git submodule backend (single-origin via Next.js rewrites + assetPrefix)",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-apollo-monorepo": "index.mjs"
|