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 +8 -0
- package/package.json +1 -1
- package/template/README.md +11 -7
- package/template/astro.config.ts +2 -0
- package/template/package.json +1 -1
- package/template/src/components/sections/SectionList.astro +6 -49
- package/template/src/components/sections/{registry.ts → components.gen.ts} +11 -10
- package/template/src/components/sections/definitions.gen.ts +33 -0
- package/template/src/components/sections/definitions.ts +34 -41
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
package/template/README.md
CHANGED
|
@@ -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,
|
|
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/`
|
|
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**
|
|
123
|
+
**4. Register it** with one command:
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
package/template/astro.config.ts
CHANGED
|
@@ -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)
|
package/template/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { Section } from './definitions'
|
|
3
|
-
import { sectionComponents } from './
|
|
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
|
-
|
|
31
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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>
|