WIP on download cleanup and version diff analysis

Refs #82
Refs #83
diff --git a/index.js b/index.js
index 56e8c02..49b096e 100644
--- a/index.js
+++ b/index.js
@@ -47,6 +47,7 @@
 var precisionModel = new jsts.geom.PrecisionModel(1000000)
 var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel)
 var distZones = {}
+var lastReleaseJSONfile
 var minRequestGap = 4
 var curRequestGap = 4
 
@@ -653,6 +654,47 @@
   ], callback)
 }
 
+var cleanDownloadsDir = function (cb) {
+  // TODO:
+
+  // list all files in downloads dir
+  // for each file
+  // if file does not exist in osmBoundarySources.json file, then remove
+  cb()
+}
+
+var downloadLastRelease = function (cb) {
+  // TODO:
+
+  // download latest release info
+  // determine last release version name
+  lastReleaseJSONfile = `./dist/${lastReleaseName}.json`
+
+  // check if file already downloaded, if so immediately callback
+  fetchIfNeeded(lastReleaseJSONfile, cb, cb, function () {
+    // find download link for geojson with oceans
+    // download the latest release data into the dist directory
+    // unzip geojson
+    cb()
+  })
+}
+
+var analyzeChangesFromLastRelease = function (cb) {
+  // TODO
+
+  // load last release data into memory
+
+  // generate set of keys from last release and current
+
+  // for each zone
+  // diff current - last = additions
+  // diff last - current = removals
+
+  // write file of additions
+  // write file of removals
+  cb()
+}
+
 const autoScript = {
   makeDownloadsDir: function (cb) {
     overallProgress.beginTask('Creating downloads dir')
@@ -662,14 +704,26 @@
     overallProgress.beginTask('Creating dist dir')
     safeMkdir('./dist', cb)
   },
+  cleanDownloadsDir: ['makeDownloadsDir', function (results, cb) {
+    overallProgress.beginTask('Cleaning downloads directory of unused files')
+    cleanDownloadsDir(cb)
+  }],
   getOsmBoundaries: ['makeDownloadsDir', function (results, cb) {
     overallProgress.beginTask('Downloading osm boundaries')
     asynclib.eachSeries(Object.keys(osmBoundarySources), downloadOsmBoundary, cb)
   }],
-  zipInputData: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
+  zipInputData: ['cleanDownloadsDir', 'makeDistDir', 'getOsmBoundaries', function (results, cb) {
     overallProgress.beginTask('Zipping up input data')
     exec('zip dist/input-data.zip downloads/* timezones.json osmBoundarySources.json expectedZoneOverlaps.json', cb)
   }],
+  downloadLastRelease: ['makeDistDir', function (results, cb) {
+    if (process.argv.indexOf('analyze-changes') > -1) {
+      overallProgress.beginTask('Downloading last release for analysis')
+      downloadLastRelease(cb)
+    } else {
+      overallProgress.beginTask('WARNING: Skipping download of last release for analysis!')
+    }
+  }],
   createZones: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
     overallProgress.beginTask('Creating timezone boundaries')
     asynclib.each(Object.keys(zoneCfg), makeTimezoneBoundary, cb)
@@ -736,7 +790,15 @@
       JSON.stringify(zoneNames),
       cb
     )
-  }
+  },
+  analyzeChangesFromLastRelease: ['downloadLastRelease', 'mergeZones', function (results, cb) {
+    if (process.argv.indexOf('analyze-changes') > -1) {
+      overallProgress.beginTask('Analyzing changes from last release')
+      analyzeChangesFromLastRelease(cb)
+    } else {
+      overallProgress.beginTask('WARNING: Skipping analysis of changes from last release!')
+    }
+  }]
 }
 
 const overallProgress = new ProgressStats('Overall', Object.keys(autoScript).length)