-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
225 lines (168 loc) · 6.35 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
214
215
216
217
218
219
220
221
222
223
224
225
/* Gulp set up
--------------------------------------------------------------------------------- */
const gulp = require('gulp');
// load all plugins with prefix 'gulp'
const $ = require('gulp-load-plugins')();
const connect = require('gulp-connect-php');
const sequence = require('run-sequence');
const _ = require('./assets/build')(gulp);
/* Task: Compile SCSS
--------------------------------------------------------------------------------- */
gulp.task('build:styles', ['lint:styles'], () => {
_.conf.sass.includePaths = _.depsPath;
const styles = gulp.src(_.paths.styles, {base: _.paths.src})
.pipe($.sass(_.conf.sass).on('error', $.sass.logError))
.pipe($.autoprefixer(_.conf.autoprefixer))
.pipe($.cleanCss())
.on('error', _.logErrors);
return _.build(styles);
});
/* Task: Minify JS
--------------------------------------------------------------------------------- */
gulp.task('build:scripts', ['lint:scripts'], () => {
const scripts = gulp.src(_.paths.scripts, {base: _.paths.src})
.pipe($.babel({presets: ['es2015']}))
.on('error', _.logErrors)
.pipe($.uglify(_.conf.uglify))
.on('error', _.logErrors);
return _.build(scripts);
});
/* Task: Optimize image
--------------------------------------------------------------------------------- */
gulp.task('build:images', () => {
const images = gulp.src(_.paths.images, {base: _.paths.src})
.pipe($.changed(_.paths.dest))
.pipe($.imagemin(_.conf.imagemin))
.on('error', _.logErrors);
return _.build(images);
});
/* Task: Optimize image
--------------------------------------------------------------------------------- */
gulp.task('build:fonts', (done) => {
const path = require('path');
gulp.src(_.paths.fonts, {base: _.paths.src})
.pipe(gulp.dest((file) => {
file.path = file.base + path.basename(file.path);
return _.paths.dest + 'fonts/';
}));
return done();
});
/* Task: Lint SCSS
--------------------------------------------------------------------------------- */
gulp.task('lint:styles', () => {
_.conf.sass.includePaths = _.depsPath;
return gulp.src(_.paths.styles, {base: _.paths.src})
.pipe($.sassLint(_.conf.sasslint))
.pipe($.sassLint.format())
.pipe($.sassLint.failOnError());
});
/* Task: Lint JS
--------------------------------------------------------------------------------- */
gulp.task('lint:scripts', () => {
return gulp.src(_.paths.scripts, {base: _.paths.src})
.pipe($.eslint(_.conf.eslint))
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
});
/* Task: Vendor
--------------------------------------------------------------------------------- */
gulp.task('vendor:copy', ['modernizr'], () => {
return gulp.src(_.vendors)
.pipe(gulp.dest(_.paths.vendor));
});
/* Task: Minify Vendor scripts
--------------------------------------------------------------------------------- */
gulp.task('vendor:scripts', () => {
return gulp.src(_.paths.vendor + '/**/*.js')
.pipe($.uglify(_.conf.uglify))
.on('error', _.logErrors)
.pipe(gulp.dest(_.paths.vendor));
});
/* Task: Minify Vendor scripts
--------------------------------------------------------------------------------- */
gulp.task('vendor:styles', () => {
return gulp.src(_.paths.vendor + '/**/*.css')
.pipe($.cleanCss())
.on('error', _.logErrors)
.pipe(gulp.dest(_.paths.vendor));
});
/* Task: Modernizr
--------------------------------------------------------------------------------- */
gulp.task('modernizr', () => {
const conf = _.conf.modernizr;
return gulp.src(_.paths.src + '**/*.{js,scss}')
.pipe($.modernizr(conf.filename, conf.settings))
.pipe(gulp.dest(_.paths.vendor));
});
/* Task: Serve
--------------------------------------------------------------------------------- */
gulp.task('serve', () => {
if (_.isLocal) {
return connect.server(_.server, _.sync);
}
return _.sync();
});
/* Task: Watch
--------------------------------------------------------------------------------- */
gulp.task('watch', ['serve'], (done) => {
// SCSS & Minify
gulp.watch(_.paths.styles, ['build:styles']);
// ES2015 & Uglify
gulp.watch(_.paths.scripts, ['build:scripts']);
// Imagemin
gulp.watch(_.paths.images, ['build:images']);
// Reload
gulp.watch(_.conf.patterns.server)
.on('change', _.bSync.reload);
// Done
return done();
});
/* Task: Test Behaviour
--------------------------------------------------------------------------------- */
gulp.task('test:bdd', (done) => {
gulp.src('./tests/webdriver.js')
.pipe($.webdriver(_.wdio));
return done();
});
/* Task: Deploy Wiki Pages
--------------------------------------------------------------------------------- */
gulp.task('deploy:wiki', (done) => {
const exec = require('child_process').exec;
const ghUser = !_.isLocal && 'GH_USER_TOKEN' in process.env ? process.env.GH_USER_TOKEN : 'git';
let command = [
'git subtree push -P docs/wiki',
ghUser + '@github.com:projek-xyz/slim-skeleton.wiki.git',
'master'
];
exec(command.join(' '), (err, stdout, stderr) => {
_.log(stdout);
_.log(stderr, 'red');
done(err);
});
});
/* Task: Clean
--------------------------------------------------------------------------------- */
gulp.task('clean', () => {
const del = require('del');
return del([_.paths.dest, _.paths.vendor]).then(() => {
_.log('Assets directory cleaned', 'green');
});
});
/* Task: Vendor
--------------------------------------------------------------------------------- */
gulp.task('vendor', (done) => {
sequence('vendor:copy', 'vendor:scripts', 'vendor:styles', done);
});
/* Task: Build
--------------------------------------------------------------------------------- */
gulp.task('build', (done) => {
sequence('build:styles', 'build:scripts', 'build:images', 'build:fonts', done);
});
/* Task: Lint
--------------------------------------------------------------------------------- */
gulp.task('lint', ['lint:styles', 'lint:scripts']);
/* Task: Default
--------------------------------------------------------------------------------- */
gulp.task('default', (done) => {
sequence('clean', 'build', 'vendor', done);
});