Convert to esm module syntax (#606)
* switch to esm module * Update package.json * change to maplibre package * fix tests * eslint * remove extra package updates * Delete package-lock.json * change 'fs' to 'node:fs' * put back node 10. without the package updates this still works * remove trailing commas * remove unassociated fix / formatting * remove unassociated fix * remove eslint from this PR * remove unassociated fix * lint * Merge remote-tracking branch 'upstream/master' into esm_update * fix mlgl * update maplibre-native to new version with arm64 * update minor version
This commit is contained in:
+30
-29
@@ -2,22 +2,24 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
require = require('esm')(module);
|
||||
import fs from 'node:fs';
|
||||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import request from 'request';
|
||||
import {server} from './server.js';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const request = require('request');
|
||||
import MBTiles from '@mapbox/mbtiles';
|
||||
|
||||
const MBTiles = require('@mapbox/mbtiles');
|
||||
|
||||
const packageJson = require('../package');
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8'));
|
||||
|
||||
const args = process.argv;
|
||||
if (args.length >= 3 && args[2][0] !== '-') {
|
||||
args.splice(2, 0, '--mbtiles');
|
||||
}
|
||||
|
||||
const { program } = require('commander');
|
||||
import {program} from 'commander';
|
||||
program
|
||||
.description('tileserver-gl startup options')
|
||||
.usage('tileserver-gl [mbtiles] [options]')
|
||||
@@ -79,7 +81,7 @@ const startServer = (configPath, config) => {
|
||||
if (publicUrl && publicUrl.lastIndexOf('/') !== publicUrl.length - 1) {
|
||||
publicUrl += '/';
|
||||
}
|
||||
return require('./server')({
|
||||
return server({
|
||||
configPath: configPath,
|
||||
config: config,
|
||||
bind: opts.bind,
|
||||
@@ -120,38 +122,37 @@ const startWithMBTiles = (mbtilesFile) => {
|
||||
}
|
||||
const bounds = info.bounds;
|
||||
|
||||
const styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
|
||||
const styleDir = path.resolve(__dirname, '../node_modules/tileserver-gl-styles/');
|
||||
|
||||
const config = {
|
||||
"options": {
|
||||
"paths": {
|
||||
"root": styleDir,
|
||||
"fonts": "fonts",
|
||||
"styles": "styles",
|
||||
"mbtiles": path.dirname(mbtilesFile)
|
||||
'options': {
|
||||
'paths': {
|
||||
'root': styleDir,
|
||||
'fonts': 'fonts',
|
||||
'styles': 'styles',
|
||||
'mbtiles': path.dirname(mbtilesFile)
|
||||
}
|
||||
},
|
||||
"styles": {},
|
||||
"data": {}
|
||||
'styles': {},
|
||||
'data': {}
|
||||
};
|
||||
|
||||
if (info.format === 'pbf' &&
|
||||
info.name.toLowerCase().indexOf('openmaptiles') > -1) {
|
||||
|
||||
config['data'][`v3`] = {
|
||||
"mbtiles": path.basename(mbtilesFile)
|
||||
'mbtiles': path.basename(mbtilesFile)
|
||||
};
|
||||
|
||||
|
||||
const styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
||||
for (let styleName of styles) {
|
||||
for (const styleName of styles) {
|
||||
const styleFileRel = styleName + '/style.json';
|
||||
const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
|
||||
if (fs.existsSync(styleFile)) {
|
||||
config['styles'][styleName] = {
|
||||
"style": styleFileRel,
|
||||
"tilejson": {
|
||||
"bounds": bounds
|
||||
'style': styleFileRel,
|
||||
'tilejson': {
|
||||
'bounds': bounds
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -159,10 +160,10 @@ const startWithMBTiles = (mbtilesFile) => {
|
||||
} else {
|
||||
console.log(`WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`);
|
||||
config['data'][(info.id || 'mbtiles')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/:/g, '_')
|
||||
.replace(/\?/g, '_')] = {
|
||||
"mbtiles": path.basename(mbtilesFile)
|
||||
.replace(/\//g, '_')
|
||||
.replace(/:/g, '_')
|
||||
.replace(/\?/g, '_')] = {
|
||||
'mbtiles': path.basename(mbtilesFile)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ fs.stat(path.resolve(opts.config), (err, stats) => {
|
||||
if (!mbtiles) {
|
||||
// try to find in the cwd
|
||||
const files = fs.readdirSync(process.cwd());
|
||||
for (let filename of files) {
|
||||
for (const filename of files) {
|
||||
if (filename.endsWith('.mbtiles')) {
|
||||
const mbTilesStats = fs.statSync(filename);
|
||||
if (mbTilesStats.isFile() && mbTilesStats.size > 0) {
|
||||
|
||||
Reference in New Issue
Block a user