forked from element-hq/element-design-tokens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
78 lines (70 loc) · 2.12 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
const StyleDictionary = require('style-dictionary');
const fs = require('fs-extra');
const iosPath = `types/ios/`;
// before this runs we should clean the directories we are generating files in
// to make sure they are ✨clean✨
console.log(`cleaning ${iosPath}...`);
fs.removeSync(iosPath);
/**
* This function will wrap a built-in format and replace `.value` with `.darkValue`
* if a token has a `.darkValue`.
* @param {String} format - the name of the built-in format
* @returns {Function}
*/
function darkFormatWrapper(format) {
return function(args) {
const dictionary = Object.assign({}, args.dictionary);
// Override each token's `value` with `darkValue`
dictionary.allProperties = dictionary.allProperties.map(token => {
const {darkValue} = token;
if (darkValue) {
return Object.assign({}, token, {
value: token.darkValue
});
} else {
return token;
}
});
// Use the built-in format but with our customized dictionary object
// so it will output the darkValue instead of the value
return StyleDictionary.format[format]({ ...args, dictionary })
}
}
StyleDictionary.extend({
// custom actions
action: {
generateColorsets: require('./actions/ios/colorsets')
},
// custom transforms
transform: {
'attribute/cti': require('./transforms/attributeCTI'),
'colorRGB': require('./transforms/colorRGB'),
'size/remToFloat': require('./transforms/remToFloat')
},
// custom formats
format: {
swiftColor: require('./formats/swiftColor')
},
source: [
`tokens/**/*.json`
],
platforms: {
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: `ElementColors.swift`,
format: `swiftColor`,
filter: (token) => token.attributes.category === `color`,
options: {
outputReferences: true
}
}]
}
}
}).buildAllPlatforms();