forked from PedalPlayground/pedalplayground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
158 lines (141 loc) · 4.42 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
// RESOURCES USED TO MAKE THIS GULP FILE:
// http://www.revsys.com/blog/2014/oct/21/ultimate-front-end-development-setup/
// http://ericlbarnes.com/setting-gulp-bower-bootstrap-sass-fontawesome/
// https://markgoodyear.com/2014/01/getting-started-with-gulp/
// https://github.com/mikaelbr/gulp-notify/issues/81
// ------------------------------------------------------------------------------------
var gulp = require("gulp");
var sass = require("gulp-sass");
var watch = require("gulp-watch");
var plumber = require("gulp-plumber");
var minifycss = require("gulp-minify-css");
var rename = require("gulp-rename");
var gzip = require("gulp-gzip");
var livereload = require("gulp-livereload");
var notify = require("gulp-notify");
var gutil = require("gulp-util");
var concat = require("gulp-concat");
var imagemin = require("gulp-imagemin");
var responsive = require("gulp-responsive");
var cache = require("gulp-cached");
var minify = require("gulp-minify");
var gzip_options = {
threshold: "1kb",
gzipOptions: {
level: 9,
},
};
var reportError = function (error) {
var lineNumber = error.lineNumber ? "LINE " + error.lineNumber + " -- " : "";
notify({
title: "Task Failed [" + error.plugin + "]",
message: lineNumber + "See console.",
sound: "Sosumi", // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
}).write(error);
gutil.beep(); // Beep 'sosumi' again
// Inspect the error object
// console.log(error);
// Easy error reporting
// console.log(error.toString());
// Pretty error reporting
var report = "";
var chalk = gutil.colors.black.bgRed;
report += chalk("TASK:") + " [" + error.plugin + "]\n";
report += chalk("PROB:") + " " + error.message + "\n";
if (error.lineNumber) {
report += chalk("LINE:") + " " + error.lineNumber + "\n";
}
if (error.fileName) {
report += chalk("FILE:") + " " + error.fileName + "\n";
}
console.error(report);
// Prevent the 'watch' task from stopping
this.emit("end");
};
// SCSS
gulp.task("styles", function () {
return gulp
.src("app/stylesheets/*.scss")
.pipe(
plumber({
errorHandler: reportError,
})
)
.pipe(sass())
.pipe(gulp.dest("public/stylesheets"))
.pipe(rename({ suffix: ".min" }))
.pipe(minifycss())
.pipe(gulp.dest("public/stylesheets"))
.pipe(gzip(gzip_options))
.pipe(gulp.dest("public/stylesheets"))
.pipe(notify("SCSS Compiled!"))
.on("error", reportError)
.pipe(livereload());
});
// JS
gulp.task("scripts", function () {
return gulp
.src([
"bower_components/jquery/dist/jquery.js",
"bower_components/draggabilly/dist/draggabilly.pkgd.js",
"bower_components/bootstrap-sass/assets/javascripts/bootstrap.js",
"bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js",
"bower_components/select2/dist/js/select2.js",
"app/scripts/scripts.js",
])
.pipe(
plumber({
errorHandler: reportError,
})
)
.pipe(concat("scripts.js"))
.pipe(minify())
.pipe(gulp.dest("public/scripts/"))
.pipe(gzip(gzip_options))
.pipe(gulp.dest("public/scripts/"))
.pipe(notify("JS Compiled!"))
.on("error", reportError)
.pipe(livereload());
});
gulp.task("process-images", function () {
return gulp
.src("app/images/pedals/*")
.pipe(cache("images"))
.pipe(
responsive({
"*.*": {
withoutEnlargement: false,
errorOnUnusedConfig: false,
width: "700",
height: "700",
max: true,
},
})
)
.pipe(imagemin())
.pipe(gulp.dest("public/images/pedals/"));
});
/* Watch Files For Changes */
gulp.task("watch", function () {
livereload.listen();
gulp.watch("app/stylesheets/**", ["styles"]);
gulp.watch("app/scripts/**", ["scripts"]);
gulp.watch("*.php").on("change", livereload.changed);
gulp.watch("includes/**").on("change", livereload.changed);
gulp.watch("*.html").on("change", livereload.changed);
});
gulp.task("watch-all", function () {
livereload.listen();
//gulp.watch(['app/images/pedals/*.png','!app/images/pedals/*_tmp*.*'], ['images']);
gulp.watch(
["app/images/pedals-new/**/*.png", "!app/images/pedals-new/**/*_tmp*.*"],
["process-images"]
);
gulp.watch("app/stylesheets/**", ["styles"]);
gulp.watch("app/scripts/**", ["scripts"]);
gulp.watch("*.php").on("change", livereload.changed);
gulp.watch("includes/**").on("change", livereload.changed);
gulp.watch("*.html").on("change", livereload.changed);
});
gulp.task("default", ["styles", "scripts", "watch"]);
gulp.task("all", ["styles", "scripts", "process-images", "watch-all"]);