-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathoptions.js
54 lines (48 loc) · 1.4 KB
/
options.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
const path = require("path");
const resolveConfig = require("tailwindcss/resolveConfig");
const { elmBodyHtml, elmBodyString, elmBodySvg} = require("./code-gen.js")
const defaultOpts = {
tailwindConfig: null,
splitByScreens: true,
elmFile: "src/TW.elm",
elmModuleName: "TW",
prefix: "",
nameStyle: "snake",
formats: {
/*
string: {
elmFile: "src/TW/String.elm",
},
svg: {
elmFile: "src/TW/Svg.elm",
}
*/
},
};
function cleanOpts(opts) {
opts = { ...defaultOpts, ...opts };
opts.formats = { ...opts.formats };
// grab resolved tailwind config:
if (opts.tailwindConfig === null) {
throw new Error("Failed to specify Tailwind config file. Add a `tailwindConfig` key to your config.");
}
const twConfig = resolveConfig(require(path.resolve(opts.tailwindConfig)));
opts.prefix = twConfig.prefix;
opts.screens = Object.keys(twConfig.theme.screens);
return opts;
}
function formats(opts) {
return [
cleanFormat(opts, elmBodyHtml),
cleanFormat({ ...opts.formats.string }, elmBodyString),
cleanFormat({ ...opts.formats.svg }, elmBodySvg),
].filter((f) => f);
}
function cleanFormat({ elmFile, elmModuleName }, elmBodyFn) {
if (!elmFile) return false;
if (!elmModuleName) return false;
return { elmFile, elmModuleName, elmBodyFn };
}
exports.cleanOpts = cleanOpts;
exports.defaultOpts = defaultOpts;
exports.formats = formats;