forked from themeum/kirki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
211 lines (193 loc) · 5.91 KB
/
Gruntfile.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* global module */
module.exports = function( grunt ) {
grunt.initConfig( {
// Get json file from the google-fonts API
http: {
'google-fonts-alpha': {
options: { url: 'https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha&key=AIzaSyCDiOc36EIOmwdwspLG3LYwCg9avqC5YLs' },
dest: 'modules/webfonts/webfonts-alpha.json'
},
'google-fonts-popularity': {
options: { url: 'https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=AIzaSyCDiOc36EIOmwdwspLG3LYwCg9avqC5YLs' },
dest: 'modules/webfonts/webfonts-popularity.json'
},
'google-fonts-trending': {
options: { url: 'https://www.googleapis.com/webfonts/v1/webfonts?sort=trending&key=AIzaSyCDiOc36EIOmwdwspLG3LYwCg9avqC5YLs' },
dest: 'modules/webfonts/webfonts-trending.json'
}
},
// Compile CSS
sass: {
dist: {
files: {
'assets/vendor/selectWoo/kirki.css': 'assets/vendor/selectWoo/kirki.scss',
'modules/tooltips/tooltip.css': 'modules/tooltips/tooltip.scss',
'modules/custom-sections/sections.css': 'modules/custom-sections/sections.scss',
'controls/css/styles.css': 'controls/scss/styles.scss'
}
}
},
// Convert readme.txt to readme.md
wp_readme_to_markdown: {
your_target: {
files: {
'README.md': 'readme.txt'
}
}
},
// Check JS syntax
jscs: {
src: [
'Gruntfile.js',
'controls/**/*.js',
'modules/**/*.js',
'!modules/search/fuse.js',
'!modules/search/fuse.min.js',
'!assets/vendor/*'
],
options: {
config: '.jscsrc',
verbose: true
}
},
// Watch task (run with "grunt watch")
watch: {
css: {
files: [
'assets/**/*.scss',
'controls/scss/*.scss',
'modules/**/*.scss'
],
tasks: [ 'sass' ]
},
scripts: {
files: [
'Gruntfile.js',
'controls/js/src/*.js',
'modules/**/*.js'
],
tasks: [ 'concat', 'uglify' ]
}
},
concat: {
options: {
separator: ''
},
dist: {
src: [
'controls/js/src/set-setting-value.js',
'controls/js/src/kirki.js',
'controls/js/src/kirki.control.js',
'controls/js/src/kirki.input.js',
'controls/js/src/kirki.setting.js',
'controls/js/src/kirki.util.js',
'controls/js/src/dynamic-control.js',
'controls/js/src/background.js',
'controls/js/src/color-palette.js',
'controls/js/src/dashicons.js',
'controls/js/src/date.js',
'controls/js/src/dimension.js',
'controls/js/src/dimensions.js',
'controls/js/src/editor.js',
'controls/js/src/fontawesome.js',
'controls/js/src/image.js',
'controls/js/src/multicheck.js',
'controls/js/src/multicolor.js',
'controls/js/src/number.js',
'controls/js/src/palette.js',
'controls/js/src/preset.js',
'controls/js/src/radio-buttonset.js',
'controls/js/src/radio-image.js',
'controls/js/src/repeater.js',
'controls/js/src/slider.js',
'controls/js/src/sortable.js',
'controls/js/src/switch.js',
'controls/js/src/toggle.js',
'controls/js/src/typography.js'
],
dest: 'controls/js/script.js'
}
},
uglify: {
dev: {
options: {
mangle: {
reserved: [ 'jQuery', 'wp', '_' ]
}
},
files: [ {
expand: true,
src: [ 'controls/js/*.js', '!controls/js/*.min.js' ],
dest: '.',
cwd: '.',
rename: function( dst, src ) {
return dst + '/' + src.replace( '.js', '.min.js' );
}
} ]
}
}
} );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks( 'grunt-contrib-concat' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-http' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.loadNpmTasks( 'grunt-jscs' );
grunt.registerTask( 'dev', [ 'sass', 'jscs', 'watch' ] );
grunt.registerTask( 'googlefontsProcess', function() {
var alphaFonts,
popularityFonts,
trendingFonts,
finalObject = {
items: {},
order: {
popularity: [],
trending: []
}
},
finalJSON,
i,
fontNames = [];
// Get file contents.
alphaFonts = grunt.file.readJSON( 'modules/webfonts/webfonts-alpha.json' );
popularityFonts = grunt.file.readJSON( 'modules/webfonts/webfonts-popularity.json' );
trendingFonts = grunt.file.readJSON( 'modules/webfonts/webfonts-trending.json' );
// Populate the fonts.
for ( i = 0; i < alphaFonts.items.length; i++ ) {
finalObject.items[ alphaFonts.items[ i ].family ] = {
family: alphaFonts.items[ i ].family,
category: alphaFonts.items[ i ].category,
variants: alphaFonts.items[ i ].variants.sort()
/* Deprecated
subsets: alphaFonts.items[ i ].subsets.sort(),
files: alphaFonts.items[ i ].files
*/
};
}
// Add the popularity order.
for ( i = 0; i < popularityFonts.items.length; i++ ) {
finalObject.order.popularity.push( popularityFonts.items[ i ].family );
fontNames.push( popularityFonts.items[ i ].family );
}
// Add the rrending order.
for ( i = 0; i < trendingFonts.items.length; i++ ) {
finalObject.order.trending.push( trendingFonts.items[ i ].family );
}
// Write the final object to json.
finalJSON = JSON.stringify( finalObject );
grunt.file.write( 'modules/webfonts/webfonts.json', finalJSON );
grunt.file.write( 'modules/webfonts/webfont-names.json', JSON.stringify( fontNames ) );
// Delete files no longer needed.
grunt.file.delete( 'modules/webfonts/webfonts-alpha.json' ); // jshint ignore:line
grunt.file.delete( 'modules/webfonts/webfonts-popularity.json' ); // jshint ignore:line
grunt.file.delete( 'modules/webfonts/webfonts-trending.json' ); // jshint ignore:line
} );
grunt.registerTask( 'googlefonts', function() {
grunt.task.run( 'http' );
grunt.task.run( 'googlefontsProcess' );
} );
grunt.registerTask( 'default', [ 'sass:dist', 'concat', 'uglify' ] );
grunt.registerTask( 'readme', [ 'wp_readme_to_markdown' ] );
grunt.registerTask( 'all', [ 'default', 'googlefonts', 'wp_readme_to_markdown' ] );
};