generated from tokens-studio/plugin-example-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
73 lines (58 loc) · 2.09 KB
/
build.ts
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
import StyleDictionaryPackage from 'style-dictionary';
import { getJsonPlatform, mergeJsonDictFiles } from './build-json';
import { concatXamlFiles, getXamlPlatform } from './build-xaml';
import { getTsPlatform } from './build-ts';
import { getCssPlatform } from './build-css';
// HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED
const toPixelValue = (value: string) => {
const numericValue = parseFloat(value);
return Number.isNaN(numericValue) || numericValue === 0
? value
: `${numericValue}px`;
}
// NOTE: Built-in 'size/px' only working if prop.attributes.category === 'size'.
StyleDictionaryPackage.registerTransform({
name: 'sizes/px',
type: 'value',
matcher: (token) =>
[
'fontSizes',
'lineHeights',
'borderRadius',
'borderWidth'
].includes(token.type),
transformer: (token) => toPixelValue(token.original.value)
});
StyleDictionaryPackage.registerTransform({
name: 'shadow/boxShadow',
type: 'value',
matcher: (token) => token.type === 'boxShadow',
transformer: (token) => token.value.map((v: any) => `${[v.x, v.y, v.blur, v.spread].map(pv => toPixelValue(pv)).join(' ')} ${v.color}`).join(', ')
});
const getStyleDictionaryConfig = (theme: string) => ({
source: [
`generated/tokens/${theme}.json`,
],
platforms: {
css: getCssPlatform(theme),
ts: getTsPlatform(theme),
xaml: getXamlPlatform(theme),
json: getJsonPlatform(theme),
}
});
console.log('Build started...');
// PROCESS THE DESIGN TOKENS FOR THE DIFFERENT BRANDS AND PLATFORMS
['global', 'dark', 'light'].map((theme) => {
console.log('\n==============================================');
console.log(`\nProcessing: ${theme}`);
const StyleDictionary = StyleDictionaryPackage.extend(getStyleDictionaryConfig(theme));
StyleDictionary.buildPlatform('css');
StyleDictionary.buildPlatform('ts');
StyleDictionary.buildPlatform('xaml');
StyleDictionary.buildPlatform('json');
console.log('\nEnd processing');
});
concatXamlFiles();
mergeJsonDictFiles();
console.log('\n==============================================');
console.log('\nBuild completed!');