diff --git a/package.json b/package.json index dad8b02..19cf314 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "src/module.js", "type": "module", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node src/main.js" }, "author": "Lukasz Cepowski (https://loskoderos.com)", "license": "MIT", diff --git a/src/app.js b/src/app.js index 5c27342..bb69f72 100644 --- a/src/app.js +++ b/src/app.js @@ -8,6 +8,7 @@ Usage: georender [options] \n \ -i, --in , --in ... - Path to input file (.geojson, .gpx, .kml, .kmz)\n \ -o, --out - Path to output file (.png or .jpg)\n \ -t, --tile - Name of the tile source [osm, otm, esri]\n \ + --timeout - Timeout in seconds before aborting\n \ '; const options = { @@ -16,6 +17,7 @@ const options = { 'in': { type: 'string', short: 'i', multiple: true }, 'out': { type: 'string', short: 'o' }, 'tile': { type: 'string', short: 't', default: 'osm' }, + 'timeout': { type: 'string', default: '30' }, }; export class Application { @@ -60,6 +62,7 @@ export class Application { in: args.values.in, out: args.values.out, tile: args.values.tile, + timeout: args.values.timeout, }); return 0; diff --git a/src/defaults.js b/src/defaults.js index eda6d31..4ca62b9 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -59,6 +59,5 @@ export const defaults = { }) }) ], - padding: [50, 50, 50, 50], - timeout: 30 + padding: [50, 50, 50, 50] }; diff --git a/src/renderer.js b/src/renderer.js index d4f470d..02d0ef8 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -17,6 +17,7 @@ export class Renderer { const inputFiles = options.in || []; const outputFile = options.out || "out.png"; const tile = defaults.tile[options.tile || 'osm']; + const timeoutInSecs = parseInt(options.timeout, 10); const style = defaults.style; const padding = defaults.padding; @@ -24,8 +25,11 @@ export class Renderer { console.log(' height:', height); console.log(' input files:', inputFiles); console.log(' output file:', outputFile); + console.log(' tile:', options.tile || 'osm'); + console.log(' timeout (in seconds):', timeoutInSecs); - const timeout = setTimeout(reject, defaults.timeout * 1000); + const timeout = setTimeout(() => reject(new Error(`Timeout after ${timeoutInSecs}s`)), + timeoutInSecs * 1000); const element = document.createElement('div'); element.style.width = `${width}px`; @@ -74,7 +78,7 @@ export class Renderer { } }) .then(() => console.log("Done!")) - .catch(err => console.error(err instanceof Error ? err.message : "\nTimeout!")) + .catch(err => console.error(err)) ; }