@@ -10,10 +10,10 @@ const tasksPath = './tasks/topojson';
1010const outputPath = './build/geodata' ;
1111
1212// Download Natural Earth vectors
13- for ( const [ vector , source ] of Object . entries ( vectors ) ) {
13+ for ( const vector of Object . values ( vectors ) ) {
1414 for ( const resolution of resolutions ) {
1515 const url = getNEDownloadUrl ( { resolution, vector } ) ;
16- const filename = getNEFilename ( { resolution, source } ) ;
16+ const filename = getNEFilename ( { resolution, source : vector . source } ) ;
1717 const archivePath = `${ outputPath } /${ filename } .zip` ;
1818
1919 if ( fs . existsSync ( archivePath ) ) {
@@ -46,11 +46,12 @@ for (const [vector, source] of Object.entries(vectors)) {
4646// Download UN GeoJSON file
4747const url = unDownloadUrl ;
4848const archivePath = `${ tasksPath } /${ unFilename } .zip` ;
49- const geojsonPath = `${ outputPath } /${ unFilename } .geojson` ;
49+ const geojsonPath = `${ outputPath } ` ;
50+ const geojsonFilePath = `${ geojsonPath } /${ unFilename } .geojson` ;
5051
5152if ( fs . existsSync ( archivePath ) ) {
5253 console . log ( `File ${ archivePath } already exists. Skipping download.` ) ;
53- if ( fs . existsSync ( geojsonPath ) ) console . log ( `File ${ geojsonPath } already exists. Skipping decompression.` ) ;
54+ if ( fs . existsSync ( geojsonFilePath ) ) console . log ( `File ${ geojsonFilePath } already exists. Skipping decompression.` ) ;
5455 else exec ( `unzip -o ${ archivePath } -d ${ geojsonPath } ` ) ;
5556} else {
5657 try {
@@ -59,17 +60,17 @@ if (fs.existsSync(archivePath)) {
5960 const response = await fetch ( url ) ;
6061 if ( ! response . ok || ! response . body ) throw new Error ( `Bad response: ${ response . status } ` ) ;
6162
62- if ( ! fs . existsSync ( outputPath ) ) fs . mkdirSync ( outputPath , { recursive : true } ) ;
63- const file = fs . createWriteStream ( geojsonPath ) ;
63+ // if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
64+ const file = fs . createWriteStream ( geojsonFilePath ) ;
6465 await pipeline ( Readable . fromWeb ( response . body ) , file ) ;
65- console . log ( `UN GeoJSON file saved to ${ geojsonPath } ` ) ;
66+ console . log ( `UN GeoJSON file saved to ${ geojsonFilePath } ` ) ;
6667
6768 console . log ( 'Compressing UN GeoJSON for future use' ) ;
6869 // Use the shell to handle compression
69- exec ( `zip ${ archivePath } ${ geojsonPath } ` ) ;
70+ exec ( `zip -j ${ archivePath } ${ geojsonFilePath } ` ) ;
7071
7172 console . log ( `UN GeoJSON archive saved to ${ archivePath } ` ) ;
7273 } catch ( error ) {
73- console . error ( `Error when downloading file '${ geojsonPath } ': ${ error } ` ) ;
74+ console . error ( `Error when downloading file '${ geojsonFilePath } ': ${ error } ` ) ;
7475 }
7576}
0 commit comments