33'use strict' ;
44
55import fs from 'node:fs' ;
6+ import fsp from 'node:fs/promises' ;
67import path from 'path' ;
78import { fileURLToPath } from 'url' ;
89import axios from 'axios' ;
@@ -23,6 +24,7 @@ if (args.length >= 3 && args[2][0] !== '-') {
2324}
2425
2526import { program } from 'commander' ;
27+ import { existsP } from './promises.js' ;
2628program
2729 . description ( 'tileserver-gl startup options' )
2830 . usage ( 'tileserver-gl [mbtiles] [options]' )
@@ -95,7 +97,7 @@ const startWithInputFile = async (inputFile) => {
9597 inputFile = path . resolve ( process . cwd ( ) , inputFile ) ;
9698 inputFilePath = path . dirname ( inputFile ) ;
9799
98- const inputFileStats = fs . statSync ( inputFile ) ;
100+ const inputFileStats = await fsp . stat ( inputFile ) ;
99101 if ( ! inputFileStats . isFile ( ) || inputFileStats . size === 0 ) {
100102 console . log ( `ERROR: Not a valid input file: ` ) ;
101103 process . exit ( 1 ) ;
@@ -140,11 +142,11 @@ const startWithInputFile = async (inputFile) => {
140142 } ;
141143 }
142144
143- const styles = fs . readdirSync ( path . resolve ( styleDir , 'styles' ) ) ;
145+ const styles = await fsp . readdir ( path . resolve ( styleDir , 'styles' ) ) ;
144146 for ( const styleName of styles ) {
145147 const styleFileRel = styleName + '/style.json' ;
146148 const styleFile = path . resolve ( styleDir , 'styles' , styleFileRel ) ;
147- if ( fs . existsSync ( styleFile ) ) {
149+ if ( await existsP ( styleFile ) ) {
148150 config [ 'styles' ] [ styleName ] = {
149151 style : styleFileRel ,
150152 tilejson : {
@@ -189,7 +191,7 @@ const startWithInputFile = async (inputFile) => {
189191 process . exit ( 1 ) ;
190192 }
191193
192- instance . getInfo ( ( err , info ) => {
194+ instance . getInfo ( async ( err , info ) => {
193195 if ( err || ! info ) {
194196 console . log ( 'ERROR: Metadata missing in the MBTiles.' ) ;
195197 console . log (
@@ -207,11 +209,11 @@ const startWithInputFile = async (inputFile) => {
207209 mbtiles : path . basename ( inputFile ) ,
208210 } ;
209211
210- const styles = fs . readdirSync ( path . resolve ( styleDir , 'styles' ) ) ;
212+ const styles = await fsp . readdir ( path . resolve ( styleDir , 'styles' ) ) ;
211213 for ( const styleName of styles ) {
212214 const styleFileRel = styleName + '/style.json' ;
213215 const styleFile = path . resolve ( styleDir , 'styles' , styleFileRel ) ;
214- if ( fs . existsSync ( styleFile ) ) {
216+ if ( await existsP ( styleFile ) ) {
215217 config [ 'styles' ] [ styleName ] = {
216218 style : styleFileRel ,
217219 tilejson : {
@@ -254,10 +256,10 @@ fs.stat(path.resolve(opts.config), async (err, stats) => {
254256 return startWithInputFile ( inputFile ) ;
255257 } else {
256258 // try to find in the cwd
257- const files = fs . readdirSync ( process . cwd ( ) ) ;
259+ const files = await fsp . readdir ( process . cwd ( ) ) ;
258260 for ( const filename of files ) {
259261 if ( filename . endsWith ( '.mbtiles' ) || filename . endsWith ( '.pmtiles' ) ) {
260- const inputFilesStats = fs . statSync ( filename ) ;
262+ const inputFilesStats = await fsp . stat ( filename ) ;
261263 if ( inputFilesStats . isFile ( ) && inputFilesStats . size > 0 ) {
262264 inputFile = filename ;
263265 break ;
0 commit comments