2018-05-10 01:43:23 +00:00
|
|
|
const fs = require('fs-extra');
|
2017-06-03 01:36:17 +00:00
|
|
|
const path = require('path');
|
|
|
|
const util = require('util');
|
|
|
|
const logger = require('winston');
|
2017-06-07 07:32:12 +00:00
|
|
|
const request = require('request-promise');
|
2017-06-07 04:48:39 +00:00
|
|
|
const tomlify = require('tomlify-j0.4');
|
2017-06-03 01:36:17 +00:00
|
|
|
const exec = require('sync-exec');
|
|
|
|
|
2019-08-06 03:10:45 +00:00
|
|
|
const tenant = 'citra'
|
|
|
|
|
|
|
|
const fsPathCode = `./${tenant}-games-wiki/games`
|
2019-08-06 03:32:54 +00:00
|
|
|
const fsPathHugo = '../../site'
|
2019-08-06 03:10:45 +00:00
|
|
|
const fsPathHugoContent = `${fsPathHugo}/content/game`
|
|
|
|
const fsPathHugoBoxart = `${fsPathHugo}/static/images/game/boxart`
|
|
|
|
const fsPathHugoIcon = `${fsPathHugo}/static/images/game/icons`
|
|
|
|
const fsPathHugoScreenshots = `${fsPathHugo}/static/images/screenshots0`
|
|
|
|
const fsPathHugoSavefiles = `${fsPathHugo}/static/savefiles/`
|
2017-06-01 22:00:37 +00:00
|
|
|
|
2018-03-22 02:54:47 +00:00
|
|
|
process.on('unhandledRejection', err => {
|
|
|
|
logger.error('Unhandled rejection on process.');
|
|
|
|
logger.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
2017-06-03 01:36:17 +00:00
|
|
|
function gitPull(directory, repository) {
|
|
|
|
if (fs.existsSync(directory)) {
|
2018-05-10 01:43:23 +00:00
|
|
|
logger.info(`Fetching latest from Github : ${directory}`);
|
|
|
|
logger.info(`git --git-dir=${directory} pull`);
|
|
|
|
exec(`git --git-dir=${directory} pull`);
|
2017-06-03 01:36:17 +00:00
|
|
|
} else {
|
2018-05-10 01:43:23 +00:00
|
|
|
logger.info(`Cloning repository from Github : ${directory}`);
|
|
|
|
logger.info(`git clone ${repository}`);
|
|
|
|
exec(`git clone ${repository}`);
|
2017-06-07 07:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
async function run() {
|
2017-06-07 07:32:12 +00:00
|
|
|
// Make sure the output directories in Hugo exist.
|
|
|
|
[fsPathHugoContent, fsPathHugoBoxart, fsPathHugoIcon, fsPathHugoSavefiles, fsPathHugoScreenshots].forEach(function (path) {
|
|
|
|
if (fs.existsSync(path) == false) {
|
2018-05-10 01:43:23 +00:00
|
|
|
logger.info(`Creating Hugo output directory: ${path}`);
|
|
|
|
fs.ensureDirSync(path);
|
2017-06-07 07:32:12 +00:00
|
|
|
}
|
|
|
|
});
|
2017-07-27 09:02:02 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Fetch game files stored in games-wiki repository.
|
2019-08-06 03:10:45 +00:00
|
|
|
gitPull(`./${tenant}-games-wiki`, `https://github.com/${tenant}-emu/${tenant}-games-wiki.git`);
|
2017-07-27 09:02:02 +00:00
|
|
|
|
2017-06-07 07:32:12 +00:00
|
|
|
// Loop through each game and process it.
|
2019-08-06 03:10:45 +00:00
|
|
|
let games = await request.get({ uri: `https://api.${tenant}-emu.org/gamedb/websiteFeed/`, json: true })
|
2018-05-10 01:43:23 +00:00
|
|
|
await Promise.all(games.map(async (x) => {
|
|
|
|
try {
|
|
|
|
logger.info(`Processing game: ${x.id}`);
|
2017-06-03 20:10:29 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Set metadata.
|
|
|
|
x.date = `${new Date().toISOString()}`
|
2017-06-05 01:27:57 +00:00
|
|
|
|
2018-07-29 23:56:33 +00:00
|
|
|
// Hugo requires compatibility to be a string to link to data JSON.
|
2019-08-06 03:10:45 +00:00
|
|
|
x.compatibility = x.compatibility.toString()
|
2018-05-10 01:43:23 +00:00
|
|
|
x.testcases.forEach(x => x.compatibility = x.compatibility.toString())
|
2019-08-06 03:10:45 +00:00
|
|
|
|
|
|
|
x.issues = x.issues || []
|
2017-12-23 02:38:32 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Copy the boxart for the game.
|
2019-08-06 03:10:45 +00:00
|
|
|
if (fs.existsSync(`${fsPathCode}/${x.id}/boxart.png`)) {
|
|
|
|
fs.copySync(`${fsPathCode}/${x.id}/boxart.png`, `${fsPathHugoBoxart}/${x.id}.png`);
|
|
|
|
} else if (fs.existsSync(`${fsPathCode}/${x.id}/icon.png`)) {
|
|
|
|
fs.copySync(`${fsPathCode}/${x.id}/icon.png`, `${fsPathHugoBoxart}/${x.id}.png`);
|
|
|
|
}
|
2017-12-23 02:38:32 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Copy the icon for the game.
|
2019-08-06 03:10:45 +00:00
|
|
|
// If the icon does not exist, use the boxart in place of the icon.
|
|
|
|
if (fs.existsSync(`${fsPathCode}/${x.id}/icon.png`)) {
|
|
|
|
fs.copySync(`${fsPathCode}/${x.id}/icon.png`, `${fsPathHugoIcon}/${x.id}.png`);
|
|
|
|
} else if (fs.existsSync(`${fsPathCode}/${x.id}/boxart.png`)) {
|
|
|
|
fs.copySync(`${fsPathCode}/${x.id}/boxart.png`, `${fsPathHugoIcon}/${x.id}.png`);
|
|
|
|
}
|
2017-12-23 02:38:32 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// SAVEFILE BLOCK
|
|
|
|
var fsPathCodeSavefilesGame = `${fsPathCode}/${x.id}/savefiles/`;
|
|
|
|
var fsPathHugoSavefilesGame = `${fsPathHugoSavefiles}/${x.id}/`;
|
|
|
|
if (fs.existsSync(fsPathCodeSavefilesGame)) {
|
|
|
|
// Create the savefile directory for the game.
|
|
|
|
if (fs.existsSync(fsPathHugoSavefilesGame) == false) {
|
2017-06-07 07:32:12 +00:00
|
|
|
fs.mkdirSync(fsPathHugoSavefilesGame);
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Copy all savefiles into the output folder, and read their data.
|
|
|
|
fs.readdirSync(fsPathCodeSavefilesGame).forEach(file => {
|
|
|
|
if (path.extname(file) == '.zip') {
|
|
|
|
fs.copySync(`${fsPathCodeSavefilesGame}/${file}`, `${fsPathHugoSavefilesGame}/${file}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Finished copying all savefiles into the output folder, and reading their data.
|
|
|
|
}
|
|
|
|
// END SAVEFILE BLOCK
|
|
|
|
|
|
|
|
// Copy the screenshots for the game.
|
|
|
|
let fsPathScreenshotInputGame = `${fsPathCode}/${x.id}/screenshots/`;
|
|
|
|
let fsPathScreenshotOutputGame = `${fsPathHugoScreenshots}/${x.id}/`;
|
|
|
|
if (fs.existsSync(fsPathScreenshotInputGame)) {
|
|
|
|
// Create the savefile directory for each game.
|
|
|
|
if (fs.existsSync(fsPathScreenshotOutputGame) == false) {
|
|
|
|
fs.mkdirSync(fsPathScreenshotOutputGame);
|
2017-06-07 07:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Copy all screenshots into the output folder.
|
|
|
|
fs.readdirSync(fsPathScreenshotInputGame).forEach(file => {
|
|
|
|
if (path.extname(file) == '.png') {
|
|
|
|
fs.copySync(`${fsPathScreenshotInputGame}/${file}`, `${fsPathScreenshotOutputGame}/${file}`);
|
|
|
|
}
|
|
|
|
});
|
2017-06-05 01:27:57 +00:00
|
|
|
}
|
2017-06-03 01:36:17 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
// Clear out the wiki markdown so it won't be stored with the metadata.
|
2019-08-06 03:10:45 +00:00
|
|
|
let wikiText = x.wiki_markdown || ''
|
2018-05-10 01:43:23 +00:00
|
|
|
x.wiki_markdown = null
|
2017-06-07 07:32:12 +00:00
|
|
|
|
2019-08-06 03:10:45 +00:00
|
|
|
let meta = tomlify.toToml(x, {space: 2})
|
|
|
|
let contentOutput = `+++\r\nleft_sidebar = true\r\n${meta}\r\n+++\r\n\r\n${wikiText}\r\n`;
|
2017-06-07 07:32:12 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
await fs.writeFile(`${fsPathHugoContent}/${x.id}.md`, contentOutput);
|
2017-06-07 07:32:12 +00:00
|
|
|
|
2018-05-10 01:43:23 +00:00
|
|
|
return x
|
|
|
|
} catch (ex) {
|
|
|
|
logger.warn(`${x.id} ${x.title} failed to generate: ${ex}`);
|
|
|
|
logger.error(ex);
|
|
|
|
throw ex
|
|
|
|
}
|
|
|
|
}))
|
2017-06-03 01:36:17 +00:00
|
|
|
}
|
2018-05-10 01:43:23 +00:00
|
|
|
|
|
|
|
// Script start
|
|
|
|
run()
|