Added [[testcases]] that are stored in game dat file, instead of single variables. Split metadata out into a template file for easier modification.
This commit is contained in:
@ -6,6 +6,7 @@ const logger = require('winston');
|
||||
|
||||
const sanitizeHtml = require('sanitize-html');
|
||||
|
||||
const toml = require('toml');
|
||||
const blackfriday = require('./blackfriday.js');
|
||||
|
||||
const del = require('delete');
|
||||
@ -27,9 +28,11 @@ function url(title) {
|
||||
function gitPull(directory, repository) {
|
||||
if (fs.existsSync(directory)) {
|
||||
logger.info(`Fetching latest from Github : ${directory}`);
|
||||
exec(`cd ${directory} && git pull && cd -`);
|
||||
logger.info(`git --git-dir=${directory} pull`);
|
||||
exec(`git --git-dir=${directory} pull`);
|
||||
} else {
|
||||
logger.info(`Cloning repository from Github : ${directory}`);
|
||||
logger.info(`git clone ${repository}`);
|
||||
exec(`git clone ${repository}`);
|
||||
}
|
||||
}
|
||||
@ -39,17 +42,6 @@ function getDirectories (srcpath) {
|
||||
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
|
||||
}
|
||||
|
||||
String.prototype.trimNewline = function() {
|
||||
let string = this.toString();
|
||||
if (string.endsWith('\r\n')) {
|
||||
return string.slice(0, -2);
|
||||
} else if (string.endsWith('\r') || string.endsWith('\n')) {
|
||||
return string.slice(0, -1);
|
||||
} else {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch game information stored in Github repository.
|
||||
gitPull(inputDirectoryGame, 'https://github.com/citra-emu/citra-games-wiki.git');
|
||||
|
||||
@ -119,10 +111,7 @@ try {
|
||||
fsextra.copySync(`${inputDirectorySavefilesGame}/${file}`, `${outputDirectorySavefilesGame}/${file.replace('.zip', '.zip')}`);
|
||||
} else if (path.extname(file) == '.dat') {
|
||||
// Store the contents of the file in memory for adding it into the markdown later.
|
||||
savefileMetadataContents.push({
|
||||
filename: file.replace('.dat', '.zip'),
|
||||
contents: fs.readFileSync(`${inputDirectorySavefilesGame}/${file}`, 'utf8').trimNewline()
|
||||
});
|
||||
savefileMetadataContents.push({ filename: file.replace('.dat', '.zip'), contents: fs.readFileSync(`${inputDirectorySavefilesGame}/${file}`, 'utf8') });
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -150,14 +139,28 @@ try {
|
||||
var stats = fs.statSync(`${inputDirectoryGame}/${game}/game.dat`);
|
||||
let modified = new Date(util.inspect(stats.mtime));
|
||||
|
||||
let datContents = fs.readFileSync(`${inputDirectoryGame}/${game}/game.dat`, 'utf8').trimNewline();
|
||||
let datContents = fs.readFileSync(`${inputDirectoryGame}/${game}/game.dat`, 'utf8');
|
||||
datContents = `date = "${modified.toISOString()}"\r\n` + datContents;
|
||||
|
||||
// Parse testcase information out of the dat to reinject as shortcut values.
|
||||
try {
|
||||
var dat = toml.parse(datContents);
|
||||
if (dat.testcases == null || dat.testcases.length == 0) {
|
||||
datContents = `compatibility = 99"\r\ntestcase_date = "2000-01-01"\r\n` + datContents;
|
||||
} else {
|
||||
let recent = dat.testcases[0];
|
||||
datContents = `compatibility = ${recent.compatibility}\r\ntestcase_date = "${recent.date}"\r\n` + datContents;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Parsing dat file error on line ${e.line}, column ${e.column}: ${e.message}`);
|
||||
}
|
||||
|
||||
var wikiContents = "";
|
||||
let wikiPathGame = `${inputDirectoryWiki}/${game}.md`;
|
||||
if (fs.existsSync(wikiPathGame)) {
|
||||
wikiContents = fs.readFileSync(wikiPathGame, 'utf8').trimNewline();
|
||||
wikiContents = fs.readFileSync(wikiPathGame, 'utf8');
|
||||
} else {
|
||||
wikiContents = "## No wiki exists yet for this game.";
|
||||
wikiContents = "No wiki exists yet for this game.";
|
||||
}
|
||||
|
||||
// Fix Blackfriday markdown rendering differences.
|
||||
@ -167,14 +170,13 @@ try {
|
||||
// Read all savefiles from array and copy them into the markdown.
|
||||
savefileMetadataContents.forEach(function(savefile) {
|
||||
let modified = new Date(util.inspect(stats.mtime));
|
||||
datContents += `\r\n\r\n[[ savefiles ]]\r\nfilename = "${savefile.filename}"\r\ndate = "${modified.toISOString()}"\r\n${savefile.contents}`;
|
||||
datContents += `\r\n\r\n[[ savefiles ]]\r\n${savefile.contents}\r\nfilename = "${savefile.filename}"\r\ndate = "${modified.toISOString()}"\r\n`;
|
||||
});
|
||||
|
||||
let output = `+++\r\ndate = "${modified.toISOString()}"\r\n${datContents}\r\n+++\r\n\r\n${wikiContents}\r\n`;
|
||||
let output = `+++\r\n${datContents}\r\n+++\r\n\r\n${wikiContents}\r\n`;
|
||||
fs.writeFileSync(`${outputDirectoryMd}/${game}.md`, output);
|
||||
} catch (ex) {
|
||||
logger.error(`${game} failed to generate: ${ex}`);
|
||||
logger.error(ex);
|
||||
}
|
||||
});
|
||||
} catch (ex) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
"rimraf": "^2.6.1",
|
||||
"sanitize-html": "^1.14.1",
|
||||
"sync-exec": "^0.6.2",
|
||||
"toml": "^2.3.2",
|
||||
"winston": "^2.2.0"
|
||||
},
|
||||
"preferGlobal": false,
|
||||
|
Reference in New Issue
Block a user