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": {
|
||||
"@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/sphericalmercator": "1.2.0",
|
||||
"@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",
|
||||
"canvas": "2.10.1",
|
||||
"chokidar": "3.5.3",
|
||||
|
|
@ -42,8 +42,11 @@
|
|||
"tileserver-gl-styles": "2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^10.0.0",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
publish.js
16
publish.js
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
// SYNC THE `light` FOLDER
|
||||
require('child_process').execSync('rsync -av --exclude="light" --exclude=".git" --exclude="node_modules" --delete . light', {
|
||||
stdio: 'inherit'
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
// PATCH `package.json`
|
||||
var fs = require('fs');
|
||||
var packageJson = require('./package');
|
||||
const fs = require('fs');
|
||||
const packageJson = require('./package');
|
||||
|
||||
packageJson.name += '-light';
|
||||
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles';
|
||||
|
|
@ -30,25 +30,25 @@ delete packageJson.devDependencies;
|
|||
|
||||
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.renameSync('light/README_light.md', 'light/README.md');
|
||||
fs.renameSync('light/Dockerfile_light', 'light/Dockerfile');
|
||||
fs.renameSync('light/docker-entrypoint_light.sh', 'light/docker-entrypoint.sh');
|
||||
|
||||
// for Build tileserver-gl-light docker image, don't publish
|
||||
if (process.argv.length > 2 && process.argv[2] == "--no-publish") {
|
||||
process.exit(0)
|
||||
if (process.argv.length > 2 && process.argv[2] == '--no-publish') {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
/* PUBLISH */
|
||||
|
||||
// tileserver-gl
|
||||
require('child_process').execSync('npm publish .', {
|
||||
stdio: 'inherit'
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
// tileserver-gl-light
|
||||
require('child_process').execSync('npm publish light', {
|
||||
stdio: 'inherit'
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
|
|
|||
24
src/main.js
24
src/main.js
|
|
@ -26,51 +26,51 @@ program
|
|||
.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'
|
||||
'config.json',
|
||||
)
|
||||
.option(
|
||||
'-b, --bind <address>',
|
||||
'Bind address'
|
||||
'Bind address',
|
||||
)
|
||||
.option(
|
||||
'-p, --port <port>',
|
||||
'Port [8080]',
|
||||
8080,
|
||||
parseInt
|
||||
parseInt,
|
||||
)
|
||||
.option(
|
||||
'-C|--no-cors',
|
||||
'Disable Cross-origin resource sharing headers'
|
||||
'Disable Cross-origin resource sharing headers',
|
||||
)
|
||||
.option(
|
||||
'-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(
|
||||
'-V, --verbose',
|
||||
'More verbose output'
|
||||
'More verbose output',
|
||||
)
|
||||
.option(
|
||||
'-s, --silent',
|
||||
'Less verbose output'
|
||||
'Less verbose output',
|
||||
)
|
||||
.option(
|
||||
'-l|--log_file <file>',
|
||||
'output log file (defaults to standard out)'
|
||||
'output log file (defaults to standard out)',
|
||||
)
|
||||
.option(
|
||||
'-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(
|
||||
packageJson.version,
|
||||
'-v, --version'
|
||||
)
|
||||
'-v, --version',
|
||||
);
|
||||
program.parse(process.argv);
|
||||
const opts = program.opts();
|
||||
console.log(`Starting ${packageJson.name} v${packageJson.version}`);
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ export const serve_data = {
|
|||
}
|
||||
let source;
|
||||
const sourceInfoPromise = new Promise((resolve, reject) => {
|
||||
source = new MBTiles(mbtilesFile, err => {
|
||||
source = new MBTiles(mbtilesFile, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ export const serve_rendered = {
|
|||
|
||||
if (z > 2 && tileMargin > 0) {
|
||||
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({
|
||||
left: tileMargin * scale,
|
||||
top: (tileMargin + yoffset) * scale,
|
||||
|
|
@ -764,7 +764,7 @@ export const serve_rendered = {
|
|||
if (!mbtilesFileStats.isFile() || mbtilesFileStats.size === 0) {
|
||||
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) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
var testTileJSONArray = function(url) {
|
||||
const testTileJSONArray = function(url) {
|
||||
describe(url + ' is array of TileJSONs', function() {
|
||||
it('is json', function(done) {
|
||||
supertest(app)
|
||||
|
|
@ -18,7 +18,7 @@ var testTileJSONArray = function(url) {
|
|||
});
|
||||
};
|
||||
|
||||
var testTileJSON = function(url) {
|
||||
const testTileJSON = function(url) {
|
||||
describe(url + ' is TileJSON', function() {
|
||||
it('is json', function(done) {
|
||||
supertest(app)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
process.env.NODE_ENV = 'test';
|
||||
|
||||
import {expect} from 'chai';
|
||||
import supertest from "supertest";
|
||||
import supertest from 'supertest';
|
||||
import {server} from '../src/server.js';
|
||||
|
||||
global.expect = expect
|
||||
global.supertest = supertest
|
||||
global.expect = expect;
|
||||
global.supertest = supertest;
|
||||
|
||||
before(function() {
|
||||
console.log('global setup');
|
||||
process.chdir('test_data');
|
||||
var running = server({
|
||||
const running = server({
|
||||
configPath: 'config.json',
|
||||
port: 8888,
|
||||
publicUrl: '/test/'
|
||||
publicUrl: '/test/',
|
||||
});
|
||||
global.app = running.app;
|
||||
global.server = running.server;
|
||||
|
|
@ -22,5 +22,7 @@ before(function() {
|
|||
|
||||
after(function() {
|
||||
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';
|
||||
var path = '/styles/' + prefix + '/static/' + q + '.' + format;
|
||||
let path = '/styles/' + prefix + '/static/' + q + '.' + format;
|
||||
if (query) {
|
||||
path += query;
|
||||
}
|
||||
it(path + ' returns ' + status, function(done) {
|
||||
var test = supertest(app).get(path);
|
||||
const test = supertest(app).get(path);
|
||||
if (status) test.expect(status);
|
||||
if (type) test.expect('Content-Type', type);
|
||||
test.end(done);
|
||||
});
|
||||
};
|
||||
|
||||
var prefix = 'test-style';
|
||||
const prefix = 'test-style';
|
||||
|
||||
describe('Static endpoints', 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(),
|
||||
function(done) {
|
||||
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/' + prefix + '/style.json is valid style', function() {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
var testTile = function(prefix, z, x, y, status) {
|
||||
var path = '/data/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
|
||||
const testTile = function(prefix, z, x, y, status) {
|
||||
const path = '/data/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
|
||||
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 == 200) test.expect('Content-Type', /application\/x-protobuf/);
|
||||
test.end(done);
|
||||
});
|
||||
};
|
||||
|
||||
var prefix = 'openmaptiles';
|
||||
const prefix = 'openmaptiles';
|
||||
|
||||
describe('Vector 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';
|
||||
var path = '/styles/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
|
||||
const path = '/styles/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
|
||||
it(path + ' returns ' + status, function(done) {
|
||||
var test = supertest(app).get(path);
|
||||
const test = supertest(app).get(path);
|
||||
test.expect(status);
|
||||
if (type) test.expect('Content-Type', type);
|
||||
test.end(done);
|
||||
});
|
||||
};
|
||||
|
||||
var prefix = 'test-style';
|
||||
const prefix = 'test-style';
|
||||
|
||||
describe('Raster tiles', function() {
|
||||
describe('valid requests', function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue