diff options
author | evansiroky <evan.siroky@yahoo.com> | 2020-10-17 23:10:15 -0700 |
---|---|---|
committer | evansiroky <evan.siroky@yahoo.com> | 2020-10-17 23:10:15 -0700 |
commit | f3bcf056617bd4391423adeb3b9461a199d9b125 (patch) | |
tree | 48e0dad3154fe22689c3f8b2d562cca054b13fbb | |
parent | eabb18fc1e19245bc02e23e71f35689ca3dbd46e (diff) | |
download | timezone-boundary-builder-f3bcf056617bd4391423adeb3b9461a199d9b125.tar.gz |
Clean downloads folder before creating input data zip.
Fixes #82
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | index.js | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3008b1a..a9b0827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Switch command line flag processing to use the yargs library. Existing flags have changed: --no-validation and --filtered-zones have been renamed to --no_validation and --included_zones respectively. --included_zones now takes a list without quotes or commas. * Addition of new flags: --excluded_zones, --dist_dir, --downloads_dir, --skip_zip, --skip_shapefile. See --help and README.md for details. +* Remove unneeded downloaded files from downloads directory before creating input data zipfile ([#82](https://github.com/evansiroky/timezone-boundary-builder/issues/82)). ## 2020a @@ -1,5 +1,6 @@ var exec = require('child_process').exec var fs = require('fs') +var path = require('path') var area = require('@mapbox/geojson-area') var geojsonhint = require('@mapbox/geojsonhint') @@ -12,7 +13,6 @@ var jsts = require('jsts') var rimraf = require('rimraf') var overpass = require('query-overpass') var yargs = require('yargs') -var path = require('path') const ProgressStats = require('./progressStats') @@ -723,7 +723,24 @@ const autoScript = { overallProgress.beginTask('Downloading osm boundaries') asynclib.eachSeries(Object.keys(osmBoundarySources), downloadOsmBoundary, cb) }], - zipInputData: ['makeDistDir', 'getOsmBoundaries', function (results, cb) { + cleanDownloadFolder: ['makeDistDir', 'getOsmBoundaries', function (results, cb) { + overallProgress.beginTask('cleanDownloadFolder') + const downloadedFilenames = Object.keys(osmBoundarySources).map(name => `${name}.json`) + fs.readdir('downloads', (err, files) => { + if (err) return cb(err) + asynclib.each( + files, + (file, fileCb) => { + if (downloadedFilenames.indexOf(file) === -1) { + return fs.unlink(path.join('downloads', file), fileCb) + } + fileCb() + }, + cb + ) + }) + }], + zipInputData: ['cleanDownloadFolder', function (results, cb) { overallProgress.beginTask('Zipping up input data') exec('zip ' + distDir + '/input-data.zip ' + downloadsDir + '/* timezones.json osmBoundarySources.json expectedZoneOverlaps.json', cb) |