-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1.14 KB
/
index.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
'use strict';
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const files = fs.readdirSync(path.join(__dirname, 'src/server/static/'));
const metaBundlePath = path.join(__dirname, 'src/server/bundles.json');
const bundles = {};
console.log(chalk.green('Starting Timeworthy'));
try {
fs.unlinkSync(metaBundlePath);
console.log(leftPad('Deleted stale meta-bundle'));
} catch(e) {
console.log(leftPad('No meta-bundle found'));
}
// TODO: investigate why reduce() acts wonky
for (let i = 0; i < files.length; i++) {
const filename = files[i];
const filetype = filename.split('.').pop();
const filepath = `/static/${filename}`;
if (bundles[filetype]) {
bundles[filetype].push(filepath);
} else {
bundles[filetype] = [filepath];
}
}
fs.writeFileSync(metaBundlePath, JSON.stringify(bundles));
console.log(leftPad('Created fresh meta-bundle'));
const server = require('./src/server');
server.start((err) => {
if (err) {
console.warn('Error starting server');
return;
}
console.log(chalk.green('Timeworthy is up and running'));
});
function leftPad(text) {
return ` ${text}`;
}