forked from stamen/ecoengine-compare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
207 lines (185 loc) · 4.81 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"use strict";
var fs = require("fs");
var copy = require("gulp-copy"),
gulp = require("gulp"),
hb = require("gulp-hb"),
jshint = require("gulp-jshint"),
rename = require("gulp-rename"),
replace = require("gulp-replace"),
run = require("gulp-run"),
sourcemaps = require("gulp-sourcemaps"),
uglify = require("gulp-uglify"),
env = require('gulp-env'),
webserver = require("gulp-webserver"),
concat = require('gulp-concat'),
mainBowerFiles = require('main-bower-files'),
wrap = require("gulp-wrap"),
autopolyfiller = require("gulp-autopolyfiller"),
sass = require("gulp-sass"),
del = require("del");
// Gulp mix-ins
require("gulp-watch");
var paths = {
sass: "./sass",
css: "./build/css",
templates: "./templates/*.handlebars",
js: "./js/*.js",
viewJs: "./viewJs/*.js",
publicJs: "./build/js"
};
//
// Run all default tasks
//
gulp.task("default",function() {
gulp.start("cleanup");
gulp.start("set-env");
gulp.start("lint");
gulp.start("uglify");
gulp.start("templates");
gulp.start("templates:holos");
gulp.start("sass");
gulp.start("vendor-css");
gulp.start("autopolyfiller");
});
gulp.task("cleanup",function(cb) {
run("rm -rf ./build/*", {}).exec();
});
//
//
//
gulp.task('set-env', function () {
env({
file: ".env.json",
vars: {
//any vars you want to overwrite
}
});
});
//
// Check quality of Javascript
// warn if errors or style problems are found
//
gulp.task("lint", function() {
gulp
.src(paths.js)
.pipe(jshint({
predef: [
"define",
"document",
"location",
"navigator",
"window",
"history",
"L",
"STMN",
"STPX",
"interact",
"queryString"
],
expr: true
}))
.pipe(jshint.reporter("jshint-stylish"));
});
gulp.task("uglify", function() {
gulp
.src(mainBowerFiles({filter: new RegExp('.js$', 'i')}).concat([paths.js,paths.viewJs]))
.pipe(sourcemaps.init())
.pipe(concat('ecoengine-compare.js'))
.pipe(gulp.dest(paths.publicJs))
.pipe(uglify({
mangle: true,
output: {
beautify: false
}
}).on("error", function(e) {
console.log("Uglify error:\x07",e.message, " on line: ", e.lineNumber);
return this.end();
}))
.pipe(rename({extname: ".min.js"}))
.pipe(sourcemaps.write("./")) // Write a sourcemap for browser debugging
.pipe(gulp.dest(paths.publicJs));
});
gulp.task('autopolyfiller', function () {
return gulp.src(paths.publicJs + "/*.js")
.pipe(autopolyfiller('polyfill.js'))
.pipe(gulp.dest("./build/legacy"));
});
//
// Build handlebars templates
// and create html files from them in
// the public directory
//
gulp.task("templates", function() {
gulp
.src("./templates/*.handlebars")
.pipe(hb({
data: "./data/**/*.{js,json}",
helpers: [
"./helpers/*.js"
],
partials: [
"./templates/partials/*.handlebars"
]
}))
.pipe(rename({extname: ".html"}))
.pipe(gulp.dest("./build/"));
});
gulp.task("templates:holos", function() {
gulp
.src("./templates/*.handlebars")
.pipe(hb({
data: ["./data/**/*.{js,json}","./holos/holos-templates.json"],
helpers: [
"./helpers/*.js"
],
partials: [
"./templates/partials/*.handlebars"
]
}))
.pipe(rename({extname: ".jinja2.html"}))
.pipe(gulp.dest("./build/"));
});
//
// Serve contents of the public directory
// locally on port :5000
//
gulp.task("webserver", function() {
gulp
.src("./build/")
.pipe(webserver({
open: false, // unless you want it
livereload: false, // unless you want it
directoryListing: false,
fallback: "index.html",
host:"0.0.0.0",
port:5000
}));
});
//
// Generate CSS from Sass and move it
// to the public directory
//
//
gulp.task('sass', function () {
return gulp.src("./sass/**")
.pipe(sass())
.pipe(gulp.dest("./build/css/"));
});
gulp.task("vendor-css", function() {
gulp
.src(mainBowerFiles({filter: new RegExp('.css$', 'i')}))
.pipe(concat("vendor.css"))
.pipe(gulp.dest(paths.css));
});
//
// Watch directories for changes
//
gulp.task("watch", function() {
gulp.watch(mainBowerFiles({filter: new RegExp('.js$', 'i')}).concat([paths.js, paths.viewJs]),["lint", "uglify", "autopolyfiller"]);
console.log("watching directory:", paths.js);
gulp.watch(paths.templates, ["set-env","templates", "templates:holos"]);
console.log("watching directory:", paths.templates);
gulp.watch(mainBowerFiles({filter: new RegExp('.css$', 'i')}).concat(["sass/*.scss"]), ["sass"]);
console.log("watching directory:", paths.sass);
gulp.start("webserver");
});