@webmate-studio/builder 0.1.9 → 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 -3
- package/src/tailwind-generator.js +28 -59
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,8 +24,6 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tailwindcss/cli": "^4.1.0",
|
|
28
|
-
"@webmate-studio/builder": "^0.1.8",
|
|
29
27
|
"@webmate-studio/core": "^0.1.0",
|
|
30
28
|
"@webmate-studio/parser": "^0.1.0",
|
|
31
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 } 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,25 +17,16 @@ 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
|
|
23
|
+
function loadTailwindStyles() {
|
|
28
24
|
try {
|
|
29
|
-
//
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
} catch (
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const tailwindPackagePath = require.resolve('tailwindcss/package.json');
|
|
36
|
-
const tailwindDir = dirname(tailwindPackagePath);
|
|
37
|
-
// Tailwind v4 uses @tailwindcss/cli
|
|
38
|
-
const cliPath = join(tailwindDir, '..', '@tailwindcss', 'cli', 'dist', 'index.js');
|
|
39
|
-
return cliPath;
|
|
40
|
-
} catch (e2) {
|
|
41
|
-
throw new Error('Could not find @tailwindcss/cli. Please install it: npm install @tailwindcss/cli');
|
|
42
|
-
}
|
|
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}`);
|
|
43
30
|
}
|
|
44
31
|
}
|
|
45
32
|
|
|
@@ -131,11 +118,6 @@ export async function generateTailwindCSS(classes, options = {}) {
|
|
|
131
118
|
return '/* No Tailwind classes found */';
|
|
132
119
|
}
|
|
133
120
|
|
|
134
|
-
// Create temporary directory
|
|
135
|
-
const tempDir = mkdtempSync(join(tmpdir(), 'tailwind-gen-'));
|
|
136
|
-
const inputPath = join(tempDir, 'input.css');
|
|
137
|
-
const htmlPath = join(tempDir, 'content.html');
|
|
138
|
-
|
|
139
121
|
try {
|
|
140
122
|
// Default theme colors (complete design tokens)
|
|
141
123
|
const defaultColors = {
|
|
@@ -275,42 +257,29 @@ export async function generateTailwindCSS(classes, options = {}) {
|
|
|
275
257
|
${themeCSS}
|
|
276
258
|
`.trim();
|
|
277
259
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const builderNodeModules = join(__dirname, "..", "node_modules");
|
|
291
|
-
|
|
292
|
-
const { stdout } = await execAsync(command, {
|
|
293
|
-
cwd: tempDir,
|
|
294
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
295
|
-
env: {
|
|
296
|
-
...process.env,
|
|
297
|
-
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
|
+
}
|
|
298
272
|
}
|
|
299
273
|
});
|
|
300
274
|
|
|
301
|
-
|
|
275
|
+
// Build CSS for the specific classes
|
|
276
|
+
const result = await compiler.build(classArray);
|
|
277
|
+
|
|
278
|
+
return result;
|
|
302
279
|
|
|
303
280
|
} catch (error) {
|
|
304
281
|
console.error('[Tailwind Generator v4] Error:', error);
|
|
305
282
|
throw new Error(`Failed to generate Tailwind CSS: ${error.message}`);
|
|
306
|
-
} finally {
|
|
307
|
-
// Cleanup temp files
|
|
308
|
-
try {
|
|
309
|
-
unlinkSync(inputPath);
|
|
310
|
-
unlinkSync(htmlPath);
|
|
311
|
-
} catch (e) {
|
|
312
|
-
// Ignore cleanup errors
|
|
313
|
-
}
|
|
314
283
|
}
|
|
315
284
|
}
|
|
316
285
|
|