@webjourney/vite-plugins 1.2.15 → 1.2.17-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/dist/build.d.ts.map +1 -1
- package/dist/build.js +10 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -0
- package/package.json +1 -1
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,OAAO,GAAE,YAAiB,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,OAAO,GAAE,YAAiB,iBA6C5D"}
|
package/dist/build.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { match as matchMedia } from 'css-mediaquery';
|
|
2
2
|
import { JSDOM } from 'jsdom';
|
|
3
3
|
import { execSync } from 'node:child_process';
|
|
4
|
-
import fs from 'node:fs';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
export async function buildWithSSR(options = {}) {
|
|
@@ -18,7 +18,7 @@ export const render = createServerRenderer(App);
|
|
|
18
18
|
console.log('Building for production with SSR...\n');
|
|
19
19
|
try {
|
|
20
20
|
// Write temporary entry-server file
|
|
21
|
-
fs.
|
|
21
|
+
await fs.writeFile(generatedEntryServer, entryServerContent);
|
|
22
22
|
// Step 1: Type check
|
|
23
23
|
console.log('1. Type checking...');
|
|
24
24
|
execSync('tsc -b', { stdio: 'inherit', cwd: projectRoot });
|
|
@@ -35,9 +35,7 @@ export const render = createServerRenderer(App);
|
|
|
35
35
|
}
|
|
36
36
|
finally {
|
|
37
37
|
// Clean up temporary entry-server file
|
|
38
|
-
|
|
39
|
-
fs.unlinkSync(generatedEntryServer);
|
|
40
|
-
}
|
|
38
|
+
await fs.unlink(generatedEntryServer).catch(() => { });
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
function setupSSREnvironment() {
|
|
@@ -211,7 +209,7 @@ async function prerender(projectRoot) {
|
|
|
211
209
|
const toAbsolute = (p) => path.resolve(projectRoot, p);
|
|
212
210
|
// Read the built index.html
|
|
213
211
|
const templatePath = toAbsolute('dist/index.html');
|
|
214
|
-
const template = fs.
|
|
212
|
+
const template = await fs.readFile(templatePath, 'utf-8');
|
|
215
213
|
// Setup SSR environment with all necessary polyfills
|
|
216
214
|
const { cleanup } = setupSSREnvironment();
|
|
217
215
|
// Import the server entry after setting up globals
|
|
@@ -228,7 +226,10 @@ async function prerender(projectRoot) {
|
|
|
228
226
|
// Generate sitemap
|
|
229
227
|
const hostname = process.env.WEBJOURNEY_PROJECT_ID ? `https://${process.env.WEBJOURNEY_PROJECT_ID}.web.wbj.dev` : 'http://127.0.0.1';
|
|
230
228
|
const sitemap = generateSitemap(routes, hostname);
|
|
231
|
-
|
|
229
|
+
await Promise.all([
|
|
230
|
+
fs.writeFile(toAbsolute('public/sitemap.xml'), sitemap),
|
|
231
|
+
fs.writeFile(toAbsolute('dist/sitemap.xml'), sitemap),
|
|
232
|
+
]);
|
|
232
233
|
console.log(' Generated: sitemap.xml');
|
|
233
234
|
for (const route of routes) {
|
|
234
235
|
// Render the app HTML
|
|
@@ -248,10 +249,8 @@ async function prerender(projectRoot) {
|
|
|
248
249
|
: toAbsolute(`dist${route}/index.html`);
|
|
249
250
|
// Ensure directory exists
|
|
250
251
|
const dir = path.dirname(filePath);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
fs.writeFileSync(filePath, html);
|
|
252
|
+
await fs.mkdir(dir, { recursive: true });
|
|
253
|
+
await fs.writeFile(filePath, html);
|
|
255
254
|
console.log(` Pre-rendered: ${route}`);
|
|
256
255
|
}
|
|
257
256
|
// Wait for any pending console messages to flush
|
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":"AA0GA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAqYrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAlab,MAAM,MAAM,MAAM;;;;;;;6BA4YT,MAAM;KA0BlC"}
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,70 @@ 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';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
// Handle CommonJS default exports
|
|
7
8
|
const traverse = _traverse.default || _traverse;
|
|
8
9
|
const generate = _generate.default || _generate;
|
|
9
10
|
// Use local plugin for development, production URL for deployed sites
|
|
10
11
|
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 generate markdown documentation
|
|
36
|
+
function generateMarkdownDocs(relativePath, textNodes, imageNodes) {
|
|
37
|
+
const timestamp = new Date().toISOString().replace('T', ' ').split('.')[0];
|
|
38
|
+
let md = `# Text and Image Nodes: ${relativePath}\n\n`;
|
|
39
|
+
md += `Generated: ${timestamp}\n\n`;
|
|
40
|
+
if (textNodes.length > 0) {
|
|
41
|
+
md += `## Text Nodes\n\n`;
|
|
42
|
+
for (const node of textNodes) {
|
|
43
|
+
md += `### Line ${node.line}: ${node.tag}\n`;
|
|
44
|
+
md += `**ID**: \`${node.id}\`\n`;
|
|
45
|
+
md += `**Content**: \`${node.content}\`\n`;
|
|
46
|
+
if (node.href) {
|
|
47
|
+
md += `**Link**: \`${node.href}\`\n`;
|
|
48
|
+
}
|
|
49
|
+
md += '\n';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (imageNodes.length > 0) {
|
|
53
|
+
md += `## Image Nodes\n\n`;
|
|
54
|
+
for (const node of imageNodes) {
|
|
55
|
+
md += `### Line ${node.line}: ${node.tag}\n`;
|
|
56
|
+
md += `**ID**: \`${node.id}\`\n`;
|
|
57
|
+
md += `**Type**: ${node.type}\n`;
|
|
58
|
+
if (node.bgPattern) {
|
|
59
|
+
md += `**Pattern**: \`${node.bgPattern}\`\n`;
|
|
60
|
+
}
|
|
61
|
+
md += '\n';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (textNodes.length === 0 && imageNodes.length === 0) {
|
|
65
|
+
md += `No text or image nodes found.\n`;
|
|
66
|
+
}
|
|
67
|
+
return md;
|
|
68
|
+
}
|
|
11
69
|
// Plugin to inject source mapping attributes for WYSIWYG editing
|
|
12
70
|
export function webjourneyElementTagger() {
|
|
13
71
|
return {
|
|
@@ -30,6 +88,9 @@ export function webjourneyElementTagger() {
|
|
|
30
88
|
plugins: ['typescript', 'jsx'],
|
|
31
89
|
});
|
|
32
90
|
let modified = false;
|
|
91
|
+
// Arrays to collect node information for documentation
|
|
92
|
+
const docTextNodes = [];
|
|
93
|
+
const docImageNodes = [];
|
|
33
94
|
// Traverse the AST
|
|
34
95
|
traverse(ast, {
|
|
35
96
|
JSXElement(path) {
|
|
@@ -74,11 +135,27 @@ export function webjourneyElementTagger() {
|
|
|
74
135
|
const elementId = `${relativePath}:${lineNumber}`;
|
|
75
136
|
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
137
|
modified = true;
|
|
138
|
+
// Collect text content for documentation
|
|
139
|
+
const textContent = extractTextContent(path.node.children);
|
|
140
|
+
const hrefValue = (tagName === 'a' || tagName === 'Link')
|
|
141
|
+
? extractHrefValue(openingElement.attributes)
|
|
142
|
+
: undefined;
|
|
143
|
+
docTextNodes.push({
|
|
144
|
+
line: lineNumber,
|
|
145
|
+
tag: tagName,
|
|
146
|
+
id: elementId,
|
|
147
|
+
content: textContent,
|
|
148
|
+
href: hrefValue
|
|
149
|
+
});
|
|
77
150
|
}
|
|
78
151
|
// Case 2: Mixed children (text nodes + other elements)
|
|
79
152
|
else if (nonTextChildren.length > 0) {
|
|
80
153
|
// Wrap each text node in a span with data-wj-* attributes
|
|
81
154
|
const newChildren = [];
|
|
155
|
+
// Extract href if parent is a link element
|
|
156
|
+
const parentHref = (tagName === 'a' || tagName === 'Link')
|
|
157
|
+
? extractHrefValue(openingElement.attributes)
|
|
158
|
+
: undefined;
|
|
82
159
|
for (const child of path.node.children) {
|
|
83
160
|
if (t.isJSXText(child) && child.value.trim() !== '') {
|
|
84
161
|
// Generate unique ID for this text segment
|
|
@@ -92,6 +169,15 @@ export function webjourneyElementTagger() {
|
|
|
92
169
|
t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
|
|
93
170
|
], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
|
|
94
171
|
newChildren.push(wrapper);
|
|
172
|
+
// Collect text content for documentation
|
|
173
|
+
const textContent = child.value.trim();
|
|
174
|
+
docTextNodes.push({
|
|
175
|
+
line: textLineNumber,
|
|
176
|
+
tag: 'span',
|
|
177
|
+
id: elementId,
|
|
178
|
+
content: textContent,
|
|
179
|
+
href: parentHref
|
|
180
|
+
});
|
|
95
181
|
}
|
|
96
182
|
else {
|
|
97
183
|
// Keep whitespace text nodes, elements, etc. as-is
|
|
@@ -114,6 +200,13 @@ export function webjourneyElementTagger() {
|
|
|
114
200
|
const elementId = `${relativePath}:${lineNumber}`;
|
|
115
201
|
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)));
|
|
116
202
|
modified = true;
|
|
203
|
+
// Collect image information for documentation
|
|
204
|
+
docImageNodes.push({
|
|
205
|
+
line: lineNumber,
|
|
206
|
+
tag: tagName,
|
|
207
|
+
id: elementId,
|
|
208
|
+
type: 'image'
|
|
209
|
+
});
|
|
117
210
|
}
|
|
118
211
|
}
|
|
119
212
|
// Handle elements with bg-[url(...)] className pattern
|
|
@@ -144,6 +237,15 @@ export function webjourneyElementTagger() {
|
|
|
144
237
|
const elementId = `${relativePath}:${lineNumber}`;
|
|
145
238
|
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)));
|
|
146
239
|
modified = true;
|
|
240
|
+
// Collect background image information for documentation
|
|
241
|
+
const bgMatch = classNameValue.match(/bg-\[url\([^\)]+\)\]/);
|
|
242
|
+
docImageNodes.push({
|
|
243
|
+
line: lineNumber,
|
|
244
|
+
tag: tagName,
|
|
245
|
+
id: elementId,
|
|
246
|
+
type: 'background-image',
|
|
247
|
+
bgPattern: bgMatch ? bgMatch[0] : undefined
|
|
248
|
+
});
|
|
147
249
|
}
|
|
148
250
|
}
|
|
149
251
|
// Handle anchor elements and Link components
|
|
@@ -176,6 +278,18 @@ export function webjourneyElementTagger() {
|
|
|
176
278
|
}
|
|
177
279
|
});
|
|
178
280
|
if (modified) {
|
|
281
|
+
// Generate markdown documentation
|
|
282
|
+
if (docTextNodes.length > 0 || docImageNodes.length > 0) {
|
|
283
|
+
const markdownContent = generateMarkdownDocs(relativePath, docTextNodes, docImageNodes);
|
|
284
|
+
const markdownPath = `${id}.nodes.md`;
|
|
285
|
+
try {
|
|
286
|
+
fs.writeFileSync(markdownPath, markdownContent, 'utf-8');
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
console.error(`Error writing documentation for ${id}:`, error);
|
|
290
|
+
// Don't fail the build if documentation generation fails
|
|
291
|
+
}
|
|
292
|
+
}
|
|
179
293
|
// Generate code from the modified AST
|
|
180
294
|
const output = generate(ast, {
|
|
181
295
|
retainLines: true,
|