From a7e76217053a145e51961b47c01e1efade1988be Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Mon, 17 Aug 2020 12:02:07 +0200 Subject: [PATCH] Replace userhome with env-paths (#91) * Replace userhome with env-paths * Download the correct package --- README.md | 2 +- package-lock.json | 10 +++++----- package.json | 2 +- src/TileSource.js | 15 ++++++++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a638dbe..a78d6c6 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ If your terminal supports mouse events you can drag the map and use your scroll #### Handling the flow * [`bluebird`](https://github.com/petkaantonov/bluebird) for all the asynchronous [Promise](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise) magic * [`node-fetch`](https://github.com/bitinn/node-fetch) for HTTP requests -* [`userhome`](https://github.com/shama/userhome) to determine where to persist downloaded tiles +* [`env-paths`](https://github.com/sindresorhus/env-paths) to determine where to persist downloaded tiles ### TODOs * MapSCII diff --git a/package-lock.json b/package-lock.json index 1dec845..990e9ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1597,6 +1597,11 @@ "ansi-colors": "^4.1.1" } }, + "env-paths": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz", + "integrity": "sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA==" + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -5125,11 +5130,6 @@ "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", "dev": true }, - "userhome": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/userhome/-/userhome-1.0.0.tgz", - "integrity": "sha1-tkkf8S0hpecmcd+czIcX4cZojAs=" - }, "uuid": { "version": "8.3.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz", diff --git a/package.json b/package.json index 42cf017..08855d2 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "bluebird": "^3.7.2", "bresenham": "0.0.4", "earcut": "^2.2.2", + "env-paths": "^2.2.0", "keypress": "^0.2.1", "node-fetch": "^2.6.0", "pbf": "^3.2.1", @@ -41,7 +42,6 @@ "simplify-js": "^1.2.4", "string-width": "^4.2.0", "term-mouse": "^0.2.2", - "userhome": "^1.0.0", "x256": "0.0.2", "yargs": "^15.4.1" }, diff --git a/src/TileSource.js b/src/TileSource.js index 117a1e6..d9c4f1a 100644 --- a/src/TileSource.js +++ b/src/TileSource.js @@ -7,9 +7,11 @@ * local MBTiles and VectorTiles */ 'use strict'; -const userhome = require('userhome'); -const fetch = require('node-fetch'); const fs = require('fs'); +const path = require('path'); +const fetch = require('node-fetch'); +const envPaths = require('env-paths'); +const paths = envPaths('mapscii'); const Tile = require('./Tile'); const config = require('./config'); @@ -141,8 +143,7 @@ class TileSource { _initPersistence() { try { - this._createFolder(userhome('.mapscii')); - this._createFolder(userhome('.mapscii', 'cache')); + this._createFolder(paths.cache); } catch (error) { config.persistDownloadedTiles = false; } @@ -150,14 +151,14 @@ class TileSource { _persistTile(z, x, y, buffer) { const zoom = z.toString(); - this._createFolder(userhome('.mapscii', 'cache', zoom)); - const filePath = userhome('.mapscii', 'cache', zoom, `${x}-${y}.pbf`); + this._createFolder(path.join(paths.cache, zoom)); + const filePath = path.join(paths.cache, zoom, `${x}-${y}.pbf`); return fs.writeFile(filePath, buffer, () => null); } _getPersited(z, x, y) { try { - return fs.readFileSync(userhome('.mapscii', 'cache', z.toString(), `${x}-${y}.pbf`)); + return fs.readFileSync(path.join(paths.cache, z.toString(), `${x}-${y}.pbf`)); } catch (error) { return false; }