forked from dfabulich/choicescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatorNode.js
34 lines (29 loc) · 1.09 KB
/
generatorNode.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
var fs = require('fs');
var path = require('path');
var inputDir = process.argv[2] || "web/mygame/scenes";
var outputDir = process.argv[3] || "web/mygame/scenes";
eval(fs.readFileSync("web/scene.js", "utf-8"));
eval(fs.readFileSync("web/util.js", "utf-8"));
eval(fs.readFileSync("headless.js", "utf-8"));
var list = fs.readdirSync(inputDir);
var i = list.length;
while (i--) {
if (!/\.txt$/.test(list[i])) continue;
var filePath = inputDir + '/' + list[i];
var inputMod = fs.statSync(filePath).mtime.getTime();
var outputMod = 0;
if (fs.existsSync(filePath + ".json")) {
outputMod = fs.statSync(filePath + ".json").mtime.getTime();;
}
if (inputMod <= outputMod) {
console.log(list[i] + " up to date");
continue;
}
console.log(list[i]);
var str = slurpFile(filePath);
var scene = new Scene();
scene.loadLines(str);
var writer = fs.createWriteStream(outputDir + '/' + list[i].replace(/ /g, "_") + ".json");
writer.write("{\"crc\":" + scene.temps.choice_crc + ", \"lines\":" + toJson(scene.lines)+ ", \"labels\":" + toJson(scene.labels) + "}", "utf-8");
writer.end();
}