forked from AdoptOpenJDK/openjdk-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
189 lines (171 loc) · 5.17 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
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
const gulp = require('gulp');
const runSequence = require('run-sequence');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const cssmin = require('gulp-minify-css');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const prefix = require('gulp-autoprefixer');
const imagemin = require('gulp-imagemin');
const handlebars = require('gulp-compile-handlebars');
const eslint = require('gulp-eslint');
const gutil = require('gulp-util');
const sitemap = require('gulp-sitemap');
const hash = require('gulp-hash');
const inject = require('gulp-inject');
const robots = require('gulp-robots');
const clean = require('gulp-clean');
const babel = require('gulp-babel');
// default task
gulp.task('default', function() {
runSequence('clean',['handlebars','json','scripts','styles','images','icon'],'inject','watch','browser-sync');
});
// build task
gulp.task('build', function() {
runSequence('clean',['handlebars','json','scripts','styles','images','icon'],'inject','sitemap','robots','lint');
});
// clean task (deletes /dist dir)
gulp.task('clean', function () {
return gulp.src('dist', {read: false})
.pipe(clean());
});
// watch task
gulp.task('watch', function() {
gulp.watch(['./src/handlebars/partials/*.handlebars', './src/handlebars/*.handlebars'], function() {
runSequence('handlebars','inject', browserSync.reload);
});
gulp.watch('./src/json/*.json', function() {
runSequence('json', browserSync.reload);
});
gulp.watch('./src/js/**/*.js', function() {
runSequence('scripts','inject', browserSync.reload);
});
gulp.watch('./src/scss/*.scss', function() {
runSequence('styles','inject', browserSync.reload);
});
gulp.watch(['./src/assets/*.jp*', './src/assets/*.png', './src/assets/*.gif'], ['images']);
gulp.watch('./src/assets/*.ico', ['icon']);
});
// Handlebars HTML build task
gulp.task('handlebars', function () {
var templateData = {
},
options = {
batch : ['./src/handlebars/partials']
}
return gulp.src('./src/handlebars/*.handlebars')
.pipe(handlebars(templateData, options))
.on('error', gutil.log)
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest('./'));
});
// json task
gulp.task('json', function() {
return gulp.src('./src/json/*.json')
.pipe(gulp.dest('./dist/json/'));
});
// scripts task
gulp.task('scripts', function() {
return gulp.src('./src/js/**/*.js')
.pipe(babel({presets: ['es2015']}))
.pipe(concat('app.js'))
.on('error', gutil.log)
.pipe(gulp.dest('./dist/js/'))
.pipe(uglify())
.on('error', gutil.log)
.pipe(rename({
suffix: '.min'
}))
.pipe(hash()) // Add hashes to the files' names
.on('error', gutil.log)
.pipe(gulp.dest('./dist/js/'))
.pipe(hash.manifest('assetsJS.json', {
deleteOld: true,
sourceDir: __dirname + '/dist/js'
})) // Switch to the manifest file
.on('error', gutil.log)
.pipe(gulp.dest('./dist/')); // Write the manifest file
});
// styles task
gulp.task('styles', function() {
return gulp.src('./src/scss/*.scss')
.pipe(sass())
.on('error', gutil.log)
.pipe(prefix('last 2 versions'))
.on('error', gutil.log)
.pipe(concat('styles.css'))
.on('error', gutil.log)
.pipe(gulp.dest('./dist/css/'))
.pipe(cssmin())
.on('error', gutil.log)
.pipe(rename({
suffix: '.min'
}))
.pipe(hash()) // Add hashes to the files' names
.on('error', gutil.log)
.pipe(gulp.dest('./dist/css/'))
.pipe(hash.manifest('assetsCSS.json', {
deleteOld: true,
sourceDir: __dirname + '/dist/css'
})) // Switch to the manifest file
.on('error', gutil.log)
.pipe(gulp.dest('./dist/')); // Write the manifest file
});
// inject task
gulp.task('inject', function() {
var sourceFiles = gulp.src(['./dist/js/app.min-*.js', './dist/css/styles.min-*.css'], {read: false}, {relative: true});
var targetFiles = gulp.src('./*.html');
return targetFiles.pipe(inject(sourceFiles)) // injects the latest minified JS and CSS into all HTML files
.pipe(gulp.dest('./'));
});
// images task
gulp.task('images', function() {
return gulp.src(['./src/assets/*.jp*', './src/assets/*.png', './src/assets/*.gif'])
.pipe(imagemin())
.on('error', gutil.log)
.pipe(gulp.dest('./dist/assets/'));
});
// icon task
gulp.task('icon', function() {
return gulp.src('./src/assets/*.ico')
.pipe(gulp.dest('./dist/assets/'));
});
// lint task
gulp.task('lint', function() {
return gulp.src('./dist/js/app.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// sitemap task
gulp.task('sitemap', function () {
gulp.src('./*.html', {
read: false
})
.pipe(sitemap({
siteUrl: 'https://adoptopenjdk.net'
}))
.pipe(gulp.dest('./'));
});
// browser-sync task
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: './'
},
notify: false
});
});
// robots task
gulp.task('robots', function () {
gulp.src('index.html')
.pipe(robots({
useragent: '*',
allow: ['/'],
disallow: ['/404.html', '/banner.html']
}))
.pipe(gulp.dest('./'));
});