2017-06-03 01:36:17 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const fsextra = require('fs-extra');
|
|
|
|
const path = require('path');
|
|
|
|
const util = require('util');
|
|
|
|
const logger = require('winston');
|
2017-06-01 22:00:37 +00:00
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
const sanitizeHtml = require('sanitize-html');
|
2017-06-01 22:00:37 +00:00
|
|
|
|
2017-06-06 00:46:21 +00:00
|
|
|
const toml = require('toml');
|
2017-06-07 04:48:39 +00:00
|
|
|
const tomlify = require('tomlify-j0.4');
|
2017-06-03 01:36:17 +00:00
|
|
|
const blackfriday = require('./blackfriday.js');
|
2017-06-01 22:00:37 +00:00
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
const del = require('delete');
|
|
|
|
const exec = require('sync-exec');
|
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
const fsPathCode = './citra-games-wiki';
|
|
|
|
const fsPathWiki = './citra-games-wiki.wiki';
|
|
|
|
const fsPathHugoContent = '../../site/content/game';
|
|
|
|
const fsPathHugoBoxart = '../../site/static/images/game/boxart';
|
|
|
|
const fsPathHugoIcon = '../../site/static/images/game/icons';
|
|
|
|
const fsPathHugoScreenshots = '../../site/static/images/screenshots0';
|
|
|
|
const fsPathHugoSavefiles = '../../site/static/savefiles/';
|
2017-06-01 22:00:37 +00:00
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
function gitPull(directory, repository) {
|
|
|
|
if (fs.existsSync(directory)) {
|
|
|
|
logger.info(`Fetching latest from Github : ${directory}`);
|
2017-06-06 00:46:21 +00:00
|
|
|
logger.info(`git --git-dir=${directory} pull`);
|
|
|
|
exec(`git --git-dir=${directory} pull`);
|
2017-06-03 01:36:17 +00:00
|
|
|
} else {
|
|
|
|
logger.info(`Cloning repository from Github : ${directory}`);
|
2017-06-06 00:46:21 +00:00
|
|
|
logger.info(`git clone ${repository}`);
|
2017-06-03 01:36:17 +00:00
|
|
|
exec(`git clone ${repository}`);
|
|
|
|
}
|
2017-06-01 22:00:37 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
function getDirectories (srcpath) {
|
|
|
|
return fs.readdirSync(srcpath)
|
|
|
|
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
|
2017-06-01 22:00:37 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
// Fetch game information stored in Github repository.
|
2017-06-07 04:48:39 +00:00
|
|
|
gitPull(fsPathCode, 'https://github.com/citra-emu/citra-games-wiki.git');
|
2017-06-03 01:36:17 +00:00
|
|
|
|
|
|
|
// Fetch game articles stored in Github wiki.
|
2017-06-07 04:48:39 +00:00
|
|
|
gitPull(fsPathWiki, 'https://github.com/citra-emu/citra-games-wiki.wiki.git');
|
2017-06-01 22:00:37 +00:00
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
// Make sure the output directories in Hugo exist.
|
2017-06-07 04:48:39 +00:00
|
|
|
[fsPathHugoContent, fsPathHugoBoxart, fsPathHugoIcon, fsPathHugoSavefiles, fsPathHugoScreenshots].forEach(function (path) {
|
|
|
|
if (fs.existsSync(path) == false) {
|
|
|
|
logger.info(`Creating Hugo output directory: ${path}`);
|
|
|
|
fs.mkdirSync(path);
|
|
|
|
}
|
|
|
|
});
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
try {
|
|
|
|
// Loop through each game folder.
|
2017-06-07 04:48:39 +00:00
|
|
|
getDirectories(fsPathCode).forEach(function(game) {
|
2017-06-05 01:27:57 +00:00
|
|
|
try {
|
|
|
|
if (game == '.git') { return; }
|
2017-06-03 01:36:17 +00:00
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
logger.info(`Processing game: ${game}`);
|
2017-06-03 01:36:17 +00:00
|
|
|
|
2017-06-05 01:27:57 +00:00
|
|
|
// Copy the boxart for the game.
|
2017-06-07 04:48:39 +00:00
|
|
|
fsextra.copySync(`${fsPathCode}/${game}/boxart.png`, `${fsPathHugoBoxart}/${game}.png`);
|
2017-06-03 04:49:49 +00:00
|
|
|
|
2017-06-05 01:27:57 +00:00
|
|
|
// Copy the icon for the game.
|
2017-06-07 04:48:39 +00:00
|
|
|
fsextra.copySync(`${fsPathCode}/${game}/icon.png`, `${fsPathHugoIcon}/${game}.png`);
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
var model = toml.parse(fs.readFileSync(`${fsPathCode}/${game}/game.dat`, 'utf8'));
|
|
|
|
let currentDate = new Date();
|
|
|
|
model.date = `${currentDate.toISOString()}`;
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
// SHORTCUTS BLOCK
|
|
|
|
// Parse testcase information out of the dat to reinject as shortcut values.
|
|
|
|
if (model.testcases == null || model.testcases.length == 0) {
|
|
|
|
model.compatibility = "99";
|
|
|
|
model.testcase_date = "2000-01-01";
|
|
|
|
} else {
|
|
|
|
let recent = model.testcases[0];
|
|
|
|
|
|
|
|
model.compatibility = recent.compatibility;
|
|
|
|
model.testcase_date = recent.date;
|
|
|
|
}
|
|
|
|
// END SHORTCUTS BLOCK
|
|
|
|
|
|
|
|
// SAVEFILE BLOCK
|
|
|
|
var fsPathCodeSavefilesGame = `${fsPathCode}/${game}/savefiles/`;
|
|
|
|
var fsPathHugoSavefilesGame = `${fsPathHugoSavefiles}/${game}/`;
|
|
|
|
if (fs.existsSync(fsPathCodeSavefilesGame)) {
|
|
|
|
// Create the savefile directory for the game.
|
|
|
|
if (fs.existsSync(fsPathHugoSavefilesGame) == false) {
|
|
|
|
fs.mkdirSync(fsPathHugoSavefilesGame);
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
// Copy all savefiles into the output folder, and read their data.
|
|
|
|
model.savefiles = [];
|
|
|
|
fs.readdirSync(fsPathCodeSavefilesGame).forEach(file => {
|
2017-06-05 01:27:57 +00:00
|
|
|
if (path.extname(file) == '.zip') {
|
2017-06-07 04:48:39 +00:00
|
|
|
fsextra.copySync(`${fsPathCodeSavefilesGame}/${file}`, `${fsPathHugoSavefilesGame}/${file}`);
|
2017-06-05 01:27:57 +00:00
|
|
|
} else if (path.extname(file) == '.dat') {
|
2017-06-07 04:48:39 +00:00
|
|
|
// Read the data file into an object.
|
|
|
|
let savefile = toml.parse(fs.readFileSync(`${fsPathCodeSavefilesGame}/${file}`, 'utf8'));
|
|
|
|
|
2017-06-05 01:27:57 +00:00
|
|
|
// Store the contents of the file in memory for adding it into the markdown later.
|
2017-06-07 04:48:39 +00:00
|
|
|
model.savefiles.push({
|
|
|
|
filename: file.replace('.dat', '.zip'),
|
|
|
|
title: savefile.title,
|
|
|
|
description: savefile.description,
|
|
|
|
author: savefile.author,
|
|
|
|
title_id: savefile.title_id
|
|
|
|
});
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
|
|
|
});
|
2017-06-07 04:48:39 +00:00
|
|
|
// Finished copying all savefiles into the output folder, and reading their data.
|
2017-06-03 20:10:29 +00:00
|
|
|
}
|
2017-06-07 04:48:39 +00:00
|
|
|
// END SAVEFILE BLOCK
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-05 01:27:57 +00:00
|
|
|
// Copy the screenshots for the game.
|
2017-06-07 04:48:39 +00:00
|
|
|
let fsPathScreenshotInputGame = `${fsPathCode}/${game}/screenshots/`;
|
|
|
|
let fsPathScreenshotOutputGame = `${fsPathHugoScreenshots}/${game}/`;
|
|
|
|
if (fs.existsSync(fsPathScreenshotInputGame)) {
|
2017-06-05 01:27:57 +00:00
|
|
|
// Create the savefile directory for each game.
|
2017-06-07 04:48:39 +00:00
|
|
|
if (fs.existsSync(fsPathScreenshotOutputGame) == false) {
|
|
|
|
fs.mkdirSync(fsPathScreenshotOutputGame);
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-05 01:27:57 +00:00
|
|
|
// Copy all screenshots into the output folder.
|
2017-06-07 04:48:39 +00:00
|
|
|
fs.readdirSync(fsPathScreenshotInputGame).forEach(file => {
|
2017-06-05 01:27:57 +00:00
|
|
|
if (path.extname(file) == '.png') {
|
2017-06-07 04:48:39 +00:00
|
|
|
fsextra.copySync(`${fsPathScreenshotInputGame}/${file}`, `${fsPathScreenshotOutputGame}/${file}`);
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
|
|
|
});
|
2017-06-03 20:10:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
// WIKI BLOCK
|
|
|
|
var wikiText = "";
|
|
|
|
let fsPathWikiGame = `${fsPathWiki}/${game}.md`;
|
|
|
|
if (fs.existsSync(fsPathWikiGame)) {
|
|
|
|
wikiText = fs.readFileSync(fsPathWikiGame, 'utf8');
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
// Fix Blackfriday markdown rendering differences.
|
|
|
|
wikiText = blackfriday.fixLists(wikiText);
|
|
|
|
wikiText = blackfriday.fixLinks(wikiText);
|
2017-06-05 01:27:57 +00:00
|
|
|
} else {
|
2017-06-07 04:48:39 +00:00
|
|
|
wikiText = "## No wiki exists yet for this game.";
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
2017-06-07 04:48:39 +00:00
|
|
|
// END WIKI BLOCK
|
2017-06-03 01:36:17 +00:00
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
let modelText = tomlify(model, null, 2);
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2017-06-07 04:48:39 +00:00
|
|
|
let contentOutput = `+++\r\n${modelText}\r\n+++\r\n\r\n${wikiText}\r\n`;
|
|
|
|
fs.writeFileSync(`${fsPathHugoContent}/${game}.md`, contentOutput);
|
2017-06-05 01:27:57 +00:00
|
|
|
} catch (ex) {
|
2017-06-06 00:54:57 +00:00
|
|
|
logger.warn(`${game} failed to generate: ${ex}`);
|
|
|
|
logger.error(ex);
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
2017-06-03 01:36:17 +00:00
|
|
|
});
|
|
|
|
} catch (ex) {
|
|
|
|
logger.error(ex);
|
|
|
|
}
|