-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
202 lines (176 loc) · 4.79 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
190
191
192
193
194
195
196
197
198
199
200
201
var gulp = require('gulp'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
cp = require('child_process'),
harp = require('harp'),
harpConfig = require('./harp.json'),
jimp = require('gulp-jimp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
runSequence = require('run-sequence');
/**
* Serve the Harp Site
*/
gulp.task('serve', ['fast-build'], function () {
harp.server('.', {
port: 3330
}, function () {
browserSync({
proxy: "localhost:3330",
open: false,
port: 3333,
ui: {
port: 3335
}
});
/**
* Watch for scss changes, tell BrowserSync to refresh main.css
*/
gulp.watch(["public/**/*.scss"], function () {
reload("public/css/app.css", {stream: true});
cp.exec('harp compile . www', {stdio: 'inherit'});
});
/**
* Watch for image changes
*/
gulp.watch(["public/_posts-images/*"], ['jimp']);
gulp.watch(["public/images/**/*"], function () {
reload();
cp.exec('harp compile . www', {stdio: 'inherit'});
});
/**
* Watch for JS changes
*/
gulp.watch(["public/_scripts/*.js"], ['uglify']);
gulp.watch(["public/js/**/*"], function () {
reload();
cp.exec('harp compile . www', {stdio: 'inherit'});
});
/**
* Watch for all other changes, reload the whole page
*/
gulp.watch(["public/**/*.jade", "public/**/*.json", "public/**/*.md", "public/**/*.ejs"], function () {
reload();
cp.exec('harp compile . www', {stdio: 'inherit'});
});
});
});
/**
* Serve the Harp Site in production
*/
gulp.task('serveprod', ['build'], function() {
harp.server('.', {
port: process.env.PORT || 5000
}, function () {
});
});
/**
* Build the Harp Site
*/
gulp.task('build', ['copy-css-assets', 'jimp', 'uglify'], function () {
return cp.exec('harp compile . www', {stdio: 'inherit'});
});
/**
* Build the Harp Site without jimp
*/
gulp.task('fast-build', ['copy-css-assets', 'uglify'], function () {
return cp.exec('harp compile . www', {stdio: 'inherit'});
});
// Jimp variables
var imgSrc = 'public/_posts-images/*',
imgDest = 'public/images/posts/',
imgQuality = 80,
largeWidth = harpConfig.globals.breakpoints.large,
regularWidth = harpConfig.globals.breakpoints.regular,
mediumWidth = harpConfig.globals.breakpoints.medium,
smallWidth = harpConfig.globals.breakpoints.small;
// Clean the image folder
gulp.task('jimp-clean', function() {
return cp.exec('rm ' + imgDest + '*', {stdio: 'inherit'});
});
// Copy original image
gulp.task('jimp-original', function() {
return gulp.src(imgSrc).pipe(gulp.dest(imgDest));
});
// Create large image
gulp.task('jimp-large', function() {
return gulp.src(imgSrc).pipe(jimp({
'-large': {
resize: { width: largeWidth, height: jimp.AUTO },
quality: imgQuality
}
})).pipe(gulp.dest(imgDest));
});
// Create Regular image
gulp.task('jimp-regular', function() {
// Regular image
return gulp.src(imgSrc).pipe(jimp({
'-regular': {
resize: { width: regularWidth, height: jimp.AUTO },
quality: imgQuality
}
})).pipe(gulp.dest(imgDest));
});
// Create Medium image
gulp.task('jimp-medium', function() {
return gulp.src(imgSrc).pipe(jimp({
'-medium': {
resize: { width: mediumWidth, height: jimp.AUTO },
quality: imgQuality
}
})).pipe(gulp.dest(imgDest));
});
// Create Small image
gulp.task('jimp-small', function() {
return gulp.src(imgSrc).pipe(jimp({
'-small': {
resize: { width: smallWidth, height: jimp.AUTO },
quality: imgQuality
}
})).pipe(gulp.dest(imgDest));
});
/**
* Create responsive images with JIMP
*
* We divide this into several tasks so we can have a callback
* and make sure 'build' runs after it's finished.
*/
gulp.task('jimp', function (callback) {
runSequence(
'jimp-clean',
['jimp-original','jimp-large', 'jimp-regular', 'jimp-medium', 'jimp-small'],
callback
);
});
/**
* Copy css assets from NODE Modules
*/
gulp.task('copy-css-assets', function() {
return gulp.src(
/** Insert below the css path **/
[' ']
).pipe(gulp.dest('./public/css/vendors'));
});
/**
* Copy js assets from NODE Modules
*/
gulp.task('copy-js-assets', function() {
return gulp.src(
/** Insert below the js path **/
[' ']
).pipe(gulp.dest('./public/_scripts'));
});
/**
* Concatenate JS files
*/
gulp.task('uglify', ['copy-js-assets'], function () {
return gulp.src([
'public/_scripts/jquery-1.10.2.min.js',
'public/_scripts/site.js'
]).pipe(concat('site.min.js')).pipe(uglify()).pipe(gulp.dest('public/js'));
});
/**
* Default task, running `gulp` will fire up the Harp site,
* launch BrowserSync & watch files.
*/
gulp.task('default', ['serve']);