-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
155 lines (145 loc) · 4.79 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
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
// Libs
var fs = require('fs')
, path = require('path')
, _ = require('lodash')
, gulp = require('gulp')
, gutil = require('gulp-util')
, rename = require('gulp-rename')
, open = require('gulp-open')
, cssmin = require('gulp-clean-css')
, less = require('gulp-less')
, seq = require('run-sequence')
, svgsize = require('./lib/gulp/svgsize')
, normalize = require('./lib/gulp/normalize')
, webfont = require('./lib/gulp/webfont')
, release = require('./lib/gulp/release')
// Configs
var fontName = 'upplication-icons'
, fontNameWingu = 'wingu-icons'
, iconClass = 'icon'
// Path shorthands
var srcPath = './lib'
, dstPath = './dist'
, srcIconsPath = path.join(__dirname, srcPath, 'icons/*.svg')
, srcIconsPathWingu = path.join(__dirname, srcPath, 'iconswingu/*.svg')
, srcHtmlTpl = path.join(__dirname, srcPath, 'index.html.tpl')
, dstHtmlUpplication = path.join(__dirname, dstPath, 'upplication/index.html')
, dstHtmlWingu = path.join(__dirname, dstPath, 'wingu/index.html')
, dstJsonMapFileUpp = path.join(__dirname, dstPath, 'upplication/upplicationiconmap.json')
, dstJsonMapFileWingu = path.join(__dirname, dstPath, 'wingu/winguiconmap.json')
, srcCssTpl = path.join(__dirname, srcPath, 'iconfont.less.tpl')
, dstCssFile = path.join(__dirname, dstPath, 'upplication' , fontName + '.css')
, dstCssFileWingu = path.join(__dirname, dstPath, 'wingu', fontNameWingu + '.css')
var glyphs = [] // For sharing data among tasks
var glyphswingu = []
gulp.task('svgs', function() {
return gulp.src([ srcIconsPath ])
.pipe(normalize())
.pipe(gulp.dest('./meh'))
})
/**
* Generates a css file containing a base64 encoded version
* of the font generated by the given svg icons
*/
gulp.task('webfont', function() {
return gulp.src([ srcIconsPath ])
.pipe(svgsize())
.pipe(webfont({
fontName: fontName,
iconClass: iconClass,
cssTemplate: srcCssTpl,
extension: 'less',
centerHorizontally: true,
fixedWidth: true,
normalize: true
}))
.on('glyphs', function(g) {
glyphs = g
gutil.log('Generated webfont', gutil.colors.green(fontName), 'with', gutil.colors.cyan(g.length), 'glyphs')
})
.pipe(gulp.dest(dstPath))
.pipe(less())
.pipe(gulp.dest('dist/upplication'))
});
gulp.task('webfontwingu', function() {
return gulp.src([ srcIconsPathWingu ])
.pipe(svgsize())
.pipe(webfont({
fontName: fontNameWingu,
iconClass: iconClass,
cssTemplate: srcCssTpl,
extension: 'less',
centerHorizontally: true,
fixedWidth: true,
normalize: true,
}))
.on('glyphs', function(g) {
glyphswingu = g
gutil.log('Generated webfont', gutil.colors.green(fontNameWingu), 'with', gutil.colors.cyan(g.length), 'glyphs')
})
.pipe(gulp.dest(dstPath))
.pipe(less())
.pipe(gulp.dest('dist/wingu'))
});
gulp.task('webfont-json-map', function(cb) {
var glyphMap = _.keyBy(glyphs, 'name')
var glyphMapWingu = _.keyBy(glyphswingu, 'name')
fs.writeFileSync(dstJsonMapFileUpp, JSON.stringify(glyphMap))
fs.writeFileSync(dstJsonMapFileWingu, JSON.stringify(glyphMapWingu))
cb()
});
gulp.task('minify', function(cb) {
gulp.src(dstCssFile)
.pipe(cssmin({ compatibility: 'ie8' }))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('dist/upplication'))
gulp.src(dstCssFileWingu)
.pipe(cssmin({ compatibility: 'ie8' }))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('dist/wingu'))
cb()
})
gulp.task('demogen', function(cb) {
var htmlTemplate = fs.readFileSync(srcHtmlTpl, 'utf8');
var htmlCompiler = _.template(htmlTemplate);
var htmlCompiled = htmlCompiler({
fontName: fontName,
iconClass: iconClass,
glyphs: glyphs
});
var htmlCompiledWingu = htmlCompiler({
fontName: fontNameWingu,
iconClass: iconClass,
glyphs: glyphswingu
});
fs.writeFileSync(dstHtmlUpplication, htmlCompiled);
fs.writeFileSync(dstHtmlWingu, htmlCompiledWingu);
cb()
})
gulp.task('demo', function(cb) {
gulp.src(dstHtmlUpplication)
.pipe(open());
gulp.src(dstHtmlWingu)
.pipe(open());
cb()
})
gulp.task('gitwork', release())
gulp.task('version', function(cb) {
seq('webfont',
'webfont-json-map',
'minify',
'demogen',
'gitwork',
cb
);
})
gulp.task('default', function(cb) {
seq('webfont',
'webfontwingu',
'webfont-json-map',
'minify',
'demogen',
'demo',
cb
);
});