This repository was archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
462 lines (397 loc) · 16.6 KB
/
Copy pathgulpfile.js
File metadata and controls
462 lines (397 loc) · 16.6 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
var gulp = require('gulp'),
extender = require('gulp-html-extend'),
htmlreplace = require('gulp-html-replace'),
rename = require("gulp-rename"),
clean = require('gulp-clean'),
less = require('gulp-less'),
newer = require('gulp-newer'),
inject = require('gulp-inject'),
spritesmith = require('gulp.spritesmith'),
markdown = require('gulp-markdown'),
gutil = require('gulp-util'),
md2json = require('gulp-markdown-to-json'),
sitemap = require('gulp-sitemap'),
merge = require('merge-stream'),
minifyHTML = require('gulp-minify-html'),
minifyCss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
include = require('gulp-html-tag-include');
gulp.task('css-clean', function () {
return gulp.src(['app/style/css/*'], {read: true})
.pipe(clean());
});
/* less */
gulp.task('less',['css-clean'],function(){
return gulp.src('app/style/less/*.less')
.pipe(less())
.pipe(gulp.dest('app/style/css'))
});
gulp.task('copy-css',['less'],function(){
return gulp.src('app/style/less/lib/**/*').pipe(gulp.dest('app/style/css/lib'));
});
/*
o8o .o8
`"' "888
oooo ooo. .oo. .oooo888 .ooooo. oooo ooo
`888 `888P"Y88b d88' `888 d88' `88b `88b..8P'
888 888 888 888 888 888ooo888 Y888'
888 888 888 888 888 888 .o .o8"'88b
o888o o888o o888o `Y8bod88P" `Y8bod8P' o88' 888o */
gulp.task('index',function () {
return gulp.src('app/_index.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "index";
}))
.pipe(gulp.dest('app'));
});
gulp.task('indexEN',function () {
return gulp.src('app/en/_index.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "index";
}))
.pipe(gulp.dest('app/en'));
});
/* . .o8
.o8 "888
.ooooo. oooo ooo .o888oo .ooooo. ooo. .oo. .oooo888
d88' `88b `88b..8P' 888 d88' `88b `888P"Y88b d88' `888
888ooo888 Y888' 888 888ooo888 888 888 888 888
888 .o .o8"'88b 888 . 888 .o 888 888 888 888
`Y8bod8P' o88' 888o "888" `Y8bod8P' o888o o888o `Y8bod88P" */
/* 合併 layout */
gulp.task('extend',function () {
var a1 = gulp.src('app/_about.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "about";
}))
.pipe(gulp.dest('app'));
var a2 = gulp.src('app/_buy.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "buy";
}))
.pipe(gulp.dest('app'));
var a3 = gulp.src('app/_tutorials.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "tutorials";
}))
.pipe(gulp.dest('app'));
var a4 = gulp.src('app/_activity.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "activity";
}))
.pipe(gulp.dest('app'));
return merge(a1, a2, a3, a4);
});
gulp.task('extendEN',function () {
var b1 = gulp.src('app/en/_tutorials.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "tutorials";
}))
.pipe(gulp.dest('app/en'));
var b2 = gulp.src('app/en/_about.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "about";
}))
.pipe(gulp.dest('app/en'));
var b3 = gulp.src('app/en/_buy.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(rename(function (path) {
path.basename = "buy";
}))
.pipe(gulp.dest('app/en'));
return merge(b1, b2, b3);
});
/*
o8o oooo .o8
`"' `888 "888
oooo ooo. .oo. .ooooo. 888 oooo oooo .oooo888 .ooooo.
`888 `888P"Y88b d88' `"Y8 888 `888 `888 d88' `888 d88' `88b
888 888 888 888 888 888 888 888 888 888ooo888
888 888 888 888 .o8 888 888 888 888 888 888 .o
o888o o888o o888o `Y8bod8P' o888o `V88V"V8P' `Y8bod88P" `Y8bod8P'*/
/* 置換為合適的 js 與 css */
var contentInjectHtml = [
'app/buy.html',
'app/tutorials.html',
'app/activity.html',
'app/about.html'
];
gulp.task('include',['extend'],function(){
return gulp.src(contentInjectHtml)
.pipe(include())
.pipe(gulp.dest('app'));
});
gulp.task('include-final',['extend','copy-css'],function(){
return gulp.src(contentInjectHtml)
.pipe(include())
.pipe(gulp.dest('app'));
});
var contentInjectENHtml = [
'app/en/tutorials.html',
'app/en/about.html',
'app/en/buy.html'
];
gulp.task('include-en',['extendEN'],function(){
return gulp.src(contentInjectENHtml)
.pipe(include())
.pipe(gulp.dest('app/en'));
});
gulp.task('include-en-final',['extendEN','copy-css'],function(){
return gulp.src(contentInjectENHtml)
.pipe(include())
.pipe(gulp.dest('app/en'));
});
/* . . o8o oooo
.o8 .o8 `"' `888
.o888oo oooo oooo .o888oo .ooooo. oooo d8b oooo .oooo. 888 .oooo.o
888 `888 `888 888 d88' `88b `888""8P `888 `P )88b 888 d88( "8
888 888 888 888 888 888 888 888 .oP"888 888 `"Y88b.
888 . 888 888 888 . 888 888 888 888 d8( 888 888 o. )88b
"888" `V88V"V8P' "888" `Y8bod8P' d888b o888o `Y888""8o o888o 8""888P' */
/* tutorials 合併 layout */
gulp.task('tutorials-clean',function(){
return gulp.src(['app/tutorials/**/*'], {read: true}).pipe(clean());
});
/* markdown,需要手動修改把 id 拿掉,markdown to json 必須把 data[path].body mark 起來 */
gulp.task('md-clean',function(){
return gulp.src(['app/_tutorials-md/md2html/**/*','app/json/**/*'], {read: true}).pipe(clean());
});
gulp.task('md',['md-clean'], function () {
return gulp.src(['app/_tutorials-md/**/*.md','!app/_tutorials-md/**/temp.md'])
.pipe(markdown())
.pipe(gulp.dest('app/_tutorials-md/md2html/'));
});
gulp.task('md2json',['md'], function(){
return gulp.src(['app/_tutorials-md/**/*.md','!app/_tutorials-md/**/temp.md'])
.pipe(gutil.buffer())
.pipe(md2json('tutorials.json'))
.pipe(gulp.dest('app/json'))
});
gulp.task('md-extend',['md2json','tutorials-clean'], function () {
return gulp.src('app/_tutorials-md/md2html/*.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(gulp.dest('app/tutorials'));
});
/* tutorials 置換為合適的 js 與 css */
gulp.task('tutorials-include',['md-extend'],function(){
return gulp.src('app/tutorials/*.html')
.pipe(include())
.pipe(gulp.dest('app/tutorials'));
});
gulp.task('tutorials-include-final',['md-extend','copy-css'],function(){
return gulp.src('app/tutorials/*.html')
.pipe(include())
.pipe(gulp.dest('app/tutorials'));
});
/*
d88888b d8b db d888888b db db d888888b .d88b. d8888b. d888888b .d8b. db
88' 888o 88 `~~88~~' 88 88 `~~88~~' .8P Y8. 88 `8D `88' d8' `8b 88
88ooooo 88V8o 88 88 88 88 88 88 88 88oobY' 88 88ooo88 88
88~~~~~ 88 V8o88 C8888D 88 88 88 88 88 88 88`8b 88 88~~~88 88
88. 88 V888 88 88b d88 88 `8b d8' 88 `88. .88. 88 88 88booo.
Y88888P VP V8P YP ~Y8888P' YP `Y88P' 88 YD Y888888P YP YP Y88888P
*/
/* tutorials 合併 layout */
gulp.task('tutorials-en-clean',function(){
return gulp.src(['app/en/tutorials/**/*'], {read: true}).pipe(clean());
});
/* markdown,需要手動修改把 id 拿掉,markdown to json 必須把 data[path].body mark 起來 */
gulp.task('md-en-clean',function(){
return gulp.src(['app/en/_tutorials-md/md2html/**/*','app/en/json/**/*'], {read: true}).pipe(clean());
});
gulp.task('md-en',['md-en-clean'], function () {
return gulp.src(['app/en/_tutorials-md/**/*.md','!app/en/_tutorials-md/**/temp.md'])
.pipe(markdown())
.pipe(gulp.dest('app/en/_tutorials-md/md2html/'));
});
gulp.task('md2json-en',['md-en'], function(){
return gulp.src(['app/en/_tutorials-md/**/*.md','!app/en/_tutorials-md/**/temp.md'])
.pipe(gutil.buffer())
.pipe(md2json('tutorials-en.json'))
.pipe(gulp.dest('app/en/json'))
});
gulp.task('md-en-extend',['md2json-en','tutorials-en-clean'], function () {
return gulp.src('app/en/_tutorials-md/md2html/*.html')
.pipe(extender({annotations:false,verbose:false}))
.pipe(gulp.dest('app/en/tutorials'));
});
/* tutorials 置換為合適的 js 與 css */
gulp.task('tutorials-en-include',['md-en-extend'],function(){
return gulp.src('app/en/tutorials/*.html')
.pipe(include())
.pipe(gulp.dest('app/en/tutorials'));
});
gulp.task('tutorials-en-include-final',['tutorials-en-include'],function(){
return gulp.src('app/en/tutorials/*.html')
.pipe(include())
.pipe(gulp.dest('app/en/tutorials'));
});
/*
.o8
"888
888oooo. oooo oooo oooo ooo
d88' `88b `888 `888 `88. .8'
888 888 888 888 `88..8'
888 888 888 888 `888'
`Y8bod8P' `V88V"V8P' .8'
.o..P'
`Y8P'*/
gulp.task('buy-clean',function(){
return gulp.src(['app/buy/**/*'], {read: true}).pipe(clean());
});
gulp.task('buy-include',['buy-clean'], function () {
return gulp.src(['app/_buy-content/*.html','!app/_buy-content/_public.html'])
.pipe(extender({annotations:false,verbose:false}))
.pipe(include())
.pipe(gulp.dest('app/buy'));
});
/*en-buy*/
gulp.task('buy-en-clean',function(){
return gulp.src(['app/en/buy/**/*'], {read: true}).pipe(clean());
});
gulp.task('buy-en-include',['buy-en-clean'], function () {
return gulp.src(['app/en/_buy-content/*.html','!app/en/_buy-content/_public.html'])
.pipe(extender({annotations:false,verbose:false}))
.pipe(include())
.pipe(gulp.dest('app/en/buy'));
});
/* promote */
gulp.task('promote-clean',function(){
return gulp.src(['app/activity/promote/**/*'], {read: true}).pipe(clean());
});
gulp.task('promote-include',['promote-clean'], function () {
return gulp.src(['app/_promote-content/*.html'])
.pipe(extender({annotations:false,verbose:false}))
.pipe(include())
.pipe(gulp.dest('app/activity'));
});
/* o8o .
`"' .o8
.oooo.o oo.ooooo. oooo d8b oooo .o888oo .ooooo.
d88( "8 888' `88b `888""8P `888 888 d88' `88b
`"Y88b. 888 888 888 888 888 888ooo888
o. )88b 888 888 888 888 888 . 888 .o
8""888P' 888bod8P' d888b o888o "888" `Y8bod8P'
888
o888o*/
/* 圖片合併 */
gulp.task('layout-sprite', function () {
return gulp.src('app/img/sprite/*.png').pipe(spritesmith({
imgName: 'layout/layout-sprite.png',
cssName: '../style/temp/layout-sprite.css'
})).pipe(gulp.dest('app/img'));
});
/* . oooo
.o8 `888
oooo oooo ooo .oooo. .o888oo .ooooo. 888 .oo.
`88. `88. .8' `P )88b 888 d88' `"Y8 888P"Y88b
`88..]88..8' .oP"888 888 888 888 888
`888'`888' d8( 888 888 . 888 .o8 888 888
`8' `8' `Y888""8o "888" `Y8bod8P' o888o o888o */
gulp.task('watch',function(){
gulp.watch(['app/_buy-content/*.html','_include-buy.html'],['buy-include']);
gulp.watch(['app/_promote-content/*.html','_include-promote.html'],['promote-include']);
gulp.watch('app/_tutorials-md/**/*.md',['tutorials-include','md2json']);
gulp.watch('app/_include-tutorials.html',['tutorials-include']);
gulp.watch('app/en/_tutorials-md/**/*.md',['tutorials-en-include','md2json-en']);
gulp.watch(['app/en/_include-tutorials.html','app/en/_include-tutorials-content.html'],['tutorials-en-include']);
gulp.watch('app/style/less/*.less',['copy-css']);
gulp.watch('app/_index.html',['index']);
gulp.watch('app/en/_index.html',['indexEN']);
gulp.watch([
'app/_buy.html',
'app/_tutorials.html',
'app/_activity.html',
'app/_about.html'],['include']);
gulp.watch(['app/en/_buy-content/*.html','en/_include-buy.html'],['buy-en-include']);
gulp.watch(['app/en/_tutorials.html','app/en/_about.html','app/en/_buy.html'],['include-en']);
gulp.watch('app/_layout.html',['index','include','tutorials-include','buy-include','promote-include']);
gulp.watch('app/en/_layout.html',['indexEN','include-en']);
});
/* .o8 o8o oooo .o8
"888 `"' `888 "888
888oooo. oooo oooo oooo 888 .oooo888
d88' `88b `888 `888 `888 888 d88' `888
888 888 888 888 888 888 888 888
888 888 888 888 888 888 888 888
`Y8bod8P' `V88V"V8P' o888o o888o `Y8bod88P" */
/* build */
gulp.task('build-clean',function(){
return gulp.src(['build/*'], {read: true}).pipe(clean());
});
gulp.task('move',['build-clean'],function(){
var opts = {
conditionals: true,
spare:true,
loose: true,
quotes: true
};
var a1 = gulp.src('app/img/index/*').pipe(gulp.dest('build/img/index')),
a2 = gulp.src('app/img/layout/*').pipe(gulp.dest('build/img/layout')),
a3 = gulp.src('app/img/tutorials/**/*').pipe(gulp.dest('build/img/tutorials')),
a4 = gulp.src('app/img/buy/*').pipe(gulp.dest('build/img/buy')),
a5 = gulp.src('app/img/activity/**/*').pipe(gulp.dest('build/img/activity')),
a5 = gulp.src('app/img/about/*').pipe(gulp.dest('build/img/about')),
a6 = gulp.src('app/js/lib/*').pipe(gulp.dest('build/js/lib')),
a7 = gulp.src('app/style/css/lib/*').pipe(gulp.dest('build/style/css/lib')),
a7 = gulp.src('app/style/css/lib/fonts/*').pipe(gulp.dest('build/style/css/lib/fonts')),
a8 = gulp.src('app/robots.txt').pipe(gulp.dest('build')),
a9 = gulp.src('app/json/**/*').pipe(gulp.dest('build/json')),
a10 = gulp.src('app/ga/**/*').pipe(gulp.dest('build/ga')),
a11 = gulp.src('app/config/*').pipe(gulp.dest('build/config')),
s = gulp.src('app/onsale/**/*').pipe(gulp.dest('build/onsale')),
a12 = gulp.src('app/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('build/js')),
a13 = gulp.src('app/style/css/*.css')
.pipe(minifyCss())
.pipe(gulp.dest('build/style/css')),
a14 = gulp.src('app/tutorials/*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build/tutorials')),
a15 = gulp.src('app/buy/*')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build/buy')),
a16 = gulp.src('app/activity/**/*')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build/activity')),
a17 = gulp.src([
'app/index.html',
'app/tutorials.html',
'app/buy.html',
'app/about.html',
'app/activity.html'])
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build')),
b1 = gulp.src('app/en/json/**/*').pipe(gulp.dest('build/en/json')),
b2 = gulp.src('app/en/tutorials/*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build/en/tutorials')),
b3 = gulp.src('app/en/buy/*')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build/en/buy')),
b4 = gulp.src([
'app/en/index.html',
'app/en/tutorials.html',
'app/en/about.html',
'app/en/buy.html'])
.pipe(minifyHTML(opts))
.pipe(gulp.dest('build/en'));
return merge(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, b1, b2, b3, b4,s);
});
gulp.task('build',['move'], function () {
return gulp.src(['build/**/*.html','!build/ga/*.html'])
.pipe(sitemap({
siteUrl: 'https://webduino.io'
}))
.pipe(gulp.dest('build'));
});
gulp.task('default',['index','indexEN','include-final','buy-include','promote-include','tutorials-include-final','md2json','include-en-final','tutorials-en-include-final','md2json-en','less','watch']);