UNPKG

2.17 kBJavaScriptView Raw
1import fs from 'fs'
2
3import Global from './props.global.js'
4import Sizes from './props.sizes.js'
5import * as OpenColors from './props.colors.js'
6import BrandColors from './props.colors.brand.js'
7import Fonts from './props.fonts.js'
8import Borders from './props.borders.js'
9import Shadows from './props.shadows.js'
10import Zindex from './props.zindex.js'
11
12const [,,prefix,useWhere] = process.argv
13const selector = useWhere === 'true' ? ':where(html)' : 'html'
14
15const mainbundle = {
16 'props.global.css': Global,
17 'props.fonts.css': Fonts,
18 'props.sizes.css': Sizes,
19 'props.zindex.css': Zindex,
20 'props.shadows.css': Shadows,
21 'props.colors.css': OpenColors.default,
22 'props.colors.brand.css': BrandColors,
23 'props.borders.css': Borders,
24}
25
26const jsonbundle = {
27 ...Global,
28 ...OpenColors,
29 ...BrandColors,
30 ...Sizes,
31 ...Zindex,
32 ...Borders,
33}
34const designtokens = Object.entries(jsonbundle).map(([key, token]) => {
35 return [key, {
36 value: token
37 }]
38})
39
40const JSONtokens = fs.createWriteStream('../cc-props.tokens.json')
41JSONtokens.end(JSON.stringify(Object.fromEntries(designtokens), null, 2))
42
43const buildPropsStylesheet = ({filename, props}) => {
44 const file = fs.createWriteStream(filename)
45
46 let appendedMeta = ''
47 if (filename.includes('shadows')) {
48 file.write(`@import 'props.media.css';\n\n`)
49 appendedMeta = `@media (--OSdark) {
50 ${selector} {
51 --shadow-strength: 25%;
52 --shadow-color: 220 40% 2%;
53 }
54}`
55 }
56 file.write(`${selector} {\n`)
57
58 Object.entries(props).forEach(([prop, val]) => {
59 if (prefix)
60 prop = `--${prefix}-` + prop.slice(2)
61
62 if (Array.isArray(val)) {
63 let [animation, keyframes] = val
64 appendedMeta += keyframes
65 val = animation
66 }
67
68 file.write(` ${prop}: ${val};\n`)
69 })
70
71 file.write('}\n')
72 file.end(appendedMeta)
73}
74
75// gen prop variants
76Object.entries({...mainbundle}).forEach(([filename, props]) => {
77 buildPropsStylesheet({filename, props})
78})
79
80// gen index.css
81const entry = fs.createWriteStream('index.css')
82entry.write(`@import 'props.media.css';
83`)
84Object.keys(mainbundle).forEach(filename => {
85 entry.write(`@import '${filename}';\n`)
86})
87entry.end()
\No newline at end of file