This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
gulpfile.js
103 lines (88 loc) · 2.8 KB
/
gulpfile.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
const fs = require('fs');
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const theo = require('theo');
const ms = require('ms');
const $ = gulpLoadPlugins();
const addPrefix = {prefix: 'polaris-'};
const removePrefix = (gulpRenameOptions) => {
gulpRenameOptions.basename = gulpRenameOptions.basename.replace(
'polaris-',
'',
);
return gulpRenameOptions;
};
theo.registerValueTransform(
'timing/ms-unitless',
(prop) => prop.get('type') === 'time',
(prop) => (prop.get('value') === 0 ? 0 : ms(prop.get('value'))),
);
const {tokenify} = require('./formats/tokens');
theo.registerTransform('theme', ['color/hex']);
theo.registerTransform('web/js', ['color/rgb', 'timing/ms-unitless']);
theo.registerFormat('android.xml', require('./formats/android.xml.js'));
theo.registerFormat('ios.json', require('./formats/ios.json.js'));
theo.registerFormat('figma.json', require('./formats/figma.json.js'));
theo.registerFormat(
'polaris.custom-properties.css',
fs.readFileSync('./formats/polaris.custom-properties.css.hbs', 'utf8'),
);
theo.registerFormat('light.yml', tokenify('light'));
theo.registerFormat('dark.yml', tokenify('dark'));
const colorSchemes = [
{transformType: 'raw', formatType: 'light.yml'},
{transformType: 'raw', formatType: 'dark.yml'},
];
const colorSystemFormats = [
{transformType: 'web/js', formatType: 'json'},
{transformType: 'android', formatType: 'android.xml'},
{transformType: 'ios', formatType: 'ios.json'},
{transformType: 'raw', formatType: 'figma.json'},
{transformType: 'web', formatType: 'polaris.custom-properties.css'},
];
gulp.task('themes', (done) => {
gulp
.src('tokens/themes/*.yml')
.pipe($.rename(addPrefix))
.pipe(
$.theo({
transform: {type: 'theme'},
format: {type: 'json'},
}),
)
.pipe($.rename(removePrefix))
.on('error', (err) => {
throw new Error(err);
})
.pipe(gulp.dest('dist-modern/theme'));
done();
});
gulp.task('palettes', (done) => {
colorSchemes.map(
({transformType: schemeTransform, formatType: schemeFormat}) =>
colorSystemFormats.map(({transformType, formatType}) =>
gulp
.src('tokens/themes/*.yml')
.pipe(
$.theo({
transform: {type: schemeTransform},
format: {type: schemeFormat},
}),
)
.pipe($.rename(addPrefix))
.pipe(
$.theo({
transform: {type: transformType, includeMeta: true},
format: {type: formatType},
}),
)
.pipe($.rename(removePrefix))
.on('error', (err) => {
throw new Error(err);
})
.pipe(gulp.dest('dist-modern/palette')),
),
);
done();
});
gulp.task('default', gulp.series(['themes', 'palettes']));