/
gulpfile.js
166 lines (143 loc) · 3.87 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
const _ = require('underscore');
const awspublish = require('gulp-awspublish');
const del = require('del');
const es = require('event-stream');
const gulp = require('gulp');
const mkdirp = require('mkdirp');
const path = require('path');
const runSequence = require('run-sequence');
const sass = require('gulp-sass');
const transblogify = require('./lib/transblogify');
// Live Reload
// http://rhumaric.com/2014/01/livereload-magic-gulp-style/
const express = require('express');
let app;
const EXPRESS_PORT = 4000;
const EXPRESS_ROOT = __dirname + '/build';
const LIVERELOAD_PORT = 35729;
const SITE_ROOT = 'http://www.thedahv.com';
function startExpress() {
if (!app) {
app = express();
app.use(require('connect-livereload')());
app.use(express.static(EXPRESS_ROOT));
app.listen(EXPRESS_PORT);
}
}
let lr = null;
function startLiveReload() {
lr = require('tiny-lr')();
lr.listen(LIVERELOAD_PORT);
}
function notifyLivereload(event) {
if (event) {
console.log(event);
gulp.src(event.path, {read: false})
.pipe(require('gulp-livereload')(lr));
}
//var fileName = require('path').relative(EXPRESS_ROOT, event.path);
//lr.changed({ body: { files: [fileName] } });
}
// Generate pygments stylesheets:
// http://funcptr.net/2011/11/27/generating-stylesheets-for-pygments/
// https://github.com/chjj/marked
gulp.task('clean',
del.bind(del, [
'build/**/*',
'!build/about',
'!build/about/davidpierce-resume.pdf'
]
));
gulp.task('posts', () => {
return transblogify.posts({
'postsDir': 'posts',
'postsPattern': '*.md',
'outputDir': 'build',
'categories': true,
'templatesDir': 'templates',
'defaultPostTemplate': 'post'
});
});
gulp.task('pages', () => {
return transblogify.pages({
'templatesDir': 'templates',
'pagesDir': 'pages',
'outputDir': 'build'
});
});
gulp.task('sass', () => {
mkdirp.sync('./build/css');
return gulp.src('./assets/sass/application.scss')
.pipe(sass({
errLogToConsole: true,
sourceComments: 'map',
outputStyle: 'compressed'
}))
.pipe(gulp.dest('./build/css'));
});
gulp.task('watchsrc', () => {
gulp.watch([ 'assets/sass/*/**.scss' ], [ 'sass' ]);
gulp.watch(
[
'posts/**/*',
'pages/**/*',
'templates/**/*',
'data/**/*'
],
['build']
);
});
gulp.task('move-assets', () => {
mkdirp.sync('build/images');
mkdirp.sync('build/js');
gulp.src('assets/js/*')
.pipe(gulp.dest('build/js'));
return gulp.src('assets/images/**/*')
.pipe(gulp.dest('build/images'));
});
gulp.task('create-sitemap', () => {
return transblogify.sitemap({ siteRoot: SITE_ROOT });
});
gulp.task('redirects', () => {
const {client} = awspublish.create(require('./awscredentials.json'));
return transblogify.redirects()
.pipe(es.map((Key, callback) => {
console.log(Key);
client.putObject({
ACL: 'public-read',
Key,
WebsiteRedirectLocation: `https://www.thedahv.com/${Key}/`
}, callback);
}))
.pipe(awspublish.reporter());
});
gulp.task('build', () => {
runSequence(
'clean',
'pages',
'posts',
'sass',
'move-assets',
'create-sitemap'
);
});
gulp.task('autoserve', ['build', 'watchsrc'], () => {
startExpress();
startLiveReload();
// Wait 2 seconds before watching for live reload
setTimeout(function () {
gulp.watch(['build/**/*'], function (changeEvent) {
let changedFile = path.relative(EXPRESS_ROOT, changeEvent.path);
lr.changed({ body: { files: [changedFile] } });
});
}, 2000);
});
gulp.task('publish', () => {
const publisher = awspublish.create(require('./awscredentials.json'));
return gulp.src('build/**/*')
.pipe(publisher.publish())
.pipe(publisher.sync())
.pipe(publisher.cache())
.pipe(awspublish.reporter());
});
gulp.task('default', ['build']);