68 lines
1.9 KiB
JavaScript
Executable File
68 lines
1.9 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Script to update asset-map.json with new media entries
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Configuration
|
|
const RAW_DATA_DIR = path.join(__dirname, '..', 'data', 'raw', '2025-12-30T15-21-49-331Z');
|
|
const PROCESSED_DATA_DIR = path.join(__dirname, '..', 'data', 'processed');
|
|
|
|
// New media IDs to add
|
|
const NEW_MEDIA_IDS = [10432, 10440, 10382, 10616, 10615, 45569, 10638];
|
|
|
|
function updateAssetMap() {
|
|
console.log('🔄 Updating asset-map.json with new media entries');
|
|
|
|
// Load current media.json
|
|
const mediaJsonPath = path.join(RAW_DATA_DIR, 'media.json');
|
|
const mediaData = JSON.parse(fs.readFileSync(mediaJsonPath, 'utf8'));
|
|
|
|
// Load current asset-map.json
|
|
const assetMapPath = path.join(PROCESSED_DATA_DIR, 'asset-map.json');
|
|
let assetMap = {};
|
|
|
|
if (fs.existsSync(assetMapPath)) {
|
|
assetMap = JSON.parse(fs.readFileSync(assetMapPath, 'utf8'));
|
|
}
|
|
|
|
// Add new entries
|
|
let addedCount = 0;
|
|
NEW_MEDIA_IDS.forEach(id => {
|
|
const mediaEntry = mediaData.find(m => m.id === id);
|
|
if (mediaEntry) {
|
|
const localPath = `/media/${mediaEntry.filename}`;
|
|
assetMap[mediaEntry.url] = localPath;
|
|
console.log(`✅ Added: ${id} → ${localPath}`);
|
|
addedCount++;
|
|
} else {
|
|
console.warn(`⚠️ Media ID ${id} not found in media.json`);
|
|
}
|
|
});
|
|
|
|
// Save updated asset-map.json
|
|
fs.writeFileSync(
|
|
assetMapPath,
|
|
JSON.stringify(assetMap, null, 2)
|
|
);
|
|
|
|
console.log(`\n🎉 Asset map updated! Added ${addedCount} new entries`);
|
|
console.log(`Total entries in asset-map.json: ${Object.keys(assetMap).length}`);
|
|
|
|
return assetMap;
|
|
}
|
|
|
|
// Run if called directly
|
|
if (require.main === module) {
|
|
try {
|
|
updateAssetMap();
|
|
} catch (error) {
|
|
console.error('❌ Failed to update asset map:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
module.exports = { updateAssetMap }; |