DingusCraft/csv-import.js
2025-05-11 10:01:48 -06:00

38 lines
974 B
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');
// Split lines and remove the header
const lines = data.trim().split('\n').slice(1);
for (const line of lines) {
const [name, url] = line.split(',');
let command = '';
if (url.startsWith('https://modrinth.com')) {
command = `packwiz mr add ${url}`;
} else if (url.startsWith('https://www.curseforge.com')) {
command = `packwiz cf add ${url}`;
} else {
console.log(`Skipping unknown URL source: ${url}`);
continue;
}
console.log(`Running: ${command}`);
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error running command: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
});
}