41 lines
No EOL
1.3 KiB
JavaScript
41 lines
No EOL
1.3 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const CAPTAINS_DIR = path.join(__dirname, '../src/assets/captains');
|
|
const INDEX_FILE = path.join(CAPTAINS_DIR, 'index.json');
|
|
|
|
function generateCaptainsIndex() {
|
|
try {
|
|
// Read all JSON files in the captains directory
|
|
const files = fs.readdirSync(CAPTAINS_DIR)
|
|
.filter(file => file.endsWith('.json') && file !== 'index.json');
|
|
|
|
// Parse each captain file to get their id and name
|
|
const captains = files.map(file => {
|
|
const content = fs.readFileSync(path.join(CAPTAINS_DIR, file), 'utf-8');
|
|
const captain = JSON.parse(content);
|
|
return {
|
|
id: captain.id,
|
|
name: captain.name
|
|
};
|
|
});
|
|
|
|
// Create the index object
|
|
const index = {
|
|
captains: captains
|
|
};
|
|
|
|
// Write the index file
|
|
fs.writeFileSync(INDEX_FILE, JSON.stringify(index, null, 4));
|
|
console.log('Successfully generated captains index');
|
|
} catch (error) {
|
|
console.error('Error generating captains index:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
generateCaptainsIndex();
|