-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
72 lines (58 loc) · 1.89 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
var gulp = require('gulp');
var webserver = require('gulp-webserver');
var opn = require('opn');
var tap = require('gulp-tap');
var fs = require('fs');
var iconfont = require('gulp-iconfont');
var iconfontCss = require('gulp-iconfont-css');
var svgmin = require('gulp-svgmin');
var path = require('path');
var server = {
host: 'localhost',
port: 4000
};
var fontName = 'my-icon-font';
gulp.task('default', ['write-filenames-to-js-array', 'iconfont', 'html', 'webserver', 'opn']);
gulp.task('write-filenames-to-js-array', function() {
var jsFilename = 'dist/iconList.js';
fs.writeFile(jsFilename);
var iconList = fs.createWriteStream(jsFilename, {'flags': 'w'});
iconList.write('var iconList = [];\n');
var iconFileRegex = new RegExp("[a-z0-9-]*.svg");
gulp.src('assets/*.svg')
.pipe(tap(function(file, t) {
iconList.write('iconList.push("' + file.path.match(iconFileRegex)[0] + '");\n');
}));
});
gulp.task('iconfont', function() {
gulp.src(['assets/*.svg'])
.pipe(svgmin())
.pipe(iconfontCss({
fontName: fontName,
path: 'src/icons-template.ejs',
fontPath: '/fonts/' + fontName + '/',
targetPath: path.resolve(__dirname, 'dist') + '/css/' + fontName + '.css'
}))
.pipe(iconfont({
normalize: true,
fontName: fontName,
appendCodepoints: true
}))
.pipe(gulp.dest('dist/fonts/' + fontName));
});
gulp.task('html', function() {
return gulp.src(['./src/index.html'])
.pipe(gulp.dest('./dist'));
});
gulp.task('webserver', function() {
gulp.src( 'dist' )
.pipe(webserver({
host: server.host,
port: server.port,
livereload: true,
directoryListing: false
}));
});
gulp.task('opn', function() {
opn( 'http://' + server.host + ':' + server.port );
});