-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
135 lines (124 loc) · 3.1 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
var fs = require('fs');
var del = require('del');
var gulp = require('gulp');
var inject = require('gulp-inject');
var sitemap = require('gulp-sitemap');
var robots = require('gulp-robots');
var favicon = require('gulp-real-favicon');
var inlinesource = require('gulp-inline-source');
var htmlmin = require('gulp-htmlmin');
var imagemin = require('gulp-imagemin');
// Common pathes
var path = {
index: './src/index.html',
css: './src/css/**/*.css',
js: './src/js/**/*.js',
images: './src/images/**/*.*',
assets: './src/assets/**/rm-logo-border.png',
partials: './src/partials/*.html',
og: './src/partials/og-image.jpg',
gh: ['CNAME', '.nojekyll'],
favicon: {
description: './src/favicon/faviconDescription.json',
data: './src/favicon/faviconData.json',
},
dest: './build',
url: 'https://repometric.com',
};
// Clean output
gulp.task('clean', function () {
return del([
path.dest + '/**/*',
]);
});
// Copy static files
gulp.task('static', function () {
return gulp
.src([path.images, path.assets], {base: 'src'})
.pipe(gulp.dest(path.dest));
});
// Copy GitHub files
gulp.task('gh', function () {
return gulp
.src(path.gh)
.pipe(gulp.dest(path.dest));
});
// Inject partials
gulp.task('inject', ['favicons'], function() {
var faviconData = fs.readFileSync(path.favicon.data);
var code = JSON.parse(faviconData).favicon.html_code;
return gulp
.src(path.index)
.pipe(inlinesource({
compress: false,
}))
.pipe(favicon.injectFaviconMarkups(code))
.pipe(inject(gulp.src([path.partials]), {
starttag: '<!-- inject:{{path}} -->',
relative: true,
transform: function (filePath, file) {
return file.contents.toString('utf8');
},
}))
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
removeCommentsFromCDATA: true,
minifyCSS: true,
minifyJS: true,
}))
.pipe(gulp.dest(path.dest));
});
// Generate favicons
gulp.task('favicons', function(done) {
var faviconDescription = JSON.parse(fs.readFileSync(path.favicon.description));
faviconDescription.markupFile = path.favicon.data;
faviconDescription.dest = path.dest;
return favicon.generateFavicon(faviconDescription, function() {
done();
});
});
// Generate sitemap file
gulp.task('sitemap', function() {
return gulp
.src(path.index)
.pipe(sitemap({
siteUrl: path.url,
}))
.pipe(gulp.dest(path.dest));;
});
// Generate robots file
gulp.task('robots', function() {
return gulp
.src(path.index)
.pipe(robots({
useragent: '*',
allow: [],
disallow: [],
}))
.pipe(gulp.dest(path.dest));;
});
// Copy Open Graph image
gulp.task('og', function() {
return gulp
.src(path.og)
.pipe(gulp.dest(path.dest));
});
// Optimize images
gulp.task('images', ['favicons', 'inject'], function() {
return gulp
.src(path.dest + '/**/*')
.pipe(imagemin())
.pipe(gulp.dest(path.dest));
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', [
'static',
'favicons',
'sitemap',
'robots',
'og',
'gh',
'inject',
'images',
]);