-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
94 lines (85 loc) · 2.68 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
var gulp = require('gulp');
var svgstore = require('gulp-svgstore');
var svgmin = require('gulp-svgmin');
var path = require('path');
const rename= require('gulp-rename');
const inject = require('gulp-inject');
const replace = require('gulp-replace');
const zip = require('gulp-zip');
const iso="be,bg,cz,dk,de,ee,ie,gr,es,fr,hr,it,cy,lv,lt,lu,hu,mt,nl,at,pl,pt,ro,si,sk,fi,se,gb,eu";
//gb, not uk. ee, not gr
gulp.task('init', function(){
return gulp.src(["node_modules/d3/dist/d3.min.js"])
.pipe(gulp.dest("./dist/js"));
});
gulp.task('copy', function () {
var files=[];
iso.split(",").map((c)=>{ files.push("node_modules/flag-icon-css/flags/4x3/"+c+".svg")});
return gulp.src(files)
.pipe(gulp.dest('./svg/country'));
});
gulp.task('html', function() {
return gulp.src('src/index.html')
.pipe(inject(gulp.src(['svg/eu-flags.svg']),
{starttag: '<!-- inject:{{path}} -->',
relative: true,
transform: function (filePath, file) {
console.log(filePath);
return file.contents.toString('utf8')}
}))
.pipe(gulp.dest('.'));
});
gulp.task('svg', function () {
var files=[];
iso.split(",").map((c)=>{ files.push("svg/country/"+c+".svg")});
return gulp
.src(files)
.pipe(rename({prefix: 'flag-'}))
.pipe(svgmin(function (file) {
var prefix = path.basename(file.relative, path.extname(file.relative));
return {
plugins: [
{
removeDoctype: true
}, {
removeComments: true
}, {
cleanupNumericValues: {
floatPrecision: 1
}},
{
convertPathData: {
floatPrecision: 2
}
},
{
transformsWithOnePath: {
floatPrecision: 2
}
},
{
convertTransform: {
floatPrecision: 2
}
},
{
cleanupListOfValues: {
floatPrecision: 2
}
},{
cleanupIDs: {
prefix: prefix + '-',
minify: true
}
}]
}
}))
.pipe(svgstore())
.pipe(replace('<symbol ','<symbol viewBox="0 0 640 480" '))
.pipe(replace('</svg>','<symbol id="flag-uk"><use href="#flag-gb" /></symbol><symbol id="flag-el"><use href="#flag-gr" /></symbol></svg>'))
.pipe(rename("eu-flags.svg"))
.pipe(gulp.dest('svg'))
.pipe(zip(("eu-flags.svg.zip")))
.pipe(gulp.dest('svg'))
});
gulp.task('default', ['init','copy','svg','html']);