aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js48
1 files changed, 27 insertions, 21 deletions
diff --git a/index.js b/index.js
index 3425eb5..775ccb6 100644
--- a/index.js
+++ b/index.js
@@ -12,6 +12,7 @@ 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')
@@ -55,6 +56,10 @@ const argv = yargs
.alias('help', 'h')
.argv
+// Resolve the arguments with paths so relative paths become absolute.
+let downloads_dir = path.resolve(argv.downloads_dir)
+let dist_dir = path.resolve(argv.dist_dir)
+
// allow building of only a specified zones
let includedZones = []
let excludedZones = []
@@ -202,7 +207,7 @@ var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
} else {
query += 'relation'
}
- var boundaryFilename = argv.downloads_dir + '/' + boundaryId + '.json'
+ var boundaryFilename = downloads_dir + '/' + boundaryId + '.json'
var debug = 'getting data for ' + boundaryId
var queryKeys = Object.keys(cfg)
@@ -310,7 +315,7 @@ var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
}
var getTzDistFilename = function (tzid) {
- return argv.dist_dir + '/' + tzid.replace(/\//g, '__') + '.json'
+ return dist_dir + '/' + tzid.replace(/\//g, '__') + '.json'
}
/**
@@ -325,7 +330,7 @@ var getTzDistFilename = function (tzid) {
var getDataSource = function (source) {
var geoJson
if (source.source === 'overpass') {
- geoJson = require(argv.downloads_dir + '/' + source.id + '.json')
+ geoJson = require(downloads_dir + '/' + source.id + '.json')
} else if (source.source === 'manual-polygon') {
geoJson = polygon(source.data).geometry
} else if (source.source === 'manual-multipolygon') {
@@ -665,8 +670,8 @@ var addOceans = function (callback) {
}
var combineAndWriteZones = function (callback) {
- var stream = fs.createWriteStream(argv.dist_dir + '/combined.json')
- var streamWithOceans = fs.createWriteStream(argv.dist_dir + '/combined-with-oceans.json')
+ var stream = fs.createWriteStream(dist_dir + '/combined.json')
+ var streamWithOceans = fs.createWriteStream(dist_dir + '/combined-with-oceans.json')
var zones = Object.keys(zoneCfg)
stream.write('{"type":"FeatureCollection","features":[')
@@ -708,11 +713,11 @@ var combineAndWriteZones = function (callback) {
const autoScript = {
makeDownloadsDir: function (cb) {
overallProgress.beginTask('Creating downloads dir')
- safeMkdir(argv.downloads_dir, cb)
+ safeMkdir(downloads_dir, cb)
},
makeDistDir: function (cb) {
overallProgress.beginTask('Creating dist dir')
- safeMkdir(argv.dist_dir, cb)
+ safeMkdir(dist_dir, cb)
},
getOsmBoundaries: ['makeDownloadsDir', function (results, cb) {
overallProgress.beginTask('Downloading osm boundaries')
@@ -720,7 +725,8 @@ const autoScript = {
}],
zipInputData: ['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)
+ exec('zip ' + dist_dir + '/input-data.zip ' + downloads_dir
+ + '/* timezones.json osmBoundarySources.json expectedZoneOverlaps.json', cb)
}],
createZones: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
overallProgress.beginTask('Creating timezone boundaries')
@@ -750,8 +756,8 @@ const autoScript = {
return cb()
}
overallProgress.beginTask('Zipping geojson')
- let zipFile = argv.dist_dir + '/timezones.geojson.zip'
- let jsonFile = argv.dist_dir + '/combined.json'
+ let zipFile = dist_dir + '/timezones.geojson.zip'
+ let jsonFile = dist_dir + '/combined.json'
exec('zip ' + zipFile + ' ' + jsonFile, cb)
}],
zipGeoJsonWithOceans: ['mergeZones', function (results, cb) {
@@ -760,8 +766,8 @@ const autoScript = {
return cb()
}
overallProgress.beginTask('Zipping geojson with oceans')
- let zipFile = argv.dist_dir + '/timezones-with-oceans.geojson.zip'
- let jsonFile = argv.dist_dir + '/combined-with-oceans.json'
+ let zipFile = dist_dir + '/timezones-with-oceans.geojson.zip'
+ let jsonFile = dist_dir + '/combined-with-oceans.json'
exec('zip ' + zipFile + ' ' + jsonFile, cb)
}],
makeShapefile: ['mergeZones', function (results, cb) {
@@ -770,15 +776,15 @@ const autoScript = {
return cb()
}
overallProgress.beginTask('Converting from geojson to shapefile')
- let shapeFileGlob = argv.dist_dir + '/combined-shapefile.*'
+ let shapeFileGlob = dist_dir + '/combined-shapefile.*'
rimraf.sync(shapeFileGlob)
- let shapeFile = argv.dist_dir + '/combined-shapefile.shp'
- let jsonFile = argv.dist_dir + '/combined.json'
+ let shapeFile = dist_dir + '/combined-shapefile.shp'
+ let jsonFile = dist_dir + '/combined.json'
exec(
'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile,
function (err, stdout, stderr) {
if (err) { return cb(err) }
- let shapeFileZip = argv.dist_dir + '/timezones.shapefile.zip'
+ let shapeFileZip = dist_dir + '/timezones.shapefile.zip'
exec('zip ' + shapeFileZip + ' ' + shapeFileGlob, cb)
}
)
@@ -789,15 +795,15 @@ const autoScript = {
return cb()
}
overallProgress.beginTask('Converting from geojson with oceans to shapefile')
- let shapeFileGlob = argv.dist_dir + '/combined-shapefile-with-oceans.*'
+ let shapeFileGlob = dist_dir + '/combined-shapefile-with-oceans.*'
rimraf.sync(shapeFileGlob)
- let shapeFile = argv.dist_dir + '/combined-shapefile-with-oceans.shp'
- let jsonFile = argv.dist_dir + '/combined-with-oceans.json'
+ let shapeFile = dist_dir + '/combined-shapefile-with-oceans.shp'
+ let jsonFile = dist_dir + '/combined-with-oceans.json'
exec(
'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile,
function (err, stdout, stderr) {
if (err) { return cb(err) }
- let shapeFileZip = argv.dist_dir + '/timezones-with-oceans.shapefile.zip'
+ let shapeFileZip = dist_dir + '/timezones-with-oceans.shapefile.zip'
exec('zip ' + shapeFileZip + ' ' + shapeFileGlob, cb)
}
)
@@ -815,7 +821,7 @@ const autoScript = {
zoneNames = zoneNames.filter(zoneName => excludedZones.indexOf(zoneName) === -1)
}
fs.writeFile(
- argv.dist_dir + '/timezone-names.json',
+ dist_dir + '/timezone-names.json',
JSON.stringify(zoneNames),
cb
)