1 | import fs from 'fs'
|
2 |
|
3 | import Animations from '../src/props.animations.js'
|
4 | import Sizes from '../src/props.sizes.js'
|
5 | import * as Colors from '../src/props.colors.js'
|
6 | import * as ColorsHSL from '../src/props.colors-hsl.js'
|
7 | import ColorsOKLCH from '../src/props.colors-oklch.js'
|
8 | import ColorsOKLCHgray from '../src/props.gray-oklch.js'
|
9 | import ColorHues from '../src/props.colors-oklch-hues.js'
|
10 | import Fonts from '../src/props.fonts.js'
|
11 | import Borders from '../src/props.borders.js'
|
12 | import Aspects from '../src/props.aspects.js'
|
13 | import Easings from '../src/props.easing.js'
|
14 | import Gradients from '../src/props.gradients.js'
|
15 | import Shadows from '../src/props.shadows.js'
|
16 | import SVG from '../src/props.svg.js'
|
17 | import Zindex from '../src/props.zindex.js'
|
18 | import MaskEdges from '../src/props.masks.edges.js'
|
19 | import MaskCornerCuts from '../src/props.masks.corner-cuts.js'
|
20 |
|
21 | import {buildPropsStylesheet} from './to-stylesheet.js'
|
22 | import {toTokens} from './to-tokens.js'
|
23 | import {toObject} from './to-object.js'
|
24 | import {toFigmaTokens} from './to-figmatokens.js'
|
25 | import {toStyleDictionary} from './to-style-dictionary.js'
|
26 |
|
27 | const [,,prefix='',useWhere,customSubject='',filePrefix=''] = process.argv
|
28 |
|
29 | const subject = customSubject === '' ? 'html' : customSubject
|
30 | const selector = useWhere === 'true' ? `:where(${subject})` : subject
|
31 | const pfx = filePrefix ? filePrefix + '.' : ''
|
32 |
|
33 | const mainbundle = {
|
34 | [`${pfx}props.fonts.css`]: Fonts,
|
35 | [`${pfx}props.sizes.css`]: Sizes,
|
36 | [`${pfx}props.easing.css`]: Easings,
|
37 | [`${pfx}props.zindex.css`]: Zindex,
|
38 | [`${pfx}props.shadows.css`]: Shadows,
|
39 | [`${pfx}props.aspects.css`]: Aspects,
|
40 | [`${pfx}props.colors.css`]: Colors.default,
|
41 |
|
42 | [`${pfx}props.gradients.css`]: Gradients,
|
43 | [`${pfx}props.animations.css`]: Animations,
|
44 | [`${pfx}props.borders.css`]: Borders,
|
45 | }
|
46 |
|
47 | const individual_colors = Object.keys(Colors)
|
48 | .filter(exportName => exportName !== "default")
|
49 | .reduce((root, hueName) => ({
|
50 | ...root,
|
51 | [`${pfx}props.${hueName.toLowerCase()}.css`]: Colors[hueName]
|
52 | }), {})
|
53 |
|
54 | const individual_colors_hsl = Object.keys(ColorsHSL)
|
55 | .filter(exportName => exportName !== "default")
|
56 | .reduce((root, hueName) => ({
|
57 | ...root,
|
58 | [`${pfx}props.${hueName.toLowerCase()}-hsl.css`]: ColorsHSL[hueName]
|
59 | }), {})
|
60 |
|
61 | const individuals = {
|
62 | [`${pfx}props.masks.edges.css`]: MaskEdges,
|
63 | [`${pfx}props.masks.corner-cuts.css`]: MaskCornerCuts,
|
64 | }
|
65 |
|
66 |
|
67 | const jsonbundle = Object.entries({
|
68 | ...Object.assign({}, ...Object.values(individual_colors)),
|
69 | ...Sizes,
|
70 | ...Easings,
|
71 | ...Zindex,
|
72 | ...Aspects,
|
73 | ...Gradients,
|
74 | ...Borders,
|
75 | }).reverse()
|
76 |
|
77 | const designtokens = toTokens(jsonbundle)
|
78 | const JSONtokens = fs.createWriteStream('../open-props.tokens.json')
|
79 | JSONtokens.end(JSON.stringify(Object.fromEntries(designtokens), null, 2))
|
80 |
|
81 |
|
82 | const styledictionarytokens = toStyleDictionary(jsonbundle)
|
83 | const StyleDictionaryTokens = fs.createWriteStream('../open-props.style-dictionary-tokens.json')
|
84 | StyleDictionaryTokens.end(JSON.stringify(styledictionarytokens, null, 2))
|
85 |
|
86 |
|
87 | const figmatokens = toFigmaTokens(jsonbundle)
|
88 | const FigmaTokens = fs.createWriteStream('../open-props.figma-tokens.json')
|
89 | FigmaTokens.end(JSON.stringify(figmatokens, null, 2))
|
90 |
|
91 | const figmatokensSYNC = { 'open-props': { ...figmatokens } }
|
92 | const FigmaTokensSync = fs.createWriteStream('../open-props.figma-tokens.sync.json')
|
93 | FigmaTokensSync.end(JSON.stringify(figmatokensSYNC, null, 2))
|
94 |
|
95 | if (!fs.existsSync('../dist'))
|
96 | fs.mkdirSync('../dist')
|
97 |
|
98 | const JS = fs.createWriteStream('../dist/open-props.js')
|
99 | JS.end(`var OpenProps = ${JSON.stringify(toObject(), null, 2)}`)
|
100 |
|
101 | const ES = fs.createWriteStream('../dist/open-props.module.js')
|
102 | ES.end(`export default ${JSON.stringify(toObject(), null, 2)}`)
|
103 |
|
104 | const CJS = fs.createWriteStream('../dist/open-props.cjs')
|
105 | CJS.end(`module.exports = ${JSON.stringify(toObject(), null, 2)}`)
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | Object.entries({
|
113 | ...mainbundle,
|
114 | ...individual_colors,
|
115 | ...individual_colors_hsl,
|
116 | ...individuals,
|
117 | }).forEach(([filename, props]) => {
|
118 | buildPropsStylesheet({filename, props}, {selector, prefix})
|
119 | })
|
120 |
|
121 |
|
122 | buildPropsStylesheet({
|
123 | filename: pfx + 'props.colors-hsl.css',
|
124 | props: ColorsHSL.default},
|
125 | {selector, prefix}
|
126 | )
|
127 |
|
128 |
|
129 | buildPropsStylesheet({
|
130 | filename: pfx + 'props.colors-oklch.css',
|
131 | props: ColorsOKLCH},
|
132 | {
|
133 | selector: useWhere === 'true' ? `:where(*)` : '*',
|
134 | prefix
|
135 | }
|
136 | )
|
137 | buildPropsStylesheet({
|
138 | filename: pfx + 'props.gray-oklch.css',
|
139 | props: ColorsOKLCHgray},
|
140 | {
|
141 | selector: useWhere === 'true' ? `:where(*)` : '*',
|
142 | prefix
|
143 | }
|
144 | )
|
145 | buildPropsStylesheet({
|
146 | filename: pfx + 'props.colors-oklch-hues.css',
|
147 | props: ColorHues},
|
148 | {selector, prefix}
|
149 | )
|
150 |
|
151 |
|
152 | const entry = fs.createWriteStream(`../src/${pfx}index.css`)
|
153 | entry.write(`@import 'props.media.css';
|
154 | `)
|
155 | Object.keys(mainbundle).forEach(filename => {
|
156 | entry.write(`@import '${filename}';\n`)
|
157 | })
|
158 | entry.end() |
\ | No newline at end of file |