forked from lbrande/games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateIndex.js
38 lines (29 loc) · 863 Bytes
/
generateIndex.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
#!/usr/bin/env node
const Handlebars = require("handlebars");
const fs = require("fs");
const glob = require("glob");
const map = require("ramda/src/map");
const path = require("path");
let files = glob.sync("**/*.json", { cwd: "./games" });
let public_games = [];
// Create proper data for template
let games = map((file) => {
let dir = path.dirname(file);
let group = dir === "." ? undefined : dir;
let name = path.basename(file, ".json");
let object = name.replace(/[-\.]/g, "_");
let game = { name, file, dir, object };
if (group) {
game.group = group;
if (group === "public") {
public_games.push(game);
}
}
return game;
}, files);
const template = Handlebars.compile(
fs.readFileSync("./index.js.hb", { encoding: "UTF8" })
);
fs.writeFileSync("./index.js", template({ games, public_games }), {
mode: "644",
});