forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostcss.config.cjs
More file actions
60 lines (48 loc) · 1.56 KB
/
Copy pathpostcss.config.cjs
File metadata and controls
60 lines (48 loc) · 1.56 KB
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 path = require("path");
const fs = require("fs");
let didCreateInterface = false;
module.exports = {
plugins: [
{
postcssPlugin: "postcss-collect-all-variables",
Once(root) {
if (didCreateInterface) return;
const filename = path.basename(root.source.input.file);
if (filename === "colors.css") {
const variables = {};
root.walkDecls((decl) => {
if (decl.prop.startsWith("--")) {
variables[decl.prop] = decl.value;
}
});
// Create TypeScript interface
const interfaceContent = generateInterface(variables);
// Ensure the directory exists
const dir = path.resolve(__dirname, "src/types");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
// Write the interface to the file
const filePath = path.resolve(dir, "css.ts");
fs.writeFileSync(filePath, interfaceContent);
didCreateInterface = true;
}
},
},
// require("tailwindcss"),
// require("autoprefixer"),
],
};
function generateInterface(variables) {
const interfaceLines = [
"// autogenerated (see postcss.config.cjs) - do not edit",
'import { CSSProperties } from "react";',
"",
"export interface CopilotKitCSSProperties extends CSSProperties {",
];
for (const [prop, value] of Object.entries(variables)) {
interfaceLines.push(` "${prop}"?: string;`);
}
interfaceLines.push("}");
return interfaceLines.join("\n") + "\n";
}