-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
176 lines (143 loc) · 4.41 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
var gulp = require("gulp");
var gutil = require("gulp-util");
var browserify = require("gulp-browserify");
var sass = require("gulp-sass");
var jshint = require("gulp-jshint");
var stylish = require('jshint-stylish');
var notify = require("gulp-notify");
var path = require("path");
var marked = require("marked");
var maki = require("gulp-pagemaki");
var fs = require("fs");
var yaml = require("js-yaml");
var moment = require("moment");
var _ = require("lodash");
var express = require("express");
var argv = require('yargs').argv;
// Markdown options for content parsing later
marked.setOptions({
gfm: true,
tables: true,
breaks: false
});
// globs and build directories
var paths = {
scripts: {
all: "./src/**/*.js",
lint: ["./src/js/**/*.js", "!./src/js/vendor/**/*.js"],
watch: ["./src/js/**/*.js", "./src/js/app/templates/**/*.html", "!./src/js/vendor/**/*.js"],
build: ["./src/js/main.js"]
},
styles: {
all: ["./src/sass/**/*.sass", "./src/sass/**/*.scss", "./src/sass/**/*.css"],
build: ["./src/sass/*.sass", "./src/sass/*.scss", "./src/sass/*.css"]
},
pages: {
build: ["./src/pages/**/*"],
watch: ["./src/pages/**/*", "./config.yml"]
},
statics: ["./src/statics/**/*"]
};
paths.buildDir = path.join(process.cwd(), "assets");
/** ========================================================================
*
* TASK DEFINITIONS
*
*/
gulp.task("default", ["serve"]);
gulp.task("build", ["scripts", "styles", "pages", "statics"]);
gulp.task("pages", function () {
return gulp.src(paths.pages.build)
.pipe(maki({
globals: prepareGlobals(),
templatesDir: path.join(__dirname, "src", "layouts"),
contentParse: function (string, extension) {
if (extension.toLowerCase() === "markdown" || extension.toLowerCase() === "md") {
return marked(string);
} else {
return string;
}
}
}))
.pipe(gulp.dest("."));
})
gulp.task("scripts", ["jshint"], function () {
return gulp.src(paths.scripts.build)
.pipe(browserify({
debug: !gutil.env.production,
transform: ["node-underscorify"]
}))
.pipe(gulp.dest(paths.buildDir));
});
gulp.task("jshint", function () {
return gulp.src(paths.scripts.lint)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task("styles", function () {
return gulp.src(paths.styles.build)
.pipe(sass())
.pipe(gulp.dest(paths.buildDir));
});
gulp.task("statics", function () {
return gulp.src(paths.statics)
.pipe(gulp.dest(path.join(paths.buildDir)));
});
gulp.task("watch", ["build"], function () {
gulp.watch(paths.scripts.watch, ["scripts"]);
gulp.watch(paths.styles.all, ["styles"]);
gulp.watch(paths.pages.watch, ["pages"]);
gulp.watch(paths.statics, ["statics"]);
});
gulp.task("serve", ["watch"], function () {
var app = express();
app.use(express.static("."));
app.use("/baltimore", express.static("."));
var server = app.listen(argv.port || 4000, function () {
console.log("\n*****************\nServer listening on port " + server.address().port);
});
});
function prepareGlobals() {
var globals = yaml.safeLoad(fs.readFileSync("./config.yml", { encoding: "utf-8" }));
if (!globals.site) {
throw new Error('global config not loaded');
}
globals.site.upcoming = prepareUpcoming(globals);
globals.site.future = prepareEvents(globals.site.events);
return globals;
}
function formatDates(start, end) {
var startDate = moment(start)
, endDate = moment(end);
return {
date: startDate.format('dddd, MMMM Do, YYYY'),
time: startDate.format('ha') + ' to ' + endDate.format('ha')
};
}
function prepareEvents(events) {
return _.map(events, function(event) {
event.pretty = formatDates(event.start, event.end);
return event;
});
}
function prepareUpcoming(globals) {
var upcoming = globals.site.events.shift();
upcoming.pretty = formatDates(upcoming.start, upcoming.end);
upcoming.workshops = prepareEventWorkshops(upcoming, globals.workshops);
upcoming.sponsors = prepareEventSponsors(upcoming, globals.sponsors);
return upcoming;
}
/**
* Translate a workshop string into the full workshop object
*
*/
function prepareEventWorkshops(event, workshops) {
return _.map(event.workshops, function(w) {
return _.find(workshops, 'name', w);
});
}
function prepareEventSponsors(event, sponsors) {
return _.map(event.sponsors, function(s) {
return _.find(sponsors, 'name', s);
});
}