63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
const fs = require('fs');
|
|
const { exec } = require('child_process');
|
|
|
|
// Read the CSV file as text
|
|
const filePath = 'import.csv'; // Replace with your file
|
|
const data = fs.readFileSync(filePath, 'utf8');
|
|
var errors = 0;
|
|
var good = 0;
|
|
// Split lines and remove the header
|
|
const lines = data.trim().split('\n').slice(1);
|
|
var delay = 0;
|
|
|
|
|
|
const doThing = (line) => {
|
|
const [name, url, filename] = line.split(',');
|
|
|
|
let command = '';
|
|
parts = url.split('/');
|
|
if (parts[2] === 'modrinth.com') {
|
|
command = `packwiz mr add --project-id ${parts[4]} --version-filename ${encodeURIComponent(filename)}`;
|
|
} else if (parts[2] === 'www.curseforge.com') {
|
|
command = `packwiz cf add --addon-id ${parts[4]}`;
|
|
} else {
|
|
console.log(`Skipping unknown URL source: ${url}`);
|
|
command = '';
|
|
}
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error) {
|
|
console.error(`Error running command: ${error.message}`);
|
|
errors++;
|
|
console.log(`Error #${errors} running command: ${error.message}`);
|
|
return;
|
|
}
|
|
if (stderr) {
|
|
errors++;
|
|
console.log(`Error #${errors} running command: ${stderr}`);
|
|
}
|
|
if (stdout) {
|
|
|
|
good++;
|
|
console.log(`Good #${good} running command: ${stdout}`);
|
|
}
|
|
});
|
|
if (watchdog) {
|
|
clearTimeout(watchdog);
|
|
var watchdog = setTimeout(() => {
|
|
console.log(`Done; ${good} good, ${errors} errors`);
|
|
clearTimeout(watchdog);
|
|
})
|
|
} else {
|
|
var watchdog = setTimeout(() => {
|
|
console.log(`Done; ${good} good, ${errors} errors`);
|
|
clearTimeout(watchdog);
|
|
}, 3000)
|
|
}
|
|
}
|
|
|
|
for (const line of lines) {
|
|
setTimeout(doThing, delay, line);
|
|
delay += 1000; // 1 second delay between each line
|
|
}
|
|
|