-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
141 lines (122 loc) · 3.32 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
var browserify = require("browserify");
var browserSync = require("browser-sync");
var fs = require("fs");
var gulp = require("gulp");
var concat = require("gulp-concat");
var ghPages = require("gulp-gh-pages");
var mocha = require("gulp-spawn-mocha");
var rename = require("gulp-rename");
var gutil = require("gulp-util");
var watch = require("gulp-watch");
var source = require("vinyl-source-stream");
var watchify = require("watchify");
/*
* Tasks to build app and vendor javascript files
*/
gulp.task("js", function () {
// Build app js files
var bundler= watchify(browserify("./app/main.jsx", {
paths: ["./app"],
extensions: [".jsx"],
cache: {},
packageCache: {},
fullPaths: true
}));
var bundle = function () {
return bundler.bundle()
.on("error", gutil.log.bind(gutil, "Browserify Error"))
.pipe(source("bundle.js"))
.pipe(rename("app.js"))
.pipe(gulp.dest("./builds/assets/js/"))
.pipe(reload({stream: true}));
};
bundler.transform("reactify");
bundler.on("update", bundle);
bundler.on("log", gutil.log);
bundle();
// Build vendor js files
var buildVendorJs = function () {
var deps = JSON.parse(fs.readFileSync("./deps.json"));
gulp.src(deps.js)
.pipe(concat("vendor.js"))
.pipe(gulp.dest("./builds/assets/js/"))
.pipe(reload({stream: true}));
};
watch("./deps.json", buildVendorJs);
buildVendorJs();
});
/*
* Tasks to build app html files
*/
gulp.task("html", function () {
var buildHtml = function () {
gulp.src("./app/main.html")
.pipe(rename("index.html"))
.pipe(gulp.dest("./builds/"))
.pipe(reload({stream: true}));
};
watch("./app/main.html", buildHtml);
buildHtml();
});
/*
* Tasks to build app and vendor css files
*/
gulp.task("css", function () {
var buildVendorCss = function () {
var deps = JSON.parse(fs.readFileSync("./deps.json"));
gulp.src(deps.css)
.pipe(concat("vendor.css"))
.pipe(gulp.dest("./builds/assets/css/"));
};
watch("./deps.json", buildVendorCss);
buildVendorCss();
});
/*
* Tasks to build app images
*/
gulp.task("images", function () {
var buildAppImages = function () {
gulp.src("./app/assets/images/*")
.pipe(gulp.dest("./builds/assets/images/"));
};
watch("./app/assets/images/*", buildAppImages);
buildAppImages();
});
/*
* Task to setup the development server
*/
var reload = browserSync.reload;
gulp.task("serve", function() {
var reg = new RegExp("/assets/|/tests/|/coverage/");
browserSync({
server: {
baseDir: "./builds",
middleware: function (req, res, next) {
if (!reg.test(req.url)) {
req.url = "/";
}
next();
}
},
port: 8080,
ghostMode: false,
injectChanges: false,
notify: false
});
});
/*
* Task to deploy to github pages
*/
gulp.task("deploy", function() {
return gulp.src("./builds/**/*").pipe(ghPages());
});
/*
* Default task
*/
gulp.task("default", [
"js",
"html",
"css",
"images",
"serve"
]);