style: fix lint issues in code 🕺 (#626)
* style: fix lint issues in code 🕺 Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: lint fix all files Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * chore: add `keywords` for better reach Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * feat: add `husky` & `commitlint` Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * chore: ignore `public` directory Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * revert: do not lint `public` directory Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: fix issues with lint Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * feat: add eslint config Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * feat: add lint-staged Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: lint fix all file(s) Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * fix: ignore rules for light version Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * fix: remove unnecessary space Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * chore(deps): update lockfile Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> * style: autofix linting issue(s) Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
+57
-65
@@ -4,73 +4,52 @@
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import { fileURLToPath } from 'url';
|
||||
import request from 'request';
|
||||
import {server} from './server.js';
|
||||
import { server } from './server.js';
|
||||
|
||||
import MBTiles from '@mapbox/mbtiles';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8'));
|
||||
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');
|
||||
}
|
||||
|
||||
import {program} from 'commander';
|
||||
import { program } from 'commander';
|
||||
program
|
||||
.description('tileserver-gl startup options')
|
||||
.usage('tileserver-gl [mbtiles] [options]')
|
||||
.option(
|
||||
'--mbtiles <file>',
|
||||
'MBTiles file (uses demo configuration);\n' +
|
||||
'\t ignored if the configuration file is also specified'
|
||||
'\t ignored if the configuration file is also specified',
|
||||
)
|
||||
.option(
|
||||
'-c, --config <file>',
|
||||
'Configuration file [config.json]',
|
||||
'config.json'
|
||||
)
|
||||
.option(
|
||||
'-b, --bind <address>',
|
||||
'Bind address'
|
||||
)
|
||||
.option(
|
||||
'-p, --port <port>',
|
||||
'Port [8080]',
|
||||
8080,
|
||||
parseInt
|
||||
)
|
||||
.option(
|
||||
'-C|--no-cors',
|
||||
'Disable Cross-origin resource sharing headers'
|
||||
'config.json',
|
||||
)
|
||||
.option('-b, --bind <address>', 'Bind address')
|
||||
.option('-p, --port <port>', 'Port [8080]', 8080, parseInt)
|
||||
.option('-C|--no-cors', 'Disable Cross-origin resource sharing headers')
|
||||
.option(
|
||||
'-u|--public_url <url>',
|
||||
'Enable exposing the server on subpaths, not necessarily the root of the domain'
|
||||
)
|
||||
.option(
|
||||
'-V, --verbose',
|
||||
'More verbose output'
|
||||
)
|
||||
.option(
|
||||
'-s, --silent',
|
||||
'Less verbose output'
|
||||
)
|
||||
.option(
|
||||
'-l|--log_file <file>',
|
||||
'output log file (defaults to standard out)'
|
||||
'Enable exposing the server on subpaths, not necessarily the root of the domain',
|
||||
)
|
||||
.option('-V, --verbose', 'More verbose output')
|
||||
.option('-s, --silent', 'Less verbose output')
|
||||
.option('-l|--log_file <file>', 'output log file (defaults to standard out)')
|
||||
.option(
|
||||
'-f|--log_format <format>',
|
||||
'define the log format: https://github.com/expressjs/morgan#morganformat-options'
|
||||
)
|
||||
.version(
|
||||
packageJson.version,
|
||||
'-v, --version'
|
||||
'define the log format: https://github.com/expressjs/morgan#morganformat-options',
|
||||
)
|
||||
.version(packageJson.version, '-v, --version');
|
||||
program.parse(process.argv);
|
||||
const opts = program.opts();
|
||||
|
||||
@@ -91,14 +70,16 @@ const startServer = (configPath, config) => {
|
||||
silent: opts.silent,
|
||||
logFile: opts.log_file,
|
||||
logFormat: opts.log_format,
|
||||
publicUrl: publicUrl
|
||||
publicUrl: publicUrl,
|
||||
});
|
||||
};
|
||||
|
||||
const startWithMBTiles = (mbtilesFile) => {
|
||||
console.log(`[INFO] Automatically creating config file for ${mbtilesFile}`);
|
||||
console.log(`[INFO] Only a basic preview style will be used.`);
|
||||
console.log(`[INFO] See documentation to learn how to create config.json file.`);
|
||||
console.log(
|
||||
`[INFO] See documentation to learn how to create config.json file.`,
|
||||
);
|
||||
|
||||
mbtilesFile = path.resolve(process.cwd(), mbtilesFile);
|
||||
|
||||
@@ -110,60 +91,70 @@ const startWithMBTiles = (mbtilesFile) => {
|
||||
const instance = new MBTiles(mbtilesFile + '?mode=ro', (err) => {
|
||||
if (err) {
|
||||
console.log('ERROR: Unable to open MBTiles.');
|
||||
console.log(` Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
|
||||
console.log(`Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
instance.getInfo((err, info) => {
|
||||
if (err || !info) {
|
||||
console.log('ERROR: Metadata missing in the MBTiles.');
|
||||
console.log(` Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`);
|
||||
console.log(
|
||||
`Make sure ${path.basename(mbtilesFile)} is valid MBTiles.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
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) {
|
||||
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 (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,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`WARN: MBTiles not in "openmaptiles" format. Serving raw data only...`);
|
||||
config['data'][(info.id || 'mbtiles')
|
||||
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, '_')
|
||||
] = {
|
||||
mbtiles: path.basename(mbtilesFile),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -197,7 +188,8 @@ fs.stat(path.resolve(opts.config), (err, stats) => {
|
||||
console.log(`No MBTiles specified, using ${mbtiles}`);
|
||||
return startWithMBTiles(mbtiles);
|
||||
} else {
|
||||
const url = 'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
|
||||
const url =
|
||||
'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
|
||||
const filename = 'zurich_switzerland.mbtiles';
|
||||
const stream = fs.createWriteStream(filename);
|
||||
console.log(`No MBTiles found`);
|
||||
|
||||
Reference in New Issue
Block a user