-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
86 lines (77 loc) · 3.03 KB
/
compile.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
'use strict'
const settings = require('nconf').argv().env().file({ file: 'settings.json' }).defaults({ 'port': 3000 });
const optionalRequire = require('optional-require')(require);
const ncp = require('ncp').ncp;
const fs = require('graceful-fs');
const ejs = require('ejs');
const express = require('express');
const app = express();
ncp.limit = 16;
ejs.delimiter = ':';
app.set('view engine', 'html');
app.engine('html', ejs.renderFile);
function dumpPage (url, data, filename) {
app.render(`pages/${url}`, data, (err, html) => {
if (err) throw err;
console.log(`build/${filename}`);
fs.writeFileSync(`build/${filename}`, html);
});
}
function dumpPlatforms () {
fs.mkdirSync('build/platform', { recursive: true }, (err) => { if (err) throw err });
const platforms = optionalRequire('./data/platforms.json');
Object.keys(platforms).forEach((guid) => {
let platform = optionalRequire(`./data/platform/${guid}`);
dumpPage('platform/view', {
platform: platform,
data_path: `/data/platform/${guid}.json`
}, `platform/${guid}.html`);
});
}
function dumpGames () {
const games = optionalRequire('./data/games.json').games;
games.forEach((game) => {
dumpGame(game.guid);
});
}
function dumpGame (guid) {
const game = optionalRequire(`./data/game/${guid}`);
fs.mkdirSync(`build/${guid}`, { recursive: true }, (err) => { if (err) throw err });
dumpPage('view', {
game: game,
page_title: `"${game.title}" | Sound Test`,
data_path: `/data/game/${guid}.json`
}, `${game.guid}/index.html`);
fs.mkdirSync(`build/${guid}/track`, { recursive: true }, (err) => { if (err) throw err });
game.playlist.forEach((track, i) => {
dumpPage('track', {
game: game,
track: track,
page_title: `"${track.title}" from "${game.title}" | Sound Test`,
data_path: `/data/game/${guid}.json`
}, `${guid}/track/${i + 1}.html`);
});
}
app.listen(settings.get('port'), () => {
console.log(`Starting node on http://localhost:${settings.get('port')}/`);
fs.mkdirSync('build', { recursive: true }, (err) => { if (err) throw err });
fs.copyFile('static/favicon.ico', 'build/favicon.ico', (err) => { if (err) throw err });
fs.mkdirSync('build/data', { recursive: true }, (err) => { if (err) throw err });
ncp('data', 'build/data', (err) => {
if (err) throw err;
console.log('✔️ Copied data');
fs.mkdirSync('build/static', { recursive: true }, (err) => { if (err) throw err });
ncp('static', 'build/static', (err) => {
if (err) throw err;
console.log('✔️ Copied static assets');
dumpPage('index', {}, 'index.html');
fs.mkdirSync('build/about', { recursive: true }, (err) => { if (err) throw err });
fs.mkdirSync('build/about/privacy', { recursive: true }, (err) => { if (err) throw err });
dumpPage('about/privacy', {}, 'about/privacy/index.html');
fs.mkdirSync('build/game', { recursive: true }, (err) => { if (err) throw err });
dumpPage('guess', {}, 'game/index.html');
dumpPlatforms();
dumpGames();
});
});
});