@webmate-studio/builder 0.2.25 → 0.2.27
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 +19 -5
- package/package.json +1 -1
package/build-service.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import http from 'http';
|
|
9
9
|
import { generateComponentCSS } from './src/tailwind-generator.js';
|
|
10
10
|
import { bundleIsland } from './src/bundler.js';
|
|
11
|
+
import { cleanComponentHTML } from './src/html-cleaner.js';
|
|
11
12
|
import { mkdtemp, writeFile, rm, mkdir } from 'fs/promises';
|
|
12
13
|
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
13
14
|
import { join } from 'path';
|
|
@@ -101,9 +102,13 @@ function injectSvelteOptions(filename, content, componentMetadata) {
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
// Generate <svelte:options> block
|
|
104
|
-
// IMPORTANT: props must be
|
|
105
|
-
|
|
106
|
-
const
|
|
105
|
+
// IMPORTANT: props must be a JavaScript object literal, not JSON string
|
|
106
|
+
// Convert to JS syntax: { title: { type: "Number" } } instead of {"title":{"type":"Number"}}
|
|
107
|
+
const propsEntries = Object.entries(props).map(([name, config]) => {
|
|
108
|
+
return `${name}: { type: "${config.type}" }`;
|
|
109
|
+
}).join(', ');
|
|
110
|
+
const propsLiteral = `{ ${propsEntries} }`;
|
|
111
|
+
const svelteOptions = `<svelte:options customElement={{ tag: "${tagName}", shadow: "none", props: ${propsLiteral} }} />\n\n`;
|
|
107
112
|
|
|
108
113
|
// Check if <svelte:options> already exists
|
|
109
114
|
if (content.includes('<svelte:options')) {
|
|
@@ -203,11 +208,19 @@ async function buildComponent(payload) {
|
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
|
|
211
|
+
// Transform HTML: Convert <IslandName /> to <island-name> Custom Elements
|
|
212
|
+
let transformedHtml = html;
|
|
213
|
+
if (html && islands.length > 0) {
|
|
214
|
+
const islandNames = islands.map(i => i.file.replace(/\.(jsx?|tsx?|svelte|vue)$/, ''));
|
|
215
|
+
transformedHtml = cleanComponentHTML(html, islandNames);
|
|
216
|
+
console.log(`[Build Service] ✓ Transformed HTML: ${islandNames.length} island(s) → Custom Elements`);
|
|
217
|
+
}
|
|
218
|
+
|
|
206
219
|
// Generate CSS
|
|
207
220
|
let css = '';
|
|
208
|
-
if (
|
|
221
|
+
if (transformedHtml) {
|
|
209
222
|
console.log('[Build Service] Generating CSS...');
|
|
210
|
-
const cssResult = await generateComponentCSS(
|
|
223
|
+
const cssResult = await generateComponentCSS(transformedHtml, {
|
|
211
224
|
designTokens: null,
|
|
212
225
|
minify: true
|
|
213
226
|
});
|
|
@@ -219,6 +232,7 @@ async function buildComponent(payload) {
|
|
|
219
232
|
success: true,
|
|
220
233
|
bundledIslands,
|
|
221
234
|
css,
|
|
235
|
+
html: transformedHtml, // Return transformed HTML
|
|
222
236
|
stats: {
|
|
223
237
|
islands: bundledIslands.length,
|
|
224
238
|
totalSize: bundledIslands.reduce((sum, i) => sum + i.size, 0) + css.length
|