forked from inevitable-team/compiled-mcr-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (46 loc) · 2.5 KB
/
script.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
require('dotenv').config();
let fs = require('fs-extra'),
shell = require('shelljs'),
beautify = require('beautify'),
moment = require('moment'),
ical = require('ical-generator'),
dataGatherClass = require(`${__dirname}/_data/dataGather`),
htmlConverter = require(`${__dirname}/_static/scripts/dataToHTML`),
indexLayout = require(`${__dirname}/_layout/index`);
require('events').EventEmitter.prototype._maxListeners = 0;
let cal = ical({domain: 'https://events.compiledmcr.com/', name: 'CompiledMCR Events (Edinburgh Tech Meetups)'});
// Moving static files to site
shell.mkdir('-p', `${__dirname}/_site`);
shell.rm('-rf', `${__dirname}/_site/*`);
fs.copySync(`${__dirname}/_static`, `${__dirname}/_site`);
fs.copySync(`${__dirname}/_data/sources/groupIds`, `${__dirname}/_site/data`);
// Creating Data
shell.mkdir('-p', `${__dirname}/_exports`);
shell.mkdir('-p', `${__dirname}/_site/data`);
let dataGather = new dataGatherClass();
dataGather.getData().then(data => {
// Got data and images
fs.writeFileSync(`${__dirname}/_exports/groups.json`, beautify(JSON.stringify(data[0]), { format: 'json' }), () => {});
fs.writeFileSync(`${__dirname}/_exports/events.json`, beautify(JSON.stringify(data[1]), { format: 'json' }), () => {});
// Output
fs.writeFileSync(`${__dirname}/_site/data/groups.json`, beautify(JSON.stringify(data[0]), { format: 'json' }), () => {});
fs.writeFileSync(`${__dirname}/_site/data/groups.txt`, data[0].map(group => `- [${group.name}](${group.link})`).join(" \n"), () => {});
fs.writeFileSync(`${__dirname}/_site/data/events.json`, beautify(JSON.stringify(data[1]), { format: 'json' }), () => {});
// Creating HTML
let eventsHTML = data[1].map(htmlConverter.eventHTML).join(""),
groupsHTML = data[0].map(htmlConverter.groupHTML).join("");
let index = indexLayout(eventsHTML, groupsHTML);
fs.writeFileSync(`${__dirname}/_site/index.html`, index, () => {});
// Create Calender
data[1].forEach(event => {
cal.createEvent({
start: moment(event.startTimeISO),
end: moment(event.endTimeISO),
summary: event.name,
description: `Source:\n${event.link}\n\n${event.desc.length > 280 ? event.desc.substr(0, 280) : event.desc}`,
location: event.location,
url: event.link
});
});
fs.writeFileSync("./_site/data/events.ical", cal.toString(), () => {});
});