create-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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # create-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bearminion",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Create a BearMinion site: an Astro website you edit by clicking on it. No database, no server.",
5
5
  "license": "MIT",
6
6
  "author": "Jakub Lange",
@@ -38,7 +38,7 @@ src/components/
38
38
  atoms/ Typography, Button, Image, LogoMark, Emphasis
39
39
  molecules/ SectionShell, SectionHeader, MediaFrame, Pill, CommandLine
40
40
  organisms/ Header, Navigation, MobileMenu, Footer, plus site-definition.ts (header and footer layouts, limits)
41
- sections/ one directory per type, plus definitions.ts, registry.ts, shared.ts, SectionList.astro
41
+ sections/ one directory per type, plus definitions.ts, shared.ts, SectionList.astro and the generated definitions.gen.ts, components.gen.ts
42
42
  hero/ definition.ts (zod schema, defaults, options), wireframe.ts (picker thumbnail), Hero.astro, Hero.stories.ts
43
43
  logo-strip/ steps/ gallery/ features/ text/ text-image/ stats/ testimonials/ pricing/ media/ faq/ cta/ contact/
44
44
  seo/ Seo
@@ -48,7 +48,7 @@ src/components/
48
48
 
49
49
  ## Add a section type
50
50
 
51
- A section type is one directory under `src/components/sections/` plus three one-line registrations. This walks through a `quote` section: a pull quote with an attribution.
51
+ A section type is one directory under `src/components/sections/` and one command, `npx bearminion sync`. This walks through a `quote` section: a pull quote with an attribution.
52
52
 
53
53
  **1. The definition** (`quote/definition.ts`). The Zod schema validates the JSON and drives the editor's Content fields; `defaults` is what a new section starts with and must pass the schema.
54
54
 
@@ -120,15 +120,19 @@ const field = (path: string) => `sections.${index}.props.${path}`
120
120
  </SectionShell>
121
121
  ```
122
122
 
123
- **4. Register it** in three places:
123
+ **4. Register it** with one command:
124
124
 
125
- - `sections/definitions.ts`: add `quote` to `sectionDefinitions`. This is the schema side, loaded by `astro.config.ts` and the editor, so it must not import `.astro` files.
126
- - `sections/registry.ts`: add `quote: Quote`. The `satisfies Record<SectionType, unknown>` check fails until you do.
127
- - `sections/SectionList.astro`: add a `case 'quote'` that renders `<Quote section={section} index={index} motion={motion} />`. The switch is what gives each component its exact section type.
125
+ ```sh
126
+ npx bearminion sync
127
+ ```
128
+
129
+ It lists every directory under `sections/` that holds a `definition.ts` in two generated files, `definitions.gen.ts` (the schemas, with no `.astro` imports, so `astro.config.ts` and the editor can load them) and `components.gen.ts` (type → component). The names follow the directory: `quote/` exports `quote` from `definition.ts` and `Quote` from `Quote.astro`, and `logo-strip/` becomes `logoStrip` and `LogoStrip`. `SectionList.astro` renders whatever the map holds, so it needs no edit. Do not edit the generated files; commit them. `astro build`, `astro check` and `astro sync` stop with a reminder when they are stale, and `astro dev` warns. `npx bearminion sync --check` is the same test for CI.
130
+
131
+ The Add section menu lists the types in the order of `order` in `sections/definitions.ts`; a type that is not listed there (yours) comes last, by name.
128
132
 
129
133
  Restart `npm run dev`. The section appears in the Add section picker, its fields in the sidebar, and `npm run typecheck` checks the component against the schema. Add a `Quote.stories.ts` next to it if you use Storybook.
130
134
 
131
- Removing a section type later is safe: pages that still hold it open in the editor with an "Unknown" section you can delete, and `astro build` fails until they are cleaned up.
135
+ Removing a section type later means deleting its directory and running `npx bearminion sync`. It is safe: pages that still hold it open in the editor with an "Unknown" section you can delete, and `astro build` fails until they are cleaned up.
132
136
 
133
137
  ## Atoms
134
138
 
@@ -50,6 +50,8 @@ export default defineConfig({
50
50
  bearminion({
51
51
  contentDir,
52
52
  ...contentModel,
53
+ // `astro build` stops when the files `bearminion sync` writes no longer match the section directories.
54
+ sectionsDir: 'src/components/sections',
53
55
  git: process.env.BEARMINION_GIT === 'true',
54
56
  uploadsDir: process.env.BEARMINION_UPLOADS_DIR
55
57
  ? path.resolve(process.env.BEARMINION_UPLOADS_DIR)
@@ -19,7 +19,7 @@
19
19
  "@fontsource/jetbrains-mono": "^5.3.0",
20
20
  "@tailwindcss/vite": "^4.1.12",
21
21
  "astro": "^7.4.1",
22
- "bearminion": "^1.7.0",
22
+ "bearminion": "^1.8.0",
23
23
  "class-variance-authority": "^0.7.1",
24
24
  "sharp": "^0.35.5",
25
25
  "tailwind-merge": "^3.7.0",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import type { Section } from './definitions'
3
- import { sectionComponents } from './registry'
3
+ import { sectionComponents } from './components.gen'
4
4
 
5
5
  interface Props {
6
6
  sections: Section[]
@@ -8,58 +8,15 @@ interface Props {
8
8
  motion?: boolean
9
9
  }
10
10
 
11
+ /** What every section component takes. Each one narrows `section` to its own type. */
12
+ type SectionComponent = (props: { section: Section; index: number; motion?: boolean }) => unknown
13
+
11
14
  const { sections, motion = true } = Astro.props
12
- const Hero = sectionComponents.hero
13
- const LogoStrip = sectionComponents.logoStrip
14
- const Steps = sectionComponents.steps
15
- const Gallery = sectionComponents.gallery
16
- const Features = sectionComponents.features
17
- const Text = sectionComponents.text
18
- const TextImage = sectionComponents.textImage
19
- const Stats = sectionComponents.stats
20
- const Testimonials = sectionComponents.testimonials
21
- const Pricing = sectionComponents.pricing
22
- const Media = sectionComponents.media
23
- const Faq = sectionComponents.faq
24
- const Cta = sectionComponents.cta
25
- const Contact = sectionComponents.contact
26
15
  ---
27
16
 
28
17
  {
29
18
  sections.map((section, index) => {
30
- switch (section.type) {
31
- case 'hero':
32
- return <Hero section={section} index={index} motion={motion} />
33
- case 'logoStrip':
34
- return <LogoStrip section={section} index={index} motion={motion} />
35
- case 'steps':
36
- return <Steps section={section} index={index} motion={motion} />
37
- case 'gallery':
38
- return <Gallery section={section} index={index} motion={motion} />
39
- case 'features':
40
- return <Features section={section} index={index} motion={motion} />
41
- case 'text':
42
- return <Text section={section} index={index} motion={motion} />
43
- case 'textImage':
44
- return <TextImage section={section} index={index} motion={motion} />
45
- case 'stats':
46
- return <Stats section={section} index={index} motion={motion} />
47
- case 'testimonials':
48
- return <Testimonials section={section} index={index} motion={motion} />
49
- case 'pricing':
50
- return <Pricing section={section} index={index} motion={motion} />
51
- case 'media':
52
- return <Media section={section} index={index} motion={motion} />
53
- case 'faq':
54
- return <Faq section={section} index={index} motion={motion} />
55
- case 'cta':
56
- return <Cta section={section} index={index} motion={motion} />
57
- case 'contact':
58
- return <Contact section={section} index={index} motion={motion} />
59
- default: {
60
- const unreachable: never = section
61
- return unreachable
62
- }
63
- }
19
+ const Component = sectionComponents[section.type] as unknown as SectionComponent
20
+ return <Component section={section} index={index} motion={motion} />
64
21
  })
65
22
  }
@@ -1,3 +1,4 @@
1
+ // Generated by `bearminion sync`. Do not edit: add or remove a directory under sections/ and run it again.
1
2
  import type { SectionType } from './definitions'
2
3
  import Contact from './contact/Contact.astro'
3
4
  import Cta from './cta/Cta.astro'
@@ -14,20 +15,20 @@ import Testimonials from './testimonials/Testimonials.astro'
14
15
  import Text from './text/Text.astro'
15
16
  import TextImage from './text-image/TextImage.astro'
16
17
 
17
- /** Maps a content section `type` to the component that renders it. Definitions live in `definitions.ts`. */
18
+ /** Maps a content section `type` to the component that renders it. */
18
19
  export const sectionComponents = {
20
+ contact: Contact,
21
+ cta: Cta,
22
+ faq: Faq,
23
+ features: Features,
24
+ gallery: Gallery,
19
25
  hero: Hero,
20
26
  logoStrip: LogoStrip,
27
+ media: Media,
28
+ pricing: Pricing,
29
+ stats: Stats,
21
30
  steps: Steps,
22
- gallery: Gallery,
23
- features: Features,
31
+ testimonials: Testimonials,
24
32
  text: Text,
25
33
  textImage: TextImage,
26
- stats: Stats,
27
- testimonials: Testimonials,
28
- pricing: Pricing,
29
- media: Media,
30
- faq: Faq,
31
- cta: Cta,
32
- contact: Contact,
33
34
  } satisfies Record<SectionType, unknown>
@@ -0,0 +1,33 @@
1
+ // Generated by `bearminion sync`. Do not edit: add or remove a directory under sections/ and run it again.
2
+ import type { SectionRegistry } from 'bearminion'
3
+ import { contact } from './contact/definition'
4
+ import { cta } from './cta/definition'
5
+ import { faq } from './faq/definition'
6
+ import { features } from './features/definition'
7
+ import { gallery } from './gallery/definition'
8
+ import { hero } from './hero/definition'
9
+ import { logoStrip } from './logo-strip/definition'
10
+ import { media } from './media/definition'
11
+ import { pricing } from './pricing/definition'
12
+ import { stats } from './stats/definition'
13
+ import { steps } from './steps/definition'
14
+ import { testimonials } from './testimonials/definition'
15
+ import { text } from './text/definition'
16
+ import { textImage } from './text-image/definition'
17
+
18
+ export const sectionDefinitions = {
19
+ contact,
20
+ cta,
21
+ faq,
22
+ features,
23
+ gallery,
24
+ hero,
25
+ logoStrip,
26
+ media,
27
+ pricing,
28
+ stats,
29
+ steps,
30
+ testimonials,
31
+ text,
32
+ textImage,
33
+ } satisfies SectionRegistry
@@ -1,49 +1,42 @@
1
- import {
2
- createPageSchema,
3
- createSectionSchema,
4
- type Option,
5
- type Page as ContentPage,
6
- type SectionOf,
7
- type SectionRegistry,
8
- } from 'bearminion'
9
- import { contact } from './contact/definition'
10
- import { cta } from './cta/definition'
11
- import { faq } from './faq/definition'
12
- import { features } from './features/definition'
13
- import { gallery } from './gallery/definition'
14
- import { hero } from './hero/definition'
15
- import { logoStrip } from './logo-strip/definition'
16
- import { media } from './media/definition'
17
- import { pricing } from './pricing/definition'
18
- import { stats } from './stats/definition'
19
- import { steps } from './steps/definition'
20
- import { testimonials } from './testimonials/definition'
21
- import { text } from './text/definition'
22
- import { textImage } from './text-image/definition'
1
+ import { createPageSchema, createSectionSchema, type Option, type Page as ContentPage, type SectionOf } from 'bearminion'
2
+ import { sectionDefinitions as generated } from './definitions.gen'
23
3
 
24
4
  /**
25
- * Every section type of this site. Each one is defined in its own directory:
26
- * `definition.ts` (zod schema, defaults, options), `wireframe.ts` (the Add section thumbnail),
27
- * and the Astro component. Add a directory and list it here (and in `registry.ts`) to add a type.
5
+ * Where a section type sits in the editor's Add section menu and on the variants page. A type that is not listed
6
+ * (one you added) comes after these, by name.
7
+ */
8
+ const order = [
9
+ 'hero',
10
+ 'logoStrip',
11
+ 'steps',
12
+ 'gallery',
13
+ 'features',
14
+ 'text',
15
+ 'textImage',
16
+ 'stats',
17
+ 'testimonials',
18
+ 'pricing',
19
+ 'media',
20
+ 'faq',
21
+ 'cta',
22
+ 'contact',
23
+ ] as const
24
+
25
+ const rank = (type: string) => {
26
+ const index = (order as readonly string[]).indexOf(type)
27
+ return index === -1 ? order.length : index
28
+ }
29
+
30
+ /**
31
+ * Every section type of this site. A type is a directory next to this file with a `definition.ts` (zod schema,
32
+ * defaults, options), a `wireframe.ts` (the Add section thumbnail) and the Astro component. `bearminion sync` lists
33
+ * the directories in `definitions.gen.ts` and `components.gen.ts`: add a directory, run it, and the type exists.
28
34
  *
29
35
  * It holds no `.astro` imports, so `astro.config.ts` and the editor can load it.
30
36
  */
31
- export const sectionDefinitions = {
32
- hero,
33
- logoStrip,
34
- steps,
35
- gallery,
36
- features,
37
- text,
38
- textImage,
39
- stats,
40
- testimonials,
41
- pricing,
42
- media,
43
- faq,
44
- cta,
45
- contact,
46
- } satisfies SectionRegistry
37
+ export const sectionDefinitions = Object.fromEntries(
38
+ Object.entries(generated).sort(([a], [b]) => rank(a) - rank(b) || a.localeCompare(b)),
39
+ ) as typeof generated
47
40
 
48
41
  export type SectionType = keyof typeof sectionDefinitions
49
42
  export type Section = SectionOf<typeof sectionDefinitions>