forked from nkoterba/material-design-iconsets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
129 lines (107 loc) · 3.32 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
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
var gulp = require('gulp');
var mkdirp = require('mkdirp');
var git = require('gulp-git');
var exec = require('child_process').exec;
var rename = require('gulp-rename');
var print = require('gulp-print');
var replace = require('gulp-replace');
var concat = require('gulp-concat');
var xmlEdit = require('gulp-edit-xml');
var insert = require('gulp-insert');
var fs = require('fs');
var path = require('path');
var es = require('event-stream');
var tap = require('gulp-tap');
var gulpif = require('gulp-if');
var del = require('del');
var ICONSRC = "material-design-icons";
var ICONSRC_GOOGLE = ICONSRC+'/google';
var ICONSRC_COMMUNITY = ICONSRC+'/community';
var ORIGIN_GOOGLE = "git://github.com/google/material-design-icons.git";
var ORIGIN_COMMUNITY = "git://github.com/Templarian/MaterialDesign.git";
var ICONDEST = "iconsets";
gulp.task('init', function () {
mkdirp.sync(ICONSRC_GOOGLE);
process.chdir(ICONSRC_GOOGLE);
exec(
'git init; ' +
'git config core.sparsecheckout true; ' +
'echo "*/svg/production/*_24px.svg" >> .git/info/sparse-checkout; ' +
'git remote add -f origin ' + ORIGIN_GOOGLE);
process.chdir('../../');
mkdirp.sync(ICONSRC_COMMUNITY);
process.chdir(ICONSRC_COMMUNITY);
exec(
'git init; ' +
'git config core.sparsecheckout true; ' +
'echo "/icons/svg/*.svg" >> .git/info/sparse-checkout; ' +
'git remote add -f origin ' + ORIGIN_COMMUNITY);
});
gulp.task('pull', function (cb) {
git.pull('origin', 'master', {cwd: ICONSRC_GOOGLE}, function (err) {
if (err)
throw err;
else {
git.pull('origin', 'master', {cwd: ICONSRC_COMMUNITY}, function (err) {
if (err)
throw err;
else
cb();
});
}
});
});
gulp.task('build-community', ['pull'], function() {
return gulp.src(path.join(ICONSRC_COMMUNITY, '**', '*.svg'))
.pipe(xmlEdit(function (doc) {
delete doc.svg.$;
var test = {
g: doc.svg
};
test.g.$ = {id: 'REPLACEME'};
delete test.g.path[0].$.fill;
return test;
}))
.pipe(tap(function (file,t) {
var iconName = path.basename(file.path).replace(/^|.svg/g, '');
file.contents = new Buffer(file.contents.toString().replace('REPLACEME', iconName));
}))
.pipe(concat('mdi-icons.svg'))
.pipe(insert.wrap('<svg>\n<defs>\n', '\n</defs>\n</svg>'))
.pipe(gulp.dest(ICONDEST));
});
gulp.task('build', ['pull'], function() {
var folders = getFolders(ICONSRC_GOOGLE);
var tasks = folders.map(function (folder) {
return gulp.src(path.join(ICONSRC_GOOGLE, folder, '**', '*.svg'))
//.pipe(print())
.pipe(xmlEdit(function (doc) {
delete doc.svg.$;
var test = {
g: doc.svg
};
test.g.$ = {id: 'REPLACEME'};
return test;
}))
.pipe(tap(function (file,t) {
var iconName = path.basename(file.path).replace(/^ic_|_..px.svg/g, '');
file.contents = new Buffer(file.contents.toString().replace('REPLACEME', iconName));
}))
.pipe(concat(folder + '-icons.svg'))
.pipe(insert.wrap('<svg>\n<defs>\n', '\n</defs>\n</svg>'))
.pipe(gulp.dest(ICONDEST))
});
return es.concat.apply(null, tasks);
});
gulp.task('clean', function(cb) {
del(ICONDEST, cb);
});
gulp.task('cleanAll', function(cb) {
del([ICONSRC_GOOGLE, ICONSRC_COMMUNITY, ICONSRC, ICONDEST], cb);
});
function getFolders(dir){
return fs.readdirSync(dir)
.filter(function(file){
return fs.statSync(path.join(dir, file)).isDirectory();
});
}