@webjourney/vite-plugins 1.2.17-1 → 1.2.19
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 +12 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -108
- 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));
|
|
@@ -246,7 +247,9 @@ async function prerender(projectRoot) {
|
|
|
246
247
|
// Write the pre-rendered HTML
|
|
247
248
|
const filePath = route === '/'
|
|
248
249
|
? toAbsolute('dist/index.html')
|
|
249
|
-
:
|
|
250
|
+
: route.endsWith('.html')
|
|
251
|
+
? toAbsolute(`dist${route}`)
|
|
252
|
+
: toAbsolute(`dist${route}/index.html`);
|
|
250
253
|
// Ensure directory exists
|
|
251
254
|
const dir = path.dirname(filePath);
|
|
252
255
|
await fs.mkdir(dir, { recursive: true });
|
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":"AAeA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAsUrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAnWb,MAAM,MAAM,MAAM;;;;;;;6BA6UT,MAAM;KA0BlC"}
|
package/dist/index.js
CHANGED
|
@@ -2,62 +2,12 @@ import _generate from '@babel/generator';
|
|
|
2
2
|
import { parse } from '@babel/parser';
|
|
3
3
|
import _traverse from '@babel/traverse';
|
|
4
4
|
import * as t from '@babel/types';
|
|
5
|
-
import * as fs from 'fs';
|
|
6
5
|
import path from 'path';
|
|
7
6
|
// Handle CommonJS default exports
|
|
8
7
|
const traverse = _traverse.default || _traverse;
|
|
9
8
|
const generate = _generate.default || _generate;
|
|
10
9
|
// Use local plugin for development, production URL for deployed sites
|
|
11
10
|
const webjourneyPluginScriptHost = process.env.WEBJOURNEY_PLUGIN_SCRIPT_HOST || 'https://app.webjourney.pro';
|
|
12
|
-
// Helper function to extract text content from JSX children
|
|
13
|
-
function extractTextContent(children) {
|
|
14
|
-
return children
|
|
15
|
-
.filter(child => t.isJSXText(child))
|
|
16
|
-
.map(child => child.value.trim())
|
|
17
|
-
.filter(text => text !== '')
|
|
18
|
-
.join(' ');
|
|
19
|
-
}
|
|
20
|
-
// Helper function to extract href or to attribute value
|
|
21
|
-
function extractHrefValue(attributes) {
|
|
22
|
-
const hrefAttr = attributes.find((attr) => t.isJSXAttribute(attr) &&
|
|
23
|
-
t.isJSXIdentifier(attr.name) &&
|
|
24
|
-
(attr.name.name === 'href' || attr.name.name === 'to'));
|
|
25
|
-
if (hrefAttr && t.isJSXAttribute(hrefAttr)) {
|
|
26
|
-
if (t.isStringLiteral(hrefAttr.value)) {
|
|
27
|
-
return hrefAttr.value.value;
|
|
28
|
-
}
|
|
29
|
-
else if (t.isJSXExpressionContainer(hrefAttr.value) && t.isStringLiteral(hrefAttr.value.expression)) {
|
|
30
|
-
return hrefAttr.value.expression.value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
// Helper function to extract src attribute value
|
|
36
|
-
function extractSrcValue(attributes) {
|
|
37
|
-
const srcAttr = attributes.find((attr) => t.isJSXAttribute(attr) &&
|
|
38
|
-
t.isJSXIdentifier(attr.name) &&
|
|
39
|
-
attr.name.name === 'src');
|
|
40
|
-
if (srcAttr && t.isJSXAttribute(srcAttr)) {
|
|
41
|
-
if (t.isStringLiteral(srcAttr.value)) {
|
|
42
|
-
return srcAttr.value.value;
|
|
43
|
-
}
|
|
44
|
-
else if (t.isJSXExpressionContainer(srcAttr.value) && t.isStringLiteral(srcAttr.value.expression)) {
|
|
45
|
-
return srcAttr.value.expression.value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
// Helper function to generate JSON documentation
|
|
51
|
-
function generateJsonDocs(relativePath, textNodes, imageNodes) {
|
|
52
|
-
const timestamp = new Date().toISOString();
|
|
53
|
-
const data = {
|
|
54
|
-
file: relativePath,
|
|
55
|
-
generatedAt: timestamp,
|
|
56
|
-
textNodes: textNodes,
|
|
57
|
-
imageNodes: imageNodes
|
|
58
|
-
};
|
|
59
|
-
return JSON.stringify(data, null, 2);
|
|
60
|
-
}
|
|
61
11
|
// Plugin to inject source mapping attributes for WYSIWYG editing
|
|
62
12
|
export function webjourneyElementTagger() {
|
|
63
13
|
return {
|
|
@@ -80,9 +30,6 @@ export function webjourneyElementTagger() {
|
|
|
80
30
|
plugins: ['typescript', 'jsx'],
|
|
81
31
|
});
|
|
82
32
|
let modified = false;
|
|
83
|
-
// Arrays to collect node information for documentation
|
|
84
|
-
const docTextNodes = [];
|
|
85
|
-
const docImageNodes = [];
|
|
86
33
|
// Traverse the AST
|
|
87
34
|
traverse(ast, {
|
|
88
35
|
JSXElement(path) {
|
|
@@ -127,27 +74,11 @@ export function webjourneyElementTagger() {
|
|
|
127
74
|
const elementId = `${relativePath}:${lineNumber}`;
|
|
128
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)));
|
|
129
76
|
modified = true;
|
|
130
|
-
// Collect text content for documentation
|
|
131
|
-
const textContent = extractTextContent(path.node.children);
|
|
132
|
-
const hrefValue = (tagName === 'a' || tagName === 'Link')
|
|
133
|
-
? extractHrefValue(openingElement.attributes)
|
|
134
|
-
: undefined;
|
|
135
|
-
docTextNodes.push({
|
|
136
|
-
line: lineNumber,
|
|
137
|
-
tag: tagName,
|
|
138
|
-
id: elementId,
|
|
139
|
-
content: textContent,
|
|
140
|
-
href: hrefValue
|
|
141
|
-
});
|
|
142
77
|
}
|
|
143
78
|
// Case 2: Mixed children (text nodes + other elements)
|
|
144
79
|
else if (nonTextChildren.length > 0) {
|
|
145
80
|
// Wrap each text node in a span with data-wj-* attributes
|
|
146
81
|
const newChildren = [];
|
|
147
|
-
// Extract href if parent is a link element
|
|
148
|
-
const parentHref = (tagName === 'a' || tagName === 'Link')
|
|
149
|
-
? extractHrefValue(openingElement.attributes)
|
|
150
|
-
: undefined;
|
|
151
82
|
for (const child of path.node.children) {
|
|
152
83
|
if (t.isJSXText(child) && child.value.trim() !== '') {
|
|
153
84
|
// Generate unique ID for this text segment
|
|
@@ -161,15 +92,6 @@ export function webjourneyElementTagger() {
|
|
|
161
92
|
t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
|
|
162
93
|
], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
|
|
163
94
|
newChildren.push(wrapper);
|
|
164
|
-
// Collect text content for documentation
|
|
165
|
-
const textContent = child.value.trim();
|
|
166
|
-
docTextNodes.push({
|
|
167
|
-
line: textLineNumber,
|
|
168
|
-
tag: 'span',
|
|
169
|
-
id: elementId,
|
|
170
|
-
content: textContent,
|
|
171
|
-
href: parentHref
|
|
172
|
-
});
|
|
173
95
|
}
|
|
174
96
|
else {
|
|
175
97
|
// Keep whitespace text nodes, elements, etc. as-is
|
|
@@ -192,15 +114,6 @@ export function webjourneyElementTagger() {
|
|
|
192
114
|
const elementId = `${relativePath}:${lineNumber}`;
|
|
193
115
|
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('image')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
194
116
|
modified = true;
|
|
195
|
-
// Collect image information for documentation
|
|
196
|
-
const srcValue = extractSrcValue(openingElement.attributes);
|
|
197
|
-
docImageNodes.push({
|
|
198
|
-
line: lineNumber,
|
|
199
|
-
tag: tagName,
|
|
200
|
-
id: elementId,
|
|
201
|
-
type: 'image',
|
|
202
|
-
src: srcValue
|
|
203
|
-
});
|
|
204
117
|
}
|
|
205
118
|
}
|
|
206
119
|
// Handle elements with bg-[url(...)] className pattern
|
|
@@ -231,15 +144,6 @@ export function webjourneyElementTagger() {
|
|
|
231
144
|
const elementId = `${relativePath}:${lineNumber}`;
|
|
232
145
|
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('background-image')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
233
146
|
modified = true;
|
|
234
|
-
// Collect background image information for documentation
|
|
235
|
-
const bgMatch = classNameValue.match(/bg-\[url\([^\)]+\)\]/);
|
|
236
|
-
docImageNodes.push({
|
|
237
|
-
line: lineNumber,
|
|
238
|
-
tag: tagName,
|
|
239
|
-
id: elementId,
|
|
240
|
-
type: 'background-image',
|
|
241
|
-
bgPattern: bgMatch ? bgMatch[0] : undefined
|
|
242
|
-
});
|
|
243
147
|
}
|
|
244
148
|
}
|
|
245
149
|
// Handle anchor elements and Link components
|
|
@@ -272,18 +176,6 @@ export function webjourneyElementTagger() {
|
|
|
272
176
|
}
|
|
273
177
|
});
|
|
274
178
|
if (modified) {
|
|
275
|
-
// Generate JSON documentation
|
|
276
|
-
if (docTextNodes.length > 0 || docImageNodes.length > 0) {
|
|
277
|
-
const jsonContent = generateJsonDocs(relativePath, docTextNodes, docImageNodes);
|
|
278
|
-
const jsonPath = `${id}.nodes.json`;
|
|
279
|
-
try {
|
|
280
|
-
fs.writeFileSync(jsonPath, jsonContent, 'utf-8');
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
console.error(`Error writing documentation for ${id}:`, error);
|
|
284
|
-
// Don't fail the build if documentation generation fails
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
179
|
// Generate code from the modified AST
|
|
288
180
|
const output = generate(ast, {
|
|
289
181
|
retainLines: true,
|