-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
91 lines (80 loc) · 2.66 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
86
87
88
89
90
91
var gulp = require('gulp')
var less = require('gulp-less')
var connect = require('gulp-connect')
var autoprefixer = require('gulp-autoprefixer')
var cleanCSS = require('gulp-clean-css')
var ghPages = require('@justeat/gulp-gh-pages')
var paths = {
styleSrc: './src/style/**/*.less',
styleEntries: ['./src/style/main.less', './src/style/views/demo-entry.less'],
styleDist: './dist/style',
scriptSrc: './src/script/**/*',
scriptDist: './dist/script',
imageSrc: './src/resource/image/**/*',
imageDist: './dist/resource/image',
templateSrc: './src/*',
templateDist: './dist',
staticPageSrc: ['./src/gallery/**/*', './src/plugins/**/*', './src/api/**/*'],
staticPageDist: ['./dist/gallery', './dist/plugins', './dist/api']
}
gulp.task('buildStyle', function () {
return gulp.src(paths.styleEntries)
.pipe(less())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cleanCSS())
.pipe(gulp.dest(paths.styleDist))
})
gulp.task('buildScript', function () {
return gulp.src(paths.scriptSrc)
.pipe(gulp.dest(paths.scriptDist))
})
gulp.task('copyPages', function () {
var tasks = paths.staticPageSrc.map(function (pageSrc, idx) {
return new Promise(function (resolve, reject) {
var stream = gulp.src(pageSrc).pipe(gulp.dest(paths.staticPageDist[idx]))
stream.on('end', function () {
resolve()
})
stream.on('error', function (err) {
reject(err)
})
})
})
return Promise.all(tasks)
})
gulp.task('buildImage', function () {
return gulp.src(paths.imageSrc)
.pipe(gulp.dest(paths.imageDist))
})
gulp.task('buildTemplate', function () {
return gulp.src(paths.templateSrc)
.pipe(gulp.dest(paths.templateDist))
})
gulp.task('watch', function () {
gulp.watch(paths.scriptSrc, ['buildScript'])
gulp.watch(paths.styleSrc, ['buildStyle'])
gulp.watch(paths.templateSrc, ['buildTemplate'])
gulp.watch(paths.imageSrc, ['buildImage'])
paths.staticPageSrc.forEach(function (pageSrc) {
gulp.watch(paths.pageSrc, ['copyPages'])
})
})
gulp.task('connect', function () {
connect.server({
root: 'dist',
livereload: true,
port: 2000
})
})
gulp.task('build', ['buildImage', 'buildTemplate', 'buildStyle', 'buildScript', 'copyPages'])
gulp.task('deploy', ['build'], function () {
return gulp.src('dist/**/*')
.pipe(ghPages({
branch: 'master',
message: 'Deploy to GitHub Pages [ci skip]'
}))
})
gulp.task('default', ['build', 'watch', 'connect'])