citra-emu
/
citra-web
Archived
1
0
Fork 0

Replaced app with shared code revision. Eventually will submodule.

This commit is contained in:
Chris 2019-08-05 23:10:45 -04:00
parent 7ba99885f8
commit 97e4bbad99
1 changed files with 30 additions and 23 deletions

View File

@ -1,3 +1,5 @@
require('checkenv').check();
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const util = require('util'); const util = require('util');
@ -6,13 +8,15 @@ const request = require('request-promise');
const tomlify = require('tomlify-j0.4'); const tomlify = require('tomlify-j0.4');
const exec = require('sync-exec'); const exec = require('sync-exec');
const fsPathCode = './citra-games-wiki/games' const tenant = 'citra'
const fsPathWiki = './citra-games-wiki.wiki'
const fsPathHugoContent = '../../site/content/game' const fsPathCode = `./${tenant}-games-wiki/games`
const fsPathHugoBoxart = '../../site/static/images/game/boxart' const fsPathHugo = '../../../site'
const fsPathHugoIcon = '../../site/static/images/game/icons' const fsPathHugoContent = `${fsPathHugo}/content/game`
const fsPathHugoScreenshots = '../../site/static/images/screenshots0' const fsPathHugoBoxart = `${fsPathHugo}/static/images/game/boxart`
const fsPathHugoSavefiles = '../../site/static/savefiles/' const fsPathHugoIcon = `${fsPathHugo}/static/images/game/icons`
const fsPathHugoScreenshots = `${fsPathHugo}/static/images/screenshots0`
const fsPathHugoSavefiles = `${fsPathHugo}/static/savefiles/`
process.on('unhandledRejection', err => { process.on('unhandledRejection', err => {
logger.error('Unhandled rejection on process.'); logger.error('Unhandled rejection on process.');
@ -32,10 +36,6 @@ function gitPull(directory, repository) {
} }
} }
async function getDirectories(x) {
return fs.readdir(x).filter(file => fs.lstatSync(path.join(x, file)).isDirectory())
}
async function run() { async function run() {
// Make sure the output directories in Hugo exist. // Make sure the output directories in Hugo exist.
[fsPathHugoContent, fsPathHugoBoxart, fsPathHugoIcon, fsPathHugoSavefiles, fsPathHugoScreenshots].forEach(function (path) { [fsPathHugoContent, fsPathHugoBoxart, fsPathHugoIcon, fsPathHugoSavefiles, fsPathHugoScreenshots].forEach(function (path) {
@ -46,10 +46,10 @@ async function run() {
}); });
// Fetch game files stored in games-wiki repository. // Fetch game files stored in games-wiki repository.
gitPull('./citra-games-wiki', 'https://github.com/citra-emu/citra-games-wiki.git'); gitPull(`./${tenant}-games-wiki`, `https://github.com/${tenant}-emu/${tenant}-games-wiki.git`);
// Loop through each game and process it. // Loop through each game and process it.
let games = await request.get({ uri: 'https://api.citra-emu.org/gamedb/websiteFeed/', json: true }) let games = await request.get({ uri: `https://api.${tenant}-emu.org/gamedb/websiteFeed/`, json: true })
await Promise.all(games.map(async (x) => { await Promise.all(games.map(async (x) => {
try { try {
logger.info(`Processing game: ${x.id}`); logger.info(`Processing game: ${x.id}`);
@ -57,19 +57,26 @@ async function run() {
// Set metadata. // Set metadata.
x.date = `${new Date().toISOString()}` x.date = `${new Date().toISOString()}`
// In Hugo, data keys need to be strings.
x.compatibility = x.compatibility.toString()
// Hugo requires compatibility to be a string to link to data JSON. // Hugo requires compatibility to be a string to link to data JSON.
x.compatibility = x.compatibility.toString()
x.testcases.forEach(x => x.compatibility = x.compatibility.toString()) x.testcases.forEach(x => x.compatibility = x.compatibility.toString())
x.issues = x.issues.filter(x => x.state === 'open') || [] x.issues = x.issues || []
// Copy the boxart for the game. // Copy the boxart for the game.
fs.copySync(`${fsPathCode}/${x.id}/boxart.png`, `${fsPathHugoBoxart}/${x.id}.png`); 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`);
}
// Copy the icon for the game. // Copy the icon for the game.
fs.copySync(`${fsPathCode}/${x.id}/icon.png`, `${fsPathHugoIcon}/${x.id}.png`); // 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`);
}
// SAVEFILE BLOCK // SAVEFILE BLOCK
var fsPathCodeSavefilesGame = `${fsPathCode}/${x.id}/savefiles/`; var fsPathCodeSavefilesGame = `${fsPathCode}/${x.id}/savefiles/`;
@ -108,11 +115,11 @@ async function run() {
} }
// Clear out the wiki markdown so it won't be stored with the metadata. // Clear out the wiki markdown so it won't be stored with the metadata.
let wikiText = x.wiki_markdown let wikiText = x.wiki_markdown || ''
x.wiki_markdown = null x.wiki_markdown = null
let meta = tomlify(x, null, 2); let meta = tomlify.toToml(x, {space: 2})
let contentOutput = `+++\r\n${meta}\r\n+++\r\n\r\n${wikiText}\r\n`; let contentOutput = `+++\r\nleft_sidebar = true\r\n${meta}\r\n+++\r\n\r\n${wikiText}\r\n`;
await fs.writeFile(`${fsPathHugoContent}/${x.id}.md`, contentOutput); await fs.writeFile(`${fsPathHugoContent}/${x.id}.md`, contentOutput);