forked from burt202/table-tennis-scoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (69 loc) · 2.15 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
var gulp = require("gulp");
var rename = require("gulp-rename");
var runSequence = require("run-sequence");
var clean = require("gulp-clean");
var deploy = require("gulp-gh-pages");
var es = require("event-stream");
var nunjucks = require("gulp-nunjucks");
var data = require("gulp-data");
var R = require("ramda");
var cleanCSS = require("gulp-clean-css");
var gulpWebpack = require("gulp-webpack");
var webpack = require("webpack");
var basePath = __dirname + "/leagues";
var leagues = require("./src/js/get-leagues")(basePath);
var getDataForLeague = require("./src/js/get-data-for-league")(basePath);
gulp.task("default", ["watch"]);
gulp.task("watch", function () {
gulp.watch("src/**", ["build"]);
});
gulp.task("clean", function () {
return gulp.src("build")
.pipe(clean());
});
gulp.task("process-league-templates", function () {
return es.merge(leagues.all.map(function (league) {
var leagueData = getDataForLeague(league.name, league.meta);
return gulp.src("src/templates/" + leagueData.type + ".html")
.pipe(data(R.merge(league, leagueData)))
.pipe(nunjucks.compile())
.pipe(rename(league.name + ".html"))
.pipe(gulp.dest("build"));
}));
});
gulp.task("process-index-template", function () {
return gulp.src("./src/templates/index.html")
.pipe(data({liveLeague: leagues.live, previousLeagues: leagues.previous, lastModified: new Date().toISOString()}))
.pipe(nunjucks.compile())
.pipe(gulp.dest("build"));
});
gulp.task("minify-css", function () {
return gulp.src("src/css/app.css")
.pipe(cleanCSS())
.pipe(gulp.dest("build"));
});
gulp.task("webpack", function () {
return gulp.src("src/js/app.js")
.pipe(gulpWebpack({
output: {
filename: "app.js"
},
plugins: [new webpack.optimize.UglifyJsPlugin()]
}, webpack))
.pipe(gulp.dest("build"));
});
gulp.task("build", function (callback) {
if (!leagues.all.length) return;
runSequence(
"clean",
"process-league-templates",
"process-index-template",
"minify-css",
"webpack",
callback
);
});
gulp.task("deploy", ["build"], function () {
return gulp.src("./build/**/*")
.pipe(deploy());
});