-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailwind.build.js
60 lines (52 loc) · 1.53 KB
/
tailwind.build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const chokidar = require('chokidar');
const glob = require('glob');
// Function to generate TailwindCSS for a specific Lit component
const buildCSSForComponent = (componentPath) => {
const componentDir = path.dirname(componentPath);
const componentName = path.basename(componentPath, '.ts');
const outputPath = path.join(componentDir, `${componentName}.css`);
const tempConfigPath = path.join(componentDir, 'tailwind.config.js');
fs.writeFileSync(
tempConfigPath,
`
module.exports = {
content: ['${componentPath}'],
theme: {},
corePlugins: {
preflight: false,
},
};
`
);
exec(
`npx tailwindcss -c ${tempConfigPath} -o ${outputPath} --minify`,
(err) => {
if (err) {
console.error(`Error generating CSS for ${componentPath}: ${err}`);
return;
}
fs.unlinkSync(tempConfigPath);
console.log(`Generated CSS for ${componentPath} at ${outputPath}`);
}
);
};
// Watch and build CSS when .ts files change
const watchCSS = () => {
chokidar.watch('./src/components/*/*.ts').on('change', (filePath) => {
if (filePath.endsWith('.ts')) {
buildCSSForComponent(filePath);
}
});
console.log('Watching for changes in .ts files...');
};
const args = process.argv.slice(2);
if (args.includes('--watch')) {
watchCSS();
} else {
glob
.sync('./src/components/*/*.ts', './src/components/*/*.md')
.forEach(buildCSSForComponent);
}