UNPKG

5.13 kBJavaScriptView Raw
1import fs from 'fs'
2
3import Animations from '../src/props.animations.js'
4import Sizes from '../src/props.sizes.js'
5import * as Colors from '../src/props.colors.js'
6import * as ColorsHSL from '../src/props.colors-hsl.js'
7import ColorsOKLCH from '../src/props.colors-oklch.js'
8import ColorsOKLCHgray from '../src/props.gray-oklch.js'
9import ColorHues from '../src/props.colors-oklch-hues.js'
10import Fonts from '../src/props.fonts.js'
11import Borders from '../src/props.borders.js'
12import Aspects from '../src/props.aspects.js'
13import Easings from '../src/props.easing.js'
14import Gradients from '../src/props.gradients.js'
15import Shadows from '../src/props.shadows.js'
16import SVG from '../src/props.svg.js'
17import Zindex from '../src/props.zindex.js'
18import MaskEdges from '../src/props.masks.edges.js'
19import MaskCornerCuts from '../src/props.masks.corner-cuts.js'
20
21import {buildPropsStylesheet} from './to-stylesheet.js'
22import {toTokens} from './to-tokens.js'
23import {toObject} from './to-object.js'
24import {toFigmaTokens} from './to-figmatokens.js'
25import {toStyleDictionary} from './to-style-dictionary.js'
26
27const [,,prefix='',useWhere,customSubject='',filePrefix=''] = process.argv
28
29const subject = customSubject === '' ? 'html' : customSubject
30const selector = useWhere === 'true' ? `:where(${subject})` : subject
31const pfx = filePrefix ? filePrefix + '.' : ''
32
33const 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 // [`${pfx}props.svg.css`]: SVG,
42 [`${pfx}props.gradients.css`]: Gradients,
43 [`${pfx}props.animations.css`]: Animations,
44 [`${pfx}props.borders.css`]: Borders,
45}
46
47const 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
54const 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
61const individuals = {
62 [`${pfx}props.masks.edges.css`]: MaskEdges,
63 [`${pfx}props.masks.corner-cuts.css`]: MaskCornerCuts,
64}
65
66// gen design tokens
67const 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
77const designtokens = toTokens(jsonbundle)
78const JSONtokens = fs.createWriteStream('../open-props.tokens.json')
79JSONtokens.end(JSON.stringify(Object.fromEntries(designtokens), null, 2))
80
81// gen style-dictionary tokens
82const styledictionarytokens = toStyleDictionary(jsonbundle)
83const StyleDictionaryTokens = fs.createWriteStream('../open-props.style-dictionary-tokens.json')
84StyleDictionaryTokens.end(JSON.stringify(styledictionarytokens, null, 2))
85
86// gen figma tokens
87const figmatokens = toFigmaTokens(jsonbundle)
88const FigmaTokens = fs.createWriteStream('../open-props.figma-tokens.json')
89FigmaTokens.end(JSON.stringify(figmatokens, null, 2))
90
91const figmatokensSYNC = { 'open-props': { ...figmatokens } }
92const FigmaTokensSync = fs.createWriteStream('../open-props.figma-tokens.sync.json')
93FigmaTokensSync.end(JSON.stringify(figmatokensSYNC, null, 2))
94
95if (!fs.existsSync('../dist'))
96 fs.mkdirSync('../dist')
97
98const JS = fs.createWriteStream('../dist/open-props.js')
99JS.end(`var OpenProps = ${JSON.stringify(toObject(), null, 2)}`)
100
101const ES = fs.createWriteStream('../dist/open-props.module.js')
102ES.end(`export default ${JSON.stringify(toObject(), null, 2)}`)
103
104const CJS = fs.createWriteStream('../dist/open-props.cjs')
105CJS.end(`module.exports = ${JSON.stringify(toObject(), null, 2)}`)
106
107// const UMD = fs.createWriteStream('../dist/open-props.umd.js')
108// UMD.end(`module.exports = ${JSON.stringify(toObject(), null, 2)}`)
109
110
111// gen prop variants
112Object.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// gen color hsl main file
122buildPropsStylesheet({
123 filename: pfx + 'props.colors-hsl.css',
124 props: ColorsHSL.default},
125 {selector, prefix}
126)
127
128// gen color oklch files
129buildPropsStylesheet({
130 filename: pfx + 'props.colors-oklch.css',
131 props: ColorsOKLCH},
132 {
133 selector: useWhere === 'true' ? `:where(*)` : '*',
134 prefix
135 }
136)
137buildPropsStylesheet({
138 filename: pfx + 'props.gray-oklch.css',
139 props: ColorsOKLCHgray},
140 {
141 selector: useWhere === 'true' ? `:where(*)` : '*',
142 prefix
143 }
144)
145buildPropsStylesheet({
146 filename: pfx + 'props.colors-oklch-hues.css',
147 props: ColorHues},
148 {selector, prefix}
149)
150
151// gen index.css
152const entry = fs.createWriteStream(`../src/${pfx}index.css`)
153entry.write(`@import 'props.media.css';
154`)
155Object.keys(mainbundle).forEach(filename => {
156 entry.write(`@import '${filename}';\n`)
157})
158entry.end()
\No newline at end of file