-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
213 lines (193 loc) · 5.13 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
202
203
204
205
206
207
208
209
210
211
212
213
'use strict';
/**
* gulp modules
*/
var argv = require('yargs').argv;
var autoprefixer = require('autoprefixer');
var browsersync = require('browser-sync').create();
var cp = require('child_process');
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var named = require('vinyl-named');
var newer = require('gulp-newer');
var plumber = require('gulp-plumber');
var pngquant = require('imagemin-pngquant');
var postcss = require('gulp-postcss');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
var webpack = require('webpack-stream');
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
// Load configurations & set variables
var config = require('./frasco.config.js');
var tasks = [];
var build = [];
var paths = {};
var entry = [];
/**
* Set default & build tasks
*/
Object.keys(config.tasks).forEach(function (key) {
if (config.tasks[key]) {
tasks.push(key == 'webpack' ? '_' + key : key);
}
});
Object.keys(config.tasks).forEach(function (key) {
if (config.tasks[key] && key != 'server') {
build.push(key);
}
});
/**
* Paths
*/
Object.keys(config.paths).forEach(function (key) {
if (key != 'assets') {
if (config.paths.assets === '') {
paths[key] = './' + config.paths[key];
} else {
paths[key] = config.paths.assets + '/' + config.paths[key];
}
}
});
for (var i = 0; i <= config.js.entry.length - 1; i++) {
entry.push(paths.jsSrc + '/' + config.js.entry[i]);
}
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function (done) {
var jekyllConfig = config.jekyll.config.default;
if (argv.production) {
process.env.JEKYLL_ENV = 'production';
jekyllConfig += config.jekyll.config.production ? ',' + config.jekyll.config.production : '';
} else {
jekyllConfig += config.jekyll.config.development ? ',' + config.jekyll.config.development : '';
}
return cp.spawn(jekyll, ['build', '--config', jekyllConfig], {stdio: 'inherit', env: process.env})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browsersync.notify('Rebuilded Jekyll');
browsersync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('server', ['jekyll-build'], function() {
return browsersync.init({
port: config.port,
server: {
baseDir: config.paths.dest,
}
});
});
/**
* Sass
*/
gulp.task('sass', function () {
return gulp.src(paths.sass + '/**/*')
.pipe(sass({outputStyle: config.sass.outputStyle}).on('error', sass.logError))
.pipe(postcss([
autoprefixer({
browsers: config.autoprefixer.browsers
})
]))
.pipe(gulp.dest(paths.css));
});
/**
* imagemin
*/
gulp.task('imagemin', function () {
return gulp.src(paths.imagesSrc + '/**/*')
.pipe(plumber())
.pipe(newer(paths.images))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(paths.images));
});
gulp.task('eslint', function() {
return gulp.src(entry)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
/**
* Webpack
*
* Bundle JavaScript files
*/
//gulp.task('webpack', ['eslint'], function () {
gulp.task('webpack', function () {
return gulp.src(entry)
.pipe(plumber())
.pipe(named())
.pipe(webpack({
watch: argv.watch ? true : false,
}))
.pipe(uglify())
.pipe(gulp.dest(paths.js));
});
// For internal use only
gulp.task('_webpack', function () {
argv.watch = true;
gulp.start('webpack');
});
/**
* Build
*/
gulp.task('build', build, function (done) {
var jekyllConfig = config.jekyll.config.default;
if (argv.production) {
process.env.JEKYLL_ENV = 'production';
jekyllConfig += config.jekyll.config.production ? ',' + config.jekyll.config.production : '';
} else {
jekyllConfig += config.jekyll.config.development ? ',' + config.jekyll.config.development : '';
}
return cp.spawn(jekyll, ['build', '--config', jekyllConfig], {stdio: 'inherit', env: process.env})
.on('close', done);
});
/**
* Default task, running just `gulp` will minify the images, compile the sass, js, and jekyll site,
* launch BrowserSync, and watch files. Tasks can be configured by frascoconfig.json.
*/
gulp.task('default', tasks, function () {
if (config.tasks.imagemin) {
watch(paths.imagesSrc + '/**/*', function () {
gulp.start('imagemin');
});
}
if (config.tasks.sass) {
watch(paths.sass + '/**/*', function () {
gulp.start('sass');
});
}
if (config.tasks['server']) {
watch([
'!./node_modules/**/*',
'!./README.md',
'!' + paths.dest + '/**/*',
'_includes/**/*',
'_layouts/**/*',
'*.html',
'./**/*.md',
'./**/*.markdown',
paths.posts + '/**/*',
paths.css + '/**/*',
paths.js + '/**/*',
paths.images + '/**/*'
], function () {
gulp.start('jekyll-rebuild');
});
}
});
/**
* Test
*/
gulp.task('test', ['build']);