-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
196 lines (154 loc) · 5.48 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
/**
* Gravity Department - Frontend Starter
* https://github.com/gravitydepartment/frontend-starter
*
* @author Brendan Falkowski
* @copyright Gravity Department. All rights reserved.
*/
// ==============================================
// Require Packages
// ==============================================
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var del = require('del');
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var imagemin = require('gulp-imagemin');
var minimist = require('minimist');
var notify = require('gulp-notify');
var pipeline = require('stream').pipeline;
var sass = require('gulp-sass');
var stylelint = require('gulp-stylelint');
var uglify = require('gulp-uglify');
// GravDept modules
var config = require('./gulp/config');
var errorFormatter = require('./gulp/error-formatter');
// ==============================================
// Arguments
// ==============================================
var arguments = minimist(process.argv.slice(2));
// Use "gulp --hide-notify" to suppress Mac/Windows notifications.
var hideNotify = (arguments['hide-notify']) ? true : false;
// ==============================================
// Clean
// ==============================================
/**
* Delete old generated files.
* Return a "promise" to ensure completion before proceeding to generation tasks.
* See: https://github.com/sindresorhus/del/releases/tag/v2.0.0
* @return {promise}
*/
function clean () {
return del(config.task.clean.pathsToDelete);
};
// ==============================================
// CSS
// ==============================================
function css () {
var task = config.task.css;
return pipeline([
gulp.src(task.src, { sourcemaps: true }),
sass(task.sassOptions),
autoprefixer(task.autoprefixerOptions),
gulpif(!hideNotify, notify(task.notifyOptions)),
gulp.dest(task.dest, { sourcemaps: task.mapDest })
], errorFormatter);
};
// ==============================================
// Image
// ==============================================
function image () {
var task = config.task.image;
return pipeline([
gulp.src(task.src, { since: gulp.lastRun(image) }),
imagemin([
imagemin.gifsicle(task.imageminOptions.gif),
imagemin.mozjpeg(task.imageminOptions.jpg),
imagemin.optipng(task.imageminOptions.png),
imagemin.svgo(task.imageminOptions.svg)
]),
gulpif(!hideNotify, notify(task.notifyOptions)),
gulp.dest(task.dest)
], errorFormatter);
};
// ==============================================
// JS
// ==============================================
/**
* @param {object} task - Task config object like `config.task.taskName`
* @return {function} - See: https://github.com/gulpjs/gulp/issues/2039
*/
function bundleJs (task) {
return pipeline([
gulp.src(task.src, { sourcemaps: true }),
uglify(task.uglifyOptions),
concat(task.file),
gulpif(!hideNotify, notify(task.notifyOptions)),
gulp.dest(task.dest, { sourcemaps: task.mapDest })
], errorFormatter);
}
var jsAppPost = () => bundleJs(config.task.jsAppPost);
var jsAppPostDefer = () => bundleJs(config.task.jsAppPostDefer);
var jsAppPre = () => bundleJs(config.task.jsAppPre);
var jsThing = () => bundleJs(config.task.jsThing);
// ==============================================
// Lint CSS
// ==============================================
function lintCss () {
var task = config.task.lintCss;
return pipeline([
gulp.src(task.src),
stylelint(task.stylelintOptions),
gulpif(!hideNotify, notify(task.notifyOptions))
], errorFormatter);
};
// ==============================================
// Lint JS
// ==============================================
function lintJs () {
var task = config.task.lintJs;
return pipeline([
gulp.src(task.src),
eslint(),
eslint.format(),
eslint.failOnError(),
gulpif(!hideNotify, notify(task.notifyOptions))
], errorFormatter);
};
// ==============================================
// Watch
// ==============================================
function watch () {
var task = config.task.watch;
// CSS
gulp.watch(config.task.css.src, task.options, gulp.parallel(lintCss, css));
// Image
gulp.watch(config.task.image.src, task.options, gulp.parallel(image));
// JS
gulp.watch(config.task.jsAppPre.src, task.options, gulp.parallel(lintJs, jsAppPre));
gulp.watch(config.task.jsAppPost.src, task.options, gulp.parallel(lintJs, jsAppPost));
gulp.watch(config.task.jsAppPostDefer.src, task.options, gulp.parallel(lintJs, jsAppPostDefer));
gulp.watch(config.task.jsThing.src, task.options, gulp.parallel(lintJs, jsThing));
}
// ==============================================
// Export Tasks
// ==============================================
const js = gulp.parallel(
jsAppPost,
jsAppPostDefer,
jsAppPre,
jsThing
);
const lint = gulp.parallel(lintCss, lintJs);
const build = gulp.parallel(css, image, js, lint);
exports.build = build;
exports.clean = clean;
exports.css = css;
exports.default = gulp.series(clean, build);
exports.image = image;
exports.js = js;
exports.lint = lint;
exports.lintCss = lintCss;
exports.lintJs = lintJs;
exports.watch = gulp.series(clean, watch);