mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 14:59:23 +00:00
[NAK_CVR_Mods] 2
This commit is contained in:
parent
88faf93b3b
commit
1fbfcd80cd
1 changed files with 124 additions and 36 deletions
120
.github/scripts/update-modlist.js
vendored
120
.github/scripts/update-modlist.js
vendored
|
@ -1,10 +1,56 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const https = require('https');
|
||||||
|
|
||||||
|
// Configuration
|
||||||
const ROOT = '.';
|
const ROOT = '.';
|
||||||
const EXPERIMENTAL = '.Experimental';
|
const EXPERIMENTAL = '.Experimental';
|
||||||
const README_PATH = 'README.md';
|
const README_PATH = 'README.md';
|
||||||
const MARKER_START = '<!-- BEGIN MOD LIST -->';
|
const MARKER_START = '<!-- BEGIN MOD LIST -->';
|
||||||
const MARKER_END = '<!-- END MOD LIST -->';
|
const MARKER_END = '<!-- END MOD LIST -->';
|
||||||
|
const REPO_OWNER = process.env.REPO_OWNER || 'NotAKidoS';
|
||||||
|
const REPO_NAME = process.env.REPO_NAME || 'NAK_CVR_Mods';
|
||||||
|
|
||||||
|
// Function to get latest release info from GitHub API
|
||||||
|
async function getLatestRelease() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const options = {
|
||||||
|
hostname: 'api.github.com',
|
||||||
|
path: `/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest`,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Node.js GitHub Release Checker',
|
||||||
|
'Accept': 'application/vnd.github.v3+json'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const req = https.request(options, (res) => {
|
||||||
|
let data = '';
|
||||||
|
|
||||||
|
res.on('data', (chunk) => {
|
||||||
|
data += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', () => {
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
try {
|
||||||
|
resolve(JSON.parse(data));
|
||||||
|
} catch (e) {
|
||||||
|
reject(new Error(`Failed to parse GitHub API response: ${e.message}`));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(new Error(`GitHub API request failed with status code: ${res.statusCode}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', (e) => {
|
||||||
|
reject(new Error(`GitHub API request error: ${e.message}`));
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getModFolders(baseDir) {
|
function getModFolders(baseDir) {
|
||||||
const entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
const entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
||||||
|
@ -45,27 +91,58 @@ function extractDescription(readmePath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfDllExists(modPath, modName) {
|
async function formatTable(mods, baseDir) {
|
||||||
const dllPath = path.join(modPath, `${modName}.dll`);
|
|
||||||
return fs.existsSync(dllPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTable(mods, baseDir) {
|
|
||||||
if (mods.length === 0) return '';
|
if (mods.length === 0) return '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get the latest release info from GitHub
|
||||||
|
const latestRelease = await getLatestRelease();
|
||||||
|
const releaseAssets = latestRelease.assets || [];
|
||||||
|
|
||||||
|
// Create a map of available files in the release
|
||||||
|
const availableFiles = {};
|
||||||
|
releaseAssets.forEach(asset => {
|
||||||
|
availableFiles[asset.name] = asset.browser_download_url;
|
||||||
|
});
|
||||||
|
|
||||||
let rows = mods.map(modPath => {
|
let rows = mods.map(modPath => {
|
||||||
const modName = path.basename(modPath);
|
const modName = path.basename(modPath);
|
||||||
const readmeLink = path.join(modPath, 'README.md');
|
const readmeLink = path.join(modPath, 'README.md');
|
||||||
const readmePath = path.join(modPath, 'README.md');
|
const readmePath = path.join(modPath, 'README.md');
|
||||||
const description = extractDescription(readmePath);
|
const description = extractDescription(readmePath);
|
||||||
|
|
||||||
// Check if DLL exists and format download cell accordingly
|
// Check if the DLL exists in the latest release
|
||||||
const hasDll = checkIfDllExists(modPath, modName);
|
const dllFilename = `${modName}.dll`;
|
||||||
const downloadCell = hasDll
|
let downloadSection;
|
||||||
? `[Download](${path.join(modPath, `${modName}.dll`)})`
|
|
||||||
: 'No Download';
|
|
||||||
|
|
||||||
return `| [${modName}](${readmeLink}) | ${description} | ${downloadCell} |`;
|
if (availableFiles[dllFilename]) {
|
||||||
|
downloadSection = `[Download](${availableFiles[dllFilename]})`;
|
||||||
|
} else {
|
||||||
|
downloadSection = 'No Download';
|
||||||
|
}
|
||||||
|
|
||||||
|
return `| [${modName}](${readmeLink}) | ${description} | ${downloadSection} |`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
`### ${baseDir === EXPERIMENTAL ? 'Experimental Mods' : 'Released Mods'}`,
|
||||||
|
'',
|
||||||
|
'| Name | Description | Download |',
|
||||||
|
'|------|-------------|----------|',
|
||||||
|
...rows,
|
||||||
|
''
|
||||||
|
].join('\n');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching release information:', error);
|
||||||
|
|
||||||
|
// Fallback to showing "No Download" for all mods if we can't fetch release info
|
||||||
|
let rows = mods.map(modPath => {
|
||||||
|
const modName = path.basename(modPath);
|
||||||
|
const readmeLink = path.join(modPath, 'README.md');
|
||||||
|
const readmePath = path.join(modPath, 'README.md');
|
||||||
|
const description = extractDescription(readmePath);
|
||||||
|
|
||||||
|
return `| [${modName}](${readmeLink}) | ${description} | No Download |`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -77,6 +154,7 @@ function formatTable(mods, baseDir) {
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateReadme(modListSection) {
|
function updateReadme(modListSection) {
|
||||||
const readme = fs.readFileSync(README_PATH, 'utf8');
|
const readme = fs.readFileSync(README_PATH, 'utf8');
|
||||||
|
@ -86,12 +164,22 @@ function updateReadme(modListSection) {
|
||||||
fs.writeFileSync(README_PATH, newReadme);
|
fs.writeFileSync(README_PATH, newReadme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
const mainMods = getModFolders(ROOT).filter(dir => !dir.startsWith(EXPERIMENTAL));
|
const mainMods = getModFolders(ROOT).filter(dir => !dir.startsWith(EXPERIMENTAL));
|
||||||
const experimentalMods = getModFolders(EXPERIMENTAL);
|
const experimentalMods = getModFolders(EXPERIMENTAL);
|
||||||
|
|
||||||
const tableContent = [
|
const mainModsTable = await formatTable(mainMods, ROOT);
|
||||||
formatTable(mainMods, ROOT),
|
const experimentalModsTable = await formatTable(experimentalMods, EXPERIMENTAL);
|
||||||
formatTable(experimentalMods, EXPERIMENTAL)
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
|
const tableContent = [mainModsTable, experimentalModsTable].join('\n');
|
||||||
updateReadme(tableContent);
|
updateReadme(tableContent);
|
||||||
|
|
||||||
|
console.log('README.md updated successfully!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating README:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
Loading…
Add table
Add a link
Reference in a new issue