This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
gulpfile.js
166 lines (131 loc) · 3.01 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
/* jshint node:true */
"use strict";
var gulp = require("gulp");
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var webserver = require("gulp-webserver");
var deploy = require("gulp-gh-pages");
var opt = {
outputFolder: "build",
server: {
host: "localhost",
port: 4000,
livereload: true,
open:true
},
cssAssets: [
"src/css/bootstrap.min.css",
"src/css/kept.css"
],
fontAssets: [
"src/fonts/*"
],
jsAssets: [
"src/js/**/*.*"
],
htmlAssets: [
"src/index.html"
],
app: {
src: "src/js/kept.js",
dest: "kept.js"
},
vendors: "vendors.js"
};
/**
* Assets tasks
*/
gulp.task("assets", [
"assets:html",
"assets:fonts",
"assets:css"
]);
gulp.task("assets:html", function() {
return gulp.src(opt.htmlAssets)
.pipe(gulp.dest(opt.outputFolder));
});
gulp.task("assets:css", function() {
return gulp.src(opt.cssAssets)
.pipe(gulp.dest(opt.outputFolder + "/css"));
});
gulp.task("assets:fonts", function() {
return gulp.src(opt.fontAssets)
.pipe(gulp.dest(opt.outputFolder + "/fonts"));
});
/**
* JS tasks
*/
gulp.task("js", [
"js:vendors",
"js:app"
]);
gulp.task("js:app", ["js:vendors"], function() {
return browserify("./" + opt.app.src)
.transform("reactify")
.external("react")
.external("react-bootstrap")
.external("marked")
.bundle()
.pipe(source(opt.app.dest))
.pipe(gulp.dest(opt.outputFolder + "/js"));
});
gulp.task("js:vendors", function() {
return browserify()
.require("react")
.require("react-bootstrap")
.require("marked")
.bundle()
.pipe(source(opt.vendors))
.pipe(gulp.dest(opt.outputFolder + "/js"));
});
/**
* Server task
*/
gulp.task("server", function() {
return gulp.src(opt.outputFolder)
.pipe(webserver(opt.server));
});
/**
* Watchify
*/
gulp.task("watchify", function(){
var b = browserify( "./" + opt.app.src , watchify.args)
.transform("reactify")
.external("react")
.external("react-bootstrap")
.external("marked");
function updateBundle(w){
return w.bundle()
.pipe(source(opt.app.dest))
.pipe(gulp.dest(opt.outputFolder + "/js"));
}
var watcher= watchify(b);
watcher.on("update", function(){
updateBundle(watcher);
});
return updateBundle(watcher);
});
/**
* Watch task
* Launch a server with livereload
*/
gulp.task("watch", ["assets","js:vendors", "watchify"], function() {
gulp.watch(opt.cssAssets, ["assets:css"]);
gulp.watch(opt.fontAssets, ["assets:fonts"]);
gulp.watch(opt.htmlAssets, ["assets:html"]);
});
gulp.task("dist", ["assets", "js"], function() {
return gulp.src(opt.outputFolder + "/js/*.js")
.pipe(uglify())
.pipe(gulp.dest(opt.outputFolder + "/js"));
});
/**
* Deploy to gh-pages
*/
gulp.task("deploy", ["dist"], function() {
gulp.src("./build/**/*")
.pipe(deploy("[email protected]:n1k0/kept.git"));
});
gulp.task("default", ["server", "watch"]);