@webmate-studio/builder 0.1.10 → 0.1.11
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/package.json +1 -2
- package/src/tailwind-generator.js +29 -85
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webmate-studio/builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Webmate Studio Component Builder",
|
|
6
6
|
"keywords": [
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tailwindcss/cli": "^4.1.0",
|
|
28
27
|
"@webmate-studio/core": "^0.1.0",
|
|
29
28
|
"@webmate-studio/parser": "^0.1.0",
|
|
30
29
|
"alpinejs": "^3.15.0",
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tailwind CSS v4 Generator for Components
|
|
3
|
-
* Generates scoped Tailwind CSS using Tailwind v4's
|
|
3
|
+
* Generates scoped Tailwind CSS using Tailwind v4's JavaScript API
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { writeFileSync, unlinkSync, mkdtempSync, existsSync } from 'fs';
|
|
9
|
-
import { join, dirname } from 'path';
|
|
10
|
-
import { tmpdir } from 'os';
|
|
6
|
+
import { compile } from 'tailwindcss';
|
|
7
|
+
import { readFileSync } from 'fs';
|
|
11
8
|
import { fileURLToPath } from 'url';
|
|
12
|
-
|
|
13
|
-
const execAsync = promisify(exec);
|
|
9
|
+
import { dirname, join } from 'path';
|
|
14
10
|
|
|
15
11
|
// Get the directory where this module is located
|
|
16
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -21,51 +17,17 @@ import { createRequire } from 'module';
|
|
|
21
17
|
const require = createRequire(import.meta.url);
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @returns {string}
|
|
20
|
+
* Load Tailwind CSS index styles
|
|
21
|
+
* @returns {string} Tailwind CSS content
|
|
26
22
|
*/
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
() => {
|
|
35
|
-
const pkgPath = require.resolve('@tailwindcss/cli/package.json');
|
|
36
|
-
return join(dirname(pkgPath), 'dist', 'index.js');
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
// Strategy 3: From builder's node_modules
|
|
40
|
-
() => {
|
|
41
|
-
const builderDir = dirname(import.meta.url.replace('file://', ''));
|
|
42
|
-
return join(builderDir, '..', 'node_modules', '@tailwindcss', 'cli', 'dist', 'index.js');
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
// Strategy 4: Relative to tailwindcss package
|
|
46
|
-
() => {
|
|
47
|
-
const tailwindPkg = require.resolve('tailwindcss/package.json');
|
|
48
|
-
const tailwindDir = dirname(tailwindPkg);
|
|
49
|
-
return join(tailwindDir, '..', '@tailwindcss', 'cli', 'dist', 'index.js');
|
|
50
|
-
}
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
for (const strategy of strategies) {
|
|
54
|
-
try {
|
|
55
|
-
const cliPath = strategy();
|
|
56
|
-
// Verify the file exists
|
|
57
|
-
if (existsSync(cliPath)) {
|
|
58
|
-
return cliPath;
|
|
59
|
-
}
|
|
60
|
-
} catch (e) {
|
|
61
|
-
// Try next strategy
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
23
|
+
function loadTailwindStyles() {
|
|
24
|
+
try {
|
|
25
|
+
// Resolve tailwindcss/index.css
|
|
26
|
+
const tailwindCssPath = require.resolve('tailwindcss/index.css');
|
|
27
|
+
return readFileSync(tailwindCssPath, 'utf-8');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error(`Failed to load Tailwind CSS: ${error.message}`);
|
|
64
30
|
}
|
|
65
|
-
|
|
66
|
-
throw new Error(
|
|
67
|
-
'Could not find @tailwindcss/cli. Please ensure @tailwindcss/cli is installed.'
|
|
68
|
-
);
|
|
69
31
|
}
|
|
70
32
|
|
|
71
33
|
/**
|
|
@@ -156,11 +118,6 @@ export async function generateTailwindCSS(classes, options = {}) {
|
|
|
156
118
|
return '/* No Tailwind classes found */';
|
|
157
119
|
}
|
|
158
120
|
|
|
159
|
-
// Create temporary directory
|
|
160
|
-
const tempDir = mkdtempSync(join(tmpdir(), 'tailwind-gen-'));
|
|
161
|
-
const inputPath = join(tempDir, 'input.css');
|
|
162
|
-
const htmlPath = join(tempDir, 'content.html');
|
|
163
|
-
|
|
164
121
|
try {
|
|
165
122
|
// Default theme colors (complete design tokens)
|
|
166
123
|
const defaultColors = {
|
|
@@ -300,42 +257,29 @@ export async function generateTailwindCSS(classes, options = {}) {
|
|
|
300
257
|
${themeCSS}
|
|
301
258
|
`.trim();
|
|
302
259
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const builderNodeModules = join(__dirname, "..", "node_modules");
|
|
316
|
-
|
|
317
|
-
const { stdout } = await execAsync(command, {
|
|
318
|
-
cwd: tempDir,
|
|
319
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
320
|
-
env: {
|
|
321
|
-
...process.env,
|
|
322
|
-
NODE_PATH: builderNodeModules
|
|
260
|
+
// Load Tailwind CSS styles
|
|
261
|
+
const tailwindStyles = loadTailwindStyles();
|
|
262
|
+
|
|
263
|
+
// Create compiler using Tailwind v4 JavaScript API
|
|
264
|
+
const compiler = await compile(inputCSS, {
|
|
265
|
+
loadStylesheet: async (id, base) => {
|
|
266
|
+
if (id === 'tailwindcss') {
|
|
267
|
+
return {
|
|
268
|
+
base: 'virtual:tailwindcss',
|
|
269
|
+
content: tailwindStyles
|
|
270
|
+
};
|
|
271
|
+
}
|
|
323
272
|
}
|
|
324
273
|
});
|
|
325
274
|
|
|
326
|
-
|
|
275
|
+
// Build CSS for the specific classes
|
|
276
|
+
const result = await compiler.build(classArray);
|
|
277
|
+
|
|
278
|
+
return result;
|
|
327
279
|
|
|
328
280
|
} catch (error) {
|
|
329
281
|
console.error('[Tailwind Generator v4] Error:', error);
|
|
330
282
|
throw new Error(`Failed to generate Tailwind CSS: ${error.message}`);
|
|
331
|
-
} finally {
|
|
332
|
-
// Cleanup temp files
|
|
333
|
-
try {
|
|
334
|
-
unlinkSync(inputPath);
|
|
335
|
-
unlinkSync(htmlPath);
|
|
336
|
-
} catch (e) {
|
|
337
|
-
// Ignore cleanup errors
|
|
338
|
-
}
|
|
339
283
|
}
|
|
340
284
|
}
|
|
341
285
|
|