-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsample.gulpfile.js
186 lines (122 loc) · 4.21 KB
/
sample.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
var gulp = require("gulp"), // The streaming build system
del = require("del"), // Delete files and folders
merge = require("merge-stream"), // Create a stream that emits events from multiple other streams
changed = require("gulp-changed"), // Only pass through changed files
imagemin = require("gulp-imagemin"), // Minify PNG, JPEG, GIF and SVG images
plumber = require("gulp-plumber"), // Prevent pipe breaking caused by errors from gulp plugins
notify = require("gulp-notify"), // Gulp plugin to send messages based on Vinyl Files or Errors to Mac OS X
compass = require("gulp-compass"), // Compile Sass to CSS with Compass
minifyCSS = require("gulp-minify-css"), // Create a minified CSS file
concat = require("gulp-concat"), // Concatenates files
uglify = require("gulp-uglify"), // Minify files with UglifyJS
help = require("gulp-task-listing"), // Adds the ability to provide a task listing for your gulpfile
rename = require("gulp-rename"), // Rename files
jshint = require("gulp-jshint"); // A JavaScript Code Quality Tool
/**
* Plumber error template
*/
var plumberOpts = {
"errorHandler": notify.onError({
"title": "Error",
"message": "<%=error.message %>"
})
};
/**
* Import configuration
*/
var config = require('./config.json');
/**
* Help task
*/
gulp.task('help', help);
/**
* Default task
*/
gulp.task("default", config.tasks.default);
/**
* Clean tasks
*/
gulp.task("clean", config.tasks.clean);
gulp.task("clean:assets", function (next) {
del(config.assets.files.map(function (item) {
return item.dist;
}), next);
});
gulp.task("clean:css", function (next) {
del(config.styles.files.map(function (item) {
return item.dist;
}), next);
});
gulp.task("clean:js", function (next) {
del(config.scripts.files.map(function (item) {
return item.dist;
}), next);
});
/**
* Build tasks
*/
gulp.task("build", config.tasks.build);
gulp.task("build:assets", function () {
return merge.apply(null, config.assets.files.map(function (assetsSource) {
return gulp
.src(assetsSource.src)
.pipe(changed(assetsSource.dist))
.pipe(imagemin(config.assets.options.imagemin || {}))
.pipe(gulp.dest(assetsSource.dist));
}));
});
gulp.task("build:css", function () {
return merge.apply(null, config.styles.files.map(function (style) {
function swallowError (error) { console.log(error.toString()); this.emit('end'); };
return gulp
.src(style.src)
.pipe(plumber(plumberOpts))
.pipe(compass(config.styles.options.scss))
.on('error', swallowError)
.pipe(rename(style.filename))
.pipe(minifyCSS())
.pipe(gulp.dest(style.dist))
.pipe(notify({
"title": "Build CSS complete",
"message": style.dist + style.filename
}));
}));
});
gulp.task("build:js", function () {
return merge.apply(null, config.scripts.files.map(function (script) {
return gulp
.src(script.src)
.pipe(plumber(plumberOpts))
.pipe(concat(script.filename))
.pipe(uglify())
.pipe(gulp.dest(script.dist))
.pipe(notify({
"title": "Build JS complete",
"message": script.filename
}));
}));
});
/**
* Lint tasks
*/
gulp.task("watch", config.tasks.watch);
gulp.task("watch:assets", function () {
gulp.watch(config.assets.watch, ["build:assets"]);
});
gulp.task("watch:css", function () {
gulp.watch(config.styles.watch, ["build:css"]);
});
gulp.task("watch:js", function () {
gulp.watch(config.scripts.watch, ["build:js"]);
});
/**
* Lint tasks
*/
gulp.task("lint:js", function () {
return merge.apply(null, config.scripts.files.map(function (script) {
return gulp
.src(script.src)
.pipe(jshint(config.scripts.options.jshint || {}))
.pipe(plumber(plumberOpts));
}));
});