-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
146 lines (133 loc) · 4.04 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
const gulp = require('gulp');
const gutil = require('gulp-util');
const fs = require('fs');
const os = require('os');
const path = require('path');
const configFile = path.join(os.homedir(), ".pianotriennale_site.json");
var config = {};
if (fs.existsSync(configFile)) {
gutil.log("Reading local config from [" + configFile + "]");
config = require(configFile);
} else {
gutil.log("No local config found at [" + configFile + "]");
}
const runSequence = require('run-sequence');
const clean = require('gulp-clean');
const shell = require('gulp-shell');
const imagemin = require('gulp-imagemin');
const pngquant = require('imagemin-pngquant');
const jpegtran = require('imagemin-jpegtran');
const gifsicle = require('imagemin-gifsicle');
const minifyHTML = require('gulp-htmlmin');
const cleanCss = require('gulp-clean-css');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const rsync = require('gulp-rsync');
gulp.task('jekyll', function() {
return gulp.src('README.md', {
read: false
})
.pipe(shell([
'bundle exec jekyll build'
]));
});
gulp.task('optimize-images', function() {
return gulp.src(['_site/**/*.jpg', '_site/**/*.jpeg', '_site/**/*.gif',
'_site/**/*.png'
])
.pipe(imagemin({
progressive: false,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngquant(), jpegtran(), gifsicle()]
}))
.pipe(gulp.dest('_site/'));
});
gulp.task('optimize-html', function() {
return gulp.src('_site/**/*.html')
.pipe(minifyHTML({
quotes: true
}))
.pipe(gulp.dest('_site/'));
});
gulp.task('optimize-css', function() {
return gulp.src('styles/*.css')
// .pipe(autoprefixer())
// .pipe(uncss({
// html: ['_site/**/*.html'],
// ignore: []
// }))
.pipe(cleanCss({
keepBreaks: false
}))
.pipe(gulp.dest('_site/styles'));
});
gulp.task('optimize-js', function() {
return gulp.src("js/*.js")
.pipe(concat('scripts.js'))
// .pipe(gulp.dest("_site/js"))
.pipe(rename('scripts.min.js'))
.pipe(uglify())
.pipe(gulp.dest("_site/js"));
});
gulp.task('clean', function() {
return gulp.src('_site', {
read: false
})
.pipe(clean());
});
gulp.task('build', function(cb) {
runSequence(
'clean',
'jekyll', [
// 'optimize-js',
// 'optimize-css',
'optimize-html'
//'optimize-images'
], cb);
});
if (config.staging || process.env.PIANOTRIENNALE_SITE_STAGING_SERVER) {
gulp.task('publish-staging', function() {
var publish_server = process.env.PIANOTRIENNALE_SITE_STAGING_SERVER || config.staging.server;
var publish_destination = process.env.PIANOTRIENNALE_SITE_STAGING_PATH || config.staging.path;
var publish_port = process.env.PIANOTRIENNALE_SITE_STAGING_PORT || config.staging.port;
return gulp.src('_site/**')
.pipe(rsync({
root: '_site',
hostname: publish_server,
destination: publish_destination,
port: publish_port,
recursive: true,
compress: true,
chmod: 'g+rwx',
chown: 'www-data:www-data',
perms: true,
owner: true,
group: true,
}));
});
} else {
gutil.log("No config for staging publish, task will be disabled");
}
if (config.production || process.env.PIANOTRIENNALE_SITE_PRODUCTION_SERVER) {
gulp.task('publish-production', function() {
var publish_server = process.env.PIANOTRIENNALE_SITE_PRODUCTION_SERVER || config.production.server;
var publish_destination = process.env.PIANOTRIENNALE_SITE_PRODUCTION_PATH || config.production.path;
var publish_port = process.env.PIANOTRIENNALE_SITE_PRODUCTION_PORT || config.production.port;
return gulp.src('_site/**')
.pipe(rsync({
root: '_site',
hostname: publish_server,
destination: publish_destination,
port: publish_port,
recursive: true,
compress: false,
progress: true,
command: true
}));
});
} else {
gutil.log("No config for production publish, task will be disabled");
}