@nuasite/cms-marker 0.0.64 → 0.0.66
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/dist/types/build-processor.d.ts +2 -1
- package/dist/types/build-processor.d.ts.map +1 -1
- package/dist/types/component-registry.d.ts.map +1 -1
- package/dist/types/config.d.ts +19 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/dev-middleware.d.ts +10 -2
- package/dist/types/dev-middleware.d.ts.map +1 -1
- package/dist/types/error-collector.d.ts +56 -0
- package/dist/types/error-collector.d.ts.map +1 -0
- package/dist/types/html-processor.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/manifest-writer.d.ts +11 -2
- package/dist/types/manifest-writer.d.ts.map +1 -1
- package/dist/types/source-finder.d.ts +18 -3
- package/dist/types/source-finder.d.ts.map +1 -1
- package/dist/types/tailwind-colors.d.ts +6 -30
- package/dist/types/tailwind-colors.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +25 -9
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/vite-plugin.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/build-processor.ts +73 -19
- package/src/component-registry.ts +2 -0
- package/src/config.ts +29 -0
- package/src/dev-middleware.ts +12 -4
- package/src/error-collector.ts +106 -0
- package/src/html-processor.ts +55 -37
- package/src/index.ts +20 -4
- package/src/manifest-writer.ts +38 -7
- package/src/source-finder.ts +1003 -295
- package/src/tailwind-colors.ts +511 -121
- package/src/types.ts +27 -9
- package/src/vite-plugin.ts +4 -12
- package/dist/types/astro-transform.d.ts +0 -21
- package/dist/types/astro-transform.d.ts.map +0 -1
- package/src/astro-transform.ts +0 -205
package/src/types.ts
CHANGED
|
@@ -69,12 +69,12 @@ export interface ContentConstraints {
|
|
|
69
69
|
allowedTags?: string[]
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** Represents a single Tailwind color with its shades */
|
|
72
|
+
/** Represents a single Tailwind color with its shades and values */
|
|
73
73
|
export interface TailwindColor {
|
|
74
74
|
/** Color name (e.g., 'red', 'blue', 'primary') */
|
|
75
75
|
name: string
|
|
76
|
-
/**
|
|
77
|
-
|
|
76
|
+
/** Map of shade to CSS color value (e.g., { '500': '#ef4444', '600': '#dc2626' }) */
|
|
77
|
+
values: Record<string, string>
|
|
78
78
|
/** Whether this is a custom/theme color vs default Tailwind */
|
|
79
79
|
isCustom?: boolean
|
|
80
80
|
}
|
|
@@ -103,8 +103,28 @@ export interface AvailableColors {
|
|
|
103
103
|
defaultColors: string[]
|
|
104
104
|
/** Custom/theme color names */
|
|
105
105
|
customColors: string[]
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Text style value with class name and CSS properties */
|
|
109
|
+
export interface TextStyleValue {
|
|
110
|
+
/** Tailwind class name (e.g., 'font-bold', 'text-xl') */
|
|
111
|
+
class: string
|
|
112
|
+
/** Display label for UI */
|
|
113
|
+
label: string
|
|
114
|
+
/** CSS properties to apply (e.g., { fontWeight: '700' }) */
|
|
115
|
+
css: Record<string, string>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Available text styles from Tailwind config */
|
|
119
|
+
export interface AvailableTextStyles {
|
|
120
|
+
/** Font weight options (font-normal, font-bold, etc.) */
|
|
121
|
+
fontWeight: TextStyleValue[]
|
|
122
|
+
/** Font size options (text-xs, text-sm, text-base, etc.) */
|
|
123
|
+
fontSize: TextStyleValue[]
|
|
124
|
+
/** Text decoration options (underline, line-through, etc.) */
|
|
125
|
+
textDecoration: TextStyleValue[]
|
|
126
|
+
/** Font style options (italic, not-italic) */
|
|
127
|
+
fontStyle: TextStyleValue[]
|
|
108
128
|
}
|
|
109
129
|
|
|
110
130
|
export interface ManifestEntry {
|
|
@@ -127,10 +147,6 @@ export interface ManifestEntry {
|
|
|
127
147
|
collectionSlug?: string
|
|
128
148
|
/** Path to the markdown content file (e.g., 'src/content/blog/my-post.md') */
|
|
129
149
|
contentPath?: string
|
|
130
|
-
/** Image source URL (for image entries) - deprecated, use imageMetadata */
|
|
131
|
-
imageSrc?: string
|
|
132
|
-
/** Image alt text (for image entries) - deprecated, use imageMetadata */
|
|
133
|
-
imageAlt?: string
|
|
134
150
|
|
|
135
151
|
// === Robustness fields ===
|
|
136
152
|
|
|
@@ -203,4 +219,6 @@ export interface CmsManifest {
|
|
|
203
219
|
collections?: Record<string, CollectionEntry>
|
|
204
220
|
/** Available Tailwind colors from the project's config */
|
|
205
221
|
availableColors?: AvailableColors
|
|
222
|
+
/** Available text styles from the project's Tailwind config */
|
|
223
|
+
availableTextStyles?: AvailableTextStyles
|
|
206
224
|
}
|
package/src/vite-plugin.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from 'vite'
|
|
2
|
-
import { createAstroTransformPlugin } from './astro-transform'
|
|
3
2
|
import type { ManifestWriter } from './manifest-writer'
|
|
4
3
|
import type { CmsMarkerOptions, ComponentDefinition } from './types'
|
|
5
4
|
|
|
@@ -12,7 +11,7 @@ export interface VitePluginContext {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export function createVitePlugin(context: VitePluginContext): Plugin[] {
|
|
15
|
-
const { manifestWriter, componentDefinitions
|
|
14
|
+
const { manifestWriter, componentDefinitions } = context
|
|
16
15
|
|
|
17
16
|
const virtualManifestPlugin: Plugin = {
|
|
18
17
|
name: 'cms-marker-virtual-manifest',
|
|
@@ -34,17 +33,10 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
|
|
|
34
33
|
},
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
// Create the Astro transform plugin to inject source location attributes
|
|
38
|
-
// NOTE: Disabled - Astro's native compiler already injects source location
|
|
39
|
-
// attributes (data-astro-source-file, data-astro-source-loc) in dev mode.
|
|
40
|
-
// Our html-processor recognizes these native attributes automatically.
|
|
41
|
-
const astroTransformPlugin = createAstroTransformPlugin({
|
|
42
|
-
markComponents: config.markComponents,
|
|
43
|
-
enabled: false, // Not needed - Astro provides source attributes natively
|
|
44
|
-
})
|
|
45
|
-
|
|
46
36
|
// Note: We cannot use transformIndexHtml for static Astro builds because
|
|
47
37
|
// Astro generates HTML files directly without going through Vite's HTML pipeline.
|
|
48
38
|
// HTML processing is done in build-processor.ts after pages are generated.
|
|
49
|
-
|
|
39
|
+
// Source location attributes are provided natively by Astro's compiler
|
|
40
|
+
// (data-astro-source-file, data-astro-source-loc) in dev mode.
|
|
41
|
+
return [virtualManifestPlugin]
|
|
50
42
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
export interface AstroTransformOptions {
|
|
3
|
-
markComponents?: boolean;
|
|
4
|
-
enabled?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Vite plugin that transforms .astro files to inject source location metadata.
|
|
8
|
-
*
|
|
9
|
-
* NOTE: This plugin is currently DISABLED because Astro's native compiler already
|
|
10
|
-
* injects `data-astro-source-file` and `data-astro-source-loc` attributes in dev mode.
|
|
11
|
-
* Our html-processor now recognizes both Astro's native attributes and our custom ones.
|
|
12
|
-
*
|
|
13
|
-
* HISTORICAL CONTEXT: This plugin was created before we discovered Astro's native
|
|
14
|
-
* source tracking. It caused Vite's build-import-analysis to fail with parsing errors
|
|
15
|
-
* because modifying .astro source files confuses Vite's JavaScript parser.
|
|
16
|
-
*
|
|
17
|
-
* KEEPING FOR: Potential future use cases where custom source attribute injection
|
|
18
|
-
* might be needed, or for testing purposes.
|
|
19
|
-
*/
|
|
20
|
-
export declare function createAstroTransformPlugin(options?: AstroTransformOptions): Plugin;
|
|
21
|
-
//# sourceMappingURL=astro-transform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"astro-transform.d.ts","sourceRoot":"","sources":["../../src/astro-transform.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,WAAW,qBAAqB;IACrC,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAgDtF"}
|
package/src/astro-transform.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { parse as parseAstro } from '@astrojs/compiler'
|
|
2
|
-
import fs from 'node:fs/promises'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
import type { Plugin } from 'vite'
|
|
5
|
-
|
|
6
|
-
export interface AstroTransformOptions {
|
|
7
|
-
markComponents?: boolean
|
|
8
|
-
enabled?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Vite plugin that transforms .astro files to inject source location metadata.
|
|
13
|
-
*
|
|
14
|
-
* NOTE: This plugin is currently DISABLED because Astro's native compiler already
|
|
15
|
-
* injects `data-astro-source-file` and `data-astro-source-loc` attributes in dev mode.
|
|
16
|
-
* Our html-processor now recognizes both Astro's native attributes and our custom ones.
|
|
17
|
-
*
|
|
18
|
-
* HISTORICAL CONTEXT: This plugin was created before we discovered Astro's native
|
|
19
|
-
* source tracking. It caused Vite's build-import-analysis to fail with parsing errors
|
|
20
|
-
* because modifying .astro source files confuses Vite's JavaScript parser.
|
|
21
|
-
*
|
|
22
|
-
* KEEPING FOR: Potential future use cases where custom source attribute injection
|
|
23
|
-
* might be needed, or for testing purposes.
|
|
24
|
-
*/
|
|
25
|
-
export function createAstroTransformPlugin(options: AstroTransformOptions = {}): Plugin {
|
|
26
|
-
// Component marking is intentionally disabled at the transform level
|
|
27
|
-
// const { markComponents = true } = options;
|
|
28
|
-
const { enabled = true } = options
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
name: 'astro-cms-source-injector',
|
|
32
|
-
enforce: 'pre', // Run before Astro's own transforms
|
|
33
|
-
|
|
34
|
-
async transform(code: string, id: string) {
|
|
35
|
-
// Skip transformation if disabled (e.g., during build mode)
|
|
36
|
-
if (!enabled) {
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!id.endsWith('.astro')) {
|
|
41
|
-
return null
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (id.includes('node_modules')) {
|
|
45
|
-
return null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const rawCode = await fs.readFile(id, 'utf-8')
|
|
50
|
-
const relativePath = path.relative(process.cwd(), id)
|
|
51
|
-
const result = await parseAstro(rawCode, { position: true })
|
|
52
|
-
|
|
53
|
-
if (!result.ast) {
|
|
54
|
-
return null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const transformed = injectSourceAttributes(rawCode, result.ast, relativePath)
|
|
58
|
-
|
|
59
|
-
if (transformed !== rawCode) {
|
|
60
|
-
return {
|
|
61
|
-
code: transformed,
|
|
62
|
-
map: null,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return null
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.warn(`[astro-cms-marker] Failed to transform ${id}:`, error)
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Inject source location attributes into HTML elements
|
|
77
|
-
* NOTE: Component marking is NOT done here - it breaks Astro's parser
|
|
78
|
-
*/
|
|
79
|
-
function injectSourceAttributes(code: string, ast: any, filePath: string): string {
|
|
80
|
-
const lines = code.split('\n')
|
|
81
|
-
const modifications: Array<{ line: number; column: number; insertion: string }> = []
|
|
82
|
-
|
|
83
|
-
// Find the template section (after frontmatter)
|
|
84
|
-
let inFrontmatter = false
|
|
85
|
-
let frontmatterEnd = -1
|
|
86
|
-
|
|
87
|
-
for (let i = 0; i < lines.length; i++) {
|
|
88
|
-
if (lines[i]?.trim() === '---') {
|
|
89
|
-
if (!inFrontmatter) {
|
|
90
|
-
inFrontmatter = true
|
|
91
|
-
} else {
|
|
92
|
-
frontmatterEnd = i
|
|
93
|
-
break
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// If no frontmatter, start from line 0 (all lines are template)
|
|
99
|
-
if (frontmatterEnd === -1) {
|
|
100
|
-
frontmatterEnd = -1 // Will make check start.line > 0
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Walk the AST and collect modifications
|
|
104
|
-
const collectElements = (node: any, depth: number = 0) => {
|
|
105
|
-
if (!node) {
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Only process regular HTML elements, NOT components
|
|
110
|
-
if (node.type === 'element' && node.position) {
|
|
111
|
-
const { start } = node.position
|
|
112
|
-
const tagName = node.name?.toLowerCase()
|
|
113
|
-
|
|
114
|
-
// Only process elements in template section (after frontmatter or from start if no frontmatter)
|
|
115
|
-
const templateStartLine = frontmatterEnd === -1 ? 0 : frontmatterEnd + 1
|
|
116
|
-
if (start.line > templateStartLine) {
|
|
117
|
-
// Skip certain elements
|
|
118
|
-
if (['html', 'head', 'body', 'script', 'style', 'slot', 'fragment'].includes(tagName)) {
|
|
119
|
-
// Still process children
|
|
120
|
-
if (node.children && Array.isArray(node.children)) {
|
|
121
|
-
for (const child of node.children) {
|
|
122
|
-
collectElements(child, depth + 1)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Find where to insert the attribute (after tag name, before other attributes or >)
|
|
129
|
-
const lineIndex = start.line - 1
|
|
130
|
-
if (lineIndex < 0 || lineIndex >= lines.length) {
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const line = lines[lineIndex]
|
|
135
|
-
const tagStartCol = start.column - 1
|
|
136
|
-
|
|
137
|
-
// Find the position after the tag name
|
|
138
|
-
const tagMatch = line?.slice(tagStartCol).match(/^<(\w+)/)
|
|
139
|
-
if (!tagMatch) {
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const insertCol = tagStartCol + tagMatch[0].length
|
|
144
|
-
const sourceAttr = ` data-astro-source-file="${filePath}" data-astro-source-line="${start.line}"`
|
|
145
|
-
|
|
146
|
-
modifications.push({
|
|
147
|
-
line: lineIndex,
|
|
148
|
-
column: insertCol,
|
|
149
|
-
insertion: sourceAttr,
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Recursively process children
|
|
155
|
-
if (node.children && Array.isArray(node.children)) {
|
|
156
|
-
for (const child of node.children) {
|
|
157
|
-
collectElements(child, depth + 1)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Start walking from root children
|
|
163
|
-
if (ast.children && Array.isArray(ast.children)) {
|
|
164
|
-
for (const child of ast.children) {
|
|
165
|
-
collectElements(child, 0)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Sort modifications by position (reverse order so we can apply them without recalculating positions)
|
|
170
|
-
modifications.sort((a, b) => {
|
|
171
|
-
if (a.line !== b.line) {
|
|
172
|
-
return b.line - a.line
|
|
173
|
-
}
|
|
174
|
-
return b.column - a.column
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
// Apply modifications
|
|
178
|
-
const modifiedLines = [...lines]
|
|
179
|
-
for (const mod of modifications) {
|
|
180
|
-
const line = modifiedLines[mod.line]
|
|
181
|
-
|
|
182
|
-
// Validate line exists - if not, there's a bug in AST positions or bounds checking
|
|
183
|
-
if (line === undefined) {
|
|
184
|
-
console.error(
|
|
185
|
-
`[astro-cms-marker] Invalid modification at line ${mod.line + 1} in ${filePath}. `
|
|
186
|
-
+ `This indicates a bug in @astrojs/compiler AST positions or bounds checking. Skipping modification.`,
|
|
187
|
-
)
|
|
188
|
-
continue
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Validate column is within line bounds
|
|
192
|
-
if (mod.column < 0 || mod.column > line.length) {
|
|
193
|
-
console.error(
|
|
194
|
-
`[astro-cms-marker] Invalid column ${mod.column} at line ${mod.line + 1} in ${filePath}. `
|
|
195
|
-
+ `Line length is ${line.length}. Skipping modification.`,
|
|
196
|
-
)
|
|
197
|
-
continue
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Apply the modification safely
|
|
201
|
-
modifiedLines[mod.line] = line.slice(0, mod.column) + mod.insertion + line.slice(mod.column)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return modifiedLines.join('\n')
|
|
205
|
-
}
|