bearminion 1.7.0 → 1.8.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 +8 -0
- package/dist/astro.d.ts +2 -2
- package/dist/astro.js +13 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +83 -0
- package/dist/content.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- 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/sections-manifest-CU-xBjMi.js +97 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# bearminion
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 305d094: A section type is now a directory, and nothing else has to be edited. `npx bearminion sync` (new command) writes `definitions.gen.ts` and `components.gen.ts` from the directories under `sections/`; the starter's hand-written `registry.ts` and the `case` per section in `SectionList.astro` are gone. The new `sectionsDir` option makes `astro build`, `astro check` and `astro sync` stop when the generated files are stale, and `astro dev` warn. `npx bearminion sync --check` is the same test for CI.
|
|
8
|
+
|
|
9
|
+
Sites created before this release keep working as they are. To move one over, copy `definitions.ts`, `SectionList.astro` and `astro.config.ts` from a new site, delete `registry.ts`, run `npx bearminion sync`, and read [Add a section type](https://github.com/langehelp-software/bearminion/blob/main/templates/default/README.md#add-a-section-type).
|
|
10
|
+
|
|
3
11
|
## 1.7.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/dist/astro.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as SectionRegistry, J as SiteDefinition, Y as SiteOf, Yt as ContentMigrator, k as ContentModel, t as Page, u as SectionOf } from "./page-
|
|
2
|
-
import { a as StoreKeyError, c as createFileStore, i as FileStoreOptions, n as EditorContext, o as StoreOperation, r as ContentStore, s as UploadStore, t as BearminionOptions } from "./options-
|
|
1
|
+
import { A as SectionRegistry, J as SiteDefinition, Y as SiteOf, Yt as ContentMigrator, k as ContentModel, t as Page, u as SectionOf } from "./page-CA4iyFDS.js";
|
|
2
|
+
import { a as StoreKeyError, c as createFileStore, i as FileStoreOptions, n as EditorContext, o as StoreOperation, r as ContentStore, s as UploadStore, t as BearminionOptions } from "./options-4HWVEj9O.js";
|
|
3
3
|
import { AstroIntegration } from "astro";
|
|
4
4
|
//#region src/integration.d.ts
|
|
5
5
|
interface BearminionIntegration extends AstroIntegration {
|
package/dist/astro.js
CHANGED
|
@@ -4,6 +4,7 @@ import { i as isSystemPage, n as createPageSchema$1, r as createTolerantPageSche
|
|
|
4
4
|
import { a as DEFAULT_UPLOADS_DIR, i as DEFAULT_CONTENT_DIR, n as createMigrator, o as DEFAULT_VIDEOS_DIR, r as API_PREFIX, t as SCHEMA_VERSION_KEY } from "./migrate-b408EaLp.js";
|
|
5
5
|
import { a as JSON_BODY_LIMIT, c as isInside, d as resolveDir, f as resolveInside, i as IMAGE_BYTE_LIMIT, l as isLocalRequest, n as contentReloadPlugin, o as MULTIPART_BODY_LIMIT, r as dropEarlyReloadAfterSave, s as asDirectory, u as readSlug } from "./reload-BPkPoQ-P.js";
|
|
6
6
|
import { S as isAssetPath, b as describeSiteRef, c as projectId, v as assetRefs, y as describePageRef } from "./draft-store-1Y4-sn45.js";
|
|
7
|
+
import { n as staleSectionsMessage, r as syncSections } from "./sections-manifest-CU-xBjMi.js";
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
import fs from "node:fs";
|
|
9
10
|
import path from "node:path";
|
|
@@ -1997,7 +1998,14 @@ function bearminion(options) {
|
|
|
1997
1998
|
return {
|
|
1998
1999
|
name: "bearminion",
|
|
1999
2000
|
hooks: {
|
|
2000
|
-
"astro:config:setup"({ command, config, updateConfig, injectScript }) {
|
|
2001
|
+
"astro:config:setup"({ command, config, updateConfig, injectScript, logger }) {
|
|
2002
|
+
if (options.sectionsDir !== void 0) {
|
|
2003
|
+
const { changed } = syncSections(path.resolve(rootPath(config.root), options.sectionsDir), { check: true });
|
|
2004
|
+
if (changed.length > 0) {
|
|
2005
|
+
if (command !== "dev") throw new Error(staleSectionsMessage(changed));
|
|
2006
|
+
logger.warn(staleSectionsMessage(changed));
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2001
2009
|
if (command !== "dev") return;
|
|
2002
2010
|
const context = resolveEditorContext(options, rootInput(config.root));
|
|
2003
2011
|
updateConfig({ vite: {
|
|
@@ -2087,6 +2095,10 @@ async function renderSitePreview(environment, previewModule, site, pathname) {
|
|
|
2087
2095
|
pathname
|
|
2088
2096
|
});
|
|
2089
2097
|
}
|
|
2098
|
+
function rootPath(root) {
|
|
2099
|
+
const input = rootInput(root);
|
|
2100
|
+
return input instanceof URL ? fileURLToPath(input) : input;
|
|
2101
|
+
}
|
|
2090
2102
|
function rootInput(root) {
|
|
2091
2103
|
if (typeof root === "string" || root instanceof URL) return root;
|
|
2092
2104
|
return process.cwd();
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { n as staleSectionsMessage, r as syncSections, t as SectionsError } from "./sections-manifest-CU-xBjMi.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
//#region src/command.ts
|
|
6
|
+
const DEFAULT_SECTIONS_DIR = "src/components/sections";
|
|
7
|
+
const HELP = `The bearminion command line.
|
|
8
|
+
|
|
9
|
+
Usage
|
|
10
|
+
npx bearminion sync [options]
|
|
11
|
+
|
|
12
|
+
Commands
|
|
13
|
+
sync Rewrite sections/definitions.gen.ts and components.gen.ts from the section directories
|
|
14
|
+
|
|
15
|
+
Options
|
|
16
|
+
--check Write nothing; exit 1 when the generated files are stale
|
|
17
|
+
--sections <dir> The sections folder (default: ${DEFAULT_SECTIONS_DIR})
|
|
18
|
+
--cwd <dir> Run as if started in this folder
|
|
19
|
+
-h, --help Show this help
|
|
20
|
+
`;
|
|
21
|
+
/** Runs the command line and returns the exit code. */
|
|
22
|
+
function run(argv, log = console.log) {
|
|
23
|
+
let parsed;
|
|
24
|
+
try {
|
|
25
|
+
parsed = parse(argv);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
log(error instanceof Error ? error.message : String(error));
|
|
28
|
+
log("Run `npx bearminion --help` for the options.");
|
|
29
|
+
return 2;
|
|
30
|
+
}
|
|
31
|
+
const { values, positionals } = parsed;
|
|
32
|
+
const [command, ...rest] = positionals;
|
|
33
|
+
if (values.help || command === void 0) {
|
|
34
|
+
log(HELP);
|
|
35
|
+
return command === void 0 && !values.help ? 2 : 0;
|
|
36
|
+
}
|
|
37
|
+
if (command !== "sync" || rest.length > 0) {
|
|
38
|
+
log(`I do not know "${positionals.join(" ")}". Run \`npx bearminion --help\` for the commands.`);
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
const root = path.resolve(values.cwd ?? process.cwd());
|
|
42
|
+
const sectionsDir = path.resolve(root, values.sections ?? DEFAULT_SECTIONS_DIR);
|
|
43
|
+
try {
|
|
44
|
+
const { changed, entries } = syncSections(sectionsDir, { check: values.check === true });
|
|
45
|
+
if (values.check) {
|
|
46
|
+
if (changed.length > 0) {
|
|
47
|
+
log(staleSectionsMessage(changed));
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
log(`${entries.length} sections, generated files up to date.`);
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
log(changed.length > 0 ? `Wrote ${changed.join(" and ")} (${entries.length} sections).` : `Already in sync (${entries.length} sections).`);
|
|
54
|
+
return 0;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (!(error instanceof SectionsError)) throw error;
|
|
57
|
+
log(error.message);
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function parse(argv) {
|
|
62
|
+
return parseArgs({
|
|
63
|
+
args: [...argv],
|
|
64
|
+
allowPositionals: true,
|
|
65
|
+
options: {
|
|
66
|
+
check: {
|
|
67
|
+
type: "boolean",
|
|
68
|
+
default: false
|
|
69
|
+
},
|
|
70
|
+
sections: { type: "string" },
|
|
71
|
+
cwd: { type: "string" },
|
|
72
|
+
help: {
|
|
73
|
+
type: "boolean",
|
|
74
|
+
short: "h",
|
|
75
|
+
default: false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/cli.ts
|
|
82
|
+
process.exitCode = run(process.argv.slice(2));
|
|
83
|
+
//#endregion
|
package/dist/content.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as brandLogoSchema, $t as createMigrator, A as SectionRegistry, At as wireframeIssues, B as FooterColumn, Bt as themeModes, C as jsonLdWarnings, Ct as SectionDefinition, D as upsertJsonLd, Dt as Wireframe, E as siteJsonLdIds, Et as WireRect, F as defineTheme, Ft as NumberOption, G as SiteAnalytics, Gt as FieldIcons, H as Header, Ht as tones, I as BRAND_LOGO_HEIGHT, It as Option, J as SiteDefinition, Jt as ContentMigration, K as SiteConfig, Kt as ShowCondition, L as DEFAULT_MAX_FOOTER_COLUMNS, Lt as StringOption, M as ThemeDefinition, Mt as BooleanOption, N as ThemeFont, Nt as CountRule, O as API_PREFIX, Ot as defineWireframe, P as defaultTheme, Pt as EnumOption, Q as Theme, Qt as SCHEMA_VERSION_KEY, R as DEFAULT_MAX_HEADER_ACTIONS, Rt as buttonStyles, S as jsonLdSchema, St as SectionConfig, T as parseJsonLdInput, Tt as WireKind, U as HeaderConfig, Ut as variantOption, V as FooterConfig, Vt as toneOption, W as Site, Wt as FieldChoices, X as SiteSeo, Xt as ContentVersioning, Y as SiteOf, Yt as ContentMigrator, Z as SiteWith, Zt as DocumentKind, _ as SiteJsonLdSource, _t as textMarkSchema, a as isSystemPage, at as themeSchema, b as hasJsonLdId, bt as trackingIdSchema, c as BaseSection, ct as Link, d as anchorSchema, dt as Text, et as defineSite, f as createSectionSchema, ft as Tone, g as SiteJsonLdIds, gt as richTextSchema, h as JsonLdResult, ht as linkSchema, i as createPageSchema, it as themeColorsSchema, j as ThemeConfig, jt as OptionalContent, k as ContentModel, kt as wireKinds, l as PropsOf, lt as MAX_NAV_DEPTH, m as JsonLdBlock, mt as imageSchema, n as SYSTEM_PAGES, nt as siteConsentSchema, o as seoSchema, ot as ButtonStyle, p as sectionIdSchema, pt as htmlIdSchema, q as SiteConsent, qt as ShowWhen, r as Seo, rt as siteSeoSchema, s as withoutOrphanSections, st as Image, t as Page, tt as siteAnalyticsSchema, u as SectionOf, ut as RichText, v as formatJsonLd, vt as textSchema, w as mergeJsonLd, wt as defineSection, x as isPlaceholderSiteUrl, xt as withEmphasis, y as generateSiteJsonLd, yt as toneSchema, z as Footer, zt as motionOption } from "./page-
|
|
1
|
+
import { $ as brandLogoSchema, $t as createMigrator, A as SectionRegistry, At as wireframeIssues, B as FooterColumn, Bt as themeModes, C as jsonLdWarnings, Ct as SectionDefinition, D as upsertJsonLd, Dt as Wireframe, E as siteJsonLdIds, Et as WireRect, F as defineTheme, Ft as NumberOption, G as SiteAnalytics, Gt as FieldIcons, H as Header, Ht as tones, I as BRAND_LOGO_HEIGHT, It as Option, J as SiteDefinition, Jt as ContentMigration, K as SiteConfig, Kt as ShowCondition, L as DEFAULT_MAX_FOOTER_COLUMNS, Lt as StringOption, M as ThemeDefinition, Mt as BooleanOption, N as ThemeFont, Nt as CountRule, O as API_PREFIX, Ot as defineWireframe, P as defaultTheme, Pt as EnumOption, Q as Theme, Qt as SCHEMA_VERSION_KEY, R as DEFAULT_MAX_HEADER_ACTIONS, Rt as buttonStyles, S as jsonLdSchema, St as SectionConfig, T as parseJsonLdInput, Tt as WireKind, U as HeaderConfig, Ut as variantOption, V as FooterConfig, Vt as toneOption, W as Site, Wt as FieldChoices, X as SiteSeo, Xt as ContentVersioning, Y as SiteOf, Yt as ContentMigrator, Z as SiteWith, Zt as DocumentKind, _ as SiteJsonLdSource, _t as textMarkSchema, a as isSystemPage, at as themeSchema, b as hasJsonLdId, bt as trackingIdSchema, c as BaseSection, ct as Link, d as anchorSchema, dt as Text, et as defineSite, f as createSectionSchema, ft as Tone, g as SiteJsonLdIds, gt as richTextSchema, h as JsonLdResult, ht as linkSchema, i as createPageSchema, it as themeColorsSchema, j as ThemeConfig, jt as OptionalContent, k as ContentModel, kt as wireKinds, l as PropsOf, lt as MAX_NAV_DEPTH, m as JsonLdBlock, mt as imageSchema, n as SYSTEM_PAGES, nt as siteConsentSchema, o as seoSchema, ot as ButtonStyle, p as sectionIdSchema, pt as htmlIdSchema, q as SiteConsent, qt as ShowWhen, r as Seo, rt as siteSeoSchema, s as withoutOrphanSections, st as Image, t as Page, tt as siteAnalyticsSchema, u as SectionOf, ut as RichText, v as formatJsonLd, vt as textSchema, w as mergeJsonLd, wt as defineSection, x as isPlaceholderSiteUrl, xt as withEmphasis, y as generateSiteJsonLd, yt as toneSchema, z as Footer, zt as motionOption } from "./page-CA4iyFDS.js";
|
|
2
2
|
import { _ as renderMarkedHtml, a as WeightMark, f as markClass, g as reconcileMarks, i as TextRun, l as fontMarks, m as marksFromEmphasis, o as applyTextMark, r as TextMark, t as FontMark, v as splitMarkedText, y as weightMarks } from "./marks-BzLa48Y9.js";
|
|
3
|
-
import "./options-
|
|
3
|
+
import "./options-4HWVEj9O.js";
|
|
4
4
|
import { a as TURNSTILE_FIELD, i as HONEYPOT_FIELD, n as FormResult, r as FormSubmission, t as FormFieldErrors } from "./form-contract-BURSJP3Y.js";
|
|
5
5
|
//#region src/errors.d.ts
|
|
6
6
|
/** One schema problem, addressed by a dot path such as `sections.0.props.heading`. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SectionRegistry, J as SiteDefinition, M as ThemeDefinition, Yt as ContentMigrator, k as ContentModel } from "./page-
|
|
1
|
+
import { A as SectionRegistry, J as SiteDefinition, M as ThemeDefinition, Yt as ContentMigrator, k as ContentModel } from "./page-CA4iyFDS.js";
|
|
2
2
|
//#region src/images.d.ts
|
|
3
3
|
type ImageKind = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
|
|
4
4
|
interface SavedImage {
|
|
@@ -117,6 +117,12 @@ interface BearminionOptions extends ContentModel {
|
|
|
117
117
|
* Default `/src/lib/render-preview.ts`. Preview never writes to disk.
|
|
118
118
|
*/
|
|
119
119
|
previewModule?: string;
|
|
120
|
+
/**
|
|
121
|
+
* The folder that holds the section directories and the files `bearminion sync` generates from them, relative to the
|
|
122
|
+
* project root. When set, `astro build`, `astro check` and `astro sync` stop if those files are stale, and
|
|
123
|
+
* `astro dev` warns. Default: not checked.
|
|
124
|
+
*/
|
|
125
|
+
sectionsDir?: string;
|
|
120
126
|
/**
|
|
121
127
|
* The dev route for the forms in your site. A file `src/forms/contact.ts` that default-exports `defineForm(...)`
|
|
122
128
|
* answers at `/api/contact` during `astro dev`, as a dry run unless `BEARMINION_FORMS_LIVE=on`. `dir` is the folder
|
|
@@ -275,10 +275,10 @@ declare const textMarkSchema: z.ZodObject<{
|
|
|
275
275
|
start: z.ZodNumber;
|
|
276
276
|
end: z.ZodNumber;
|
|
277
277
|
weight: z.ZodOptional<z.ZodEnum<{
|
|
278
|
+
bold: "bold";
|
|
278
279
|
regular: "regular";
|
|
279
280
|
medium: "medium";
|
|
280
281
|
semibold: "semibold";
|
|
281
|
-
bold: "bold";
|
|
282
282
|
}>>;
|
|
283
283
|
italic: z.ZodOptional<z.ZodBoolean>;
|
|
284
284
|
font: z.ZodOptional<z.ZodEnum<{
|
|
@@ -319,10 +319,10 @@ declare function withEmphasis<T extends z.ZodRawShape>(shape: T): z.ZodPipe<z.Zo
|
|
|
319
319
|
start: z.ZodNumber;
|
|
320
320
|
end: z.ZodNumber;
|
|
321
321
|
weight: z.ZodOptional<z.ZodEnum<{
|
|
322
|
+
bold: "bold";
|
|
322
323
|
regular: "regular";
|
|
323
324
|
medium: "medium";
|
|
324
325
|
semibold: "semibold";
|
|
325
|
-
bold: "bold";
|
|
326
326
|
}>>;
|
|
327
327
|
italic: z.ZodOptional<z.ZodBoolean>;
|
|
328
328
|
font: z.ZodOptional<z.ZodEnum<{
|
|
@@ -337,10 +337,10 @@ declare function withEmphasis<T extends z.ZodRawShape>(shape: T): z.ZodPipe<z.Zo
|
|
|
337
337
|
start: z.ZodNumber;
|
|
338
338
|
end: z.ZodNumber;
|
|
339
339
|
weight: z.ZodOptional<z.ZodEnum<{
|
|
340
|
+
bold: "bold";
|
|
340
341
|
regular: "regular";
|
|
341
342
|
medium: "medium";
|
|
342
343
|
semibold: "semibold";
|
|
343
|
-
bold: "bold";
|
|
344
344
|
}>>;
|
|
345
345
|
italic: z.ZodOptional<z.ZodBoolean>;
|
|
346
346
|
font: z.ZodOptional<z.ZodEnum<{
|
|
@@ -357,10 +357,10 @@ declare function withEmphasis<T extends z.ZodRawShape>(shape: T): z.ZodPipe<z.Zo
|
|
|
357
357
|
start: z.ZodNumber;
|
|
358
358
|
end: z.ZodNumber;
|
|
359
359
|
weight: z.ZodOptional<z.ZodEnum<{
|
|
360
|
+
bold: "bold";
|
|
360
361
|
regular: "regular";
|
|
361
362
|
medium: "medium";
|
|
362
363
|
semibold: "semibold";
|
|
363
|
-
bold: "bold";
|
|
364
364
|
}>>;
|
|
365
365
|
italic: z.ZodOptional<z.ZodBoolean>;
|
|
366
366
|
font: z.ZodOptional<z.ZodEnum<{
|
|
@@ -617,10 +617,10 @@ declare function createSiteSchema(header: HeaderParts, footer: FooterParts): z.Z
|
|
|
617
617
|
start: z.ZodNumber;
|
|
618
618
|
end: z.ZodNumber;
|
|
619
619
|
weight: z.ZodOptional<z.ZodEnum<{
|
|
620
|
+
bold: "bold";
|
|
620
621
|
regular: "regular";
|
|
621
622
|
medium: "medium";
|
|
622
623
|
semibold: "semibold";
|
|
623
|
-
bold: "bold";
|
|
624
624
|
}>>;
|
|
625
625
|
italic: z.ZodOptional<z.ZodBoolean>;
|
|
626
626
|
font: z.ZodOptional<z.ZodEnum<{
|
|
@@ -852,7 +852,7 @@ declare function createSiteSchema(header: HeaderParts, footer: FooterParts): z.Z
|
|
|
852
852
|
nameMarks: {
|
|
853
853
|
start: number;
|
|
854
854
|
end: number;
|
|
855
|
-
weight?: "
|
|
855
|
+
weight?: "bold" | "regular" | "medium" | "semibold" | undefined;
|
|
856
856
|
italic?: boolean | undefined;
|
|
857
857
|
font?: "sans" | "serif" | "mono" | undefined;
|
|
858
858
|
}[] | undefined;
|
|
@@ -1110,7 +1110,7 @@ declare function createSiteSchema(header: HeaderParts, footer: FooterParts): z.Z
|
|
|
1110
1110
|
nameMarks?: {
|
|
1111
1111
|
start: number;
|
|
1112
1112
|
end: number;
|
|
1113
|
-
weight?: "
|
|
1113
|
+
weight?: "bold" | "regular" | "medium" | "semibold" | undefined;
|
|
1114
1114
|
italic?: boolean | undefined;
|
|
1115
1115
|
font?: "sans" | "serif" | "mono" | undefined;
|
|
1116
1116
|
}[] | undefined;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/sections-manifest.ts
|
|
4
|
+
/** The two files `bearminion sync` writes next to the section directories. */
|
|
5
|
+
const DEFINITIONS_FILE = "definitions.gen.ts";
|
|
6
|
+
const COMPONENTS_FILE = "components.gen.ts";
|
|
7
|
+
/** A section directory that does not follow the convention. The message says what to fix. */
|
|
8
|
+
var SectionsError = class extends Error {};
|
|
9
|
+
const DIRECTORY_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
10
|
+
const toCamelCase = (dir) => dir.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
11
|
+
const toPascalCase = (dir) => {
|
|
12
|
+
const camel = toCamelCase(dir);
|
|
13
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Lists the section directories: every folder under `sectionsDir` that holds a `definition.ts`. Folders that start
|
|
17
|
+
* with `_` or `.` and folders without a definition are not sections. Sorted by name, so the result never depends on
|
|
18
|
+
* the file system.
|
|
19
|
+
*/
|
|
20
|
+
function scanSections(sectionsDir) {
|
|
21
|
+
if (!fs.existsSync(sectionsDir)) throw new SectionsError(`No sections folder at ${sectionsDir}.`);
|
|
22
|
+
const entries = [];
|
|
23
|
+
for (const child of fs.readdirSync(sectionsDir, { withFileTypes: true })) {
|
|
24
|
+
if (!child.isDirectory() || child.name.startsWith("_") || child.name.startsWith(".")) continue;
|
|
25
|
+
if (!fs.existsSync(path.join(sectionsDir, child.name, "definition.ts"))) continue;
|
|
26
|
+
if (!DIRECTORY_NAME.test(child.name)) throw new SectionsError(`"${child.name}" is not a usable section name. Use lowercase words joined by hyphens, such as "logo-strip": the directory name becomes the section type.`);
|
|
27
|
+
const component = toPascalCase(child.name);
|
|
28
|
+
if (!fs.existsSync(path.join(sectionsDir, child.name, `${component}.astro`))) throw new SectionsError(`${child.name}/ has a definition.ts but no ${component}.astro. The component is named after the directory.`);
|
|
29
|
+
entries.push({
|
|
30
|
+
dir: child.name,
|
|
31
|
+
key: toCamelCase(child.name),
|
|
32
|
+
component
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (entries.length === 0) throw new SectionsError(`No sections found in ${sectionsDir}. A section is a directory with a definition.ts.`);
|
|
36
|
+
return entries.sort((a, b) => a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0);
|
|
37
|
+
}
|
|
38
|
+
const HEADER = "// Generated by `bearminion sync`. Do not edit: add or remove a directory under sections/ and run it again.";
|
|
39
|
+
/** The contents of `definitions.gen.ts`: schemas only, no `.astro` imports, so `astro.config.ts` and the editor can load it. */
|
|
40
|
+
function renderDefinitions(entries) {
|
|
41
|
+
const imports = entries.map((entry) => `import { ${entry.key} } from './${entry.dir}/definition'`);
|
|
42
|
+
const keys = entries.map((entry) => ` ${entry.key},`);
|
|
43
|
+
return [
|
|
44
|
+
HEADER,
|
|
45
|
+
"import type { SectionRegistry } from 'bearminion'",
|
|
46
|
+
...imports,
|
|
47
|
+
"",
|
|
48
|
+
"export const sectionDefinitions = {",
|
|
49
|
+
...keys,
|
|
50
|
+
"} satisfies SectionRegistry",
|
|
51
|
+
""
|
|
52
|
+
].join("\n");
|
|
53
|
+
}
|
|
54
|
+
/** The contents of `components.gen.ts`: the section type to the component that renders it. */
|
|
55
|
+
function renderComponents(entries) {
|
|
56
|
+
const imports = entries.map((entry) => `import ${entry.component} from './${entry.dir}/${entry.component}.astro'`);
|
|
57
|
+
const map = entries.map((entry) => ` ${entry.key}: ${entry.component},`);
|
|
58
|
+
return [
|
|
59
|
+
HEADER,
|
|
60
|
+
"import type { SectionType } from './definitions'",
|
|
61
|
+
...imports,
|
|
62
|
+
"",
|
|
63
|
+
"/** Maps a content section `type` to the component that renders it. */",
|
|
64
|
+
"export const sectionComponents = {",
|
|
65
|
+
...map,
|
|
66
|
+
"} satisfies Record<SectionType, unknown>",
|
|
67
|
+
""
|
|
68
|
+
].join("\n");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Makes `definitions.gen.ts` and `components.gen.ts` match the section directories. With `check` it only reports
|
|
72
|
+
* which files are stale and writes nothing.
|
|
73
|
+
*/
|
|
74
|
+
function syncSections(sectionsDir, options = {}) {
|
|
75
|
+
const entries = scanSections(sectionsDir);
|
|
76
|
+
const wanted = {
|
|
77
|
+
[DEFINITIONS_FILE]: renderDefinitions(entries),
|
|
78
|
+
[COMPONENTS_FILE]: renderComponents(entries)
|
|
79
|
+
};
|
|
80
|
+
const changed = [];
|
|
81
|
+
for (const [file, content] of Object.entries(wanted)) {
|
|
82
|
+
const target = path.join(sectionsDir, file);
|
|
83
|
+
if ((fs.existsSync(target) ? fs.readFileSync(target, "utf8") : void 0) === content) continue;
|
|
84
|
+
changed.push(file);
|
|
85
|
+
if (!options.check) fs.writeFileSync(target, content);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
changed,
|
|
89
|
+
entries
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** The sentence for a build that stops on stale files, or for the dev server's warning. */
|
|
93
|
+
function staleSectionsMessage(changed) {
|
|
94
|
+
return `${changed.join(" and ")} no longer match the directories under sections/. Run \`npx bearminion sync\`.`;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { staleSectionsMessage as n, syncSections as r, SectionsError as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bearminion",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A git-based CMS for Astro with no database and no server: JSON content in your repo, edited by clicking on the page during astro dev.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakub Lange",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"node": ">=22.12.0"
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
|
+
"bin": {
|
|
31
|
+
"bearminion": "./dist/cli.js"
|
|
32
|
+
},
|
|
30
33
|
"exports": {
|
|
31
34
|
".": {
|
|
32
35
|
"types": "./dist/index.d.ts",
|