This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
162 lines (139 loc) · 3.35 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
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
'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',
build: 'public',
dist: 'dist'
}
paths = Object.assign(paths, {
html: `${paths.build}/**/*.html`,
images: `${paths.build}/**/*.{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.build,
paths.dist
])
))
gulp.task('htmlhint', () => (
gulp.src(paths.html)
.pipe($.htmlhint())
.pipe($.htmlhint.failReporter())
))
gulp.task('standard', () => (
gulp.src(paths.scripts)
.pipe($.standard())
.pipe($.standard.reporter('default', {
breakOnError: true
}))
))
gulp.task('sass-lint', () => (
gulp.src(paths.styles)
.pipe($.sassLint())
.pipe($.sassLint.format())
.pipe($.sassLint.failOnError())
))
gulp.task('watch:html', () => (
gulp.src(paths.html)
.pipe($.watch(paths.html))
.pipe($.plumber())
.pipe($.htmlhint())
.pipe($.htmlhint.reporter())
))
gulp.task('watch:scripts', () => (
gulp.src(paths.scripts)
.pipe($.watch(paths.scripts))
.pipe($.plumber())
.pipe($.standard())
.pipe($.standard.reporter('default'))
))
gulp.task('watch:styles', () => (
gulp.src(paths.styles)
.pipe($.watch(paths.styles))
.pipe($.plumber())
.pipe($.sassLint())
.pipe($.sassLint.format())
))
gulp.task('imagemin', () => (
gulp.src(paths.images)
.pipe($.imagemin())
.pipe(gulp.dest(paths.build))
))
gulp.task('htmlmin', () => (
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.build))
))
gulp.task('rev', ['minify'], () => {
const dontRev = [
'404.html',
'index.html',
'humans.txt',
'robots.txt',
'crossdomain.xml',
'image.png'
]
const revAll = new $.revAll({ // eslint-disable-line new-cap
prefix: typeof process.env.ASSET_PREFIX === 'string'
? process.env.ASSET_PREFIX
: '/deck-bespoke.js',
dontRenameFile: dontRev,
dontUpdateReference: dontRev
})
return gulp.src(`${paths.build}/**`)
.pipe(revAll.revision())
.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)
})