-
Notifications
You must be signed in to change notification settings - Fork 135
/
gulpfile.ls
209 lines (184 loc) · 5.06 KB
/
gulpfile.ls
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
require! {
\./package.json : pkg
\gulp
\gulp-connect
\gulp-concat-util : concat
\gulp-stylus : styl
\gulp-csscomb
\gulp-cssmin
\gulp-requirejs-optimize : rjs
\gulp-uglifyjs
\gulp-symlink
\gulp-browserify
\gulp-livescript
\gulp-jade
\gulp-plumber
\gulp-util
\gulp-watch : watch
\gulp-qunit
}
const VERSION = pkg.version
const BANNER = """
/*! 漢字標準格式 v#{VERSION} | MIT License | css.hanzi.co */
/*! Han.css: the CSS typography framework optimised for Hanzi */
\n
"""
const CSS-BANNER = """
@charset "UTF-8";
#{BANNER}
"""
const unwrap = ( name, path, src ) ->
rdefineEnd = /\}\);?[^}\w]*$/
if path is /.\/var\//
src = src
.replace( /define\([\w\W]*?return/, 'var ' + /var\/([\w-]+)/.exec(name)[1] + ' =' )
.replace( rdefineEnd, '' )
else if name is /^fibre$/
src = '\nvar Fibre =\n' + src
.replace( /void\s/, '' )
.replace( "var Finder = Finder || require( './finder.umd' )\n", '' )
.replace( /\/\/\s*EXPOSE[\w\W]*\/\/\s*EXPOSE/, 'return Fibre' )
else
src = src
.replace( /\s*return\s+[^\}]+(\}\);?[^\w\}]*)$/, '$1' )
.replace( /define\([^{]*?{/, '' )
.replace( rdefineEnd, '' )
.replace( /\/\*\s*ExcludeStart\s*\*\/[\w\W]*?\/\*\s*ExcludeEnd\s*\*\//ig, '' )
.replace( /\/\/\s*BuildExclude\n\r?[\w\W]*?\n\r?/ig, '' )
.replace( /define\(\[[^\]]+\]\)[\W\n]+$/, '' )
src
rjs-config = {
baseUrl: \src/js
name: \han
out: \./han.js
optimize: \none
findNestedDependencies: yes
skipSemiColonInsertion: yes
wrap: {
startFile: \src/js/intro.js
endFile: \src/js/outro.js
}
paths: {
fibre: \../lib/fibre.js/index
}
rawText: {}
onBuildWrite: unwrap
}
gulp-src = ->
gulp.src.apply gulp, arguments
.pipe gulp-plumber ( error ) ->
gulp-util.log gulp-util.colors.red(
"Error (#{ error.plugin }): #{ error.message }"
)
this.emit \end
gulp.task \default <[ build demo ]>
gulp.task \dev <[ build watch server ]>
gulp.task \build <[ dist:css dist:js ]>
gulp.task \demo <[ build demo:lsc demo:styl demo:jade ]>
gulp.task \asset <[ dist:font ]>
gulp.task \dep <[ normalize.css fibre.js ]>
gulp.task \server !->
gulp-connect.server {
port: 7777
livereload: true
}
# Build for distribution
gulp.task \dist:css <[ dist:styl dist:cssmin ]>
gulp.task \dist:js <[ dist:amd dist:uglify ]>
gulp.task \dist:font ->
gulp-src './font/han*.{woff2,woff,otf}'
.pipe gulp.dest \./dist/font
.pipe gulp.dest \./demo/font
gulp.task \dist:styl ->
gulp-src \./index.styl
.pipe styl!
.pipe concat \han.css, {
process: ( src ) ->
src
.replace /@charset\s(['"])UTF-8\1;\n/g, ''
.replace /@VERSION/g, "v#{VERSION}"
}
.pipe concat.header CSS-BANNER
.pipe gulp-csscomb!
.pipe gulp.dest \./dist
.pipe gulp.dest \./demo
gulp.task \dist:cssmin <[ dist:styl ]> ->
gulp-src \./dist/han.css
.pipe gulp-cssmin { keepSpecialComments: 0 }
.pipe concat \han.min.css, {
process: ( src ) ->
src.replace /@charset\s(['"])UTF-8\1;/g, ''
}
.pipe concat.header CSS-BANNER
.pipe gulp.dest \./dist
.pipe gulp.dest \./demo
gulp.task \dist:amd ->
gulp-src \./src/js/han.js
.pipe rjs rjs-config
.pipe concat \han.js, {
process: ( src ) ->
src
.replace /@VERSION/g, VERSION
.replace /\n{3,}/g, '\n\n'
}
.pipe gulp.dest \./dist
.pipe gulp.dest \./test
.pipe gulp.dest \./demo
gulp.task \dist:uglify <[ dist:amd ]> ->
gulp-src \./dist/han.js
.pipe gulp-uglifyjs \han.min.js {
output: {
ascii_only: true
}
}
.pipe concat \han.min.js
.pipe concat.header BANNER
.pipe gulp.dest \./dist
.pipe gulp.dest \./test
.pipe gulp.dest \./demo
# API test
gulp.task \test ->
gulp-src \./test/index.html
.pipe gulp-qunit!
# Demo
gulp.task \demo:styl ->
gulp-src \./demo/*.styl
.pipe styl!
.pipe gulp-cssmin { keepSpecialComments: 0 }
.pipe gulp.dest \./demo
gulp.task \demo:jade ->
gulp-src \./demo/*.jade
.pipe gulp-jade!
.pipe gulp.dest \./demo
gulp.task \demo:lsc ->
gulp-src \./demo/test-commonjs.ls
.pipe gulp-livescript!
.pipe gulp-browserify!
.pipe gulp-uglifyjs {
output: {
ascii_only: true
}
}
.pipe gulp.dest \./demo
gulp-src \./test/index.ls
.pipe gulp-livescript!
.pipe gulp.dest \./test
# Watch
gulp.task \watch <[ default ]> ->
gulp.watch \./src/styl/**/* <[ dist:css demo:styl ]>
gulp.watch \./src/js/**/* <[ dist:js demo:lsc ]>
gulp.watch \./demo/*.styl <[ demo:styl ]>
gulp.watch \./demo/*.jade <[ demo:jade ]>
gulp.watch \./demo/*.ls <[ demo:lsc ]>
gulp.watch \./test/*.ls <[ demo:lsc ]>
# Dependencies
gulp.task \normalize.css ->
gulp-src \./node_modules/normalize.css/normalize.css
.pipe concat \normalize.styl
.pipe gulp.dest \./src/styl/locale
.pipe concat \_normalize.scss
.pipe gulp.dest \./src/sass/locale
gulp.task \fibre.js ->
gulp-src \./node_modules/fibre.js/dist/fibre.js
.pipe concat \index.js
.pipe gulp.dest \./src/lib/fibre.js