eslint
This commit is contained in:
parent
982b32acd6
commit
3bf3a1cb07
13 changed files with 12150 additions and 134 deletions
11
.eslintrc.yml
Normal file
11
.eslintrc.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
env:
|
||||||
|
browser: false
|
||||||
|
es2021: true
|
||||||
|
extends: google
|
||||||
|
overrides: []
|
||||||
|
parserOptions:
|
||||||
|
ecmaVersion: latest
|
||||||
|
sourceType: module
|
||||||
|
ignorePatterns:
|
||||||
|
- /public/resources
|
||||||
|
rules: {}
|
||||||
12000
package-lock.json
generated
Normal file
12000
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -19,11 +19,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mapbox/glyph-pbf-composite": "0.0.3",
|
"@mapbox/glyph-pbf-composite": "0.0.3",
|
||||||
"@maplibre/maplibre-gl-native": "5.0.1-pre.0",
|
|
||||||
"@maplibre/maplibre-gl-style-spec": "17.0.1",
|
|
||||||
"@mapbox/mbtiles": "0.12.1",
|
"@mapbox/mbtiles": "0.12.1",
|
||||||
"@mapbox/sphericalmercator": "1.2.0",
|
"@mapbox/sphericalmercator": "1.2.0",
|
||||||
"@mapbox/vector-tile": "1.3.1",
|
"@mapbox/vector-tile": "1.3.1",
|
||||||
|
"@maplibre/maplibre-gl-native": "5.0.1-pre.0",
|
||||||
|
"@maplibre/maplibre-gl-style-spec": "17.0.1",
|
||||||
"advanced-pool": "0.3.3",
|
"advanced-pool": "0.3.3",
|
||||||
"canvas": "2.10.1",
|
"canvas": "2.10.1",
|
||||||
"chokidar": "3.5.3",
|
"chokidar": "3.5.3",
|
||||||
|
|
@ -42,8 +42,11 @@
|
||||||
"tileserver-gl-styles": "2.0.0"
|
"tileserver-gl-styles": "2.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "^10.0.0",
|
|
||||||
"chai": "4.3.6",
|
"chai": "4.3.6",
|
||||||
|
"eslint": "^8.23.1",
|
||||||
|
"eslint-config-google": "^0.14.0",
|
||||||
|
"lint": "^0.7.0",
|
||||||
|
"mocha": "^10.0.0",
|
||||||
"supertest": "^6.2.4"
|
"supertest": "^6.2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
publish.js
16
publish.js
|
|
@ -12,12 +12,12 @@
|
||||||
|
|
||||||
// SYNC THE `light` FOLDER
|
// SYNC THE `light` FOLDER
|
||||||
require('child_process').execSync('rsync -av --exclude="light" --exclude=".git" --exclude="node_modules" --delete . light', {
|
require('child_process').execSync('rsync -av --exclude="light" --exclude=".git" --exclude="node_modules" --delete . light', {
|
||||||
stdio: 'inherit'
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
|
|
||||||
// PATCH `package.json`
|
// PATCH `package.json`
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var packageJson = require('./package');
|
const packageJson = require('./package');
|
||||||
|
|
||||||
packageJson.name += '-light';
|
packageJson.name += '-light';
|
||||||
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
|
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
|
||||||
|
|
@ -30,25 +30,25 @@ delete packageJson.devDependencies;
|
||||||
|
|
||||||
packageJson.engines.node = '>= 10';
|
packageJson.engines.node = '>= 10';
|
||||||
|
|
||||||
var str = JSON.stringify(packageJson, undefined, 2);
|
const str = JSON.stringify(packageJson, undefined, 2);
|
||||||
fs.writeFileSync('light/package.json', str);
|
fs.writeFileSync('light/package.json', str);
|
||||||
fs.renameSync('light/README_light.md', 'light/README.md');
|
fs.renameSync('light/README_light.md', 'light/README.md');
|
||||||
fs.renameSync('light/Dockerfile_light', 'light/Dockerfile');
|
fs.renameSync('light/Dockerfile_light', 'light/Dockerfile');
|
||||||
fs.renameSync('light/docker-entrypoint_light.sh', 'light/docker-entrypoint.sh');
|
fs.renameSync('light/docker-entrypoint_light.sh', 'light/docker-entrypoint.sh');
|
||||||
|
|
||||||
// for Build tileserver-gl-light docker image, don't publish
|
// for Build tileserver-gl-light docker image, don't publish
|
||||||
if (process.argv.length > 2 && process.argv[2] == "--no-publish") {
|
if (process.argv.length > 2 && process.argv[2] == '--no-publish') {
|
||||||
process.exit(0)
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PUBLISH */
|
/* PUBLISH */
|
||||||
|
|
||||||
// tileserver-gl
|
// tileserver-gl
|
||||||
require('child_process').execSync('npm publish .', {
|
require('child_process').execSync('npm publish .', {
|
||||||
stdio: 'inherit'
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
|
|
||||||
// tileserver-gl-light
|
// tileserver-gl-light
|
||||||
require('child_process').execSync('npm publish light', {
|
require('child_process').execSync('npm publish light', {
|
||||||
stdio: 'inherit'
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
26
src/main.js
26
src/main.js
|
|
@ -19,58 +19,58 @@ if (args.length >= 3 && args[2][0] !== '-') {
|
||||||
args.splice(2, 0, '--mbtiles');
|
args.splice(2, 0, '--mbtiles');
|
||||||
}
|
}
|
||||||
|
|
||||||
import { program } from 'commander';
|
import {program} from 'commander';
|
||||||
program
|
program
|
||||||
.description('tileserver-gl startup options')
|
.description('tileserver-gl startup options')
|
||||||
.usage('tileserver-gl [mbtiles] [options]')
|
.usage('tileserver-gl [mbtiles] [options]')
|
||||||
.option(
|
.option(
|
||||||
'--mbtiles <file>',
|
'--mbtiles <file>',
|
||||||
'MBTiles file (uses demo configuration);\n' +
|
'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(
|
.option(
|
||||||
'-c, --config <file>',
|
'-c, --config <file>',
|
||||||
'Configuration file [config.json]',
|
'Configuration file [config.json]',
|
||||||
'config.json'
|
'config.json',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-b, --bind <address>',
|
'-b, --bind <address>',
|
||||||
'Bind address'
|
'Bind address',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-p, --port <port>',
|
'-p, --port <port>',
|
||||||
'Port [8080]',
|
'Port [8080]',
|
||||||
8080,
|
8080,
|
||||||
parseInt
|
parseInt,
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-C|--no-cors',
|
'-C|--no-cors',
|
||||||
'Disable Cross-origin resource sharing headers'
|
'Disable Cross-origin resource sharing headers',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-u|--public_url <url>',
|
'-u|--public_url <url>',
|
||||||
'Enable exposing the server on subpaths, not necessarily the root of the domain'
|
'Enable exposing the server on subpaths, not necessarily the root of the domain',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-V, --verbose',
|
'-V, --verbose',
|
||||||
'More verbose output'
|
'More verbose output',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-s, --silent',
|
'-s, --silent',
|
||||||
'Less verbose output'
|
'Less verbose output',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-l|--log_file <file>',
|
'-l|--log_file <file>',
|
||||||
'output log file (defaults to standard out)'
|
'output log file (defaults to standard out)',
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'-f|--log_format <format>',
|
'-f|--log_format <format>',
|
||||||
'define the log format: https://github.com/expressjs/morgan#morganformat-options'
|
'define the log format: https://github.com/expressjs/morgan#morganformat-options',
|
||||||
)
|
)
|
||||||
.version(
|
.version(
|
||||||
packageJson.version,
|
packageJson.version,
|
||||||
'-v, --version'
|
'-v, --version',
|
||||||
)
|
);
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
const opts = program.opts();
|
const opts = program.opts();
|
||||||
console.log(`Starting ${packageJson.name} v${packageJson.version}`);
|
console.log(`Starting ${packageJson.name} v${packageJson.version}`);
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ export const serve_data = {
|
||||||
}
|
}
|
||||||
let source;
|
let source;
|
||||||
const sourceInfoPromise = new Promise((resolve, reject) => {
|
const sourceInfoPromise = new Promise((resolve, reject) => {
|
||||||
source = new MBTiles(mbtilesFile, err => {
|
source = new MBTiles(mbtilesFile, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ export const serve_rendered = {
|
||||||
|
|
||||||
if (z > 2 && tileMargin > 0) {
|
if (z > 2 && tileMargin > 0) {
|
||||||
const [_, y] = mercator.px(params.center, z);
|
const [_, y] = mercator.px(params.center, z);
|
||||||
let yoffset = Math.max(Math.min(0, y - 128 - tileMargin), y + 128 + tileMargin - Math.pow(2, z + 8));
|
const yoffset = Math.max(Math.min(0, y - 128 - tileMargin), y + 128 + tileMargin - Math.pow(2, z + 8));
|
||||||
image.extract({
|
image.extract({
|
||||||
left: tileMargin * scale,
|
left: tileMargin * scale,
|
||||||
top: (tileMargin + yoffset) * scale,
|
top: (tileMargin + yoffset) * scale,
|
||||||
|
|
@ -764,7 +764,7 @@ export const serve_rendered = {
|
||||||
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size === 0) {
|
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size === 0) {
|
||||||
throw Error(`Not valid MBTiles file: ${mbtilesFile}`);
|
throw Error(`Not valid MBTiles file: ${mbtilesFile}`);
|
||||||
}
|
}
|
||||||
map.sources[name] = new MBTiles(mbtilesFile + '?mode=ro', err => {
|
map.sources[name] = new MBTiles(mbtilesFile + '?mode=ro', (err) => {
|
||||||
map.sources[name].getInfo((err, info) => {
|
map.sources[name].getInfo((err, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
var testTileJSONArray = function(url) {
|
const testTileJSONArray = function(url) {
|
||||||
describe(url + ' is array of TileJSONs', function() {
|
describe(url + ' is array of TileJSONs', function() {
|
||||||
it('is json', function(done) {
|
it('is json', function(done) {
|
||||||
supertest(app)
|
supertest(app)
|
||||||
|
|
@ -18,7 +18,7 @@ var testTileJSONArray = function(url) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var testTileJSON = function(url) {
|
const testTileJSON = function(url) {
|
||||||
describe(url + ' is TileJSON', function() {
|
describe(url + ' is TileJSON', function() {
|
||||||
it('is json', function(done) {
|
it('is json', function(done) {
|
||||||
supertest(app)
|
supertest(app)
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import { expect } from 'chai';
|
import {expect} from 'chai';
|
||||||
import supertest from "supertest";
|
import supertest from 'supertest';
|
||||||
import { server } from '../src/server.js';
|
import {server} from '../src/server.js';
|
||||||
|
|
||||||
global.expect = expect
|
global.expect = expect;
|
||||||
global.supertest = supertest
|
global.supertest = supertest;
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
console.log('global setup');
|
console.log('global setup');
|
||||||
process.chdir('test_data');
|
process.chdir('test_data');
|
||||||
var running = server({
|
const running = server({
|
||||||
configPath: 'config.json',
|
configPath: 'config.json',
|
||||||
port: 8888,
|
port: 8888,
|
||||||
publicUrl: '/test/'
|
publicUrl: '/test/',
|
||||||
});
|
});
|
||||||
global.app = running.app;
|
global.app = running.app;
|
||||||
global.server = running.server;
|
global.server = running.server;
|
||||||
|
|
@ -22,5 +22,7 @@ before(function() {
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
console.log('global teardown');
|
console.log('global teardown');
|
||||||
global.server.close(function() { console.log('Done'); process.exit(); });
|
global.server.close(function() {
|
||||||
|
console.log('Done'); process.exit();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
var testStatic = function(prefix, q, format, status, scale, type, query) {
|
const testStatic = function(prefix, q, format, status, scale, type, query) {
|
||||||
if (scale) q += '@' + scale + 'x';
|
if (scale) q += '@' + scale + 'x';
|
||||||
var path = '/styles/' + prefix + '/static/' + q + '.' + format;
|
let path = '/styles/' + prefix + '/static/' + q + '.' + format;
|
||||||
if (query) {
|
if (query) {
|
||||||
path += query;
|
path += query;
|
||||||
}
|
}
|
||||||
it(path + ' returns ' + status, function(done) {
|
it(path + ' returns ' + status, function(done) {
|
||||||
var test = supertest(app).get(path);
|
const test = supertest(app).get(path);
|
||||||
if (status) test.expect(status);
|
if (status) test.expect(status);
|
||||||
if (type) test.expect('Content-Type', type);
|
if (type) test.expect('Content-Type', type);
|
||||||
test.end(done);
|
test.end(done);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var prefix = 'test-style';
|
const prefix = 'test-style';
|
||||||
|
|
||||||
describe('Static endpoints', function() {
|
describe('Static endpoints', function() {
|
||||||
describe('center-based', function() {
|
describe('center-based', function() {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
var testIs = function(url, type, status) {
|
const testIs = function(url, type, status) {
|
||||||
it(url + ' return ' + (status || 200) + ' and is ' + type.toString(),
|
it(url + ' return ' + (status || 200) + ' and is ' + type.toString(),
|
||||||
function(done) {
|
function(done) {
|
||||||
supertest(app)
|
supertest(app)
|
||||||
|
|
@ -8,7 +8,7 @@ var testIs = function(url, type, status) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var prefix = 'test-style';
|
const prefix = 'test-style';
|
||||||
|
|
||||||
describe('Styles', function() {
|
describe('Styles', function() {
|
||||||
describe('/styles/' + prefix + '/style.json is valid style', function() {
|
describe('/styles/' + prefix + '/style.json is valid style', function() {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
var testTile = function(prefix, z, x, y, status) {
|
const testTile = function(prefix, z, x, y, status) {
|
||||||
var path = '/data/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
|
const path = '/data/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
|
||||||
it(path + ' returns ' + status, function(done) {
|
it(path + ' returns ' + status, function(done) {
|
||||||
var test = supertest(app).get(path);
|
const test = supertest(app).get(path);
|
||||||
if (status) test.expect(status);
|
if (status) test.expect(status);
|
||||||
if (status == 200) test.expect('Content-Type', /application\/x-protobuf/);
|
if (status == 200) test.expect('Content-Type', /application\/x-protobuf/);
|
||||||
test.end(done);
|
test.end(done);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var prefix = 'openmaptiles';
|
const prefix = 'openmaptiles';
|
||||||
|
|
||||||
describe('Vector tiles', function() {
|
describe('Vector tiles', function() {
|
||||||
describe('existing tiles', function() {
|
describe('existing tiles', function() {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
var testTile = function(prefix, z, x, y, format, status, scale, type) {
|
const testTile = function(prefix, z, x, y, format, status, scale, type) {
|
||||||
if (scale) y += '@' + scale + 'x';
|
if (scale) y += '@' + scale + 'x';
|
||||||
var path = '/styles/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
|
const path = '/styles/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
|
||||||
it(path + ' returns ' + status, function(done) {
|
it(path + ' returns ' + status, function(done) {
|
||||||
var test = supertest(app).get(path);
|
const test = supertest(app).get(path);
|
||||||
test.expect(status);
|
test.expect(status);
|
||||||
if (type) test.expect('Content-Type', type);
|
if (type) test.expect('Content-Type', type);
|
||||||
test.end(done);
|
test.end(done);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var prefix = 'test-style';
|
const prefix = 'test-style';
|
||||||
|
|
||||||
describe('Raster tiles', function() {
|
describe('Raster tiles', function() {
|
||||||
describe('valid requests', function() {
|
describe('valid requests', function() {
|
||||||
|
|
@ -41,6 +41,6 @@ describe('Raster tiles', function() {
|
||||||
testTile(prefix, 0, 0, 0, 'png', 404, 1);
|
testTile(prefix, 0, 0, 0, 'png', 404, 1);
|
||||||
testTile(prefix, 0, 0, 0, 'png', 404, 5);
|
testTile(prefix, 0, 0, 0, 'png', 404, 5);
|
||||||
|
|
||||||
//testTile('hybrid', 0, 0, 0, 'png', 404); //TODO: test this
|
// testTile('hybrid', 0, 0, 0, 'png', 404); //TODO: test this
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue