Generate Momentum CMS Collection
Create a new collection file following project conventions.
Arguments
$ARGUMENTS - Collection name (e.g., "posts", "products", "users")
Important: Collection Location
All collections are defined in libs/example-config/src/collections/. Both example apps (example-angular, example-analog) import from @momentumcms/example-config/collections. Never define collections in individual apps.
Steps
Create the collection file at libs/example-config/src/collections/<name>.collection.ts
Use this template:
import {
defineCollection,
text,
richText,
number,
date,
checkbox,
select,
relationship,
} from '@momentumcms/core';
export const <PascalName> = defineCollection({
slug: '<kebab-name>',
admin: {
useAsTitle: 'title', // or 'name' - the field to display as title
defaultColumns: ['title', 'createdAt'],
group: 'Content', // Admin sidebar group
},
access: {
read: () => true,
create: ({ req }) => !!req.user,
update: ({ req }) => req.user?.role === 'admin',
delete: ({ req }) => req.user?.role === 'admin',
},
hooks: {
beforeChange: [],
afterChange: [],
},
fields: [
text('title', { required: true }),
// Add more fields as needed
],
});
- Export from
libs/example-config/src/collections/index.ts:
// Add import at top
import { <PascalName> } from './<name>.collection';
// Add to the collections array
export const collections: CollectionConfig[] = [
// ... existing collections,
<PascalName>,
];
// Add to named exports
export {
// ... existing exports,
<PascalName>,
};
Both example apps automatically pick up changes since they import from @momentumcms/example-config/collections.
- Remind user: if migration mode is enabled, run
nx run <app>:migrate:generate after collection changes to create a migration file.
Field Types Available
Text Input Fields
text(name, options) - Short text with optional min/max length
textarea(name, options) - Multi-line text with optional rows
richText(name, options) - Rich text editor
email(name, options) - Email input
password(name, options) - Password input with optional min length
Numeric & Date Fields
number(name, options) - Numeric value with optional min/max/step
date(name, options) - Date/datetime picker
Boolean & Selection Fields
checkbox(name, options) - Boolean checkbox
select(name, { options: [...] }) - Dropdown select (supports hasMany)
radio(name, { options: [...] }) - Radio button group
Media & Files
upload(name, options) - File upload with MIME type filtering
Relationship & Data Fields
relationship(name, { collection: () => Ref }) - Reference to another collection (supports hasMany, polymorphic)
array(name, { fields: [...] }) - Array of nested fields
group(name, { fields: [...] }) - Nested object grouping
blocks(name, { blocks: [...] }) - Block-based content
json(name, options) - Raw JSON field
point(name, options) - Geolocation point
slug(name, { from: 'fieldName' }) - Auto-generated slug from another field
Layout Fields (non-data storing)
tabs(tabs: [...]) - Tabbed sections for organization
collapsible(label, { fields: [...] }) - Collapsible section
row(fields: [...]) - Horizontal row layout
1---2name: collection3description: Generate a new Momentum CMS collection with fields, access control, and hooks4---5
6# Generate Momentum CMS Collection
7
8Create a new collection file following project conventions.
9
10## Arguments
11
12- `$ARGUMENTS` - Collection name (e.g., "posts", "products", "users")
13
14## Important: Collection Location
15
16All collections are defined in `libs/example-config/src/collections/`. Both example apps (`example-angular`, `example-analog`) import from `@momentumcms/example-config/collections`. **Never define collections in individual apps.**
17
18## Steps
19
201. Create the collection file at `libs/example-config/src/collections/<name>.collection.ts`
21
222. Use this template:
23
24```typescript
25import {
26 defineCollection,
27 text,
28 richText,
29 number,
30 date,
31 checkbox,
32 select,
33 relationship,
34} from '@momentumcms/core';
35
36export const <PascalName> = defineCollection({
37 slug: '<kebab-name>',
38
39 admin: {
40 useAsTitle: 'title', // or 'name' - the field to display as title
41 defaultColumns: ['title', 'createdAt'],
42 group: 'Content', // Admin sidebar group
43 },
44
45 access: {
46 read: () => true,
47 create: ({ req }) => !!req.user,
48 update: ({ req }) => req.user?.role === 'admin',
49 delete: ({ req }) => req.user?.role === 'admin',
50 },
51
52 hooks: {
53 beforeChange: [],
54 afterChange: [],
55 },
56
57 fields: [
58 text('title', { required: true }),
59 // Add more fields as needed
60 ],
61});
62```
63
643. Export from `libs/example-config/src/collections/index.ts`:
65
66```typescript
67// Add import at top
68import { <PascalName> } from './<name>.collection';
69
70// Add to the collections array
71export const collections: CollectionConfig[] = [
72 // ... existing collections,
73 <PascalName>,
74];
75
76// Add to named exports
77export {
78 // ... existing exports,
79 <PascalName>,
80};
81```
82
83Both example apps automatically pick up changes since they import from `@momentumcms/example-config/collections`.
84
854. Remind user: if migration mode is enabled, run `nx run <app>:migrate:generate` after collection changes to create a migration file.
86
87## Field Types Available
88
89### Text Input Fields
90- `text(name, options)` - Short text with optional min/max length
91- `textarea(name, options)` - Multi-line text with optional rows
92- `richText(name, options)` - Rich text editor
93- `email(name, options)` - Email input
94- `password(name, options)` - Password input with optional min length
95
96### Numeric & Date Fields
97- `number(name, options)` - Numeric value with optional min/max/step
98- `date(name, options)` - Date/datetime picker
99
100### Boolean & Selection Fields
101- `checkbox(name, options)` - Boolean checkbox
102- `select(name, { options: [...] })` - Dropdown select (supports `hasMany`)
103- `radio(name, { options: [...] })` - Radio button group
104
105### Media & Files
106- `upload(name, options)` - File upload with MIME type filtering
107
108### Relationship & Data Fields
109- `relationship(name, { collection: () => Ref })` - Reference to another collection (supports `hasMany`, polymorphic)
110- `array(name, { fields: [...] })` - Array of nested fields
111- `group(name, { fields: [...] })` - Nested object grouping
112- `blocks(name, { blocks: [...] })` - Block-based content
113- `json(name, options)` - Raw JSON field
114- `point(name, options)` - Geolocation point
115- `slug(name, { from: 'fieldName' })` - Auto-generated slug from another field
116
117### Layout Fields (non-data storing)
118- `tabs(tabs: [...])` - Tabbed sections for organization
119- `collapsible(label, { fields: [...] })` - Collapsible section
120- `row(fields: [...])` - Horizontal row layout