Replace userhome with env-paths (#91)

* Replace userhome with env-paths

* Download the correct package
This commit is contained in:
Christian Paul 2020-08-17 12:02:07 +02:00 committed by GitHub
parent 2d88b6f16d
commit a7e7621705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

View File

@ -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

10
package-lock.json generated
View File

@ -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",

View File

@ -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"
},

View File

@ -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;
}