astrocms 0.2.0 → 0.3.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/README.md +8 -10
- package/backend/parsers/components.ts +158 -53
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -4,19 +4,17 @@ A simple, database-free CMS for [Astro](https://astro.build) static websites wit
|
|
|
4
4
|
|
|
5
5
|
AstroCMS edits your Markdown and MDX files directly, manages media assets, commits and pushes to your GitHub repository, and ships with an optional Claude Code integration for AI-assisted authoring.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
<source media="(prefers-color-scheme: dark)" srcset="./astrocms/docs/screenshots/editor-dark.png">
|
|
9
|
-
<img alt="Editing a blog post in AstroCMS: file tree, frontmatter form generated from the collection schema, and visual MDX editor" src="https://raw.githubusercontent.com/lonestone/astrocms/main/docs/screenshots/editor-light.png">
|
|
10
|
-
</picture>
|
|
7
|
+
Editing a blog post: the frontmatter form comes from your Zod schema, the body is real MDX.
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
| Light | Dark |
|
|
10
|
+
| :---: | :---: |
|
|
11
|
+
|  |  |
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/lonestone/astrocms/main/docs/screenshots/agent-dark.png">
|
|
16
|
-
<img alt="The AstroCMS agent panel writing a blog post, showing its tool calls and the generated entry in the editor" src="https://raw.githubusercontent.com/lonestone/astrocms/main/docs/screenshots/agent-light.png">
|
|
17
|
-
</picture>
|
|
13
|
+
Asking the built-in Claude Code agent for a new post, with every tool call visible as it works.
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
| Light | Dark |
|
|
16
|
+
| :---: | :---: |
|
|
17
|
+
|  |  |
|
|
20
18
|
|
|
21
19
|
## Why AstroCMS
|
|
22
20
|
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { readdir, readFile } from 'fs/promises'
|
|
2
2
|
import { join } from 'path'
|
|
3
|
-
import
|
|
3
|
+
import { parse } from '@babel/parser'
|
|
4
|
+
import type {
|
|
5
|
+
File,
|
|
6
|
+
Identifier,
|
|
7
|
+
Node,
|
|
8
|
+
Statement,
|
|
9
|
+
StringLiteral,
|
|
10
|
+
TSLiteralType,
|
|
11
|
+
TSPropertySignature,
|
|
12
|
+
TSTypeElement,
|
|
13
|
+
} from '@babel/types'
|
|
4
14
|
import { ROOT_DIR } from '../root.js'
|
|
5
15
|
import { loadConfig } from '../config.js'
|
|
6
16
|
import { extractRawFrontmatter } from '../../shared/frontmatter.js'
|
|
@@ -19,90 +29,185 @@ export interface ComponentDescriptor {
|
|
|
19
29
|
slots: string[]
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
// Parse
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
// Parse the Props declaration of an Astro frontmatter using @babel/parser with
|
|
33
|
+
// the TypeScript plugin. Malformed input is caught and yields no props, so this
|
|
34
|
+
// function never throws on invalid frontmatter.
|
|
35
|
+
export function parseProps(frontmatter: string): PropSchema[] {
|
|
36
|
+
let file: File
|
|
37
|
+
try {
|
|
38
|
+
file = parse(frontmatter, {
|
|
39
|
+
sourceType: 'module',
|
|
40
|
+
plugins: ['typescript'],
|
|
41
|
+
errorRecovery: true,
|
|
42
|
+
})
|
|
43
|
+
} catch {
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const shapes: ShapeMap = new Map()
|
|
48
|
+
for (const statement of file.program.body) {
|
|
49
|
+
const shape = declaredShape(unwrapExport(statement))
|
|
50
|
+
if (shape) shapes.set(shape.name, shape.members)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const props = shapes.get('Props')
|
|
54
|
+
if (!props) return []
|
|
55
|
+
return parseMembers(props, shapes, new Set(['Props']))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Named object shapes declared in the frontmatter, by name. */
|
|
59
|
+
type ShapeMap = Map<string, TSTypeElement[]>
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Members of a named object shape. Astro components declare their props
|
|
63
|
+
* either as `interface Props {}` or as `type Props = {}`; both are indexed
|
|
64
|
+
* so either form works for Props itself and for array element types.
|
|
65
|
+
*/
|
|
66
|
+
function declaredShape(
|
|
67
|
+
node: Node | null
|
|
68
|
+
): { name: string; members: TSTypeElement[] } | null {
|
|
69
|
+
if (node?.type === 'TSInterfaceDeclaration') {
|
|
70
|
+
return { name: node.id.name, members: node.body.body }
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
node?.type === 'TSTypeAliasDeclaration' &&
|
|
74
|
+
node.typeAnnotation.type === 'TSTypeLiteral'
|
|
75
|
+
) {
|
|
76
|
+
return { name: node.id.name, members: node.typeAnnotation.members }
|
|
77
|
+
}
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* `export interface Props {}` and `export default interface Props {}` wrap the
|
|
83
|
+
* declaration in an export node, unlike a bare `interface Props {}`. Return the
|
|
84
|
+
* declaration in both cases so exported interfaces are indexed too.
|
|
85
|
+
*/
|
|
86
|
+
function unwrapExport(statement: Statement): Node | null {
|
|
87
|
+
if (
|
|
88
|
+
statement.type === 'ExportNamedDeclaration' ||
|
|
89
|
+
statement.type === 'ExportDefaultDeclaration'
|
|
90
|
+
) {
|
|
91
|
+
return statement.declaration ?? null
|
|
92
|
+
}
|
|
93
|
+
return statement
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isIdentifier(node: Node | null | undefined): node is Identifier {
|
|
97
|
+
return !!node && node.type === 'Identifier'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isPropertySignature(node: Node): node is TSPropertySignature {
|
|
101
|
+
return node.type === 'TSPropertySignature'
|
|
102
|
+
}
|
|
37
103
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Name of a property signature, or null when it has no static name a form can
|
|
106
|
+
* bind to (a computed key such as `[key]: string`).
|
|
107
|
+
*/
|
|
108
|
+
function memberName(member: TSPropertySignature): string | null {
|
|
109
|
+
const key = member.key
|
|
110
|
+
if (!member.computed && key.type === 'Identifier') return key.name
|
|
111
|
+
if (key.type === 'StringLiteral') return key.value
|
|
112
|
+
if (key.type === 'NumericLiteral') return String(key.value)
|
|
113
|
+
return null
|
|
41
114
|
}
|
|
42
115
|
|
|
116
|
+
function isStringLiteralType(node: Node): node is TSLiteralType {
|
|
117
|
+
return node.type === 'TSLiteralType' && node.literal.type === 'StringLiteral'
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* `expanding` holds the names of the shapes on the current expansion path, so
|
|
122
|
+
* a self-referencing element type such as `interface Item { kids: Item[] }`
|
|
123
|
+
* stops at a plain json field instead of recursing forever.
|
|
124
|
+
*/
|
|
43
125
|
function parseMembers(
|
|
44
|
-
|
|
45
|
-
|
|
126
|
+
members: TSTypeElement[],
|
|
127
|
+
shapes: ShapeMap,
|
|
128
|
+
expanding: Set<string>
|
|
46
129
|
): PropSchema[] {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
130
|
+
const props: PropSchema[] = []
|
|
131
|
+
for (const member of members.filter(isPropertySignature)) {
|
|
132
|
+
const name = memberName(member)
|
|
133
|
+
if (name === null) continue
|
|
134
|
+
const optional = !!member.optional
|
|
135
|
+
if (member.typeAnnotation) {
|
|
136
|
+
props.push({
|
|
137
|
+
name,
|
|
138
|
+
optional,
|
|
139
|
+
...resolveType(member.typeAnnotation.typeAnnotation, shapes, expanding),
|
|
140
|
+
})
|
|
141
|
+
} else {
|
|
142
|
+
props.push({ name, type: 'string', optional })
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return props
|
|
53
146
|
}
|
|
54
147
|
|
|
55
148
|
function resolveType(
|
|
56
|
-
typeNode:
|
|
57
|
-
|
|
149
|
+
typeNode: Node,
|
|
150
|
+
shapes: ShapeMap,
|
|
151
|
+
expanding: Set<string>
|
|
58
152
|
): Omit<PropSchema, 'name'> {
|
|
153
|
+
// `readonly T[]` is the array type behind a type operator
|
|
154
|
+
if (typeNode.type === 'TSTypeOperator' && typeNode.operator === 'readonly') {
|
|
155
|
+
return resolveType(typeNode.typeAnnotation, shapes, expanding)
|
|
156
|
+
}
|
|
157
|
+
|
|
59
158
|
// String literal union: 'a' | 'b' | 'c'
|
|
60
|
-
if (
|
|
61
|
-
const allStringLiterals = typeNode.types.every(
|
|
62
|
-
(t) => ts.isLiteralTypeNode(t) && ts.isStringLiteral(t.literal)
|
|
63
|
-
)
|
|
159
|
+
if (typeNode.type === 'TSUnionType') {
|
|
160
|
+
const allStringLiterals = typeNode.types.every(isStringLiteralType)
|
|
64
161
|
if (allStringLiterals) {
|
|
65
162
|
const options = typeNode.types.map(
|
|
66
|
-
(t) => ((t as
|
|
163
|
+
(t) => ((t as TSLiteralType).literal as StringLiteral).value
|
|
67
164
|
)
|
|
68
165
|
return { type: 'select', options }
|
|
69
166
|
}
|
|
70
167
|
}
|
|
71
168
|
|
|
72
169
|
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
typeNode.typeName.
|
|
170
|
+
typeNode.type === 'TSTypeReference' &&
|
|
171
|
+
isIdentifier(typeNode.typeName) &&
|
|
172
|
+
typeNode.typeName.name === 'ImagePath'
|
|
76
173
|
) {
|
|
77
174
|
return { type: 'image' }
|
|
78
175
|
}
|
|
79
176
|
|
|
80
|
-
if (typeNode.
|
|
81
|
-
if (typeNode.
|
|
82
|
-
if (typeNode.
|
|
177
|
+
if (typeNode.type === 'TSStringKeyword') return { type: 'string' }
|
|
178
|
+
if (typeNode.type === 'TSNumberKeyword') return { type: 'number' }
|
|
179
|
+
if (typeNode.type === 'TSBooleanKeyword') return { type: 'boolean' }
|
|
83
180
|
|
|
84
|
-
let elementType:
|
|
85
|
-
if (
|
|
181
|
+
let elementType: Node | undefined
|
|
182
|
+
if (typeNode.type === 'TSArrayType') {
|
|
86
183
|
elementType = typeNode.elementType
|
|
87
184
|
} else if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
typeNode.typeName.
|
|
91
|
-
typeNode.
|
|
185
|
+
typeNode.type === 'TSTypeReference' &&
|
|
186
|
+
isIdentifier(typeNode.typeName) &&
|
|
187
|
+
typeNode.typeName.name === 'Array' &&
|
|
188
|
+
typeNode.typeParameters?.params.length === 1
|
|
92
189
|
) {
|
|
93
|
-
elementType = typeNode.
|
|
190
|
+
elementType = typeNode.typeParameters.params[0]
|
|
94
191
|
}
|
|
95
192
|
|
|
96
193
|
if (elementType) {
|
|
194
|
+
// Inline object elements: { label: string }[]
|
|
195
|
+
if (elementType.type === 'TSTypeLiteral') {
|
|
196
|
+
return {
|
|
197
|
+
type: 'json',
|
|
198
|
+
itemSchema: parseMembers(elementType.members, shapes, expanding),
|
|
199
|
+
}
|
|
200
|
+
}
|
|
97
201
|
if (
|
|
98
|
-
|
|
99
|
-
|
|
202
|
+
elementType.type === 'TSTypeReference' &&
|
|
203
|
+
isIdentifier(elementType.typeName)
|
|
100
204
|
) {
|
|
101
|
-
const
|
|
102
|
-
|
|
205
|
+
const name = elementType.typeName.name
|
|
206
|
+
const members = shapes.get(name)
|
|
207
|
+
if (members && !expanding.has(name)) {
|
|
103
208
|
return {
|
|
104
209
|
type: 'json',
|
|
105
|
-
itemSchema: parseMembers(
|
|
210
|
+
itemSchema: parseMembers(members, shapes, new Set(expanding).add(name)),
|
|
106
211
|
}
|
|
107
212
|
}
|
|
108
213
|
}
|
|
@@ -115,7 +220,7 @@ function resolveType(
|
|
|
115
220
|
// Parse slot names from an Astro component source.
|
|
116
221
|
// Detects <slot> tags in the template and Astro.slots.render/has calls in
|
|
117
222
|
// the frontmatter. Empty string "" represents the default (unnamed) slot.
|
|
118
|
-
function parseSlots(source: string): string[] {
|
|
223
|
+
export function parseSlots(source: string): string[] {
|
|
119
224
|
const frontmatter = extractRawFrontmatter(source) ?? ''
|
|
120
225
|
const parts = source.split('---')
|
|
121
226
|
const template = parts.slice(2).join('---')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astrocms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A headless CMS for Astro with a built-in AI agent for editing content.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,12 +38,15 @@
|
|
|
38
38
|
"dev:server": "tsx watch backend/server.ts",
|
|
39
39
|
"dev:frontend": "vite dev --config frontend/vite.config.ts",
|
|
40
40
|
"build": "vite build --config frontend/vite.config.ts",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
41
43
|
"prepack": "cp ../../README.md ./README.md",
|
|
42
44
|
"postpack": "rm -f ./README.md"
|
|
43
45
|
},
|
|
44
46
|
"dependencies": {
|
|
45
47
|
"@assistant-ui/react": "0.15.16",
|
|
46
48
|
"@assistant-ui/react-ai-sdk": "1.4.7",
|
|
49
|
+
"@babel/parser": "^7.29.8",
|
|
47
50
|
"@codemirror/language": "^6.12.4",
|
|
48
51
|
"@codemirror/language-data": "^6.5.2",
|
|
49
52
|
"@codemirror/view": "^6.43.9",
|
|
@@ -69,11 +72,11 @@
|
|
|
69
72
|
"react-router": "^8.3.0",
|
|
70
73
|
"smol-toml": "^1.8.0",
|
|
71
74
|
"tsx": "^4.23.12",
|
|
72
|
-
"typescript": "^5.8.3",
|
|
73
75
|
"yaml": "^2.9.0",
|
|
74
76
|
"zod": "^4.4.3"
|
|
75
77
|
},
|
|
76
78
|
"devDependencies": {
|
|
79
|
+
"@babel/types": "^7.29.8",
|
|
77
80
|
"@tailwindcss/vite": "^4.3.3",
|
|
78
81
|
"@types/node": "^26.2.0",
|
|
79
82
|
"@types/picomatch": "^4.0.3",
|
|
@@ -82,7 +85,9 @@
|
|
|
82
85
|
"@types/react-dom": "^19.2.5",
|
|
83
86
|
"@vitejs/plugin-react": "^6.1.0",
|
|
84
87
|
"tailwindcss": "^4.3.3",
|
|
85
|
-
"
|
|
88
|
+
"typescript": "^7.0.2",
|
|
89
|
+
"vite": "^8.2.2",
|
|
90
|
+
"vitest": "^5.0.0"
|
|
86
91
|
},
|
|
87
92
|
"comments": {
|
|
88
93
|
"overrides": "@assistant-ui publishes tightly-coupled packages whose semver ranges allow mutually incompatible combinations (e.g. a newer store drops an export that core still imports). The two direct deps above are pinned exact and these transitive ones are pinned here, so the Docker build's fresh `npm install` (no lockfile) resolves the same known-good tree we test locally."
|