-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.ls
205 lines (169 loc) · 5.46 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
require! {
\./package.json : pkg
fs
jsdom
#\cheerio : $
browserify
\vinyl-transform
\vinyl-source-stream : source
\vinyl-paths
del
gulp
\gulp-cssmin
\gulp-uglifyjs
\gulp-symlink
\gulp-livescript
\gulp-remarkable
\gulp-watch
\gulp-sass : sass
#\gulp-ruby-sass
\gulp-jade : jade
\gulp-concat-util : concat
}
const doc-sass = <[ overview.md module.md zitijixing_extend.md sectional.md inline.md variable.md ]>
const doc-js = <[ overview.md han.md rendering.md normalize.md inline.md support.md find.md selector.md unicode.md ]>
config =
han-version: pkg.dependencies['han-css'].replace( /^[\^\~]/, '' )
production: yes
config.asset-path = '/'
src = gulp.src
dest = gulp.dest
make-array = ( obj ) -> Array.prototype.slice.call obj
jsdom.defaultDocumentFeatures = ProcessExternalResources: no
jsdom = jsdom.jsdom
gulp.task \han ->
src \./node_modules/han-css/dist/**/*
.pipe dest \./_www_/latest
gulp.task \vendor <[ han vendor:hljs vendor:fa ]>
gulp.task \vendor:hljs ->
src \node_modules/highlight.js/styles/tomorrow.css
.pipe concat \_hljs.tomorrow.scss
.pipe dest \./sass/vendor
#.pipe gulp-symlink \./sass/vendor/_hljs.tomorrow.scss { +force }
gulp.task \vendor:fa ->
src 'node_modules/font-awesome/fonts/*.{woff2,woff,otf,svg}'
.pipe dest \./asset/font
gulp.task \jade ->
src './template/*.jade'
.pipe jade!
.pipe dest \./template/html
gulp.task \static <[ jade ]> ->
<[ index itff ]>.for-each ( page ) !->
src "./template/html/#{page}.html"
.pipe concat "#{page}.html", {
process: ( src ) ->
src
.replace /\{\{asset\-path\}\}/gi, config.asset-path
.replace /\{\{han\-version\}\}/gi, config.han-version
}
.pipe dest \./_www_
gulp.task \md2html <[ jade doc ]> ->
try
manual-html = fs.readFileSync \./template/html/manual.html, encoding: \utf-8
manual-html .= split '{{parsed-article-html}}'
all-doc = fs.readdirSync \./doc/ .filter ( file ) -> /\.md$/i.test file
catch e
manaual-html = new Array 2
all-doc = []
return
all-doc.for-each ( file ) !->
page-id = file - /\.md$/
dot-html = page-id + \.html
chap = if page-id is \index then \jianjie else page-id
src \./doc/ + file
.pipe gulp-remarkable preset: \commonmark
.pipe concat.header manual-html.0
.pipe concat.footer manual-html.1
.pipe concat dot-html, {
process: ( src ) ->
doc = jsdom src
title = doc.query-selector 'article h1' .text-content + ' — '
try
make-array( doc.query-selector-all 'h2, h3, h4, h5, h6' )
.for-each ( elem, i ) !->
anchor = elem.last-child
anchor-id = anchor.node-value
elem.set-attribute \id, "sec-#{i}"
if anchor and anchor.node-type == 8 and /\s?\#[\w\_\-]+\s?/.test anchor-id
elem.set-attribute \id, anchor-id.replace( /\s?\#([\w\_\-]+)\s?/i, \$1 )
elem.remove-child anchor
make-array( doc.query-selector-all 'div.info, .example, pre, table' )
.for-each ( elem, i ) !->
unless elem.get-attribute \id
elem.set-attribute \id, "info-#{i}"
src = doc.document-element.outerHTML
src
.replace /\{\{asset\-path\}\}/gi, config.asset-path
.replace /\{\{han\-version\}\}/gi, config.han-version
.replace /\{\{manual\-page\-id\}\}/gi, chap
.replace /\{\{manual\-page\-title\}\}/gi, title
}
.pipe dest \_www_/manual
gulp.task \sass ->
# gulp-ruby-sass \./sass/style.scss
sass \./sass/style.scss
.pipe gulp-cssmin { keepSpecialComments: 0 }
.pipe dest \./_www_
gulp.task \sass:deploy ->
src \./_www_/style.css
.pipe dest \./asset
gulp.task \app <[ app:main ]> ->
gulp.start \app:clean
gulp.task \app:lsc <[ app:clean ]> ->
src \./app/**/*.ls
.pipe gulp-livescript!
.pipe dest \./tmp
src \./app/**/*.js
.pipe dest \./tmp
gulp.task \app:bundle -> #<[ app:lsc ]> ->
browserify {
entries: \./app/main.js
debug: no
}
.bundle!
.pipe source \app.js
.pipe dest \./_www_
gulp.task \app:main <[ app:bundle ]> ->
src \./_www_/app.js
.pipe gulp-uglifyjs {
output: { +ascii_only }
}
.pipe dest \./_www_
/*
browserified = vinyl-transform ( file ) ->
b = browserify file
b.bundle!
src \./tmp/main.js
.pipe browserified
.pipe gulp-uglifyjs \app.js {
output: { +ascii_only }
}
.pipe dest \./_www_
*/
gulp.task \app:clean ->
src \./tmp .pipe vinyl-paths del
gulp.task \asset ->
src <[ \./LICENSE.md \./asset/** \./asset/style.css ]>
.pipe dest \./_www_
gulp.task \www <[ vendor md2html static app asset ]>
gulp.task \clean ->
src \./_www_ .pipe vinyl-paths del
gulp.task \doc ->
add-path = ( path, array ) -> array.map ( elem ) -> path + \/ + elem
src add-path \./doc/sass-api doc-sass
.pipe concat \sass-api.md
.pipe dest \./doc
src add-path \./doc/js-api doc-js
.pipe concat \js-api.md
.pipe dest \./doc
gulp.task \set-dev ->
config.production = no
config.asset-path = \/
gulp.task \dev <[ set-dev default ]> ->
# gulp.watch './doc/{sass,js}-api/*.md' <[ doc ]>
gulp.watch \./doc/**/*.md <[ md2html ]>
gulp.watch \./template/**/*.jade <[ static ]>
gulp.watch './sass/**/*.{sass,scss}' <[ sass ]>
gulp.watch './app/**/*.{ls,js}' <[ app:main ]>
gulp.task \default <[ clean ]> ->
gulp.start \www