-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
85 lines (71 loc) · 2.57 KB
/
gulpfile.js
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
const fs = require('fs');
const path = require('path');
const browserSync = require('browser-sync');
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const insert = require('gulp-insert');
const md = require('gulp-remarkable');
const name = require('gulp-rename');
const replace = require('gulp-replace');
const srcpath = 'src';
const outpath = 'build';
const postPrepend = fs.readFileSync(path.join(__dirname, srcpath, 'postprepend.html'), 'utf8');
const postAppend = fs.readFileSync(path.join(__dirname, srcpath, 'postappend.html'), 'utf8');
const titles = {
install: '安装GeoServer',
cors: '配置CORS',
wmi_intro: 'Web管理界面简介',
post_shape: '发布Shapefile图层',
style: 'WAI中设置样式',
style_udig: '使用uDig辅助样式设计',
tiles: '生成图层瓦片数据',
wms: '在Cesium中访问WMS服务',
optimize: '环境优化',
};
// Tasks
gulp.task('copyDepends', () => gulp
.src([`./${srcpath}/thirdparty/**`])
.pipe(gulp.dest(`${path.join(__dirname, outpath)}/thirdparty`)));
gulp.task('copyImages', () => gulp
.src([`./${srcpath}/images/**`])
.pipe(imagemin([imagemin.optipng()], { verbose : true }))
.pipe(gulp.dest(`${path.join(__dirname, outpath)}/images`)));
gulp.task('copyIndex', () => gulp
.src([`./${srcpath}/index.html`])
.pipe(gulp.dest(path.join(__dirname, outpath))));
gulp.task('buildPost', () => gulp
.src(`./${srcpath}/post/*.md`)
.pipe(md({
remarkableOptions: {
typographer: true,
linkify: true,
html: true,
},
}))
.pipe(insert.wrap(postPrepend, postAppend))
.pipe(name((filepath) => {
filepath.dirname += '/post';
// filepath.basename += '-goodbye';
filepath.extname = '.html';
}))
.pipe(gulp.dest(path.join(__dirname, outpath))));
gulp.task('changeTitle', ['buildPost'], () => gulp
.src(`./${outpath}/post/*.html`)
.pipe(replace('--title--', function () {
return `<title>${titles[this.file.relative.replace(/\.[^/.]+$/, '')] || 'GeoServer配置'}</title>`;
}))
.pipe(gulp.dest(`./${outpath}/post/`)));
gulp.task('md_watch', ['changeTitle'], browserSync.reload);
gulp.task('html_watch', ['copyIndex'], browserSync.reload);
// Watch
gulp.task('watch', () => {
browserSync({
server: {
baseDir: path.join(__dirname, outpath),
},
});
gulp.watch(`./${srcpath}/**/*.md`, ['md_watch']);
gulp.watch(`./${srcpath}/index.html`, ['html_watch']);
});
// Default Task
gulp.task('default', ['changeTitle', 'copyDepends', 'copyIndex', 'copyImages']);