@webjourney/vite-plugins 1.2.18 → 1.2.20
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/build.js +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -39
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -223,14 +223,15 @@ async function prerender(projectRoot) {
|
|
|
223
223
|
// Extract routes from App.tsx
|
|
224
224
|
const routes = await extractRoutes(projectRoot);
|
|
225
225
|
console.log(` Found ${routes.length} route(s): ${routes.join(', ')}`);
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
226
|
+
// TODO: @Darren temporarily disable sitemap generation
|
|
227
|
+
// Currently disabled because it causes spurious git diffs when building in different environments
|
|
228
|
+
// const hostname = process.env.WEBJOURNEY_PROJECT_ID ? `https://${process.env.WEBJOURNEY_PROJECT_ID}.web.wbj.dev` : 'http://127.0.0.1';
|
|
229
|
+
// const sitemap = generateSitemap(routes, hostname);
|
|
230
|
+
// await Promise.all([
|
|
231
|
+
// fs.writeFile(toAbsolute('public/sitemap.xml'), sitemap),
|
|
232
|
+
// fs.writeFile(toAbsolute('dist/sitemap.xml'), sitemap),
|
|
233
|
+
// ]);
|
|
234
|
+
// console.log(' Generated: sitemap.xml');
|
|
234
235
|
for (const route of routes) {
|
|
235
236
|
// Render the app HTML
|
|
236
237
|
const appHtml = renderToString(render(route));
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4EA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAqPrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAlRb,MAAM,MAAM,MAAM;;;;;;;6BA4PT,MAAM;KA0BlC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,39 @@ const traverse = _traverse.default || _traverse;
|
|
|
8
8
|
const generate = _generate.default || _generate;
|
|
9
9
|
// Use local plugin for development, production URL for deployed sites
|
|
10
10
|
const webjourneyPluginScriptHost = process.env.WEBJOURNEY_PLUGIN_SCRIPT_HOST || 'https://app.webjourney.pro';
|
|
11
|
+
// Helper to handle text element tagging (text-only or mixed content with span wrapping)
|
|
12
|
+
function handleTextElement(node, openingElement, relativePath, lineNumber) {
|
|
13
|
+
const textNodes = node.children.filter((child) => t.isJSXText(child) && child.value.trim() !== '');
|
|
14
|
+
const nonTextChildren = node.children.filter((child) => !t.isJSXText(child) || (t.isJSXText(child) && child.value.trim() === ''));
|
|
15
|
+
if (textNodes.length === 0)
|
|
16
|
+
return false;
|
|
17
|
+
// Case 1: Text-only element (no other children)
|
|
18
|
+
if (nonTextChildren.length === 0) {
|
|
19
|
+
const elementId = `${relativePath}:${lineNumber}`;
|
|
20
|
+
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// Case 2: Mixed children (text nodes + other elements) - wrap text in spans
|
|
24
|
+
const newChildren = [];
|
|
25
|
+
for (const child of node.children) {
|
|
26
|
+
if (t.isJSXText(child) && child.value.trim() !== '') {
|
|
27
|
+
const textLineNumber = child.loc?.start.line ?? lineNumber;
|
|
28
|
+
const elementId = `${relativePath}:${textLineNumber}`;
|
|
29
|
+
const wrapper = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('span'), [
|
|
30
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)),
|
|
31
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(textLineNumber))),
|
|
32
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')),
|
|
33
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
|
|
34
|
+
], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
|
|
35
|
+
newChildren.push(wrapper);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
newChildren.push(child);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
node.children = newChildren;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
11
44
|
// Plugin to inject source mapping attributes for WYSIWYG editing
|
|
12
45
|
export function webjourneyElementTagger() {
|
|
13
46
|
return {
|
|
@@ -62,45 +95,9 @@ export function webjourneyElementTagger() {
|
|
|
62
95
|
return;
|
|
63
96
|
const lineNumber = openingElement.loc?.start.line ?? 0;
|
|
64
97
|
// Handle text elements
|
|
65
|
-
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div', 'button', '
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Get all non-text children (elements, expressions, etc.)
|
|
69
|
-
const nonTextChildren = path.node.children.filter((child) => !t.isJSXText(child) || (t.isJSXText(child) && child.value.trim() === ''));
|
|
70
|
-
if (textNodes.length > 0) {
|
|
71
|
-
// Case 1: Single text node child (no other elements)
|
|
72
|
-
if (nonTextChildren.length === 0) {
|
|
73
|
-
// Add data-wj-* attributes to the current element
|
|
74
|
-
const elementId = `${relativePath}:${lineNumber}`;
|
|
75
|
-
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
76
|
-
modified = true;
|
|
77
|
-
}
|
|
78
|
-
// Case 2: Mixed children (text nodes + other elements)
|
|
79
|
-
else if (nonTextChildren.length > 0) {
|
|
80
|
-
// Wrap each text node in a span with data-wj-* attributes
|
|
81
|
-
const newChildren = [];
|
|
82
|
-
for (const child of path.node.children) {
|
|
83
|
-
if (t.isJSXText(child) && child.value.trim() !== '') {
|
|
84
|
-
// Generate unique ID for this text segment
|
|
85
|
-
const textLineNumber = child.loc?.start.line ?? lineNumber;
|
|
86
|
-
const elementId = `${relativePath}:${textLineNumber}`;
|
|
87
|
-
// Create a span wrapper
|
|
88
|
-
const wrapper = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('span'), [
|
|
89
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)),
|
|
90
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(textLineNumber))),
|
|
91
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')),
|
|
92
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
|
|
93
|
-
], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
|
|
94
|
-
newChildren.push(wrapper);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// Keep whitespace text nodes, elements, etc. as-is
|
|
98
|
-
newChildren.push(child);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
path.node.children = newChildren;
|
|
102
|
-
modified = true;
|
|
103
|
-
}
|
|
98
|
+
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div', 'button', 'label', 'li'].includes(tagName)) {
|
|
99
|
+
if (handleTextElement(path.node, openingElement, relativePath, lineNumber)) {
|
|
100
|
+
modified = true;
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
// Handle img elements
|
|
@@ -158,6 +155,12 @@ export function webjourneyElementTagger() {
|
|
|
158
155
|
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('link')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
159
156
|
modified = true;
|
|
160
157
|
}
|
|
158
|
+
else {
|
|
159
|
+
// Anchors without href/to are treated as text elements (button-like anchors)
|
|
160
|
+
if (handleTextElement(path.node, openingElement, relativePath, lineNumber)) {
|
|
161
|
+
modified = true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
161
164
|
}
|
|
162
165
|
// Handle all remaining div elements as 'frame' type
|
|
163
166
|
// This catches divs that weren't marked by other conditions
|