-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.js
56 lines (51 loc) · 1.52 KB
/
install.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
/**
* Install stailwc
*
* @param {{wasm?: string, tailwindPath?: string, silent?: boolean, strict?: boolean, engine: "emotion" | "styled-components"}} options
* @returns A nextjs plugin configuration
*/
module.exports = (options = {}) => {
const resolveConfig = require("tailwindcss/resolveConfig");
const defaultConfig = require("tailwindcss/defaultConfig");
if (options?.tailwindPath === undefined) {
const { path } = require("app-root-path");
options.tailwindPath = `${path}/tailwind.config.js`;
}
let override = {};
try {
!options?.silent &&
console.log(
`\u001b[36minfo\u001b[0m - attempting to load tailwind config at ${options.tailwindPath}`
);
override = require(options.tailwindPath);
} catch (e) {
!options?.silent &&
console.warn(
`\u001b[33mwarn\u001b[0m - could not load tailwind config at ${options.tailwindPath}: ${e}`
);
}
const config = resolveConfig(override, defaultConfig);
config.theme.colors = Object.entries(config.theme.colors)
.flatMap(([k, v]) => {
if (typeof v === "object") {
const items = Object.entries(v).map(([k2, v2]) => [
k2 === "DEFAULT" ? k : k + "-" + k2,
v2,
]);
return items;
} else {
return [[k, v]];
}
})
.reduce(
(acc, [k, v]) => ({
...acc,
[k]: v,
}),
{}
);
return [
options?.wasm ?? "stailwc",
{ config, strict: options?.strict ?? false, engine: options?.engine ?? "emotion" },
];
};