This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
110 lines (92 loc) · 2.72 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
104
105
106
107
108
109
110
// See Salesforce UX's design-tokens project for more information
var path = require('path');
var rimraf = require('rimraf');
var async = require('async');
var _ = require('lodash');
var gulp = require('gulp');
var jsonlint = require('gulp-json-lint');
var rename = require('gulp-rename');
var theo = require('theo');
////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////
function clean(f, done) {
var p = path.resolve(__dirname, f);
rimraf(f, done);
}
////////////////////////////////////////////////////////////////////
// Tasks - Clean
////////////////////////////////////////////////////////////////////
gulp.task('clean', function(done) {
async.each(['dist/tokens'], clean, done);
});
////////////////////////////////////////////////////////////////////
// Tasks - Tokens
////////////////////////////////////////////////////////////////////
// for external use
var distConvertOptions = _({
'web': [
'styl',
'less',
'sass',
'default.sass',
'scss',
'default.scss',
'map.scss',
'map.variables.scss',
'html',
'json',
'common.js',
'amd.js'
],
'ios': ['ios.json'],
'android': ['android.xml']
}).map(function(formats, transform) {
return formats.map(function(format) {
return {
format: format,
transform: transform,
outputFolder: 'dist/tokens'
};
});
}).flatten().value();
// for use in MCtheme (output one type)
var themeConvertOptions = [
{
format: 'less',
transform: 'web',
outputFolder: 'less/tokens'
}];
function convert(options, done) {
gulp.src([
'./tokens/*.json', '!./tokens/_*.json'
])
.pipe(theo.plugins.transform(options.transform))
.on('error', done)
.pipe(theo.plugins.format(options.format))
.on('error', done)
.pipe(gulp.dest(path.resolve(__dirname, options.outputFolder)))
.on('error', done)
.on('finish', done);
}
gulp.task('distTokens', ['clean', 'lint'], function(done) {
async.each(distConvertOptions, convert, done);
});
gulp.task('themeTokens', ['clean', 'lint'], function(done) {
async.each(themeConvertOptions, convert, done);
});
////////////////////////////////////////////////////////////////////
// Tasks - Lint
////////////////////////////////////////////////////////////////////
gulp.task('lint', function() {
return gulp.src('./tokens/*.json')
.pipe(jsonlint({ comments: true }))
.pipe(jsonlint.report('verbose'));
});
////////////////////////////////////////////////////////////////////
// Tasks
////////////////////////////////////////////////////////////////////
gulp.task('dev', function() {
gulp.watch('./tokens/**', ['distTokens']);
});
gulp.task('default', ['themeTokens', 'distTokens']);