create-apollo-suite-monorepo 1.0.869 → 1.0.870
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/README.md +52 -0
- package/app-selection.mjs +129 -0
- package/index.mjs +157 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ subdomains (e.g. `cms.example.com` + `example.com`).
|
|
|
81
81
|
| `-u, --url <url>` | `:3001` single-origin / `:3000` separate | `NEXT_PUBLIC_SITE_URL` |
|
|
82
82
|
| `-l, --locale <code>` | `en` | `NEXT_PUBLIC_DEFAULT_LOCALE` |
|
|
83
83
|
| `--admin-prefix <path>` | `/admin` | Single-origin admin/asset namespace; `none` to disable. Alias: `--asset-prefix` |
|
|
84
|
+
| `--apps <slug,slug>` | _(asked)_ | Suite apps to install besides the mandatory ones; `""` for mandatory only. See [Suite apps](#suite-apps) |
|
|
84
85
|
| `--skip-install` | off | Don't run `pnpm install` |
|
|
85
86
|
| `--skip-submodule` | off | Don't add the git submodule |
|
|
86
87
|
| `-h, --help` | — | Show help |
|
|
@@ -98,6 +99,34 @@ the rewrite proxies to the backend and Better Auth's cookies/origins line up
|
|
|
98
99
|
because `NEXT_PUBLIC_SITE_URL` and the backend's `trustedProxyHeaders` are wired
|
|
99
100
|
to the public origin.
|
|
100
101
|
|
|
102
|
+
## Suite apps
|
|
103
|
+
|
|
104
|
+
The scaffold writes `apollo.apps.json` at the project root: the suite apps the
|
|
105
|
+
project installs besides the mandatory ones. An app that is not listed gets no
|
|
106
|
+
tables, no screens and no jobs.
|
|
107
|
+
|
|
108
|
+
- **`--apps <slug,slug>`** — written as given, after checking it against the
|
|
109
|
+
backend that was just cloned: every slug must be an app there, and every app
|
|
110
|
+
it requires must be listed too. A missing required app is an error, never
|
|
111
|
+
added for you.
|
|
112
|
+
- **No `--apps`, in a terminal** — the installer lists the apps in the cloned
|
|
113
|
+
backend (read from its `apps/*/plugin.json`, never a list inside the
|
|
114
|
+
installer) and asks.
|
|
115
|
+
- **No `--apps`, not a terminal, or `--skip-submodule`** — mandatory apps only.
|
|
116
|
+
|
|
117
|
+
`.env.local` gets `APOLLO_APPS_FILE=../../apollo.apps.json` (resolved against
|
|
118
|
+
`apps/backend`), and the root `package.json` gets an `apl` script:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pnpm apl apps # every app and its state
|
|
122
|
+
pnpm apl install <slug...> # add apps — runs the upgrade that creates their tables
|
|
123
|
+
pnpm apl uninstall <slug> # leave an app out — its tables and data are kept
|
|
124
|
+
pnpm apl doctor # do the file, the apps and the database agree?
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Before the database has been set up once, edit the list by hand and run
|
|
128
|
+
`pnpm backend:setup`; `apl install` needs the tables setup creates.
|
|
129
|
+
|
|
101
130
|
## Updating the backend
|
|
102
131
|
|
|
103
132
|
```bash
|
|
@@ -142,6 +171,29 @@ packages:
|
|
|
142
171
|
|
|
143
172
|
then re-run `pnpm install`.
|
|
144
173
|
|
|
174
|
+
### Scaffolds created before `--apps`
|
|
175
|
+
|
|
176
|
+
They keep working unchanged: with no `apollo.apps.json` and no
|
|
177
|
+
`APOLLO_APPS_FILE`, the backend installs every app. To choose apps in one of
|
|
178
|
+
them, after `pnpm backend:update` has brought in a backend with
|
|
179
|
+
`scripts/apl.ts`:
|
|
180
|
+
|
|
181
|
+
1. Add the script to the root `package.json`:
|
|
182
|
+
|
|
183
|
+
```jsonc
|
|
184
|
+
"apl": "pnpm --filter ./apps/backend exec bun run scripts/apl.ts"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
2. Add `apollo.apps.json.apl-tmp` to `.gitignore`.
|
|
188
|
+
3. Run `pnpm apl apps`. Create `apollo.apps.json` at the project root listing
|
|
189
|
+
every app it shows as `installed` — `{ "apps": ["<slug>", "<slug>"] }` —
|
|
190
|
+
so nothing changes yet. Leave out the ones marked `mandatory`.
|
|
191
|
+
4. Add `APOLLO_APPS_FILE=../../apollo.apps.json` to the root `.env.local`.
|
|
192
|
+
⚠️ Do steps 3 and 4 in this order: without the variable, `apl` writes to
|
|
193
|
+
`apps/backend/apollo.apps.json`, inside the submodule.
|
|
194
|
+
5. `pnpm apl doctor` should report nothing. Then `pnpm apl uninstall <slug>`
|
|
195
|
+
for each app the project does not use — its tables and data are kept.
|
|
196
|
+
|
|
145
197
|
## Deploying to production
|
|
146
198
|
|
|
147
199
|
The scaffold pins `packageManager: "pnpm@11.0.0"` so Corepack picks the right
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Which suite apps a new project installs (apollo-suite
|
|
2
|
+
// docs/specs/app-install-selection.md §6.6 "scaffold").
|
|
3
|
+
//
|
|
4
|
+
// Kept apart from index.mjs so it can be tested without running the installer.
|
|
5
|
+
// Everything here reads the app list from the backend that was just cloned —
|
|
6
|
+
// the installer is published to npm on its own, so a list written into it
|
|
7
|
+
// would be wrong the day the backend gains an app.
|
|
8
|
+
|
|
9
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
|
|
12
|
+
export const APPS_FILE_NAME = "apollo.apps.json";
|
|
13
|
+
|
|
14
|
+
// Relative to apps/backend: the backend resolves a relative APOLLO_APPS_FILE
|
|
15
|
+
// against its own root, never the working directory.
|
|
16
|
+
export const APPS_FILE_ENV_VALUE = `../../${APPS_FILE_NAME}`;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The suite apps in a backend checkout, sorted by slug, or `null` when the
|
|
20
|
+
* checkout has no `apps/` directory. Same rule as the backend's resolver: a
|
|
21
|
+
* directory under `apps/` whose `plugin.json` says `"mode": "app"`.
|
|
22
|
+
*/
|
|
23
|
+
export function readSuiteAppManifests(backendDir) {
|
|
24
|
+
const appsDir = join(backendDir, "apps");
|
|
25
|
+
if (!existsSync(appsDir)) return null;
|
|
26
|
+
const apps = [];
|
|
27
|
+
for (const entry of readdirSync(appsDir, { withFileTypes: true })) {
|
|
28
|
+
if (!entry.isDirectory()) continue;
|
|
29
|
+
const manifestPath = join(appsDir, entry.name, "plugin.json");
|
|
30
|
+
if (!existsSync(manifestPath)) continue;
|
|
31
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
32
|
+
if (manifest.mode !== "app") continue;
|
|
33
|
+
apps.push({
|
|
34
|
+
slug: entry.name,
|
|
35
|
+
mandatory: manifest.mandatory === true,
|
|
36
|
+
requiresApps: manifest.requiresApps ?? [],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return apps.sort((a, b) => a.slug.localeCompare(b.slug));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* How the list gets chosen. `--apps` always wins. Without it the person is
|
|
44
|
+
* asked — unless nobody is there to answer or there is nothing to choose, and
|
|
45
|
+
* then the project starts with the mandatory apps only rather than every app's
|
|
46
|
+
* tables being created silently.
|
|
47
|
+
*/
|
|
48
|
+
export function selectionMode({ appsFlag, manifests, interactive }) {
|
|
49
|
+
if (appsFlag !== null) return "flag";
|
|
50
|
+
if (manifests === null || !interactive) return "mandatory-only";
|
|
51
|
+
if (optionalApps(manifests).length === 0) return "mandatory-only";
|
|
52
|
+
return "ask";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `--apps "a,b c"` → `["a", "b", "c"]`. */
|
|
56
|
+
export function parseAppList(text) {
|
|
57
|
+
return String(text)
|
|
58
|
+
.split(/[\s,]+/)
|
|
59
|
+
.map((s) => s.trim())
|
|
60
|
+
.filter(Boolean);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The apps a person can choose, in the order they are numbered. */
|
|
64
|
+
export function optionalApps(manifests) {
|
|
65
|
+
return manifests.filter((app) => !app.mandatory);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Check a chosen list against the backend's apps. A missing `requiresApps`
|
|
70
|
+
* entry is an error, never added for the person — they must see everything
|
|
71
|
+
* that is about to be installed (§6.1, the same rule as `apl install`).
|
|
72
|
+
* Mandatory apps are dropped: they are installed whatever the file says.
|
|
73
|
+
*/
|
|
74
|
+
export function checkAppSelection(manifests, selected) {
|
|
75
|
+
const bySlug = new Map(manifests.map((app) => [app.slug, app]));
|
|
76
|
+
const errors = [];
|
|
77
|
+
|
|
78
|
+
const unknown = selected.filter((slug) => !bySlug.has(slug));
|
|
79
|
+
if (unknown.length > 0) {
|
|
80
|
+
errors.push(
|
|
81
|
+
`${unknown.join(", ")}: not an app in this backend (apps: ${[...bySlug.keys()].join(", ")})`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const chosen = new Set(selected.filter((slug) => bySlug.has(slug)));
|
|
86
|
+
for (const app of manifests) {
|
|
87
|
+
if (app.mandatory) chosen.add(app.slug);
|
|
88
|
+
}
|
|
89
|
+
for (const slug of [...chosen].sort()) {
|
|
90
|
+
const missing = bySlug.get(slug).requiresApps.filter((dep) => !chosen.has(dep));
|
|
91
|
+
if (missing.length > 0) {
|
|
92
|
+
errors.push(`${slug} requires ${missing.join(", ")} — choose it too`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const apps = [...chosen].filter((slug) => !bySlug.get(slug).mandatory).sort();
|
|
97
|
+
return { apps, errors };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The checklist shown when `--apps` is not given. */
|
|
101
|
+
export function formatChecklist(manifests) {
|
|
102
|
+
const width = Math.max(...manifests.map((app) => app.slug.length));
|
|
103
|
+
const lines = manifests
|
|
104
|
+
.filter((app) => app.mandatory)
|
|
105
|
+
.map((app) => ` ${app.slug.padEnd(width)} (mandatory — always installed)`);
|
|
106
|
+
optionalApps(manifests).forEach((app, i) => {
|
|
107
|
+
const needs = app.requiresApps.length > 0 ? ` (requires ${app.requiresApps.join(", ")})` : "";
|
|
108
|
+
lines.push(` ${String(i + 1).padStart(3)} ${app.slug.padEnd(width)}${needs}`.trimEnd());
|
|
109
|
+
});
|
|
110
|
+
return lines;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** `"1 3"` → the slugs numbered 1 and 3 by `formatChecklist`. Empty = none. */
|
|
114
|
+
export function parseChecklistAnswer(manifests, answer) {
|
|
115
|
+
const choices = optionalApps(manifests);
|
|
116
|
+
const slugs = [];
|
|
117
|
+
const errors = [];
|
|
118
|
+
for (const token of parseAppList(answer)) {
|
|
119
|
+
const n = Number(token);
|
|
120
|
+
if (Number.isInteger(n) && n >= 1 && n <= choices.length) slugs.push(choices[n - 1].slug);
|
|
121
|
+
else errors.push(`"${token}" is not a number from the list (1-${choices.length})`);
|
|
122
|
+
}
|
|
123
|
+
return { slugs, errors };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Byte-for-byte the format `apl` writes, so its first rewrite is a clean diff. */
|
|
127
|
+
export function appsFileBody(apps) {
|
|
128
|
+
return `${JSON.stringify({ apps }, null, 2)}\n`;
|
|
129
|
+
}
|
package/index.mjs
CHANGED
|
@@ -19,6 +19,17 @@ import { randomBytes } from "node:crypto";
|
|
|
19
19
|
import { existsSync, mkdirSync, writeFileSync, symlinkSync, rmSync } from "node:fs";
|
|
20
20
|
import { resolve, basename } from "node:path";
|
|
21
21
|
import { createInterface } from "node:readline";
|
|
22
|
+
import {
|
|
23
|
+
APPS_FILE_ENV_VALUE,
|
|
24
|
+
APPS_FILE_NAME,
|
|
25
|
+
appsFileBody,
|
|
26
|
+
checkAppSelection,
|
|
27
|
+
formatChecklist,
|
|
28
|
+
parseAppList,
|
|
29
|
+
parseChecklistAnswer,
|
|
30
|
+
readSuiteAppManifests,
|
|
31
|
+
selectionMode,
|
|
32
|
+
} from "./app-selection.mjs";
|
|
22
33
|
|
|
23
34
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
24
35
|
|
|
@@ -72,6 +83,9 @@ ${COLORS.bold}Flags:${COLORS.reset}
|
|
|
72
83
|
sit alongside admin pages under one rewrite.
|
|
73
84
|
Pass "none" to disable single-origin (separate origins).
|
|
74
85
|
Alias: --asset-prefix
|
|
86
|
+
--apps <slug,slug> Suite apps to install besides the mandatory ones.
|
|
87
|
+
Asked when omitted; mandatory apps only when not
|
|
88
|
+
run from a terminal. Pass "" for mandatory only.
|
|
75
89
|
--skip-install Skip dependency installation
|
|
76
90
|
--skip-submodule Skip git submodule add (you'll add it later)
|
|
77
91
|
-h, --help Show this help message
|
|
@@ -144,6 +158,7 @@ const FLAG_TABLE = {
|
|
|
144
158
|
"--locale": { key: "locale" },
|
|
145
159
|
"--admin-prefix": { key: "adminPrefix" },
|
|
146
160
|
"--asset-prefix": { key: "adminPrefix" },
|
|
161
|
+
"--apps": { key: "apps" },
|
|
147
162
|
};
|
|
148
163
|
|
|
149
164
|
function parseArgs(argv) {
|
|
@@ -157,6 +172,7 @@ function parseArgs(argv) {
|
|
|
157
172
|
url: null,
|
|
158
173
|
locale: null,
|
|
159
174
|
adminPrefix: "/admin",
|
|
175
|
+
apps: null,
|
|
160
176
|
skipInstall: false,
|
|
161
177
|
skipSubmodule: false,
|
|
162
178
|
help: false,
|
|
@@ -386,6 +402,10 @@ function writeRootPackageJson(targetDir, dirName) {
|
|
|
386
402
|
// `pnpm backend:update` so any data-migration step from the new
|
|
387
403
|
// apollo-cms version is applied — `backend:setup` alone skips it.
|
|
388
404
|
"backend:upgrade": "pnpm --filter ./apps/backend exec bun run upgrade",
|
|
405
|
+
// Choose the suite apps this project installs (apollo.apps.json):
|
|
406
|
+
// `pnpm apl apps | install <slug...> | uninstall <slug> | doctor`. Runs
|
|
407
|
+
// the backend's own script, so it always matches the backend version.
|
|
408
|
+
apl: "pnpm --filter ./apps/backend exec bun run scripts/apl.ts",
|
|
389
409
|
},
|
|
390
410
|
devDependencies: {
|
|
391
411
|
concurrently: "^9.0.0",
|
|
@@ -893,6 +913,9 @@ function writeRootGitignore(targetDir) {
|
|
|
893
913
|
".env",
|
|
894
914
|
"*.log",
|
|
895
915
|
".DS_Store",
|
|
916
|
+
// `pnpm apl` writes the new app list here and renames it over the real
|
|
917
|
+
// file only after the upgrade succeeds.
|
|
918
|
+
`${APPS_FILE_NAME}.apl-tmp`,
|
|
896
919
|
"",
|
|
897
920
|
].join("\n");
|
|
898
921
|
writeFileSync(resolve(targetDir, ".gitignore"), ignore);
|
|
@@ -961,6 +984,10 @@ function writeRootEnv(targetDir, { dbUrl, siteUrl, locale, authSecret, cronSecre
|
|
|
961
984
|
"# `pm2 stop <namespace>` / `pm2 restart <namespace>` independently of",
|
|
962
985
|
"# other projects on the same host. Consumed by ecosystem.config.cjs.",
|
|
963
986
|
`PM2_NAMESPACE=${pm2Namespace}`,
|
|
987
|
+
"# Suite apps this project installs besides the mandatory ones. Change the",
|
|
988
|
+
"# list with `pnpm apl install <slug>` / `pnpm apl uninstall <slug>`. Resolved",
|
|
989
|
+
"# against apps/backend, so it names the project root's file — which must exist.",
|
|
990
|
+
`APOLLO_APPS_FILE=${APPS_FILE_ENV_VALUE}`,
|
|
964
991
|
"",
|
|
965
992
|
"# ── Frontend (apps/frontend) ─────────────────────────────────────",
|
|
966
993
|
);
|
|
@@ -1614,6 +1641,7 @@ pnpm workspace monorepo. Three workspaces under \`apps/\`:
|
|
|
1614
1641
|
- \`apps/backend\` — **git submodule** pointing at \`apollo-cms\`. Treat as read-only; do not edit files in here. Open PRs upstream.
|
|
1615
1642
|
- \`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.
|
|
1616
1643
|
- \`apps/proxy/server.mjs\` — zero-dep Node reverse proxy used for single-origin dev and self-hosted deploys.
|
|
1644
|
+
- \`${APPS_FILE_NAME}\` — the suite apps this project installs besides the mandatory ones. Change it with \`pnpm apl install\` / \`pnpm apl uninstall\`, which run the upgrade. \`APOLLO_APPS_FILE\` in \`.env.local\` points at it, so deleting it stops the backend.
|
|
1617
1645
|
|
|
1618
1646
|
Built-in plugins in \`apps/backend/plugins/\` always win on slug collisions with \`apps/cms-plugins/\`.
|
|
1619
1647
|
|
|
@@ -1626,6 +1654,11 @@ pnpm backend:setup # first-time: db:push + db:seed
|
|
|
1626
1654
|
pnpm backend:upgrade # release-time: db:push + replay src/upgrades/0.1.*.ts + seed
|
|
1627
1655
|
pnpm backend:update # fast-forward the apollo-cms submodule
|
|
1628
1656
|
|
|
1657
|
+
pnpm apl apps # suite apps and their state
|
|
1658
|
+
pnpm apl install <slug...> # add apps (runs the upgrade)
|
|
1659
|
+
pnpm apl uninstall <slug> # leave an app out (tables and data kept)
|
|
1660
|
+
pnpm apl doctor # file, apps and database agree?
|
|
1661
|
+
|
|
1629
1662
|
pnpm dev # FE + BE + plugin watcher (parallel)
|
|
1630
1663
|
pnpm dev:rp # same + reverse proxy on :3030 (single origin, shared cookies)
|
|
1631
1664
|
pnpm dev:frontend # FE only
|
|
@@ -1761,6 +1794,25 @@ When using \`pnpm dev:rp\`, set \`NEXT_PUBLIC_SITE_URL=http://localhost:3030\`
|
|
|
1761
1794
|
in your \`.env.local\` so Better Auth, OAuth callbacks, and email links use
|
|
1762
1795
|
the unified origin.
|
|
1763
1796
|
|
|
1797
|
+
## Suite apps
|
|
1798
|
+
|
|
1799
|
+
\`${APPS_FILE_NAME}\` lists the suite apps this project installs besides the
|
|
1800
|
+
mandatory ones. An app that is not listed gets no tables, no screens and no
|
|
1801
|
+
jobs. \`.env.local\` points the backend at this file with \`APOLLO_APPS_FILE\`,
|
|
1802
|
+
so it must exist — delete it and the backend refuses to start.
|
|
1803
|
+
|
|
1804
|
+
\`\`\`bash
|
|
1805
|
+
pnpm apl apps # every app and its state
|
|
1806
|
+
pnpm apl install <slug...> # add apps — runs the upgrade that creates their tables
|
|
1807
|
+
pnpm apl uninstall <slug> # leave an app out — its tables and data are kept
|
|
1808
|
+
pnpm apl doctor # do the file, the apps and the database agree?
|
|
1809
|
+
\`\`\`
|
|
1810
|
+
|
|
1811
|
+
\`apl\` changes the file and the database; it never builds or deploys. Commit
|
|
1812
|
+
the file, then build and deploy as usual. Before the database has been set up
|
|
1813
|
+
once, edit the list by hand and run \`pnpm backend:setup\` — \`apl install\`
|
|
1814
|
+
needs the tables that setup creates.
|
|
1815
|
+
|
|
1764
1816
|
${originSection}
|
|
1765
1817
|
## Custom plugins
|
|
1766
1818
|
|
|
@@ -1874,6 +1926,100 @@ For containerized deploys:
|
|
|
1874
1926
|
writeFileSync(resolve(targetDir, "README.md"), readme);
|
|
1875
1927
|
}
|
|
1876
1928
|
|
|
1929
|
+
// ─── Suite apps ──────────────────────────────────────────────────────────────
|
|
1930
|
+
|
|
1931
|
+
function writeAppsFile(targetDir, apps) {
|
|
1932
|
+
writeFileSync(resolve(targetDir, APPS_FILE_NAME), appsFileBody(apps));
|
|
1933
|
+
success(`${APPS_FILE_NAME}: ${apps.length > 0 ? apps.join(", ") : "mandatory apps only"}`);
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
// Write apollo.apps.json from --apps, or from a checklist of the apps in the
|
|
1937
|
+
// backend that was just cloned (apollo-suite docs/specs/app-install-selection.md
|
|
1938
|
+
// §6.6). A missing required app is reported, never ticked for the person.
|
|
1939
|
+
async function chooseApps(flags, targetDir) {
|
|
1940
|
+
if (flags.apps === undefined) {
|
|
1941
|
+
fatal(`--apps needs a value, e.g. --apps "<slug>,<slug>" — or --apps "" for the mandatory apps only.`);
|
|
1942
|
+
}
|
|
1943
|
+
const dirName = basename(targetDir);
|
|
1944
|
+
const manifests = flags.skipSubmodule
|
|
1945
|
+
? null
|
|
1946
|
+
: readSuiteAppManifests(resolve(targetDir, BACKEND_PATH));
|
|
1947
|
+
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
1948
|
+
const mode = selectionMode({ appsFlag: flags.apps, manifests, interactive });
|
|
1949
|
+
|
|
1950
|
+
if (mode === "flag") {
|
|
1951
|
+
const selected = parseAppList(flags.apps);
|
|
1952
|
+
if (manifests === null) {
|
|
1953
|
+
writeAppsFile(targetDir, [...new Set(selected)].sort());
|
|
1954
|
+
warn(`Not checked — there is no backend to check it against. Run \`pnpm apl doctor\` once apps/backend is in place.`);
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
const { apps, errors } = checkAppSelection(manifests, selected);
|
|
1958
|
+
if (errors.length === 0) {
|
|
1959
|
+
writeAppsFile(targetDir, apps);
|
|
1960
|
+
return;
|
|
1961
|
+
}
|
|
1962
|
+
for (const error of errors) warn(`--apps: ${error}`);
|
|
1963
|
+
if (!interactive) {
|
|
1964
|
+
fatal(
|
|
1965
|
+
`--apps is not valid, so ${APPS_FILE_NAME} lists the mandatory apps only.\n Fix the list in ${dirName}/${APPS_FILE_NAME}, then: cd ${dirName} && pnpm install && pnpm backend:setup`,
|
|
1966
|
+
);
|
|
1967
|
+
}
|
|
1968
|
+
// A person is there: ask instead.
|
|
1969
|
+
} else if (mode === "mandatory-only") {
|
|
1970
|
+
const reason = flags.skipSubmodule
|
|
1971
|
+
? "--skip-submodule, so there is no app list to show"
|
|
1972
|
+
: manifests === null || manifests.every((app) => app.mandatory)
|
|
1973
|
+
? "this backend has no optional apps"
|
|
1974
|
+
: "not run from a terminal";
|
|
1975
|
+
success(`${APPS_FILE_NAME}: mandatory apps only (${reason})`);
|
|
1976
|
+
if (manifests === null || manifests.some((app) => !app.mandatory)) {
|
|
1977
|
+
warn(`Add apps by listing their slugs in ${APPS_FILE_NAME} before \`pnpm backend:setup\`, or with \`pnpm apl install <slug...>\` after it.`);
|
|
1978
|
+
}
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
log("");
|
|
1983
|
+
log(` ${COLORS.bold}Suite apps to install${COLORS.reset}`);
|
|
1984
|
+
for (const line of formatChecklist(manifests)) log(` ${line}`);
|
|
1985
|
+
// Not createPrompt(): its question never settles when input ends, and node
|
|
1986
|
+
// then exits 0 with nothing awaited — skipping pnpm install without a word.
|
|
1987
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1988
|
+
let inputEnded = false;
|
|
1989
|
+
rl.on("close", () => {
|
|
1990
|
+
inputEnded = true;
|
|
1991
|
+
});
|
|
1992
|
+
const ask = (question) =>
|
|
1993
|
+
new Promise((res) => {
|
|
1994
|
+
if (inputEnded) return res(null);
|
|
1995
|
+
rl.once("close", () => res(null));
|
|
1996
|
+
rl.question(question, res);
|
|
1997
|
+
});
|
|
1998
|
+
try {
|
|
1999
|
+
for (;;) {
|
|
2000
|
+
const answer = await ask(
|
|
2001
|
+
`\n Numbers to install, separated by spaces ${COLORS.dim}(Enter = mandatory apps only)${COLORS.reset}\n > `,
|
|
2002
|
+
);
|
|
2003
|
+
if (answer === null) {
|
|
2004
|
+
log("");
|
|
2005
|
+
success(`${APPS_FILE_NAME}: mandatory apps only (input ended before an answer)`);
|
|
2006
|
+
warn(`Add apps by listing their slugs in ${APPS_FILE_NAME} before \`pnpm backend:setup\`, or with \`pnpm apl install <slug...>\` after it.`);
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
const picked = parseChecklistAnswer(manifests, answer);
|
|
2010
|
+
const { apps, errors } =
|
|
2011
|
+
picked.errors.length > 0 ? { apps: [], errors: picked.errors } : checkAppSelection(manifests, picked.slugs);
|
|
2012
|
+
if (errors.length === 0) {
|
|
2013
|
+
writeAppsFile(targetDir, apps);
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
for (const error of errors) warn(error);
|
|
2017
|
+
}
|
|
2018
|
+
} finally {
|
|
2019
|
+
rl.close();
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
|
|
1877
2023
|
// ─── Main ────────────────────────────────────────────────────────────────────
|
|
1878
2024
|
|
|
1879
2025
|
async function main() {
|
|
@@ -1923,8 +2069,12 @@ async function main() {
|
|
|
1923
2069
|
writeCheckEnvScript(targetDir);
|
|
1924
2070
|
writeWithEnvScript(targetDir);
|
|
1925
2071
|
writePm2Config(targetDir, dirName, adminPrefix);
|
|
2072
|
+
// Mandatory apps only until step 6b chooses. Written now so APOLLO_APPS_FILE
|
|
2073
|
+
// never points at a missing file — the backend refuses to start on that —
|
|
2074
|
+
// even if the installer stops before the apps are chosen.
|
|
2075
|
+
writeFileSync(resolve(targetDir, APPS_FILE_NAME), appsFileBody([]));
|
|
1926
2076
|
success(
|
|
1927
|
-
`package.json, pnpm-workspace.yaml, .gitignore, .env.local, README.md, CLAUDE.md${
|
|
2077
|
+
`package.json, pnpm-workspace.yaml, .gitignore, .env.local, ${APPS_FILE_NAME}, README.md, CLAUDE.md${
|
|
1928
2078
|
adminPrefix ? ", nginx.conf.sample" : ""
|
|
1929
2079
|
}, apps/proxy, ecosystem.config.cjs, scripts/check-env.mjs, scripts/with-env.mjs`,
|
|
1930
2080
|
);
|
|
@@ -1974,6 +2124,7 @@ async function main() {
|
|
|
1974
2124
|
`NEXT_PUBLIC_DEFAULT_LOCALE=${locale}`,
|
|
1975
2125
|
`APOLLO_EXTRA_PLUGINS_DIR=../cms-plugins`,
|
|
1976
2126
|
`PM2_NAMESPACE=${dirName}`,
|
|
2127
|
+
`APOLLO_APPS_FILE=${APPS_FILE_ENV_VALUE}`,
|
|
1977
2128
|
];
|
|
1978
2129
|
if (adminPrefix) backendFallback.push(`APOLLO_ASSET_PREFIX=${adminPrefix}`);
|
|
1979
2130
|
linkRootEnvLocal(targetDir, BACKEND_PATH, backendFallback);
|
|
@@ -1987,6 +2138,10 @@ async function main() {
|
|
|
1987
2138
|
: [`NEXT_PUBLIC_BACKEND_URL=${siteUrl || `http://localhost:${DEFAULT_BACKEND_PORT}`}`];
|
|
1988
2139
|
linkRootEnvLocal(targetDir, FRONTEND_PATH, frontendFallback);
|
|
1989
2140
|
|
|
2141
|
+
// ── Step 6b: Suite apps ──
|
|
2142
|
+
step("6b", "Choosing suite apps");
|
|
2143
|
+
await chooseApps(flags, targetDir);
|
|
2144
|
+
|
|
1990
2145
|
// ── Step 7: Install ──
|
|
1991
2146
|
if (flags.skipInstall) {
|
|
1992
2147
|
step(7, "Skipping dependency installation (--skip-install)");
|
|
@@ -2011,6 +2166,7 @@ ${COLORS.green}${COLORS.bold} Monorepo created!${COLORS.reset}
|
|
|
2011
2166
|
${COLORS.bold}cd${COLORS.reset} ${dirName}
|
|
2012
2167
|
${COLORS.bold}pnpm backend:setup${COLORS.reset} ${COLORS.dim}# push schema + seed apollo-cms${COLORS.reset}
|
|
2013
2168
|
${COLORS.bold}pnpm dev${COLORS.reset} ${COLORS.dim}# frontend :3001 + backend :3000${COLORS.reset}
|
|
2169
|
+
${COLORS.bold}pnpm apl apps${COLORS.reset} ${COLORS.dim}# suite apps and their state (${APPS_FILE_NAME})${COLORS.reset}
|
|
2014
2170
|
|
|
2015
2171
|
${COLORS.dim}APOLLO_SECRET=${authSecret}${COLORS.reset}
|
|
2016
2172
|
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-apollo-suite-monorepo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.870",
|
|
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-suite-monorepo": "index.mjs"
|