-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
128 lines (108 loc) · 2.83 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
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
'use strict'
const fs = require('fs')
const path = require('path')
const del = require('del')
const gitRevSync = require('git-rev-sync')
const ghpages = require('gh-pages')
const gulp = require('gulp')
const $ = require('gulp-load-plugins')()
const pkg = require('./package.json')
let paths = {src: 'app', dist: 'public'}
paths = Object.assign(paths, {
html: `${paths.dist}/**/*.html`,
images: `${paths.dist}/**/*.{gif,jpg,png}`,
scripts: `${paths.src}/**/*.js`,
styles: `${paths.src}/**/*.scss`
})
gulp.task('default', [
'lint',
'watch'
])
gulp.task('lint', [
'sass-lint',
'standard'
])
gulp.task('minify', [
'htmlmin',
'imagemin'
])
gulp.task('watch', [
'watch:html',
'watch:scripts',
'watch:styles'
])
gulp.task('clean', () => (del(paths.dist)))
gulp.task('htmlhint', () => {
return gulp.src(paths.html)
.pipe($.htmlhint())
.pipe($.htmlhint.failReporter())
})
gulp.task('standard', () => {
return gulp.src(paths.scripts)
.pipe($.standard())
.pipe($.standard.reporter('default', {
breakOnError: true
}))
})
gulp.task('sass-lint', () => {
return gulp.src(paths.styles)
.pipe($.sassLint())
.pipe($.sassLint.format())
.pipe($.sassLint.failOnError())
})
gulp.task('watch:html', () => {
return gulp.src(paths.html)
.pipe($.watch(paths.html))
.pipe($.plumber())
.pipe($.htmlhint())
.pipe($.htmlhint.reporter())
})
gulp.task('watch:scripts', () => {
return gulp.src(paths.scripts)
.pipe($.watch(paths.scripts))
.pipe($.plumber())
.pipe($.standard())
.pipe($.standard.reporter('default'))
})
gulp.task('watch:styles', () => {
return gulp.src(paths.styles)
.pipe($.watch(paths.styles))
.pipe($.plumber())
.pipe($.sassLint())
.pipe($.sassLint.format())
})
gulp.task('imagemin', () => {
return gulp.src(paths.images)
.pipe($.imagemin())
.pipe(gulp.dest(paths.dist))
})
gulp.task('htmlmin', () => {
return gulp.src(paths.html)
.pipe($.htmlmin({
collapseBooleanAttributes: true,
collapseWhitespace: true,
preserveLineBreaks: true,
removeComments: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest(paths.dist))
})
gulp.task('deploy', (done) => {
fs.openSync(path.join(paths.dist, '.nojekyll'), 'w')
return ghpages.publish(paths.dist, {
clone: '.deploy',
depth: 2,
dotfiles: true,
message: `Deploy ${gitRevSync.short()} from v${pkg.version} [ci skip]`,
repo: process.env.DEPLOY_REPO || `[email protected]:${pkg.repository}.git`,
branch: process.env.DEPLOY_BRANCH || 'gh-pages',
logger: (message) => { console.log(`[ deploy ] ${message}`) },
user: {
name: process.env.DEPLOY_NAME || pkg.author.name,
email: process.env.DEPLOY_EMAIL || pkg.author.email
}
}, done)
})