2020-07-03 06:55:48 +09:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const JSON_FILE_PATH = path.join(__dirname, '../site/.vuepress/data/gameVersions.json');
|
|
|
|
const CODE_VERSIONS = ['GMSE01', 'GMSJ01', 'GMSP01', 'GMSJ0A'];
|
|
|
|
const INJECTION_TAG = '<!-- injectionpoint -->';
|
|
|
|
|
2020-07-03 10:42:57 +09:00
|
|
|
const locales = require(path.join(__dirname, '../site/.vuepress/i18n/locales.json'));
|
2020-07-03 08:21:52 +09:00
|
|
|
|
2020-07-03 06:55:48 +09:00
|
|
|
// Load the current json configuration
|
|
|
|
const codeJson = JSON.parse(fs.readFileSync(JSON_FILE_PATH));
|
|
|
|
|
|
|
|
codeJson.forEach((gameVersion) => {
|
|
|
|
gameVersion.codes = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Save the codeJSON with the cleared codes
|
|
|
|
fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(codeJson));
|
|
|
|
|
2020-07-03 08:21:52 +09:00
|
|
|
Object.keys(locales).forEach((locale) => {
|
|
|
|
// Clear the code reference
|
|
|
|
for (let i = 0; i < CODE_VERSIONS.length; i++) {
|
|
|
|
const filePath = path.join(
|
|
|
|
__dirname,
|
|
|
|
`../site/${locale.trim()}/code-reference/${CODE_VERSIONS[i].toLowerCase()}.md`,
|
|
|
|
);
|
2020-07-03 06:55:48 +09:00
|
|
|
|
2020-07-03 08:21:52 +09:00
|
|
|
// Get the current reference
|
|
|
|
const reference = fs.readFileSync(filePath).toString();
|
2020-07-03 06:55:48 +09:00
|
|
|
|
2020-07-03 08:21:52 +09:00
|
|
|
if (!reference.includes(INJECTION_TAG)) {
|
|
|
|
throw new Error(`No injection tag found in ${CODE_VERSIONS[i].toLowerCase()}.md`);
|
|
|
|
}
|
2020-07-03 06:55:48 +09:00
|
|
|
|
2020-07-03 08:21:52 +09:00
|
|
|
// Clear everything after the injection tag
|
|
|
|
let fileContent = reference.split(INJECTION_TAG)[0] + INJECTION_TAG;
|
2020-07-03 06:55:48 +09:00
|
|
|
|
2020-07-03 08:21:52 +09:00
|
|
|
// Save the reference file
|
|
|
|
fs.writeFileSync(filePath, fileContent);
|
|
|
|
}
|
|
|
|
});
|