forked from uikit/uikit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
377 lines (298 loc) · 13 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
module.exports = function(grunt) {
"use strict";
var fs = require('fs'), pkginfo = grunt.file.readJSON("package.json");
grunt.initConfig({
pkg: pkginfo,
meta: {
banner: "/*! <%= pkg.title %> <%= pkg.version %> | <%= pkg.homepage %> | (c) 2014 YOOtheme | MIT License */"
},
jshint: {
src: {
options: {
jshintrc: "src/.jshintrc"
},
src: ["src/js/*.js"]
}
},
less: (function(){
var lessconf = {
"docsmin": {
options: { paths: ["docs/less"], cleancss: true },
files: { "docs/css/uikit.docs.min.css": ["docs/less/uikit.less"] }
}
},
themes = [];
//themes
["default", "custom"].forEach(function(f){
if(fs.existsSync('themes/'+f)) {
fs.readdirSync('themes/'+f).forEach(function(t){
var themepath = 'themes/'+f+'/'+t,
distpath = f=="default" ? "dist/css" : themepath+"/dist";
// Is it a directory?
if (fs.lstatSync(themepath).isDirectory() && t!=="blank" && t!=='.git') {
var files = {};
if(t=="default") {
files[distpath+"/uikit.css"] = [themepath+"/uikit.less"];
} else {
files[distpath+"/uikit."+t+".css"] = [themepath+"/uikit.less"];
}
lessconf[t] = {
"options": { paths: [themepath] },
"files": files
};
var filesmin = {};
if(t=="default") {
filesmin[distpath+"/uikit.min.css"] = [themepath+"/uikit.less"];
} else {
filesmin[distpath+"/uikit."+t+".min.css"] = [themepath+"/uikit.less"];
}
lessconf[t+"min"] = {
"options": { paths: [themepath], cleancss: true},
"files": filesmin
};
themes.push({ "path":themepath, "name":t, "dir":f });
}
});
}
});
//addons
fs.readdirSync('addons/src').forEach(function(f){
var addon = 'addons/src/'+f+'/'+f+'.less';
if(fs.existsSync(addon)) {
lessconf["addon-"+f] = {options: { paths: ['addons/src/'+f] }, files: {} };
lessconf["addon-"+f].files["dist/addons/css/"+f+".css"] = [addon];
lessconf["addon-min-"+f] = {options: { paths: ['addons/src/'+f], cleancss: true }, files: {} };
lessconf["addon-min-"+f].files["dist/addons/css/"+f+".min.css"] = [addon];
// look for theme overrides
themes.forEach(function(theme){
var override = theme.path+'/addon.'+f+'.less',
distpath = theme.dir=="default" ? "dist/addons/css" : theme.path+"/dist/addons";;
if(fs.existsSync(override)) {
if(theme.dir=="default" && theme.name=="default") {
lessconf["addon-"+f+"-"+theme.name] = {options: { paths: [theme.path] }, files: {} };
lessconf["addon-"+f+"-"+theme.name].files[distpath+"/"+f+".css"] = [override];
lessconf["addon-min-"+f+"-"+theme.name] = {options: { paths: [theme.path], cleancss: true }, files: {} };
lessconf["addon-min-"+f+"-"+theme.name].files[distpath+"/"+f+".min.css"] = [override];
} else {
lessconf["addon-"+f+"-"+theme.name] = {options: { paths: [theme.path] }, files: {} };
lessconf["addon-"+f+"-"+theme.name].files[distpath+"/"+f+"."+theme.name+".css"] = [override];
lessconf["addon-min-"+f+"-"+theme.name] = {options: { paths: [theme.path], cleancss: true }, files: {} };
lessconf["addon-min-"+f+"-"+theme.name].files[distpath+"/"+f+"."+theme.name+".min.css"] = [override];
}
}
});
}
});
return lessconf;
})(),
copy: {
fonts: {
files: [{ expand: true, cwd: "src/fonts", src: ["*"], dest: "dist/fonts/" }]
},
addons: {
files: [{ expand: true, src: ["addons/src/**/*.js"], dest: "dist/addons/js", flatten: true }]
},
scss: {
files: [{ expand: true, cwd: "src/less", src: ["*"], dest: "src/scss/", ext: '.scss' }]
},
scssthemes: {
files: [{ expand: true, src: "themes/**/*.less", ext: '.scss' }]
}
},
// convert LESS to SCSS
replace: {
scss: {
src: ['src/scss/*.scss', 'themes/**/*.scss'], // source files array
overwrite: true,
// dest: 'build/text/', // destination directory or file
replacements: [ { // replace comments
from: ' LESS ', to: ' SCSS '
}, { // change less/ dir to scss/ on imports
from: '/less/', to: '/scss/'
}, { // change .less extensions to .scss on imports
from: '\.less', to: '\.scss'
}, { // replace '@' with '$'
from: '@', to: '$'
}, { // mixins
from: /\.([\w\-]*)\s*\((.*)\)\s*\{/g, to: '@mixin $1($2){'
}, { // includes
from: /\.([\w\-]*\(.*\)\s*;)/g, to: '@include $1'
}, { // replace valid '@' statements
from: /\$(import|media|font-face)/g, to: '@$1'
}, { // string literals
// from: /~"(.*)"/g, to: '#{"$1"}'
from: /\$\{/g, to: '#{'
}]
}
},
concat: {
dist: {
options: {
separator: "\n\n"
},
src: ["src/js/core.js",
"src/js/utility.js",
"src/js/touch.js",
"src/js/alert.js",
"src/js/button.js",
"src/js/dropdown.js",
"src/js/grid.js",
"src/js/modal.js",
"src/js/offcanvas.js",
"src/js/nav.js",
"src/js/tooltip.js",
"src/js/switcher.js",
"src/js/tab.js",
"src/js/search.js",
"src/js/scrollspy.js",
"src/js/smooth-scroll.js",
"src/js/toggle.js",
],
dest: "dist/js/uikit.js"
}
},
usebanner: {
dist: {
options: {
position: 'top',
banner: "<%= meta.banner %>\n"
},
files: {
src: [ 'dist/css/*.css', 'dist/js/*.js', 'dist/addons/css/*.css', 'dist/addons/js/*.js' ]
}
}
},
uglify: {
distmin: {
options: {
//banner: "<%= meta.banner %>\n"
},
files: {
"dist/js/uikit.min.js": ["dist/js/uikit.js"]
}
},
addonsmin: {
files: (function(){
var files = {};
fs.readdirSync('addons/src').forEach(function(f){
var addon = 'addons/src/'+f+'/'+f+'.js';
if(fs.existsSync(addon)) {
files['dist/addons/js/'+f+'.min.js'] = [addon];
}
});
return files;
})()
}
},
compress: {
dist: {
options: {
archive: ("dist/uikit-"+pkginfo.version+".zip")
},
files: [
{ expand: true, cwd: "dist/", src: ["css/*", "js/*", "fonts/*", "addons/css/*", "addons/js/*"], dest: "" }
]
}
},
watch: {
src: {
files: ["src/**/*.less", "themes/**/*.less","src/js/*.js"],
tasks: ["build"]
}
}
});
grunt.registerTask('indexthemes', 'Rebuilding theme index.', function() {
var themes = [];
["default", "custom"].forEach(function(f){
if(fs.existsSync('themes/'+f)) {
fs.readdirSync('themes/'+f).forEach(function(t){
var themepath = 'themes/'+f+'/'+t;
// Is it a directory?
if (fs.lstatSync(themepath).isDirectory() && t!=="blank" && t!=='.git') {
var theme = {
"name" : t.split("-").join(" ").replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function ($1) { return $1.toUpperCase(); }),
"url" : "../"+themepath+"/uikit.less",
"config": (fs.existsSync(themepath+"/customizer.json") ? "../"+themepath+"/customizer.json" : "../themes/default/uikit/customizer.json"),
"styles": {}
};
if(fs.existsSync(themepath+'/styles')) {
var styles = {};
fs.readdirSync(themepath+'/styles').forEach(function(sf){
var stylepath = [themepath, 'styles', sf, 'style.less'].join('/');
if(fs.existsSync(stylepath)) {
styles[sf] = "../"+themepath+"/styles/"+sf+"/style.less";
}
});
theme.styles = styles;
}
themes.push(theme);
}
});
}
});
grunt.log.writeln(themes.length+' themes found: ' + themes.map(function(theme){ return theme.name;}).join(", "));
fs.writeFileSync("themes/themes.json", JSON.stringify(themes, " ", 4));
});
grunt.registerTask('sublime', 'Building Sublime Text Package', function() {
var filepath = 'dist/css/uikit.css';
if (!fs.existsSync(filepath)) {
grunt.log.error("Not found: " + filepath);
return;
}
var cssContent = grunt.file.read(filepath),
classesList = cssContent.match(/\.(uk-[a-z\d\-]+)/g),
classesSet = {},
pystring = '# copy & paste into sublime plugin code:\n';
// use object as set (no duplicates)
classesList.forEach(function(c) {
c = c.substr(1); // remove leading dot
classesSet[c] = true;
});
// convert set back to list
/*
classesList = [];
for( var c in classesSet ) {
if (classesSet.hasOwnProperty(c)){
classesList.push(c);
}
}
*/
classesList = Object.keys(classesSet);
pystring += 'uikit_classes = ["' + classesList.join('", "') + '"]\n';
filepath = 'dist/js/uikit.js';
if (!fs.existsSync(filepath)) {
grunt.log.error("Not found: " + filepath);
return;
}
var jsContent = grunt.file.read(filepath),
dataList = jsContent.match(/data-uk-[a-z\d\-]+/g),
dataSet = {};
dataList.forEach(function(s) { dataSet[s] = true; });
/*
dataList = [];
for (var p in dataSet) {
if (dataSet.hasOwnProperty(p)) {
dataList.push(p);
}
}
*/
dataList = Object.keys(dataSet);
pystring += 'uikit_data = ["' + dataList.join('", "') + '"]\n';
grunt.file.write('dist/uikit_completions.py', pystring);
grunt.log.writeln('Written: dist/uikit_completions.py');
});
// Load grunt tasks from NPM packages
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-text-replace");
grunt.loadNpmTasks("grunt-banner");
// Register grunt tasks
grunt.registerTask("build", ["jshint", "indexthemes", "less", "concat", "copy", "uglify", "usebanner"]);
grunt.registerTask("build-scss", ["copy:scss", "copy:scssthemes", "replace:scss"]);
grunt.registerTask("default", ["build", "compress"]);
};