@webjourney/vite-plugins 1.2.17-0 → 1.2.17-1
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/index.d.ts.map +1 -1
- package/dist/index.js +29 -35
- package/package.json +1 -1
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":"AAqGA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAuYrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBApab,MAAM,MAAM,MAAM;;;;;;;6BA8YT,MAAM;KA0BlC"}
|
package/dist/index.js
CHANGED
|
@@ -32,39 +32,31 @@ function extractHrefValue(attributes) {
|
|
|
32
32
|
}
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
|
-
// Helper function to
|
|
36
|
-
function
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
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';
|
|
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;
|
|
50
43
|
}
|
|
51
|
-
|
|
52
|
-
|
|
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';
|
|
44
|
+
else if (t.isJSXExpressionContainer(srcAttr.value) && t.isStringLiteral(srcAttr.value.expression)) {
|
|
45
|
+
return srcAttr.value.expression.value;
|
|
62
46
|
}
|
|
63
47
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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);
|
|
68
60
|
}
|
|
69
61
|
// Plugin to inject source mapping attributes for WYSIWYG editing
|
|
70
62
|
export function webjourneyElementTagger() {
|
|
@@ -201,11 +193,13 @@ export function webjourneyElementTagger() {
|
|
|
201
193
|
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)));
|
|
202
194
|
modified = true;
|
|
203
195
|
// Collect image information for documentation
|
|
196
|
+
const srcValue = extractSrcValue(openingElement.attributes);
|
|
204
197
|
docImageNodes.push({
|
|
205
198
|
line: lineNumber,
|
|
206
199
|
tag: tagName,
|
|
207
200
|
id: elementId,
|
|
208
|
-
type: 'image'
|
|
201
|
+
type: 'image',
|
|
202
|
+
src: srcValue
|
|
209
203
|
});
|
|
210
204
|
}
|
|
211
205
|
}
|
|
@@ -278,12 +272,12 @@ export function webjourneyElementTagger() {
|
|
|
278
272
|
}
|
|
279
273
|
});
|
|
280
274
|
if (modified) {
|
|
281
|
-
// Generate
|
|
275
|
+
// Generate JSON documentation
|
|
282
276
|
if (docTextNodes.length > 0 || docImageNodes.length > 0) {
|
|
283
|
-
const
|
|
284
|
-
const
|
|
277
|
+
const jsonContent = generateJsonDocs(relativePath, docTextNodes, docImageNodes);
|
|
278
|
+
const jsonPath = `${id}.nodes.json`;
|
|
285
279
|
try {
|
|
286
|
-
fs.writeFileSync(
|
|
280
|
+
fs.writeFileSync(jsonPath, jsonContent, 'utf-8');
|
|
287
281
|
}
|
|
288
282
|
catch (error) {
|
|
289
283
|
console.error(`Error writing documentation for ${id}:`, error);
|