@webmate-studio/builder 0.2.29 → 0.2.31
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/build-service.js +7 -1
- package/package.json +1 -1
- package/src/build.js +16 -14
- package/src/bundler.js +13 -4
- package/src/html-cleaner.js +27 -28
package/build-service.js
CHANGED
|
@@ -73,11 +73,17 @@ function injectSvelteOptions(filename, content, componentMetadata) {
|
|
|
73
73
|
// SwiperTest.svelte → swiper-test
|
|
74
74
|
// MyAwesomeComponent.svelte → my-awesome-component
|
|
75
75
|
const componentName = filename.replace('.svelte', '');
|
|
76
|
-
|
|
76
|
+
let tagName = componentName
|
|
77
77
|
.replace(/([A-Z])/g, '-$1') // Insert hyphen before capital letters
|
|
78
78
|
.toLowerCase()
|
|
79
79
|
.replace(/^-/, ''); // Remove leading hyphen
|
|
80
80
|
|
|
81
|
+
// Svelte requires custom element names to be hyphenated
|
|
82
|
+
// If there's no hyphen, add a prefix to make it valid
|
|
83
|
+
if (!tagName.includes('-')) {
|
|
84
|
+
tagName = 'wm-' + tagName; // e.g., "button" → "wm-button"
|
|
85
|
+
}
|
|
86
|
+
|
|
81
87
|
// Generate props definition from component.json
|
|
82
88
|
const props = {};
|
|
83
89
|
if (componentMetadata.props) {
|
package/package.json
CHANGED
package/src/build.js
CHANGED
|
@@ -81,24 +81,26 @@ async function installComponentDependencies(componentDir, componentName) {
|
|
|
81
81
|
* @returns {string} HTML with scoping attribute
|
|
82
82
|
*/
|
|
83
83
|
function addScopingAttribute(html, componentName) {
|
|
84
|
-
const dom = parseDocument(html);
|
|
85
84
|
const scopeId = `wm-${componentName.toLowerCase().replace(/[^a-z0-9]/g, '-')}`;
|
|
86
85
|
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
// Use regex to add attribute to first HTML element
|
|
87
|
+
// This preserves the original HTML syntax (including unquoted class: directives)
|
|
88
|
+
// Pattern: Match first opening tag, capture tag name and attributes, insert our attribute
|
|
89
|
+
const match = html.match(/^(\s*)(<([a-zA-Z][a-zA-Z0-9-]*)(\s+[^>]*)?(\/?)>)/);
|
|
90
|
+
|
|
91
|
+
if (match) {
|
|
92
|
+
const whitespace = match[1];
|
|
93
|
+
const fullTag = match[2];
|
|
94
|
+
const tagName = match[3];
|
|
95
|
+
const existingAttrs = match[4] || '';
|
|
96
|
+
const selfClosing = match[5] || '';
|
|
97
|
+
|
|
98
|
+
// Insert data-wm-component attribute
|
|
99
|
+
const newTag = `<${tagName} data-wm-component="${scopeId}"${existingAttrs}${selfClosing}>`;
|
|
100
|
+
return whitespace + newTag + html.substring(match[0].length);
|
|
96
101
|
}
|
|
97
102
|
|
|
98
|
-
return
|
|
99
|
-
encodeEntities: false,
|
|
100
|
-
selfClosingTags: true
|
|
101
|
-
});
|
|
103
|
+
return html;
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
/**
|
package/src/bundler.js
CHANGED
|
@@ -202,9 +202,16 @@ export async function bundleComponentIslands(componentDir, outputDir) {
|
|
|
202
202
|
return { islands: [], success: true };
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
// Find all
|
|
205
|
+
// Find all island files (JS, JSX, Svelte, Vue, etc.)
|
|
206
206
|
const files = await fs.readdir(islandsDir);
|
|
207
|
-
const islandFiles = files.filter((f) =>
|
|
207
|
+
const islandFiles = files.filter((f) =>
|
|
208
|
+
f.endsWith('.js') ||
|
|
209
|
+
f.endsWith('.jsx') ||
|
|
210
|
+
f.endsWith('.svelte') ||
|
|
211
|
+
f.endsWith('.vue') ||
|
|
212
|
+
f.endsWith('.ts') ||
|
|
213
|
+
f.endsWith('.tsx')
|
|
214
|
+
);
|
|
208
215
|
|
|
209
216
|
if (islandFiles.length === 0) {
|
|
210
217
|
return { islands: [], success: true };
|
|
@@ -217,7 +224,9 @@ export async function bundleComponentIslands(componentDir, outputDir) {
|
|
|
217
224
|
|
|
218
225
|
for (const islandFile of islandFiles) {
|
|
219
226
|
const inputPath = path.join(islandsDir, islandFile);
|
|
220
|
-
|
|
227
|
+
// Output file is always .js regardless of input extension (.svelte, .jsx, etc.)
|
|
228
|
+
const outputFile = islandFile.replace(/\.(svelte|jsx|vue|tsx?)$/, '.js');
|
|
229
|
+
const outputPath = path.join(outputDir, outputFile);
|
|
221
230
|
|
|
222
231
|
console.log(pc.dim(` Bundling ${islandFile}...`));
|
|
223
232
|
|
|
@@ -233,7 +242,7 @@ export async function bundleComponentIslands(componentDir, outputDir) {
|
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
results.push({
|
|
236
|
-
file:
|
|
245
|
+
file: outputFile, // Use output filename (.js) instead of input filename
|
|
237
246
|
...result
|
|
238
247
|
});
|
|
239
248
|
}
|
package/src/html-cleaner.js
CHANGED
|
@@ -11,24 +11,28 @@ import render from 'dom-serializer';
|
|
|
11
11
|
* @returns {string} Cleaned HTML without wm: attributes
|
|
12
12
|
*/
|
|
13
13
|
export function cleanComponentHTML(html, islands = []) {
|
|
14
|
-
// Transform PascalCase island elements to data-island FIRST
|
|
14
|
+
// Transform PascalCase island elements to data-island FIRST
|
|
15
15
|
if (islands && islands.length > 0) {
|
|
16
16
|
html = transformIslandsToDataAttributes(html, islands);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Remove wm: attributes using regex (avoids htmlparser2 breaking class: directives)
|
|
20
|
+
// Remove metadata attributes: wm:component, wm:prop, wm:props, wm:schema, wm:description
|
|
21
|
+
html = html.replace(/\s+wm:(component|prop|props|schema|description)="[^"]*"/g, '');
|
|
22
|
+
html = html.replace(/\s+wm:(component|prop|props|schema|description)='[^']*'/g, '');
|
|
23
|
+
html = html.replace(/\s+wm:(component|prop|props|schema|description)=\{[^}]*\}/g, '');
|
|
24
|
+
html = html.replace(/\s+wm:(component|prop|props|schema|description)/g, '');
|
|
20
25
|
|
|
21
|
-
// Remove
|
|
22
|
-
|
|
26
|
+
// Remove standalone 'wm' attribute
|
|
27
|
+
html = html.replace(/\s+wm="[^"]*"/g, '');
|
|
28
|
+
html = html.replace(/\s+wm='[^']*'/g, '');
|
|
29
|
+
html = html.replace(/\s+wm(?=\s|>|\/)/g, '');
|
|
23
30
|
|
|
24
|
-
// Remove <script wm:schema>
|
|
25
|
-
|
|
31
|
+
// Remove <script wm:schema>, <script wm:description>, <script wm:props>, <script wm="">
|
|
32
|
+
html = html.replace(/<script[^>]*\s+wm:(schema|description|props)[^>]*>[\s\S]*?<\/script>/gi, '');
|
|
33
|
+
html = html.replace(/<script[^>]*\s+wm=""[^>]*>[\s\S]*?<\/script>/gi, '');
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
return render(dom, {
|
|
29
|
-
encodeEntities: false,
|
|
30
|
-
selfClosingTags: true
|
|
31
|
-
});
|
|
35
|
+
return html;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
/**
|
|
@@ -167,28 +171,23 @@ function removeSchemaScripts(dom) {
|
|
|
167
171
|
* @returns {Object} { html: string, css: string }
|
|
168
172
|
*/
|
|
169
173
|
export function extractStyles(html) {
|
|
170
|
-
const dom = parseDocument(html);
|
|
171
174
|
let css = '';
|
|
172
175
|
|
|
173
|
-
//
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
for (const styleTag of styleTags) {
|
|
180
|
-
const styleContent = DomUtils.textContent(styleTag);
|
|
181
|
-
css += styleContent + '\n';
|
|
176
|
+
// Extract all <style> tags using regex (avoids htmlparser2 breaking class: directives)
|
|
177
|
+
const styleTagPattern = /<style(\s[^>]*)?>(.*)(?:<\/style>)/gis;
|
|
178
|
+
let match;
|
|
179
|
+
const stylesToRemove = [];
|
|
182
180
|
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
while ((match = styleTagPattern.exec(html)) !== null) {
|
|
182
|
+
css += match[2] + '\n';
|
|
183
|
+
stylesToRemove.push(match[0]);
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
//
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
186
|
+
// Remove all <style> tags from HTML
|
|
187
|
+
let cleanHtml = html;
|
|
188
|
+
for (const styleTag of stylesToRemove) {
|
|
189
|
+
cleanHtml = cleanHtml.replace(styleTag, '');
|
|
190
|
+
}
|
|
192
191
|
|
|
193
192
|
return {
|
|
194
193
|
html: cleanHtml.trim(),
|