|
| 1 | +#!/usr/bin/env node |
| 2 | +const fs = require('fs'); |
| 3 | +const https = require('https'); |
| 4 | +const path = require('path'); |
| 5 | + |
| 6 | +const targetFiles = [ |
| 7 | + 'src/assets/regions.json', |
| 8 | + 'dist/modern/assets/regions.json', |
| 9 | + 'dist/legacy/assets/regions.json' |
| 10 | +]; |
| 11 | + |
| 12 | +function downloadRegions(targetFile) { |
| 13 | + const targetDir = path.dirname(targetFile); |
| 14 | + |
| 15 | + // Ensure directory exists |
| 16 | + if (!fs.existsSync(targetDir)) { |
| 17 | + fs.mkdirSync(targetDir, { recursive: true }); |
| 18 | + } |
| 19 | + |
| 20 | + const url = 'https://artifacts.contentstack.com/regions.json'; |
| 21 | + |
| 22 | + https.get(url, { timeout: 30000 }, (response) => { |
| 23 | + if (response.statusCode === 200) { |
| 24 | + const fileStream = fs.createWriteStream(targetFile); |
| 25 | + response.pipe(fileStream); |
| 26 | + |
| 27 | + fileStream.on('close', () => { |
| 28 | + console.log(`✓ Updated ${targetFile}`); |
| 29 | + }); |
| 30 | + |
| 31 | + fileStream.on('error', (err) => { |
| 32 | + console.log(`Warning: Failed to write ${targetFile}, using bundled version`); |
| 33 | + }); |
| 34 | + } else { |
| 35 | + console.log(`Warning: HTTP ${response.statusCode}, using bundled regions.json`); |
| 36 | + } |
| 37 | + }).on('error', (err) => { |
| 38 | + console.log(`Warning: Failed to download regions.json (${err.message}), using bundled version`); |
| 39 | + }).setTimeout(30000, function() { |
| 40 | + this.destroy(); |
| 41 | + console.log('Warning: Download timeout, using bundled regions.json'); |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +// Download to all target locations |
| 46 | +targetFiles.forEach(downloadRegions); |
| 47 | + |
0 commit comments