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
|
const gulp = require('gulp'),
cp = require('child_process'),
glob = require('glob'),
fs = require('fs'),
path = require('path'),
p = require('./package.json'),
zip = require('gulp-zip'),
puppeteer = require('puppeteer');
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
const svgToPng = async (filePath, destination) => {
filePath = path.join(__dirname, filePath);
const htmlFilePath = path.join("file:", filePath);
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
height: 24,
width: 24,
deviceScaleFactor: 10
});
await page.goto(htmlFilePath);
await page.screenshot({
path: path.join(__dirname, destination),
omitBackground: true,
fullPage: true
});
await browser.close();
return page;
};
const createScreenshot = async (filePath) => {
try {
filePath = path.join(__dirname, filePath);
const fileName = filePath.replace('.svg', '');
const htmlFilePath = path.join("file:", filePath);
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
height: 10,
width: 10,
deviceScaleFactor: 2
});
await page.goto(htmlFilePath);
await page.screenshot({
path: `${fileName}.png`,
omitBackground: false,
fullPage: true
});
await browser.close();
} catch (error) {
console.error(error);
throw Error(error);
}
};
const printChangelog = function(newIcons, modifiedIcons, renamedIcons) {
if(newIcons.length > 0) {
let str = '';
str += `${newIcons.length} new icons: `;
newIcons.forEach(function(icon, i){
str += `\`${icon}\``;
if((i + 1) <= newIcons.length - 1) {
str += ', '
}
});
console.log(str);
console.log('');
}
if(modifiedIcons.length > 0) {
let str = '';
str += `Fixed icons: `;
modifiedIcons.forEach(function(icon, i){
str += `\`${icon}\``;
if((i + 1) <= modifiedIcons.length - 1) {
str += ', '
}
});
console.log(str);
console.log('');
}
if(renamedIcons.length > 0) {
console.log(`Renamed icons: `);
renamedIcons.forEach(function(icon, i){
console.log(`- \`${icon[0]}\` renamed to \`${icon[1]}\``);
});
}
};
gulp.task('build-zip', function() {
const version = p.version;
return gulp.src('{icons/**/*,icons-png/**/*,tabler-sprite.svg,tabler-sprite-nostroke.svg}')
.pipe(zip(`tabler-icons-${version}.zip`))
.pipe(gulp.dest('packages'))
});
gulp.task('build-jekyll', function(cb){
cp.exec('bundle exec jekyll build', function() {
cb();
});
});
gulp.task('build-copy', function(cb){
cp.exec('mkdir -p icons/ && rm -fd ./icons/* && cp ./_site/icons/* ./icons', function() {
cb();
});
});
gulp.task('clean-png', function(cb){
cp.exec('rm -fd ./icons-png/*', function() {
cb();
});
});
gulp.task('icons-sprite', function (cb) {
glob("_site/icons/*.svg", {}, function (er, files) {
let svgContent = '';
files.forEach(function (file, i) {
let name = path.basename(file, '.svg'),
svgFile = fs.readFileSync(file),
svgFileContent = svgFile.toString();
svgFileContent = svgFileContent
.replace(/<svg[^>]+>/g, '')
.replace(/<\/svg>/g, '')
.replace(/\n+/g, '')
.replace(/>\s+</g, '><')
.trim();
svgContent += `<symbol id="tabler-${name}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${svgFileContent}</symbol>`
});
let svg = `<svg xmlns="http://www.w3.org/2000/svg"><defs>${svgContent}</defs></svg>`;
fs.writeFileSync('tabler-sprite.svg', svg);
fs.writeFileSync('tabler-sprite-nostroke.svg', svg.replace(/stroke-width="2"\s/g, ''));
cb();
});
});
gulp.task('icons-preview', function (cb) {
const columnsCount = 17,
padding = 29,
paddingOuter = 5,
iconSize = 24;
glob("_site/icons/*.svg", {}, function (er, files) {
const iconsCount = files.length,
rowsCount = Math.ceil(iconsCount / columnsCount),
width = columnsCount * (iconSize + padding) + 2 * paddingOuter - padding,
height = rowsCount * (iconSize + padding) + 2 * paddingOuter - padding;
let svgContentSymbols = '',
svgContentIcons = '',
x = paddingOuter,
y = paddingOuter;
files.forEach(function (file, i) {
let name = path.basename(file, '.svg');
let svgFile = fs.readFileSync(file),
svgFileContent = svgFile.toString();
svgFileContent = svgFileContent
.replace('<svg xmlns="http://www.w3.org/2000/svg"', `<symbol id="${name}"`)
.replace(' width="24" height="24"', '')
.replace('</svg>', '</symbol>')
.replace(/\n\s+/g, '');
svgContentSymbols += `\t${svgFileContent}\n`;
svgContentIcons += `\t<use xlink:href="#${name}" x="${x}" y="${y}" width="${iconSize}" height="${iconSize}" />\n`;
x += padding + iconSize;
if (i % columnsCount === columnsCount - 1) {
x = paddingOuter;
y += padding + iconSize;
}
});
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" style="color: #354052"><rect x="0" y="0" width="${width}" height="${height}" fill="#fff"></rect>\n${svgContentSymbols}\n${svgContentIcons}\n</svg>`;
fs.writeFileSync('.github/icons.svg', svgContent);
createScreenshot('.github/icons.svg');
cb();
});
});
gulp.task('icons-stroke', gulp.series('build-jekyll', function (cb) {
const icon = "disabled",
strokes = ['.5', '1', '1.5', '2', '2.75'],
svgFileContent = fs.readFileSync(`icons/${icon}.svg`).toString(),
padding = 16,
paddingOuter = 5,
iconSize = 32,
width = 882,
height = iconSize + paddingOuter * 2;
let svgContentSymbols = '',
svgContentIcons = '',
x = paddingOuter;
strokes.forEach(function (stroke) {
let svgFileContentStroked = svgFileContent
.replace('<svg xmlns="http://www.w3.org/2000/svg"', `<symbol id="icon-${stroke}"`)
.replace(' width="24" height="24"', '')
.replace(' stroke-width="2"', ` stroke-width="${stroke}"`)
.replace('</svg>', '</symbol>')
.replace(/\n\s+/g, '');
svgContentSymbols += `\t${svgFileContentStroked}\n`;
svgContentIcons += `\t<use xlink:href="#icon-${stroke}" x="${x}" y="${paddingOuter}" width="${iconSize}" height="${iconSize}" />\n`;
x += padding + iconSize;
});
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" style="color: #354052"><rect x="0" y="0" width="${width}" height="${height}" fill="#fff"></rect>\n${svgContentSymbols}\n${svgContentIcons}\n</svg>`;
fs.writeFileSync('.github/icons-stroke.svg', svgContent);
createScreenshot('.github/icons-stroke.svg');
cb();
}));
gulp.task('optimize', function (cb) {
glob("src/_icons/*.svg", {}, function (er, files) {
files.forEach(function (file, i) {
let svgFile = fs.readFileSync(file),
svgFileContent = svgFile.toString();
svgFileContent = svgFileContent
.replace(/><\/(polyline|line|rect|circle|path)>/g, '/>')
.replace(/rx="([^"]+)"\s+ry="\1"/g, 'rx="$1"')
.replace(/\s?\/>/g, ' />')
.replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1")
.replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"')
.replace(/a([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s?([0-1])\s?([0-1])\s?(-?[0-9.]+)\s?(-?[0-9.]+)/g, 'a$1 $2 $3 $4 $5 $6 $7')
.replace(/\n\n+/g, "\n");
fs.writeFileSync(file, svgFileContent);
});
cb();
});
});
gulp.task('changelog-commit', function(cb) {
cp.exec('git status', function(err, ret) {
let newIcons = [], modifiedIcons = [], renamedIcons = [];
ret.replace(/new file:\s+src\/_icons\/([a-z1-9-]+)\.svg/g, function (m, fileName) {
newIcons.push(fileName);
});
ret.replace(/modified:\s+src\/_icons\/([a-z1-9-]+)\.svg/g, function (m, fileName) {
modifiedIcons.push(fileName);
});
ret.replace(/renamed:\s+src\/_icons\/([a-z1-9-]+).svg -> src\/_icons\/([a-z1-9-]+).svg/g, function (m, fileNameBefore, fileNameAfter) {
renamedIcons.push([fileNameBefore, fileNameAfter]);
});
modifiedIcons = modifiedIcons.filter( function( el ) {
return newIcons.indexOf( el ) < 0;
});
printChangelog(newIcons, modifiedIcons, renamedIcons);
cb();
});
});
gulp.task('changelog-diff', function(cb) {
const version = p.version;
cp.exec(`git diff v${version} HEAD --name-status`, function(err, ret) {
let newIcons = [], modifiedIcons = [], renamedIcons = [];
ret.replace(/A\s+src\/_icons\/([a-z1-9-]+)\.svg/g, function (m, fileName) {
newIcons.push(fileName);
});
ret.replace(/M\s+src\/_icons\/([a-z1-9-]+)\.svg/g, function (m, fileName) {
modifiedIcons.push(fileName);
});
ret.replace(/R[0-9]+\s+src\/_icons\/([a-z1-9-]+)\.svg\s+src\/_icons\/([a-z1-9-]+).svg/g, function (m, fileNameBefore, fileNameAfter) {
renamedIcons.push([fileNameBefore, fileNameAfter]);
});
modifiedIcons = modifiedIcons.filter( function( el ) {
return newIcons.indexOf( el ) < 0;
});
printChangelog(newIcons, modifiedIcons, renamedIcons);
cb();
});
});
gulp.task('svg-to-png', gulp.series('build-jekyll', 'clean-png', async (cb) => {
let files = glob.sync("_site/icons/*.svg");
await asyncForEach(files, async function (file, i) {
let name = path.basename(file, '.svg');
console.log('name', name);
await svgToPng(file, `icons-png/${name}.png`);
});
cb();
}));
gulp.task('build', gulp.series('optimize', 'build-jekyll', 'build-copy', 'icons-sprite', 'icons-preview', 'build-zip'));
|