-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenSizing.js
81 lines (66 loc) · 2.06 KB
/
genSizing.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const _ = require("lodash");
const fs = require("fs");
const FILEPATH = "src/less/";
const SIZING_FILENAME = "sizing.less";
const SPACING_FILENAME = "spacing.less";
const sizes = {
none: 0,
"4xs": 0.0625,
"3xs": 0.125,
"2xs": 0.25,
xs: 0.5,
s: 0.75,
m: 1,
l: 1.5,
xl: 2,
"2xl": 2.5,
"3xl": 3,
"4xl": 3.5,
"5xl": 4,
};
let sizingContents = [];
let spacingContents = [];
_.forEach(sizes, (size, sizeName) => {
// Trim leading 0s on fractional sizes.
const sizeStr = `${size}`.replace("0.", ".");
const sizeVar = `@size_${sizeName}`;
sizingContents.push(`${sizeVar}: ${sizeStr}rem; /* ${size * 16}px */`);
spacingContents.push("/**");
spacingContents.push(` * ${sizeVar}`);
spacingContents.push(" */");
["margin", "padding"].forEach((type) => {
const classPrefix = `${type}`;
spacingContents = spacingContents.concat([
`.${classPrefix}--${sizeName} { ${type}: ${sizeVar} }\n`,
`.${classPrefix}--top--${sizeName} { ${type}-top: ${sizeVar} }\n`,
`.${classPrefix}--right--${sizeName} { ${type}-right: ${sizeVar} }\n`,
`.${classPrefix}--bottom--${sizeName} { ${type}-bottom: ${sizeVar} }\n`,
`.${classPrefix}--left--${sizeName} { ${type}-left: ${sizeVar} }\n`,
`.${classPrefix}--x--${sizeName} { ${type}-left: ${sizeVar}; ${type}-right: ${sizeVar} }\n`,
`.${classPrefix}--y--${sizeName} { ${type}-top: ${sizeVar}; ${type}-bottom: ${sizeVar} }`,
]);
spacingContents.push("");
});
});
sizingContents.push("");
sizingContents = [
"/**",
" * Common sizing definitions.",
" *",
" * Auto-generated file.",
" * To re-generate, run `make sizing-styles`",
" */",
"",
].concat(sizingContents);
fs.writeFileSync(`${FILEPATH}${SIZING_FILENAME}`, sizingContents.join("\n"));
spacingContents = [
"/**",
" * Common spacing definitions.",
" *",
" * Auto-generated file.",
" * To re-generate, run `make sizing-styles`",
" */",
`@import (reference) "./${SIZING_FILENAME}";`,
"",
].concat(spacingContents);
fs.writeFileSync(`${FILEPATH}${SPACING_FILENAME}`, spacingContents.join("\n"));