-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.coffee
127 lines (108 loc) · 2.88 KB
/
gulpfile.coffee
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
del = require 'del'
run = require 'run-sequence'
gulp = require 'gulp'
gutil = require 'gulp-util'
which = require('npm-which')(__dirname)
rename = require 'gulp-rename'
sketch = require 'gulp-sketch'
cssnano = require 'gulp-cssnano'
htmlmin = require 'gulp-htmlmin'
iconfont = require 'gulp-iconfont'
imagemin = require 'gulp-imagemin'
browserSync = require 'browser-sync'
consolidate = require 'gulp-consolidate'
cssbeautify = require 'gulp-cssbeautify'
pkg = require './package.json'
fontName = 'talk-iconfonts'
className = 'ti'
iconfontName = 'Talk Iconfonts'
iconfontProcess = (cb, dest) ->
try which.sync 'sketchtool'
catch err
gutil.log err
return
gulp
.src './sketch/16px.sketch'
.pipe sketch
export: 'artboards'
compact: true
formats: 'svg'
saveForWeb: true
.pipe imagemin()
.pipe iconfont
formats: ['eot', 'svg', 'ttf', 'woff', 'woff2']
fontName: fontName
.on 'glyphs', (glyphs) ->
info =
glyphs: glyphs.reduce (arr, glyph) ->
names = glyph.name
.split '&'
.map (name) ->
name: name
unicode: glyph.unicode[0].charCodeAt(0).toString(16).toUpperCase()
arr.concat names
, []
version: pkg.version
fontName: fontName
fontPath: '../fonts/'
className: className
fontFamily: iconfontName
cb info
.pipe gulp.dest dest
###
* @开发
###
gulp.task 'dev', (cb) ->
run 'dev:clean', 'dev:iconfonts', 'dev:browser', 'dev:watch', cb
bs = browserSync.create 'dev'
gulp.task 'dev:browser', ->
bs.init
open: false
server:
baseDir: './examples'
directory: true
gulp.task 'dev:clean', (cb) ->
del ['./examples/'], cb
gulp.task 'dev:iconfonts', ->
iconfontProcess (info) ->
gulp.src "./src/#{fontName}.css"
.pipe consolidate 'lodash', info
.pipe rename basename: fontName
.pipe gulp.dest './examples/css/'
gulp.src './src/index.html'
.pipe consolidate 'lodash', info
.pipe gulp.dest './examples/'
, './examples/fonts/'
gulp.task 'dev:watch', ->
gulp.watch './sketch/*.sketch', ['compile:iconfonts']
###
* @编译
###
gulp.task 'compile', (cb) ->
run 'compile:clean', 'compile:iconfonts', 'compile:beautify', 'compile:minify', cb
gulp.task 'compile:beautify', ->
gulp.src "./lib/css/#{fontName}.css"
.pipe cssbeautify
indent: ' '
openbrace: 'end-of-line'
autosemicolon: true
.pipe gulp.dest './lib/css/'
gulp.task 'compile:clean', (cb)->
del ['./lib/'], cb
gulp.task 'compile:iconfonts', ->
iconfontProcess (info) ->
gulp.src "./src/#{fontName}.css"
.pipe consolidate 'lodash', info
.pipe rename basename: fontName
.pipe gulp.dest './lib/css/'
,'./lib/fonts/'
gulp.task 'compile:minify', ->
gulp.src "./lib/css/#{fontName}.css"
.pipe cssnano()
.pipe rename suffix: '.min'
.pipe gulp.dest './lib/css/'
###
* @快捷任务命令
###
gulp.task 'build', (cb) ->
run 'compile', cb