forked from BrowserSync/UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
159 lines (146 loc) · 4.02 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
var gulp = require("gulp");
var jshint = require("gulp-jshint");
var contribs = require("gulp-contribs");
var sass = require("gulp-sass");
var autoprefix = require("gulp-autoprefixer");
var browserify = require("gulp-browserify");
var rename = require("gulp-rename");
var filter = require("gulp-filter");
var minifyCSS = require("gulp-minify-css");
var sprites = require("gulp-svg-sprites");
var browserSync = require("browser-sync");
var crossbow = require("crossbow/plugins/stream");
/**
* Lint all JS files
*/
gulp.task("lint", function () {
return gulp.src([
"test/client/specs/**/*.js",
"test/server/**/*.js",
"public/js/scripts/*.js",
"index.js",
"server/*.js",
"gulpfile.js"
])
.pipe(require("no-abs")())
.pipe(jshint(".jshintrc"))
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"));
});
/**
* Update Contributors list
*/
gulp.task("contribs", function () {
gulp.src("README.md")
.pipe(contribs())
.pipe(gulp.dest("./"));
});
/**
* Build the app.
*/
gulp.task("js", function () {
return gulp.src("src/scripts/app.js")
.pipe(browserify())
.pipe(rename("app.js"))
.pipe(gulp.dest("./public/js"));
});
/**
* Start BrowserSync
*/
gulp.task("browser-sync", function () {
browserSync({
proxy: "http://localhost:3001/",
files: ["lib/*.html"]
});
});
/**
* Start BrowserSync
*/
gulp.task("browser-sync-dev", function () {
browserSync.use(require("./"));
//browserSync.use(require("bs-html-injector"), {
// files: "lib/*.html"
//});
browserSync({
notify: false,
open: false,
server: {
baseDir: ["static", "public"],
directory: true
},
ui: false
});
});
/**
* Compile CSS
*/
gulp.task("sass", function () {
return gulp.src("src/scss/**/*.scss")
.pipe(sass())
.on("error", function(err){
browserSync.notify(err.message, 3000);
console.log(err.message);
this.emit("end");
})
.pipe(autoprefix())
.pipe(gulp.dest("public/css"))
.pipe(minifyCSS({keepBreaks:true}))
.pipe(filter("**/*.css"))
.pipe(rename("core.min.css"))
.pipe(gulp.dest("public/css"))
.pipe(browserSync.reload({stream:true}));
});
/**
* Compile CSS
*/
gulp.task("bs-inject", function () {
browserSync.reload(["core.css", "components.css"]);
});
/**
* Compile HTML
*/
gulp.task("crossbow", function () {
crossbow.clearCache();
//crossbow.emitter.on("_error", function (err) {
// console.log(err.message);
//});
return gulp.src(["src/crossbow/*.hbs", "src/crossbow/_components/*.hbs"])
.pipe(crossbow({
cwd: "src/crossbow",
siteConfig: "src/crossbow/_config.yml"
}))
.pipe(gulp.dest("./static"));
});
/**
* Compile SVG Symbols
*/
gulp.task("svg", function () {
return gulp.src("src/svg/*.svg")
.pipe(sprites({
mode: "symbols",
svgId: "svg-%f",
templates: {
symbols: require("fs").readFileSync("src/svg-template.tmpl", "utf-8")
},
afterTransform: function (data) {
data.svg = data.svg.map(function (item) {
item.raw = item.raw.replace(/ fill="(.+?)"/g, function () {
return "";
});
return item;
});
return data;
}
}))
.pipe(gulp.dest("public/img/icons"));
});
/**
* Build Front-end stuff
*/
gulp.task("dev-frontend", ["sass", "svg", "crossbow", "js", "browser-sync-dev"], function () {
gulp.watch("src/scss/**/*.scss", ["sass"]);
gulp.watch(["src/crossbow/**"], ["crossbow", browserSync.reload]);
gulp.watch(["src/svg/**"], ["svg", "crossbow", browserSync.reload]);
gulp.watch("src/scripts/**/*.js", ["js", browserSync.reload]);
});
gulp.task("build", ["sass", "js", "lint"]);