Skip to content

Commit 0b0a85b

Browse files
committed
bump dependencies
1 parent 6a9b7fb commit 0b0a85b

File tree

4 files changed

+582
-605
lines changed

4 files changed

+582
-605
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ You can also create a `.env` file which specifies any of the following variables
1717
- `MAX_ZOOM`: The maximum zoom level for which to generate tiles (zero-indexed)
1818
- `MIN_ZOOM`: The minimum zoom level for which to generate tiles (zero-indexed)
1919
- `TILE_SIZE`: The size of tiles, defaults to an optimal value at runtime, can be chosen at runtime, and falls back to 256
20+
- `THREAD_LIMIT`: The number of worker threads to use. If not supplied, defaults to `os.availableParallelism()`

index.mjs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import fs from 'fs/promises';
22
import path from 'path';
3+
import { availableParallelism } from 'os';
4+
import readline from 'readline';
35

46
import sharp from 'sharp';
57
import ora from 'ora';
6-
import promptSync from 'prompt-sync';
78
import dotenv from 'dotenv';
89
import { DateTime } from 'luxon';
910

1011
import WorkerPromise, { activeWorkerCount, workerEvents } from './worker-promise.mjs';
1112

1213
dotenv.config();
13-
const prompt = promptSync();
14+
const prompt = (textPrompt, defaultValue) => {
15+
return new Promise((resolve) => {
16+
const input = readline.createInterface({
17+
input: process.stdin,
18+
output: process.stdout
19+
});
20+
input.question(textPrompt, response => {
21+
input.close();
22+
if (response === '') {
23+
response = undefined;
24+
}
25+
resolve(response ?? String(defaultValue));
26+
});
27+
});
28+
};
1429

1530
let imagePath = process.env.IMAGE_PATH || process.argv[2];
1631
if (!imagePath) {
@@ -19,7 +34,7 @@ if (!imagePath) {
1934
}
2035
const minTileSize = process.env.MIN_TILE_SIZE || 100;
2136
const maxTileSize = process.env.MAX_TILE_SIZE || 400;
22-
const threadLimit = isNaN(process.env.THREAD_LIMIT) ? 8 : parseInt(process.env.THREAD_LIMIT);
37+
const threadLimit = isNaN(process.env.THREAD_LIMIT) ? availableParallelism() : parseInt(process.env.THREAD_LIMIT);
2338
const testOutput = Boolean(process.env.TEST_OUTPUT || false);
2439

2540
async function getTileSettings() {
@@ -45,7 +60,7 @@ async function getTileSettings() {
4560
for (let i = 0; i < files.length; i++) {
4661
console.log(`${i + 1}. ${files[i]}`);
4762
}
48-
const index = prompt(`[1-${files.length}]: `);
63+
const index = await prompt(`[1-${files.length}]: `);
4964
if (isNaN(index) || index < 1 || index > files.length) {
5065
return Promise.reject(new Error(`${index} is an invalid input image selection`));
5166
}
@@ -58,7 +73,7 @@ async function getTileSettings() {
5873
tileSettings.imagePath.lastIndexOf(path.sep) + 1,
5974
tileSettings.imagePath.lastIndexOf('.')
6075
);
61-
const newMapName = prompt(`Output folder (${tileSettings.mapName}): `, tileSettings.mapName);
76+
const newMapName = await prompt(`Output folder (${tileSettings.mapName}): `, tileSettings.mapName);
6277
tileSettings.mapName = newMapName.replace(' ', '_');
6378

6479
let inputImage = sharp(tileSettings.imagePath, {
@@ -69,8 +84,9 @@ async function getTileSettings() {
6984
let metadata = await inputImage.metadata();
7085
console.log(`Image size: ${metadata.width}x${metadata.height}`);
7186

72-
tileSettings.rotation = prompt('Rotate image 90, 180, or 270 degrees (0): ', 0).trim();
87+
tileSettings.rotation = await prompt('Rotate image 90, 180, or 270 degrees (0): ', 0);
7388
if (tileSettings.rotation) {
89+
tileSettings.rotation = tileSettings.rotation.trim();
7490
if (!['0', '90', '180', '270'].includes(tileSettings.rotation)) {
7591
return Promise.reject(new Error(`${tileSettings.rotation} is not a valid rotation`));
7692
}
@@ -152,7 +168,7 @@ async function getTileSettings() {
152168
}px)`
153169
);
154170
}
155-
const newTileSize = prompt(`Tile size (${tileSize}): `, tileSize);
171+
const newTileSize = await prompt(`Tile size (${tileSize}): `, tileSize);
156172
if (isNaN(newTileSize)) {
157173
return Promise.reject(new Error(`${newTileSize} is not a valid tile size`));
158174
}
@@ -382,8 +398,8 @@ async function createTiles(options) {
382398
if (tileSettings.length > 0) {
383399
console.log(`Queued tiles: ${tileSettings.map(setting => setting.mapName).join(', ')}`);
384400
}
385-
const again = prompt(`Do you want to queue another tileset? (n): `, 'n').trim().toLocaleLowerCase();
386-
if (!again.startsWith('y')) {
401+
const again = (await prompt(`Do you want to queue another tileset? (n): `, 'n'))?.trim().toLocaleLowerCase();
402+
if (!again?.startsWith('y')) {
387403
break;
388404
}
389405
}

0 commit comments

Comments
 (0)