forked from ethantw/Han
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.ls
More file actions
182 lines (156 loc) · 4.66 KB
/
gulpfile.ls
File metadata and controls
182 lines (156 loc) · 4.66 KB
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
require! <[ gulp gulp-connect gulp-concat-util gulp-sass gulp-csscomb gulp-cssmin gulp-requirejs-optimize gulp-uglifyjs gulp-symlink gulp-browserify gulp-livescript gulp-jade gulp-watch gulp-qunit ]>
concat = gulp-concat-util
sass = gulp-sass
rjs = gulp-requirejs-optimize
watch = gulp-watch
pkg = require \./package.json
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}
"""
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.task \default <[ build demo ]>
gulp.task \dev <[ watch server ]>
gulp.task \build <[ dist:font dist:sass dist:cssmin dist:js dist:uglify ]>
gulp.task \dep <[ normalize.css fibre.js ]>
gulp.task \server !->
gulp-connect.server {
port: 7777
livereload: true
}
# Build for distribution
gulp.task \dist:font ->
gulp.src './font/han*.{woff,otf}'
.pipe gulp.dest \./dist/font
gulp.task \dist:sass ->
gulp.src \./src/sass/han.scss
.pipe sass!
.pipe concat \han.css, {
process: ( src ) ->
src.replace /@charset\s(['"])UTF-8\1;\n/g, ''
}
.pipe concat.header CSS-BANNER
.pipe gulp-csscomb!
.pipe gulp.dest \./dist
gulp.task \dist:cssmin <[ dist:sass ]> ->
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
gulp.task \dist:js ->
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
gulp.task \dist:uglify <[ dist:js ]> ->
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
# API test
gulp.task \test ->
gulp.src \./test/api.html
.pipe gulp-qunit!
# Demo
gulp.task \demo ->
gulp.start <[ demo:font demo:dist demo:sass demo:jade demo:lsc ]>
gulp.task \demo:dist <[ build ]> ->
gulp.src <[ ./dist/han*.css ./dist/han*.js ]>
.pipe gulp.dest \./test
gulp.task \demo:font ->
gulp.src './dist/font/*.{woff,otf}'
.pipe gulp.dest \./test/font
gulp.task \demo:sass <[ dist:cssmin ]> ->
gulp.src \./test/*.scss
.pipe sass!
.pipe gulp-cssmin { keepSpecialComments: 0 }
.pipe gulp.dest \./test
gulp.task \demo:jade ->
gulp.src \./test/*.jade
.pipe gulp-jade!
.pipe gulp.dest \./test
gulp.task \demo:lsc ->
gulp.src \./test/test-commonjs.ls
.pipe gulp-livescript!
.pipe gulp-browserify!
.pipe gulp-uglifyjs {
output: {
ascii_only: true
}
}
.pipe gulp.dest \./test
gulp.src \./test/api.ls
.pipe gulp-livescript!
.pipe gulp.dest \./test
# Watch
gulp.task \watch <[ build demo ]> ->
gulp.watch \./src/sass/**/* <[ dist:sass dist:cssmin demo:dist demo:sass ]>
gulp.watch \./src/js/**/* <[ dist:js dist:uglify demo:dist demo:lsc ]>
gulp.watch \./test/*.scss <[ demo:sass ]>
gulp.watch \./test/*.jade <[ demo:jade ]>
gulp.watch \./test/*.ls <[ demo:lsc ]>
# Dependencies
gulp.task \normalize.css !->
gulp.src \./node_modules/normalize.css/normalize.css
.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