-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
98 lines (88 loc) · 2.72 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
'use strict';
const gulp = require('gulp')
, browserSync = require('browser-sync').create()
, reload = browserSync.reload
, moment = require('moment')
, less = require('gulp-less')
, autoprefixer = require('gulp-autoprefixer')
, plumber = require('gulp-plumber')
, notify = require('gulp-notify')
, pug = require('gulp-pug')
, inline = require('gulp-inline-source')
, ghPages = require('gh-pages')
, countdown = require('countdown')
, del = require('del')
, dist = './dist'
, episodeName = 'Star Wars: The Mandalorian Season 3'
, nextReleaseArr = require('./nextRelease.json')
, nextRelease = new Date(...nextReleaseArr)
;
// browser-sync task for starting the server.
gulp.task('browser-sync', () => {
browserSync.init({
server: {
baseDir: [dist, './static']
}
});
});
gulp.task('less', () => {
return gulp.src('less/*.less')
.pipe(plumber())
.pipe(less({
paths: ['./node_modules']
}))
.pipe(autoprefixer())
.pipe(gulp.dest(dist))
.pipe(notify('Finished file: <%= file.relative %>'));
});
gulp.task('js', () => {
return gulp.src(['js/*.js'])
.pipe(plumber())
.pipe(gulp.dest(dist))
.pipe(notify('Finished file: <%= file.relative %>'));
});
gulp.task('pug', ['js', 'less'], () => {
return gulp.src('pug/index.pug')
.pipe(plumber())
.pipe(pug({
locals: {
description: timeString(),
episodeName,
nextRelease,
dateString: moment(nextRelease).format('MMMM D, YYYY')
// dateString: moment(nextRelease).format('MMMM YYYY')
}
}))
.pipe(inline())
.pipe(gulp.dest(dist))
.pipe(notify('Finished file: <%= file.relative %>'));
});
gulp.task('static', () => {
return gulp.src('static/**/*')
.pipe(gulp.dest(dist))
});
gulp.task('clean', () => {
del.sync('./dist')
});
// Default task to be run with `gulp`
gulp.task('default', ['pug', 'less', 'js', 'browser-sync'], () => {
gulp.watch(['pug/*.pug', 'less/*.less', 'js/*.js'], ['pug']);
gulp.watch('./dist/*.html').on('change', reload);
});
gulp.task('deploy', ['clean', 'pug', 'less', 'js', 'static'], cb => {
const opt = {
message: `Update ${new Date().toISOString()} [skip ci]`
};
if (process.env.REMOTE_URL) {
opt.repo = process.env.REMOTE_URL;
}
ghPages.publish('./dist', opt, cb);
});
function timeString() {
const time = countdown(nextRelease);
const str = [];
if (time.years) str.push(time.years + ' year' + (time.years > 1 ? 's' : ''));
if (time.months) str.push(time.months + ' month' + (time.months > 1 ? 's' : ''));
if (time.days) str.push(time.days + ' day' + (time.days > 1 ? 's' : ''));
return str.join(', ') + ` until ${episodeName}!`;
}