bearminion 1.7.0 → 1.9.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 +20 -0
- package/dist/astro.d.ts +2 -2
- package/dist/astro.js +17 -5
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +819 -0
- package/dist/content.d.ts +1 -1
- package/dist/content.js +2 -2
- package/dist/hash-BeBymBO1.js +59 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/marks-DPBilumg.js +174 -0
- package/dist/marks.js +1 -174
- package/dist/{options-BeJQnsZM.d.ts → options-4HWVEj9O.d.ts} +7 -1
- package/dist/{page-BfI9cD8g.d.ts → page-CA4iyFDS.d.ts} +7 -7
- package/dist/{page-NOFVEqn1.js → page-X-WnOu7-.js} +1 -1
- package/dist/{preview--S1QUrMM.js → preview-B_88I5Jm.js} +1 -1
- package/dist/{reload-BPkPoQ-P.js → reload-Dkp3xC0l.js} +1 -1
- package/dist/rich-text-70hddxMC.js +403 -0
- package/dist/rich-text.js +1 -403
- package/dist/sections-manifest-CO9QfJPG.js +97 -0
- package/dist/{theme-DFjHjgFO.js → theme-Dv7_7B56.js} +2 -2
- package/dist/ui/mount.js +20 -7
- package/package.json +7 -1
- package/registry/default/files/src/components/atoms/Button.astro +64 -0
- package/registry/default/files/src/components/atoms/Emphasis.astro +24 -0
- package/registry/default/files/src/components/atoms/Image.astro +78 -0
- package/registry/default/files/src/components/atoms/Typography.astro +53 -0
- package/registry/default/files/src/components/atoms/button.ts +31 -0
- package/registry/default/files/src/components/atoms/image.ts +34 -0
- package/registry/default/files/src/components/atoms/options.ts +39 -0
- package/registry/default/files/src/components/atoms/typography.ts +64 -0
- package/registry/default/files/src/components/molecules/CommandLine.astro +109 -0
- package/registry/default/files/src/components/molecules/MediaFrame.astro +71 -0
- package/registry/default/files/src/components/molecules/Pill.astro +24 -0
- package/registry/default/files/src/components/molecules/SectionHeader.astro +63 -0
- package/registry/default/files/src/components/molecules/SectionShell.astro +33 -0
- package/registry/default/files/src/components/sections/contact/Contact.astro +231 -0
- package/registry/default/files/src/components/sections/contact/definition.ts +52 -0
- package/registry/default/files/src/components/sections/contact/form.ts +313 -0
- package/registry/default/files/src/components/sections/contact/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/cta/Cta.astro +206 -0
- package/registry/default/files/src/components/sections/cta/definition.ts +49 -0
- package/registry/default/files/src/components/sections/cta/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/faq/Faq.astro +136 -0
- package/registry/default/files/src/components/sections/faq/definition.ts +54 -0
- package/registry/default/files/src/components/sections/faq/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/features/Features.astro +146 -0
- package/registry/default/files/src/components/sections/features/definition.ts +54 -0
- package/registry/default/files/src/components/sections/features/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/gallery/Gallery.astro +128 -0
- package/registry/default/files/src/components/sections/gallery/definition.ts +59 -0
- package/registry/default/files/src/components/sections/gallery/lightbox.ts +159 -0
- package/registry/default/files/src/components/sections/gallery/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/hero/Hero.astro +185 -0
- package/registry/default/files/src/components/sections/hero/HeroBadge.astro +26 -0
- package/registry/default/files/src/components/sections/hero/definition.ts +74 -0
- package/registry/default/files/src/components/sections/hero/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/logo-strip/LogoStrip.astro +107 -0
- package/registry/default/files/src/components/sections/logo-strip/definition.ts +30 -0
- package/registry/default/files/src/components/sections/logo-strip/wireframe.ts +11 -0
- package/registry/default/files/src/components/sections/media/Media.astro +118 -0
- package/registry/default/files/src/components/sections/media/MediaPlayer.astro +176 -0
- package/registry/default/files/src/components/sections/media/definition.ts +77 -0
- package/registry/default/files/src/components/sections/media/source.ts +3 -0
- package/registry/default/files/src/components/sections/media/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/pricing/Pricing.astro +210 -0
- package/registry/default/files/src/components/sections/pricing/definition.ts +62 -0
- package/registry/default/files/src/components/sections/pricing/wireframe.ts +18 -0
- package/registry/default/files/src/components/sections/shared.ts +13 -0
- package/registry/default/files/src/components/sections/stats/Stats.astro +110 -0
- package/registry/default/files/src/components/sections/stats/definition.ts +41 -0
- package/registry/default/files/src/components/sections/stats/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/steps/Steps.astro +139 -0
- package/registry/default/files/src/components/sections/steps/definition.ts +62 -0
- package/registry/default/files/src/components/sections/steps/icons.ts +27 -0
- package/registry/default/files/src/components/sections/steps/wireframe.ts +16 -0
- package/registry/default/files/src/components/sections/testimonials/Testimonials.astro +172 -0
- package/registry/default/files/src/components/sections/testimonials/definition.ts +42 -0
- package/registry/default/files/src/components/sections/testimonials/wireframe.ts +21 -0
- package/registry/default/files/src/components/sections/text/Text.astro +43 -0
- package/registry/default/files/src/components/sections/text/definition.ts +36 -0
- package/registry/default/files/src/components/sections/text/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/text-image/TextImage.astro +107 -0
- package/registry/default/files/src/components/sections/text-image/definition.ts +39 -0
- package/registry/default/files/src/components/sections/text-image/wireframe.ts +12 -0
- package/registry/default/files/src/lib/assets.ts +13 -0
- package/registry/default/files/src/lib/cn.ts +6 -0
- package/registry/default/files/src/lib/contact-form.ts +97 -0
- package/registry/default/files/src/lib/hidden-text.ts +32 -0
- package/registry/default/files/src/lib/image-url.ts +38 -0
- package/registry/default/files/src/lib/link-attrs.ts +74 -0
- package/registry/default/registry.json +670 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { i as syncSections, r as staleSectionsMessage, t as SectionsError } from "./sections-manifest-CO9QfJPG.js";
|
|
3
|
+
import { i as writeLock, n as readLock, r as recordFiles, t as hashContent } from "./hash-BeBymBO1.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { parseArgs } from "node:util";
|
|
8
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
9
|
+
import { createInterface } from "node:readline/promises";
|
|
10
|
+
//#region src/add/packages.ts
|
|
11
|
+
const LOCKFILES = [
|
|
12
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
13
|
+
["yarn.lock", "yarn"],
|
|
14
|
+
["bun.lock", "bun"],
|
|
15
|
+
["bun.lockb", "bun"],
|
|
16
|
+
["package-lock.json", "npm"]
|
|
17
|
+
];
|
|
18
|
+
/** The package manager the site uses, by its lock file. npm when there is none. */
|
|
19
|
+
function detectPackageManager(root) {
|
|
20
|
+
for (const [file, manager] of LOCKFILES) if (fs.existsSync(path.join(root, file))) return manager;
|
|
21
|
+
return "npm";
|
|
22
|
+
}
|
|
23
|
+
/** The command that installs `packages` (name to range). */
|
|
24
|
+
function installCommand(manager, packages) {
|
|
25
|
+
const specs = Object.entries(packages).map(([name, range]) => `${name}@${range}`);
|
|
26
|
+
return {
|
|
27
|
+
command: manager,
|
|
28
|
+
args: [manager === "npm" ? "install" : "add", ...specs]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const formatCommand = ({ command, args }) => [command, ...args].join(" ");
|
|
32
|
+
/** The packages `wanted` that the site's `package.json` lists in neither `dependencies` nor `devDependencies`. */
|
|
33
|
+
function missingPackages(root, wanted) {
|
|
34
|
+
const file = path.join(root, "package.json");
|
|
35
|
+
const pkg = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
36
|
+
const have = {
|
|
37
|
+
...pkg.devDependencies,
|
|
38
|
+
...pkg.dependencies
|
|
39
|
+
};
|
|
40
|
+
return Object.fromEntries(Object.entries(wanted).filter(([name]) => have[name] === void 0));
|
|
41
|
+
}
|
|
42
|
+
const runInstall = (command, args, cwd) => spawnSync(command, args, {
|
|
43
|
+
cwd,
|
|
44
|
+
stdio: "inherit"
|
|
45
|
+
}).status ?? 1;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/add/plan.ts
|
|
48
|
+
const WRITES = /* @__PURE__ */ new Set([
|
|
49
|
+
"create",
|
|
50
|
+
"update",
|
|
51
|
+
"overwrite"
|
|
52
|
+
]);
|
|
53
|
+
const writesFile = (action) => WRITES.has(action);
|
|
54
|
+
/** Decides what happens to every file the sections need. Reads the site, writes nothing. */
|
|
55
|
+
function planAdd(root, registry, sections, options = {}) {
|
|
56
|
+
const needed = /* @__PURE__ */ new Map();
|
|
57
|
+
for (const section of sections) for (const file of section.files) needed.set(file, [...needed.get(file) ?? [], section.dir]);
|
|
58
|
+
const files = [...needed.entries()].sort(([a], [b]) => a < b ? -1 : 1).map(([file, owners]) => {
|
|
59
|
+
const entry = registry.files[file];
|
|
60
|
+
if (entry === void 0) throw new Error(`The registry lists ${file} for a section but holds no copy of it.`);
|
|
61
|
+
const target = path.join(root, file);
|
|
62
|
+
let action;
|
|
63
|
+
if (!fs.existsSync(target)) action = "create";
|
|
64
|
+
else {
|
|
65
|
+
const hash = hashContent(file, fs.readFileSync(target));
|
|
66
|
+
if (hash === entry.hash) action = "same";
|
|
67
|
+
else if (entry.history.includes(hash) || options.lock?.files[file]?.hash === hash) action = "update";
|
|
68
|
+
else action = options.overwrite ? "overwrite" : "conflict";
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
path: file,
|
|
72
|
+
action,
|
|
73
|
+
sections: owners
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const npm = missingPackages(root, Object.assign({}, ...sections.map((section) => section.npm)));
|
|
77
|
+
return {
|
|
78
|
+
sections: [...sections],
|
|
79
|
+
files,
|
|
80
|
+
npm,
|
|
81
|
+
dirty: dirtyFiles(root, files.filter((file) => file.action === "update" || file.action === "overwrite").map((file) => file.path))
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Which of `paths` git reports as changed or untracked. Empty when there is no git or no repository. */
|
|
85
|
+
function dirtyFiles(root, paths) {
|
|
86
|
+
if (paths.length === 0) return [];
|
|
87
|
+
try {
|
|
88
|
+
return execFileSync("git", [
|
|
89
|
+
"status",
|
|
90
|
+
"--porcelain",
|
|
91
|
+
"--",
|
|
92
|
+
...paths
|
|
93
|
+
], {
|
|
94
|
+
cwd: root,
|
|
95
|
+
encoding: "utf8",
|
|
96
|
+
stdio: [
|
|
97
|
+
"ignore",
|
|
98
|
+
"pipe",
|
|
99
|
+
"ignore"
|
|
100
|
+
]
|
|
101
|
+
}).split("\n").filter(Boolean).map((line) => line.slice(3).replace(/^"|"$/g, ""));
|
|
102
|
+
} catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** A section is added when every file it needs is the release's. */
|
|
107
|
+
const isPresent = (plan) => plan.files.every((file) => file.action === "same");
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/add/apply.ts
|
|
110
|
+
const SECTIONS_PATH = "src/components/sections";
|
|
111
|
+
/**
|
|
112
|
+
* Writes what the plan says, then lists the new directories in the generated section files and records the files in
|
|
113
|
+
* the lock. Returns the paths written. A plan with conflicts is never applied.
|
|
114
|
+
*/
|
|
115
|
+
function applyPlan(root, registryDir, registry, plan) {
|
|
116
|
+
if (plan.files.some((file) => file.action === "conflict")) throw new Error("The plan has conflicts. Nothing was written.");
|
|
117
|
+
const written = [];
|
|
118
|
+
for (const file of plan.files) {
|
|
119
|
+
if (!writesFile(file.action)) continue;
|
|
120
|
+
const target = path.join(root, file.path);
|
|
121
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
122
|
+
fs.copyFileSync(path.join(registryDir, "files", file.path), target);
|
|
123
|
+
written.push(file.path);
|
|
124
|
+
}
|
|
125
|
+
syncSections(path.join(root, SECTIONS_PATH));
|
|
126
|
+
const lock = recordFiles(readLock(root, registry.template), registry, plan.files.map((file) => file.path));
|
|
127
|
+
writeLock(root, lock);
|
|
128
|
+
return written;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/add/forms.ts
|
|
132
|
+
/** Where the handler goes: the Contact form posts to `/api/contact`, and this file answers there. */
|
|
133
|
+
const HANDLER_PATH = "src/forms/contact.ts";
|
|
134
|
+
const HANDLERS = [{
|
|
135
|
+
name: "resend",
|
|
136
|
+
description: "Send the message as an email with Resend",
|
|
137
|
+
env: [
|
|
138
|
+
"RESEND_API_KEY",
|
|
139
|
+
"CONTACT_FROM",
|
|
140
|
+
"CONTACT_TO"
|
|
141
|
+
],
|
|
142
|
+
source: `import { defineForm } from 'bearminion/forms'
|
|
143
|
+
|
|
144
|
+
const oneLine = (text: string) => text.replace(/\\s+/g, ' ').trim()
|
|
145
|
+
|
|
146
|
+
export default defineForm(async (submission, { env }) => {
|
|
147
|
+
// Both addresses live in the environment, so they are not in the repository. CONTACT_FROM has to be on a domain you
|
|
148
|
+
// verified with Resend; CONTACT_TO is where the messages arrive.
|
|
149
|
+
if (!env.CONTACT_FROM || !env.CONTACT_TO) throw new Error('Set CONTACT_FROM and CONTACT_TO in the environment.')
|
|
150
|
+
const response = await fetch('https://api.resend.com/emails', {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: { Authorization: \`Bearer \${env.RESEND_API_KEY}\`, 'Content-Type': 'application/json' },
|
|
153
|
+
body: JSON.stringify({
|
|
154
|
+
from: env.CONTACT_FROM,
|
|
155
|
+
to: env.CONTACT_TO,
|
|
156
|
+
reply_to: submission.email,
|
|
157
|
+
subject: \`New message from \${oneLine(submission.name ?? '')}\`,
|
|
158
|
+
text: \`\${submission.message}\\n\\nFrom: \${submission.name} <\${submission.email}>\\nTopic: \${submission.topic ?? '-'}\\nPage: \${submission.page}\`,
|
|
159
|
+
}),
|
|
160
|
+
})
|
|
161
|
+
if (!response.ok) throw new Error(\`Resend answered \${response.status}\`)
|
|
162
|
+
})
|
|
163
|
+
`
|
|
164
|
+
}];
|
|
165
|
+
const GLUE = [{
|
|
166
|
+
name: "vercel",
|
|
167
|
+
description: "A Vercel Function",
|
|
168
|
+
path: "api/contact.ts",
|
|
169
|
+
source: `import form from '../src/forms/contact'
|
|
170
|
+
|
|
171
|
+
export const POST = (request: Request) => form.fetch(request, process.env)
|
|
172
|
+
export const OPTIONS = POST
|
|
173
|
+
`
|
|
174
|
+
}];
|
|
175
|
+
/**
|
|
176
|
+
* Which host a site deploys to, from the files that name one. A site with config for two hosts, or for none, answers
|
|
177
|
+
* undefined and the person says it with `--host`. An Astro adapter in `package.json` means the site already runs a
|
|
178
|
+
* server build, so the Astro endpoint is the glue.
|
|
179
|
+
*/
|
|
180
|
+
function detectHost(root) {
|
|
181
|
+
const has = (file) => fs.existsSync(path.join(root, file));
|
|
182
|
+
const found = [
|
|
183
|
+
has("vercel.json") || has(".vercel") ? "vercel" : void 0,
|
|
184
|
+
has("netlify.toml") ? "netlify" : void 0,
|
|
185
|
+
has("wrangler.toml") || has("wrangler.json") || has("wrangler.jsonc") ? "cloudflare" : void 0
|
|
186
|
+
].filter((host) => host !== void 0);
|
|
187
|
+
if (found.length > 1) return void 0;
|
|
188
|
+
if (found[0] !== void 0) return found[0];
|
|
189
|
+
try {
|
|
190
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
191
|
+
if (Object.keys({
|
|
192
|
+
...manifest.dependencies,
|
|
193
|
+
...manifest.devDependencies
|
|
194
|
+
}).some((name) => /^@astrojs\/(node|vercel|netlify|cloudflare)$/.test(name))) return "astro";
|
|
195
|
+
} catch {}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* What writing the handler and the glue would do. These files have no earlier releases to compare with, so a file
|
|
199
|
+
* either does not exist (`create`), is already the recipe (`same`), or is the owner's (`conflict`, or `overwrite` when
|
|
200
|
+
* they asked for it).
|
|
201
|
+
*/
|
|
202
|
+
function planForm(root, handler, glue, overwrite) {
|
|
203
|
+
const files = [];
|
|
204
|
+
const add = (file, source) => {
|
|
205
|
+
const target = path.join(root, file);
|
|
206
|
+
let action = "create";
|
|
207
|
+
if (fs.existsSync(target)) {
|
|
208
|
+
if (hashContent(file, fs.readFileSync(target)) === hashContent(file, source)) action = "same";
|
|
209
|
+
else action = overwrite ? "overwrite" : "conflict";
|
|
210
|
+
}
|
|
211
|
+
files.push({
|
|
212
|
+
path: file,
|
|
213
|
+
action,
|
|
214
|
+
source
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
if (handler) add(HANDLER_PATH, handler.source);
|
|
218
|
+
if (glue) add(glue.path, glue.source);
|
|
219
|
+
return {
|
|
220
|
+
files,
|
|
221
|
+
env: handler?.env ?? [],
|
|
222
|
+
needs: glue?.needs
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** Writes the files that need writing and records every file of the plan in the lock. Returns the paths written. */
|
|
226
|
+
function applyForm(root, plan, version, lock) {
|
|
227
|
+
const written = [];
|
|
228
|
+
const files = { ...lock.files };
|
|
229
|
+
for (const file of plan.files) {
|
|
230
|
+
if (file.action === "conflict") throw new Error("The plan has conflicts. Nothing was written.");
|
|
231
|
+
if (file.action === "create" || file.action === "overwrite") {
|
|
232
|
+
const target = path.join(root, file.path);
|
|
233
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
234
|
+
fs.writeFileSync(target, file.source);
|
|
235
|
+
written.push(file.path);
|
|
236
|
+
}
|
|
237
|
+
files[file.path] = {
|
|
238
|
+
version,
|
|
239
|
+
hash: hashContent(file.path, file.source)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const sorted = Object.fromEntries(Object.entries(files).sort(([a], [b]) => a < b ? -1 : 1));
|
|
243
|
+
return {
|
|
244
|
+
written,
|
|
245
|
+
lock: {
|
|
246
|
+
...lock,
|
|
247
|
+
files: sorted
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/add/status.ts
|
|
253
|
+
/** Decides the state of one file from its hash in the site, in the release, and in the lock. */
|
|
254
|
+
function classify(siteHash, release, lockHash) {
|
|
255
|
+
if (siteHash === void 0) return "missing";
|
|
256
|
+
if (siteHash === release.hash) return "current";
|
|
257
|
+
if (release.history.includes(siteHash) || siteHash === lockHash) return "outdated";
|
|
258
|
+
if (lockHash === void 0) return "differs";
|
|
259
|
+
return lockHash === release.hash ? "edited" : "conflict";
|
|
260
|
+
}
|
|
261
|
+
/** Reads the site and compares it with the release. Writes nothing. */
|
|
262
|
+
function statusOf(root, registry, lock, sectionsPath) {
|
|
263
|
+
const state = /* @__PURE__ */ new Map();
|
|
264
|
+
const users = /* @__PURE__ */ new Map();
|
|
265
|
+
const stateOf = (file) => {
|
|
266
|
+
let known = state.get(file);
|
|
267
|
+
if (known === void 0) {
|
|
268
|
+
const target = path.join(root, file);
|
|
269
|
+
known = classify(fs.existsSync(target) ? hashContent(file, fs.readFileSync(target)) : void 0, registry.files[file] ?? {
|
|
270
|
+
hash: "",
|
|
271
|
+
history: []
|
|
272
|
+
}, lock.files[file]?.hash);
|
|
273
|
+
state.set(file, known);
|
|
274
|
+
}
|
|
275
|
+
return known;
|
|
276
|
+
};
|
|
277
|
+
const sections = [];
|
|
278
|
+
for (const item of Object.values(registry.items)) {
|
|
279
|
+
const added = fs.existsSync(path.join(root, sectionsPath, item.dir, "definition.ts"));
|
|
280
|
+
const counts = {};
|
|
281
|
+
if (added) for (const file of item.files) {
|
|
282
|
+
const fileState = stateOf(file);
|
|
283
|
+
counts[fileState] = (counts[fileState] ?? 0) + 1;
|
|
284
|
+
users.set(file, [...users.get(file) ?? [], item.dir]);
|
|
285
|
+
}
|
|
286
|
+
sections.push({
|
|
287
|
+
dir: item.dir,
|
|
288
|
+
label: item.label,
|
|
289
|
+
added,
|
|
290
|
+
counts
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const files = [...users.keys()].sort().map((file) => ({
|
|
294
|
+
path: file,
|
|
295
|
+
state: stateOf(file),
|
|
296
|
+
sections: users.get(file) ?? []
|
|
297
|
+
})).filter((file) => file.state !== "current");
|
|
298
|
+
const updatable = sections.filter((section) => section.added && (section.counts.outdated ?? 0) > 0).filter((section) => !section.counts.conflict && !section.counts.differs).map((section) => section.dir);
|
|
299
|
+
return {
|
|
300
|
+
version: registry.version,
|
|
301
|
+
files,
|
|
302
|
+
sections,
|
|
303
|
+
updatable
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/command.ts
|
|
308
|
+
const DEFAULT_SECTIONS_DIR = "src/components/sections";
|
|
309
|
+
const HELP = `The bearminion command line.
|
|
310
|
+
|
|
311
|
+
Usage
|
|
312
|
+
npx bearminion add <section...> [options]
|
|
313
|
+
npx bearminion add --list
|
|
314
|
+
npx bearminion add form [<service>] [--host <host>]
|
|
315
|
+
npx bearminion status [--json]
|
|
316
|
+
npx bearminion sync [options]
|
|
317
|
+
|
|
318
|
+
Commands
|
|
319
|
+
add Copy sections into this site, with the files they need
|
|
320
|
+
status Show which sections are in this site and whether their files match this release
|
|
321
|
+
sync Rewrite sections/definitions.gen.ts and components.gen.ts from the section directories
|
|
322
|
+
|
|
323
|
+
Options for add
|
|
324
|
+
--list List the sections that can be added
|
|
325
|
+
--dry-run Show what would be written, and write nothing
|
|
326
|
+
-y, --yes Do not ask before writing
|
|
327
|
+
--overwrite Replace files you changed (git keeps your version)
|
|
328
|
+
--diff Show how your changed files differ from this release
|
|
329
|
+
--install Install the npm packages the sections need
|
|
330
|
+
--json Print one JSON document instead of text (needs --yes or --dry-run)
|
|
331
|
+
|
|
332
|
+
Options for add form
|
|
333
|
+
--host <host> Where the site runs (found from the project when omitted). See --list
|
|
334
|
+
--list List the services and hosts
|
|
335
|
+
|
|
336
|
+
Options for sync
|
|
337
|
+
--check Write nothing; exit 1 when the generated files are stale
|
|
338
|
+
--sections <dir> The sections folder (default: ${DEFAULT_SECTIONS_DIR})
|
|
339
|
+
|
|
340
|
+
Options for both
|
|
341
|
+
--cwd <dir> Run as if started in this folder
|
|
342
|
+
-h, --help Show this help
|
|
343
|
+
`;
|
|
344
|
+
/** Runs the command line and returns the exit code. */
|
|
345
|
+
async function run(argv, io = {}) {
|
|
346
|
+
const surroundings = {
|
|
347
|
+
log: console.log,
|
|
348
|
+
exec: runInstall,
|
|
349
|
+
...io
|
|
350
|
+
};
|
|
351
|
+
const log = surroundings.log;
|
|
352
|
+
let parsed;
|
|
353
|
+
try {
|
|
354
|
+
parsed = parse(argv);
|
|
355
|
+
} catch (error) {
|
|
356
|
+
log(error instanceof Error ? error.message : String(error));
|
|
357
|
+
log("Run `npx bearminion --help` for the options.");
|
|
358
|
+
return 2;
|
|
359
|
+
}
|
|
360
|
+
const { values, positionals } = parsed;
|
|
361
|
+
const [command, ...rest] = positionals;
|
|
362
|
+
if (values.help || command === void 0) {
|
|
363
|
+
log(HELP);
|
|
364
|
+
return command === void 0 && !values.help ? 2 : 0;
|
|
365
|
+
}
|
|
366
|
+
const root = path.resolve(values.cwd ?? process.cwd());
|
|
367
|
+
if (command === "sync" && rest.length === 0) return runSync(root, values, log);
|
|
368
|
+
if (command === "add") return runAdd(root, rest, values, surroundings);
|
|
369
|
+
if (command === "status" && rest.length === 0) return runStatus(root, values, surroundings);
|
|
370
|
+
log(`I do not know "${positionals.join(" ")}". Run \`npx bearminion --help\` for the commands.`);
|
|
371
|
+
return 2;
|
|
372
|
+
}
|
|
373
|
+
function parse(argv) {
|
|
374
|
+
return parseArgs({
|
|
375
|
+
args: [...argv],
|
|
376
|
+
allowPositionals: true,
|
|
377
|
+
options: {
|
|
378
|
+
check: {
|
|
379
|
+
type: "boolean",
|
|
380
|
+
default: false
|
|
381
|
+
},
|
|
382
|
+
sections: { type: "string" },
|
|
383
|
+
cwd: { type: "string" },
|
|
384
|
+
list: {
|
|
385
|
+
type: "boolean",
|
|
386
|
+
default: false
|
|
387
|
+
},
|
|
388
|
+
"dry-run": {
|
|
389
|
+
type: "boolean",
|
|
390
|
+
default: false
|
|
391
|
+
},
|
|
392
|
+
yes: {
|
|
393
|
+
type: "boolean",
|
|
394
|
+
short: "y",
|
|
395
|
+
default: false
|
|
396
|
+
},
|
|
397
|
+
overwrite: {
|
|
398
|
+
type: "boolean",
|
|
399
|
+
default: false
|
|
400
|
+
},
|
|
401
|
+
diff: {
|
|
402
|
+
type: "boolean",
|
|
403
|
+
default: false
|
|
404
|
+
},
|
|
405
|
+
install: {
|
|
406
|
+
type: "boolean",
|
|
407
|
+
default: false
|
|
408
|
+
},
|
|
409
|
+
json: {
|
|
410
|
+
type: "boolean",
|
|
411
|
+
default: false
|
|
412
|
+
},
|
|
413
|
+
host: { type: "string" },
|
|
414
|
+
help: {
|
|
415
|
+
type: "boolean",
|
|
416
|
+
short: "h",
|
|
417
|
+
default: false
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
function runSync(root, values, log) {
|
|
423
|
+
const sectionsDir = path.resolve(root, values.sections ?? DEFAULT_SECTIONS_DIR);
|
|
424
|
+
try {
|
|
425
|
+
const { changed, entries } = syncSections(sectionsDir, { check: values.check === true });
|
|
426
|
+
if (values.check) {
|
|
427
|
+
if (changed.length > 0) {
|
|
428
|
+
log(staleSectionsMessage(changed));
|
|
429
|
+
return 1;
|
|
430
|
+
}
|
|
431
|
+
log(`${entries.length} sections, generated files up to date.`);
|
|
432
|
+
return 0;
|
|
433
|
+
}
|
|
434
|
+
log(changed.length > 0 ? `Wrote ${changed.join(" and ")} (${entries.length} sections).` : `Already in sync (${entries.length} sections).`);
|
|
435
|
+
return 0;
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (!(error instanceof SectionsError)) throw error;
|
|
438
|
+
log(error.message);
|
|
439
|
+
return 1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function loadRegistry(registryDir) {
|
|
443
|
+
if (registryDir === void 0) throw new Error("This copy of bearminion has no registry. Reinstall the package.");
|
|
444
|
+
const file = path.join(registryDir, "registry.json");
|
|
445
|
+
if (!fs.existsSync(file)) throw new Error(`No registry at ${registryDir}. Reinstall the package.`);
|
|
446
|
+
const registry = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
447
|
+
if (registry.schemaVersion !== 1) throw new Error(`The registry is version ${registry.schemaVersion}, and this command reads version 1.`);
|
|
448
|
+
return {
|
|
449
|
+
registry,
|
|
450
|
+
dir: registryDir
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
/** The item for a name given on the command line: the directory (`logo-strip`) or the section type (`logoStrip`). */
|
|
454
|
+
function findItem(registry, name) {
|
|
455
|
+
return registry.items[name] ?? Object.values(registry.items).find((item) => item.type === name);
|
|
456
|
+
}
|
|
457
|
+
const LABELS = {
|
|
458
|
+
create: "create",
|
|
459
|
+
same: "same",
|
|
460
|
+
update: "update",
|
|
461
|
+
conflict: "conflict",
|
|
462
|
+
overwrite: "overwrite"
|
|
463
|
+
};
|
|
464
|
+
const NOTES = {
|
|
465
|
+
update: "an earlier release that you did not change",
|
|
466
|
+
conflict: "you changed it",
|
|
467
|
+
overwrite: "you changed it"
|
|
468
|
+
};
|
|
469
|
+
function diffAgainstRelease(root, registryDir, file) {
|
|
470
|
+
const result = spawnSync("git", [
|
|
471
|
+
"diff",
|
|
472
|
+
"--no-index",
|
|
473
|
+
"--no-color",
|
|
474
|
+
"--",
|
|
475
|
+
path.join(root, file),
|
|
476
|
+
path.join(registryDir, "files", file)
|
|
477
|
+
], { encoding: "utf8" });
|
|
478
|
+
return result.error ? "(git is not available to show the difference)" : result.stdout.trimEnd();
|
|
479
|
+
}
|
|
480
|
+
async function runAdd(root, names, values, io) {
|
|
481
|
+
if (names[0] === "form") return runAddForm(root, names.slice(1), values, io);
|
|
482
|
+
const { log } = io;
|
|
483
|
+
const json = values.json === true;
|
|
484
|
+
const fail = (message, code = 1, extra = {}) => {
|
|
485
|
+
log(json ? JSON.stringify({
|
|
486
|
+
ok: false,
|
|
487
|
+
error: message,
|
|
488
|
+
...extra
|
|
489
|
+
}, null, 2) : message);
|
|
490
|
+
return code;
|
|
491
|
+
};
|
|
492
|
+
let loaded;
|
|
493
|
+
try {
|
|
494
|
+
loaded = loadRegistry(io.registryDir);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
497
|
+
}
|
|
498
|
+
const { registry, dir: registryDir } = loaded;
|
|
499
|
+
const sectionsDir = path.join(root, SECTIONS_PATH);
|
|
500
|
+
if (values.list) {
|
|
501
|
+
const rows = Object.values(registry.items).map((item) => ({
|
|
502
|
+
name: item.dir,
|
|
503
|
+
type: item.type,
|
|
504
|
+
label: item.label,
|
|
505
|
+
description: item.description,
|
|
506
|
+
added: fs.existsSync(path.join(sectionsDir, item.dir, "definition.ts"))
|
|
507
|
+
}));
|
|
508
|
+
if (json) log(JSON.stringify({
|
|
509
|
+
ok: true,
|
|
510
|
+
version: registry.version,
|
|
511
|
+
sections: rows
|
|
512
|
+
}, null, 2));
|
|
513
|
+
else {
|
|
514
|
+
const width = Math.max(...rows.map((row) => row.name.length));
|
|
515
|
+
for (const row of rows) log(`${row.added ? "*" : " "} ${row.name.padEnd(width)} ${row.description}`);
|
|
516
|
+
log("");
|
|
517
|
+
log("* is already in this site. Add one with `npx bearminion add <name>`.");
|
|
518
|
+
}
|
|
519
|
+
return 0;
|
|
520
|
+
}
|
|
521
|
+
if (names.length === 0) return fail("Name the sections to add, or use --list to see them. For example: npx bearminion add gallery text", 2);
|
|
522
|
+
if (!fs.existsSync(path.join(sectionsDir, "definitions.gen.ts"))) return fail(`This site has no ${SECTIONS_PATH}/definitions.gen.ts, so it lists its sections by hand and \`add\` cannot register a new one. Sites made with bearminion 1.8 and later have it. To move this site over, see "Add a section type" in the template README.`);
|
|
523
|
+
const items = [];
|
|
524
|
+
for (const name of names) {
|
|
525
|
+
const item = findItem(registry, name);
|
|
526
|
+
if (item === void 0) return fail(`There is no section called "${name}". The sections are: ${Object.keys(registry.items).join(", ")}.`, 1, { available: Object.keys(registry.items) });
|
|
527
|
+
if (!items.includes(item)) items.push(item);
|
|
528
|
+
}
|
|
529
|
+
let plan;
|
|
530
|
+
try {
|
|
531
|
+
plan = planAdd(root, registry, items, {
|
|
532
|
+
overwrite: values.overwrite,
|
|
533
|
+
lock: readLock(root, registry.template)
|
|
534
|
+
});
|
|
535
|
+
} catch (error) {
|
|
536
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
537
|
+
}
|
|
538
|
+
const conflicts = plan.files.filter((file) => file.action === "conflict");
|
|
539
|
+
const changes = plan.files.filter((file) => file.action !== "same");
|
|
540
|
+
const installPlan = Object.keys(plan.npm).length > 0 ? installCommand(detectPackageManager(root), plan.npm) : void 0;
|
|
541
|
+
const report = (extra) => JSON.stringify({
|
|
542
|
+
ok: conflicts.length === 0,
|
|
543
|
+
version: registry.version,
|
|
544
|
+
sections: plan.sections.map((section) => section.dir),
|
|
545
|
+
files: plan.files.map(({ path: file, action }) => ({
|
|
546
|
+
path: file,
|
|
547
|
+
action
|
|
548
|
+
})),
|
|
549
|
+
npm: plan.npm,
|
|
550
|
+
dirty: plan.dirty,
|
|
551
|
+
...extra
|
|
552
|
+
}, null, 2);
|
|
553
|
+
if (!json) {
|
|
554
|
+
log(`${values["dry-run"] ? "Would add" : "Adding"} ${plan.sections.map((section) => section.dir).join(", ")} (bearminion ${registry.version})`);
|
|
555
|
+
log("");
|
|
556
|
+
for (const file of changes) {
|
|
557
|
+
const note = NOTES[file.action];
|
|
558
|
+
log(` ${LABELS[file.action].padEnd(9)} ${file.path}${note ? ` (${note})` : ""}`);
|
|
559
|
+
}
|
|
560
|
+
const same = plan.files.length - changes.length;
|
|
561
|
+
if (same > 0) log(` ${same} file${same === 1 ? "" : "s"} already match this release.`);
|
|
562
|
+
log("");
|
|
563
|
+
}
|
|
564
|
+
if (isPresent(plan)) {
|
|
565
|
+
log(json ? report({ written: [] }) : `${plan.sections.map((section) => section.dir).join(", ")} already in this site, and every file matches this release.`);
|
|
566
|
+
return 0;
|
|
567
|
+
}
|
|
568
|
+
if (conflicts.length > 0) {
|
|
569
|
+
if (values.diff && !json) for (const file of conflicts) {
|
|
570
|
+
log(diffAgainstRelease(root, registryDir, file.path));
|
|
571
|
+
log("");
|
|
572
|
+
}
|
|
573
|
+
if (json) log(report({
|
|
574
|
+
error: "Some files differ from this release and were changed by you.",
|
|
575
|
+
written: []
|
|
576
|
+
}));
|
|
577
|
+
else {
|
|
578
|
+
log(`${conflicts.length} file${conflicts.length === 1 ? "" : "s"} differ${conflicts.length === 1 ? "s" : ""} from this release because you changed ${conflicts.length === 1 ? "it" : "them"}. Nothing was written.`);
|
|
579
|
+
log("Use --diff to see how, or --overwrite to replace them with this release. Commit first: git keeps your version.");
|
|
580
|
+
}
|
|
581
|
+
return 1;
|
|
582
|
+
}
|
|
583
|
+
if (!json && plan.files.some((file) => file.action === "update")) log("Shared files that you did not change are replaced by this release. Other sections use them: read the diff and run your build.");
|
|
584
|
+
if (!json && plan.dirty.length > 0) log(`Uncommitted changes in ${plan.dirty.join(", ")} will be overwritten.`);
|
|
585
|
+
if (values["dry-run"]) {
|
|
586
|
+
log(json ? report({
|
|
587
|
+
dryRun: true,
|
|
588
|
+
written: []
|
|
589
|
+
}) : "Dry run: nothing was written.");
|
|
590
|
+
return 0;
|
|
591
|
+
}
|
|
592
|
+
if (!values.yes) {
|
|
593
|
+
if (json || io.confirm === void 0) return fail("Not asking in here: pass --yes to write, or --dry-run to look first.", 1, { files: plan.files });
|
|
594
|
+
const count = plan.files.filter((file) => writesFile(file.action)).length;
|
|
595
|
+
if (!await io.confirm(`Write ${count} file${count === 1 ? "" : "s"}?`)) {
|
|
596
|
+
log("Nothing was written.");
|
|
597
|
+
return 1;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
let written;
|
|
601
|
+
try {
|
|
602
|
+
written = applyPlan(root, registryDir, registry, plan);
|
|
603
|
+
} catch (error) {
|
|
604
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
605
|
+
}
|
|
606
|
+
let installed;
|
|
607
|
+
if (installPlan && values.install) installed = io.exec(installPlan.command, installPlan.args, root) === 0 ? "done" : "failed";
|
|
608
|
+
if (json) log(report({
|
|
609
|
+
written,
|
|
610
|
+
installed: installed ?? null
|
|
611
|
+
}));
|
|
612
|
+
else {
|
|
613
|
+
log(`Wrote ${written.length} file${written.length === 1 ? "" : "s"}, listed them in definitions.gen.ts and components.gen.ts, and noted them in bearminion.lock.json.`);
|
|
614
|
+
if (installPlan && installed === void 0) log(`The sections import packages this site does not list. Install them: ${formatCommand(installPlan)}`);
|
|
615
|
+
if (installed === "failed") log(`Installing failed. Run it yourself: ${formatCommand(installPlan)}`);
|
|
616
|
+
}
|
|
617
|
+
return installed === "failed" ? 1 : 0;
|
|
618
|
+
}
|
|
619
|
+
const STATE_TEXT = {
|
|
620
|
+
current: "current",
|
|
621
|
+
outdated: "outdated (you did not change it; `add` replaces it)",
|
|
622
|
+
edited: "edited by you (nothing to do)",
|
|
623
|
+
conflict: "conflict (you and the release both changed it; `add` stops)",
|
|
624
|
+
differs: "differs (not this release's, and no lock says why; `add` stops)",
|
|
625
|
+
missing: "missing"
|
|
626
|
+
};
|
|
627
|
+
function runStatus(root, values, io) {
|
|
628
|
+
const { log } = io;
|
|
629
|
+
const json = values.json === true;
|
|
630
|
+
const fail = (message) => {
|
|
631
|
+
log(json ? JSON.stringify({
|
|
632
|
+
ok: false,
|
|
633
|
+
error: message
|
|
634
|
+
}, null, 2) : message);
|
|
635
|
+
return 1;
|
|
636
|
+
};
|
|
637
|
+
let loaded;
|
|
638
|
+
try {
|
|
639
|
+
loaded = loadRegistry(io.registryDir);
|
|
640
|
+
} catch (error) {
|
|
641
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
642
|
+
}
|
|
643
|
+
const { registry } = loaded;
|
|
644
|
+
let status;
|
|
645
|
+
try {
|
|
646
|
+
status = statusOf(root, registry, readLock(root, registry.template), SECTIONS_PATH);
|
|
647
|
+
} catch (error) {
|
|
648
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
649
|
+
}
|
|
650
|
+
if (json) {
|
|
651
|
+
log(JSON.stringify({
|
|
652
|
+
ok: true,
|
|
653
|
+
...status
|
|
654
|
+
}, null, 2));
|
|
655
|
+
return 0;
|
|
656
|
+
}
|
|
657
|
+
log(`This release has ${status.sections.length} sections.`);
|
|
658
|
+
const width = Math.max(...status.sections.map((section) => section.dir.length));
|
|
659
|
+
for (const section of status.sections) {
|
|
660
|
+
const detail = section.added ? Object.entries(section.counts).filter(([state]) => state !== "current").map(([state, count]) => `${count} ${state}`).join(", ") || "current" : "not in this site";
|
|
661
|
+
log(`${section.added ? "*" : " "} ${section.dir.padEnd(width)} ${detail}`);
|
|
662
|
+
}
|
|
663
|
+
if (status.files.length > 0) {
|
|
664
|
+
log("");
|
|
665
|
+
for (const file of status.files) log(`${file.path}: ${STATE_TEXT[file.state]} (${file.sections.join(", ")})`);
|
|
666
|
+
}
|
|
667
|
+
log("");
|
|
668
|
+
if (status.updatable.length > 0) log(`Bring up to date: npx bearminion add ${status.updatable.join(" ")}`);
|
|
669
|
+
else log("Nothing to update.");
|
|
670
|
+
return 0;
|
|
671
|
+
}
|
|
672
|
+
async function runAddForm(root, names, values, io) {
|
|
673
|
+
const { log } = io;
|
|
674
|
+
const json = values.json === true;
|
|
675
|
+
const fail = (message, code = 1, extra = {}) => {
|
|
676
|
+
log(json ? JSON.stringify({
|
|
677
|
+
ok: false,
|
|
678
|
+
error: message,
|
|
679
|
+
...extra
|
|
680
|
+
}, null, 2) : message);
|
|
681
|
+
return code;
|
|
682
|
+
};
|
|
683
|
+
if (values.list) {
|
|
684
|
+
if (json) {
|
|
685
|
+
log(JSON.stringify({
|
|
686
|
+
ok: true,
|
|
687
|
+
services: HANDLERS.map(({ name, description, env }) => ({
|
|
688
|
+
name,
|
|
689
|
+
description,
|
|
690
|
+
env
|
|
691
|
+
})),
|
|
692
|
+
hosts: GLUE.map(({ name, description, path: file }) => ({
|
|
693
|
+
name,
|
|
694
|
+
description,
|
|
695
|
+
path: file
|
|
696
|
+
}))
|
|
697
|
+
}, null, 2));
|
|
698
|
+
return 0;
|
|
699
|
+
}
|
|
700
|
+
log(`Services (the handler, written to ${HANDLER_PATH}):`);
|
|
701
|
+
for (const handler of HANDLERS) log(` ${handler.name.padEnd(10)} ${handler.description}`);
|
|
702
|
+
log("");
|
|
703
|
+
log("Hosts (the glue that hands the request to the handler):");
|
|
704
|
+
for (const glue of GLUE) log(` ${glue.name.padEnd(10)} ${glue.description}, ${glue.path}`);
|
|
705
|
+
return 0;
|
|
706
|
+
}
|
|
707
|
+
if (names.length > 1) return fail("Name one service: npx bearminion add form <service> --host <host>. Use --list to see them.", 2);
|
|
708
|
+
const handler = names[0] === void 0 ? void 0 : HANDLERS.find((candidate) => candidate.name === names[0]);
|
|
709
|
+
if (names[0] !== void 0 && handler === void 0) return fail(`There is no form service called "${names[0]}". The services are: ${HANDLERS.map((candidate) => candidate.name).join(", ")}.`);
|
|
710
|
+
const detected = values.host === void 0 ? detectHost(root) : void 0;
|
|
711
|
+
const hostName = values.host ?? detected;
|
|
712
|
+
const glue = hostName === void 0 ? void 0 : GLUE.find((candidate) => candidate.name === hostName);
|
|
713
|
+
if (values.host !== void 0 && glue === void 0) return fail(`There is no host called "${hostName}". The hosts are: ${GLUE.map((candidate) => candidate.name).join(", ")}.`);
|
|
714
|
+
if (handler === void 0 && glue === void 0) return fail("Name a service, a host, or both. For example: npx bearminion add form resend --host vercel. Use --list to see them.", 2);
|
|
715
|
+
let loaded;
|
|
716
|
+
try {
|
|
717
|
+
loaded = loadRegistry(io.registryDir);
|
|
718
|
+
} catch (error) {
|
|
719
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
720
|
+
}
|
|
721
|
+
const { registry } = loaded;
|
|
722
|
+
const plan = planForm(root, handler, glue, values.overwrite === true);
|
|
723
|
+
const conflicts = plan.files.filter((file) => file.action === "conflict");
|
|
724
|
+
const changes = plan.files.filter((file) => file.action !== "same");
|
|
725
|
+
const report = (extra) => JSON.stringify({
|
|
726
|
+
ok: conflicts.length === 0,
|
|
727
|
+
version: registry.version,
|
|
728
|
+
service: handler?.name ?? null,
|
|
729
|
+
host: glue?.name ?? null,
|
|
730
|
+
hostDetected: detected !== void 0,
|
|
731
|
+
files: plan.files.map(({ path: file, action }) => ({
|
|
732
|
+
path: file,
|
|
733
|
+
action
|
|
734
|
+
})),
|
|
735
|
+
env: plan.env,
|
|
736
|
+
...extra
|
|
737
|
+
}, null, 2);
|
|
738
|
+
if (!json) {
|
|
739
|
+
log(`${values["dry-run"] ? "Would add" : "Adding"} the form recipe${glue ? ` for ${glue.name}${detected ? " (found from the project)" : ""}` : ""}${handler ? ` with ${handler.name}` : ""}`);
|
|
740
|
+
log("");
|
|
741
|
+
for (const file of changes) log(` ${LABELS[file.action].padEnd(9)} ${file.path}`);
|
|
742
|
+
const same = plan.files.length - changes.length;
|
|
743
|
+
if (same > 0) log(` ${same} file${same === 1 ? "" : "s"} already match the recipe.`);
|
|
744
|
+
log("");
|
|
745
|
+
}
|
|
746
|
+
if (conflicts.length > 0) {
|
|
747
|
+
if (json) log(report({
|
|
748
|
+
error: "Some files are yours and differ from the recipe.",
|
|
749
|
+
written: []
|
|
750
|
+
}));
|
|
751
|
+
else {
|
|
752
|
+
log(`${conflicts.map((file) => file.path).join(", ")} already exist${conflicts.length === 1 ? "s" : ""} and differ${conflicts.length === 1 ? "s" : ""} from the recipe. Nothing was written.`);
|
|
753
|
+
log("Use --overwrite to replace them. Commit first: git keeps your version.");
|
|
754
|
+
}
|
|
755
|
+
return 1;
|
|
756
|
+
}
|
|
757
|
+
if (changes.length === 0) {
|
|
758
|
+
log(json ? report({ written: [] }) : "Already in this site, and every file matches the recipe.");
|
|
759
|
+
return 0;
|
|
760
|
+
}
|
|
761
|
+
if (values["dry-run"]) {
|
|
762
|
+
log(json ? report({
|
|
763
|
+
dryRun: true,
|
|
764
|
+
written: []
|
|
765
|
+
}) : "Dry run: nothing was written.");
|
|
766
|
+
return 0;
|
|
767
|
+
}
|
|
768
|
+
if (!values.yes) {
|
|
769
|
+
if (json || io.confirm === void 0) return fail("Not asking in here: pass --yes to write, or --dry-run to look first.", 1, { files: plan.files.map(({ path: file, action }) => ({
|
|
770
|
+
path: file,
|
|
771
|
+
action
|
|
772
|
+
})) });
|
|
773
|
+
if (!await io.confirm(`Write ${changes.length} file${changes.length === 1 ? "" : "s"}?`)) {
|
|
774
|
+
log("Nothing was written.");
|
|
775
|
+
return 1;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
let written;
|
|
779
|
+
try {
|
|
780
|
+
const applied = applyForm(root, plan, registry.version, readLock(root, registry.template));
|
|
781
|
+
writeLock(root, applied.lock);
|
|
782
|
+
written = applied.written;
|
|
783
|
+
} catch (error) {
|
|
784
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
785
|
+
}
|
|
786
|
+
if (json) {
|
|
787
|
+
log(report({ written }));
|
|
788
|
+
return 0;
|
|
789
|
+
}
|
|
790
|
+
log(`Wrote ${written.length} file${written.length === 1 ? "" : "s"} and noted them in bearminion.lock.json.`);
|
|
791
|
+
if (plan.env.length > 0) {
|
|
792
|
+
log(`Set ${plan.env.join(", ")} in your host's settings, and in .env for \`astro dev\`.`);
|
|
793
|
+
if (plan.env.includes("CONTACT_FROM")) log("CONTACT_FROM has to be an address on a domain you verified with Resend; CONTACT_TO is where the messages arrive. Until both are set the form refuses to send.");
|
|
794
|
+
}
|
|
795
|
+
if (plan.needs && Object.keys(missingPackages(root, { [plan.needs]: "latest" })).length > 0) log(`The glue imports types from ${plan.needs}. Install it: ${formatCommand(installCommand(detectPackageManager(root), { [plan.needs]: "latest" }))}`);
|
|
796
|
+
if (glue === void 0) log(detected !== void 0 ? `This project deploys to ${detected}, and \`add form\` has no tested glue for it yet. The glue for each host is in the Forms guide: https://docs.bearminion.com/forms` : `No host found in this project, so no glue was written. Add it with: npx bearminion add form --host <${GLUE.map((candidate) => candidate.name).join("|")}>`);
|
|
797
|
+
if (handler === void 0) log(`The glue calls ${HANDLER_PATH}. Add it with: npx bearminion add form <service>`);
|
|
798
|
+
return 0;
|
|
799
|
+
}
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/cli.ts
|
|
802
|
+
/** `npx bearminion`. The registry sits next to `dist/` in the installed package. */
|
|
803
|
+
const registryDir = fileURLToPath(new URL("../registry/default", import.meta.url));
|
|
804
|
+
async function confirm(question) {
|
|
805
|
+
const rl = createInterface({
|
|
806
|
+
input: process.stdin,
|
|
807
|
+
output: process.stdout
|
|
808
|
+
});
|
|
809
|
+
try {
|
|
810
|
+
return /^y(es)?$/i.test((await rl.question(`${question} (y/N) `)).trim());
|
|
811
|
+
} finally {
|
|
812
|
+
rl.close();
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
process.exitCode = await run(process.argv.slice(2), {
|
|
816
|
+
registryDir,
|
|
817
|
+
...process.stdin.isTTY ? { confirm } : {}
|
|
818
|
+
});
|
|
819
|
+
//#endregion
|