1 | import fs from 'fs'
|
2 |
|
3 | import Global from './props.global.js'
|
4 | import Sizes from './props.sizes.js'
|
5 | import * as OpenColors from './props.colors.js'
|
6 | import BrandColors from './props.colors.brand.js'
|
7 | import Fonts from './props.fonts.js'
|
8 | import Borders from './props.borders.js'
|
9 | import Shadows from './props.shadows.js'
|
10 | import Zindex from './props.zindex.js'
|
11 |
|
12 | const [,,prefix,useWhere] = process.argv
|
13 | const selector = useWhere === 'true' ? ':where(html)' : 'html'
|
14 |
|
15 | const 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 |
|
26 | const jsonbundle = {
|
27 | ...Global,
|
28 | ...OpenColors,
|
29 | ...BrandColors,
|
30 | ...Sizes,
|
31 | ...Zindex,
|
32 | ...Borders,
|
33 | }
|
34 | const designtokens = Object.entries(jsonbundle).map(([key, token]) => {
|
35 | return [key, {
|
36 | value: token
|
37 | }]
|
38 | })
|
39 |
|
40 | const JSONtokens = fs.createWriteStream('../cc-props.tokens.json')
|
41 | JSONtokens.end(JSON.stringify(Object.fromEntries(designtokens), null, 2))
|
42 |
|
43 | const 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 |
|
76 | Object.entries({...mainbundle}).forEach(([filename, props]) => {
|
77 | buildPropsStylesheet({filename, props})
|
78 | })
|
79 |
|
80 |
|
81 | const entry = fs.createWriteStream('index.css')
|
82 | entry.write(`@import 'props.media.css';
|
83 | `)
|
84 | Object.keys(mainbundle).forEach(filename => {
|
85 | entry.write(`@import '${filename}';\n`)
|
86 | })
|
87 | entry.end() |
\ | No newline at end of file |