forked from ioBroker/ioBroker.icons-mfd-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
97 lines (89 loc) · 3.5 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
// To use this file in WebStorm, right click on the file name in the Project Panel (normally left) and select "Open Grunt Console"
/** @namespace __dirname */
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
"use strict";
module.exports = function (grunt) {
var prefix = "https://raw.githubusercontent.com/OpenAutomationProject/knx-uf-iconset/master/raw_svg/";
var httpSrcPath = 'https://github.com/OpenAutomationProject/knx-uf-iconset/tarball/master';
var imgSrcPath = 'OpenAutomationProject-knx-uf-iconset-*/raw_svg/*.svg';
// Project configuration.
grunt.initConfig({
clean: {
all: ['www/*.svg', 'www/*.png', 'www/*.jpg', '.build']
},
copy: {
icons: {
files: [
{
expand: true,
cwd: __dirname + '/.build/icons/',
src: [imgSrcPath],
dest: __dirname + '/www',
rename: function (dest, src) {
var parts = src.replace(/\\/g, '/').split('/');
return __dirname + '/www/' + parts[parts.length - 1];
}
}
]
}
},
curl: {
'.build/icons.tar.gz': httpSrcPath
},
exec: {
icons: {
command: 'mkdir .build/icons/ && tar -xvf .build/icons.tar.gz -C .build/icons/',
stdout: true
}
}
});
grunt.registerTask('updateList', function () {
var fs = require('fs');
var dir = fs.readdirSync(__dirname + '/www');
var readme = '';
var html = '<html><body style="background: grey"><table>';
var htmlLineImg = '<tr>';
var htmlLineName = '<tr>';
var inLine = 6;
var currentWord = "";
var cur = 0;
for (var i = 0; i < dir.length; i++) {
cur++;
var parts = dir[i].split('_');
if ((currentWord && currentWord != parts[0]) || (!(cur % inLine))) {
html += htmlLineImg + '</tr>';
html += htmlLineName + '</tr>';
htmlLineImg = '<tr>';
htmlLineName = '<tr>';
if (currentWord && currentWord != parts[0]) {
html += '<tr style="height:15px;background:lightblue"><td colspan="' + inLine + '" style="height:15px"></td></tr>';
readme += '===========================\n';
}
currentWord = parts[0];
cur = 0;
}
if (!currentWord) currentWord = parts[0]
//readme += '![' + dir[i] + '](www/' + dir[i] + ')\n';
readme += '![' + dir[i] + '](' + prefix + dir[i] + ')\n';
htmlLineImg += '<td style="text-align: center"><img src="' + dir[i] + '" width="64" height="64"></td>\n';
htmlLineName += '<td style="text-align: center">' + dir[i] + '</td>\n';
}
html += htmlLineImg + '</tr>';
html += htmlLineName + '</tr>';
html += '</table></body></html>';
grunt.file.write('ICONLIST.md', readme);
grunt.file.write('www/index.html', html);
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-curl');
grunt.registerTask('default', [
'clean',
'curl',
'exec',
'copy',
'updateList'
]);
};