Skip to content

Commit

Permalink
Replace userhome with env-paths (#91)
Browse files Browse the repository at this point in the history
* Replace userhome with env-paths

* Download the correct package
  • Loading branch information
jaller94 authored Aug 17, 2020
1 parent 2d88b6f commit a7e7621
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"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",
"rbush": "^3.0.1",
"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"
},
Expand Down
15 changes: 8 additions & 7 deletions src/TileSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -141,23 +143,22 @@ class TileSource {

_initPersistence() {
try {
this._createFolder(userhome('.mapscii'));
this._createFolder(userhome('.mapscii', 'cache'));
this._createFolder(paths.cache);
} catch (error) {
config.persistDownloadedTiles = false;
}
}

_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;
}
Expand Down

0 comments on commit a7e7621

Please sign in to comment.