forked from Teamwork/mobile-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
196 lines (185 loc) · 6.77 KB
/
build.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const StyleDictionary = require('style-dictionary');
const fs = require('fs-extra');
const iosPath = `ios/Sources/DesignSystem/`;
const androidPath = `android/styledictionary/teamwork-design-system/src/main/res/`;
const composePath = `android/styledictionary/teamwork-design-system/src/main/java/com/teamwork/design/generated/`;
const webPath = `web/dist/`;
// the name of the class generated for holding the color tokens for Compose
const composeColorsClassName = "TeamworkColors";
// before this runs we should clean the directories we are generating files in
// to make sure they are ✨clean✨
// TODO clean the Android directory again!
[iosPath, composePath, webPath].forEach(dir => {
console.log(`🧹 Cleaning ${dir}...`);
fs.removeSync(dir);
});
['global', 'light', 'dark'].map(function (theme) {
console.log(`\n\n🌈 Building ${theme} mode...`);
StyleDictionary.extend({
// custom actions
action: {
generateColorsets: require('./actions/ios/colorsets'),
generateGraphics: require('./actions/generateGraphics'),
},
// custom transforms
transform: {
'attribute/cti': require('./transforms/attributeCTI'),
'colorRGB': require('./transforms/colorRGB'),
'size/remToFloat': require('./transforms/remToFloat'),
// compose
'colorCompose': require('./transforms/colorCompose'),
},
// custom formats
format: {
swiftColor: require('./formats/swiftColor'),
swiftImage: require('./formats/swiftImage'),
swiftUIColor: require('./formats/swiftUIColor'),
swiftSize: require('./formats/swiftSize'),
//android
androidColor: require('./formats/androidColor'),
androidSize: require('./formats/androidSize'),
androidTypography: require('./formats/androidTypography'),
composeColor: require('./formats/composeColor'),
composeColorPalette: require('./formats/composeColorPalette'),
composeTeamworkColors: require('./formats/composeTeamworkColors'),
composeSize: require('./formats/composeSize'),
composeTypography: require('./formats/composeTypography')
},
source: [
`tokens/${theme}.json`
],
platforms: {
assets: {
transforms: [`attribute/cti`,`color/hex`,`size/remToFloat`,`name/ti/camel`],
buildPath: `${webPath}/images/`,
iosPath,
androidPath,
actions: [`generateGraphics`]
},
iosColors: {
buildPath: iosPath,
transforms: [`attribute/cti`,`colorRGB`,`name/ti/camel`],
actions: [`generateColorsets`]
},
iOS: {
buildPath: iosPath,
transforms: [`attribute/cti`,`name/ti/camel`,`size/swift/remToCGFloat`],
files: [{
destination: `PaletteColor.swift`,
format: `swiftColor`,
filter: (token) => token.type === `color` && theme === `global`,
options: {
outputReferences: true
}
},{
destination: `PaletteUIColor.swift`,
format: `swiftUIColor`,
filter: (token) => token.type === `color` && theme === `global`,
options: {
outputReferences: true
}
},{
destination: `Color.swift`,
format: `swiftColor`,
filter: (token) => token.type === `color`,
options: {
outputReferences: true
}
},{
destination: `UIColor.swift`,
format: `swiftUIColor`,
filter: (token) => token.type === `color`,
options: {
outputReferences: true
}
},{
destination: `DesignSystem.swift`,
filter: (token) => typeof token.value == 'number',
className: `DesignSystem`,
format: `swiftSize`
},{
destination: `Image.swift`,
filter: (token) => token.type === `image`,
format: `swiftImage`
}]
},
compose: {
transformGroup: 'compose',
buildPath: composePath,
transforms: ["color/composeColor", "name/ti/camel", "colorCompose"],
files: [{
destination: "ColorPalette.kt",
format: `composeColorPalette`,
filter: (token) => token.type === `color` && token.filePath === `tokens/global.json`,
options: {
className: "ColorPalette"
}
},{
destination: "ColorsLight.kt",
format: `composeColor`,
filter: (token) => token.type === `color` && token.filePath === `tokens/light.json`,
options: {
colorsClassName: composeColorsClassName
}
},{
destination: "ColorsDark.kt",
format: `composeColor`,
filter: (token) => token.type === `color` && token.filePath === `tokens/dark.json`,
options: {
colorsClassName: composeColorsClassName
}
},{
destination: `${composeColorsClassName}.kt`,
filter: (token) => token.type === 'color',
format: `composeTeamworkColors`,
options: {
className: composeColorsClassName
}
},{
destination: `TeamworkTypography.kt`,
filter: (token) => token.type === 'typography',
format: `composeTypography`,
options: {
className: "TeamworkTypography"
}
},{
destination: `Sizes.kt`,
filter: (token) => token.type !== 'color' && token.type != 'typography',
format: `composeSize`
}]
},
android: {
transformGroup: `android`,
buildPath: androidPath,
files: [{
destination: `values/colors.xml`,
format: `androidColor`,
filter: (token) => token.type === `color` && token.filePath === `tokens/light.json`,
options: {
// this is important!
// this will keep token references intact so that we don't need
// to generate *all* color resources for dark mode, only
// the specific ones that change
outputReferences: true
},
},{
// Here we are outputting a 'night' resource file that only has
// the colors that have dark values. All the references
// from the above file will properly reference
// these colors if the OS is set to night mode.
destination: `values-night/colors.xml`,
format: `androidColor`,
filter: (token) => token.type === `color` && token.filePath === `tokens/dark.json`
},{
destination: `values/typography.xml`,
filter: (token) => token.type === 'typography',
format: `androidTypography`
},{
destination: `values/dimens.xml`,
filter: (token) => token.type !== `color`,
format: `androidSize`
}]
}
}
}).buildAllPlatforms();
})