-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·159 lines (132 loc) · 5.01 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
// modified from generator-jekyllized 1.0.0-rc.6
var gulp = require('gulp');
var requireDir = require('require-dir');
var fs = require('fs');
var yargs = require('yargs');
var yaml = require('js-yaml');
var del = require('del');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();;
var cssnano = require('gulp-cssnano');
var gulpif = require('gulp-if');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var rsync = require('gulp-rsync');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var wiredep = require('wiredep').stream;
var autoprefixer = require('gulp-autoprefixer');
var spawn = require('cross-spawn');
var sequence = require('run-sequence');
var purify = require('gulp-purifycss');
// --- Arguments
var PRODUCTION = !!(yargs.argv.production);
// Set the banner content
var banner = ['/*!\n',
' * Victor Caldas - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
' * Copyright 2016-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
' * Licensed under <%= pkg.license %> (https://github.com/vcaldas/<%= pkg.name %>/blob/master/LICENSE)\n',
' */\n',
''
].join('');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
// Gulp tasks
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
// Load configuration parameters
function loadConfig() {
var ymlFile = fs.readFileSync('gulp/gulpconfig.yml', 'utf8');
return yaml.load(ymlFile);
}
var config = loadConfig();
module.exports = config;
// Clean all compiled files
gulp.task('clean', function(done) {
del(config.clean);
done();
});
gulp.task('sass', function(done) {
return gulp.src(config.sass.src)
// .pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer(config.sass.compatibility))
.pipe(gulp.dest(config.sass.dest.jekyllRoot))
.pipe(gulpif(PRODUCTION, cssnano()))
// .pipe(gulpif(!PRODUCTION, sourcemaps.write()))
.pipe(gulp.dest(config.sass.dest.buildDir))
;
});
gulp.task('javascript', function(done) {
browserSync.notify(config.javascript.notification);
return gulp.src(config.javascript.src)
// .pipe(sourcemaps.init())
// .pipe(concat(config.javascript.filename))
// .pipe(gulpif(PRODUCTION, uglify()))
.pipe(gulp.dest(config.javascript.dest.jekyllRoot))
.pipe(gulp.dest(config.javascript.dest.buildDir));
});
gulp.task('css', function(done) {
return gulp.src(config.jekyll.css)
.pipe(purify([config.jekyll.site]))
.pipe(gulp.dest(config.sass.dest.jekyllRoot))
.pipe(gulpif(PRODUCTION, cssnano()))
// .pipe(gulpif(!PRODUCTION, sourcemaps.write()))
.pipe(gulp.dest(config.sass.dest.buildDir));
});
gulp.task('fonts', function() {
browserSync.notify(config.fonts.notification);
return gulp.src(config.fonts.src)
.pipe(gulp.dest(config.fonts.dest.jekyllRoot))
.pipe(gulp.dest(config.fonts.dest.buildDir));
});
gulp.task('copy', function() {
browserSync.notify(config.copy.notification);
return gulp.src(config.copy.assets)
.pipe(gulpif(PRODUCTION, imagemin()))
.pipe(gulp.dest(config.copy.dist));
});
/*
* Specify if tasks run in series or parallel using `gulp.series` and `gulp.parallel`
*/
var styles = gulp.series('sass');
var scripts = gulp.series('javascript');
var assets = gulp.series(styles, scripts, 'fonts');
// Define tasks
gulp.task('assets', assets)
gulp.task('jekyll-build', function(done) {
browserSync.notify(config.jekyll.notification);
return spawn('jekyll', ['build'], {
stdio: 'inherit'
})
.on('close', done);
});
//functions to have in the end
// build, deploy, dev, server
gulp.task('build', gulp.series('clean', assets, 'jekyll-build', 'copy'))
gulp.task('browser-sync', function() {
browserSync.init({
notify: config.browsersync.notify,
open: config.browsersync.open,
port: config.browsersync.port,
server: {
baseDir: config.browsersync.server.basedir
},
xip: config.browsersync.xip,
browser: config.browsersync.browser
});
});
gulp.task('watch', function() {
gulp.watch(config.watch.pages, gulp.series('jekyll-build') );
gulp.watch(config.watch.javascript, gulp.series(scripts));
gulp.watch(config.watch.sass, gulp.series(styles));
// gulp.watch(config.watch.images, gulp.series('copy', browserSync.reload));
gulp.watch('_site/**/*.*').on('change', browserSync.reload);
});
gulp.task('build-clean', gulp.series('build', 'css'))
gulp.task('default', gulp.series('build', gulp.parallel( 'browser-sync', 'watch')));
gulp.task('develop', gulp.parallel('browser-sync', 'watch'))
// gulp.task('deploy', function(done){
// sequence('build', 'rsync', done);
// });