8000 feat: switch to es modules · blacha/xyz-tile-debug@63638bc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 63638bc

Browse files
committed
feat: switch to es modules
1 parent fe30ed2 commit 63638bc

File tree

9 files changed

+813
-1009
lines changed

9 files changed

+813
-1009
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"bin": {
77
"xyz-tile-debug": "./xyz-tile-debug"
88
},
9+
"type": "module",
910
"scripts": {
1011
"start": "node build/src/index.js",
1112
"build": "tsc --pretty",
@@ -28,13 +29,13 @@
2829
"ospec": "^4.1.1"
2930
},
3031
"dependencies": {
31-
"@basemaps/geo": "^4.20.0",
32+
"@basemaps/geo": "^6.21.1",
3233
"@linzjs/tile-matrix-set": "^0.0.1",
33-
"bblog": "^2.0.0",
3434
"canvas": "^2.6.1",
3535
"cors": "^2.8.5",
3636
"express": "^4.17.1",
37-
"pretty-json-log": "^0.3.1",
37+
"pino": "^7.10.0",
38+
"pretty-json-log": "^1.0.0",
3839
"source-map-support": "^0.5.19"
3940
}
4041
}

src/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GoogleTms, Nztm2000QuadTms } from '@basemaps/geo';
2-
import { V } from './vdom';
2+
import { V } from './vdom.js';
33

44
export function buildIndex(): string {
55
let startX = 6624592;

src/img.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { QuadKey } from '@basemaps/geo';
2-
import { TileMatrixSet } from '@basemaps/geo/build/tile.matrix.set';
3-
import { GoogleTms } from '@basemaps/geo/build/tms/google';
4-
import * as NodeCanvas from 'canvas';
5-
import { Vector } from './vector';
6-
import { BorderColors } from './wmts';
2+
import { TileMatrixSet } from '@basemaps/geo/build/tile.matrix.set.js';
3+
import { GoogleTms } from '@basemaps/geo/build/tms/google.js';
4+
import NodeCanvas from 'canvas';
5+
import { Vector } from './vector.js';
6+
import { BorderColors } from './wmts/index.js';
77

88
const CanvasSize = 512;
99
const FontSize = 80;
@@ -20,12 +20,10 @@ async function toXyz(v: Vector, tms?: TileMatrixSet): Promise<Buffer> {
2020
const espgName = tms?.def.identifier ?? GoogleTms.def.identifier;
2121

2222
let qk = isQuadKeyCapable(tms ?? GoogleTms) ? QuadKey.fromTile(v) : '';
23-
console.log(qk);
2423

2524
// Quad keys get too long for tiles so shorten them
2625
const halfQk = Math.ceil(qk.length / 2);
2726
if (halfQk > 6) qk = qk.slice(0, halfQk) + '\n' + qk.slice(halfQk);
28-
// console.log(qk);
2927

3028
const xyzS = `${v.x},${v.y}`;
3129
const canvas = NodeCanvas.createCanvas(CanvasSize, CanvasSize);

src/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import express from 'express';
22
import { performance } from 'perf_hooks';
3-
import 'source-map-support/register';
3+
import 'source-map-support/register.js';
44
import cors from 'cors';
5-
import { Png } from './img';
6-
import { Logger } from './log';
7-
import { Vector } from './vector';
8-
import { TileMatrixes } from './wmts';
9-
import { buildWmts } from './wmts/build';
10-
import { buildIndex } from './html';
5+
import { Png } from './img.js';
6+
import { Logger } from './log.js';
7+
import { Vector } from './vector.js';
8+
import { TileMatrixes } from './wmts/index.js';
9+
import { buildWmts } from './wmts/build.js';
10+
import { buildIndex } from './html.js';
1111

1212
const PORT = process.env.PORT || 8855;
1313
const BASE_URL = process.env.BASE_URL || `http://localhost:${PORT}`;
@@ -98,7 +98,11 @@ app.get('/', asyncRequest(serveIndex));
9898
async function init(): Promise<void> {
9999
await app.listen(PORT);
100100
Logger.info(
101-
{ wmts: `${BASE_URL}/v1/wmts/WMTSCapabilities.xml`, xyz: `${ F438 BASE_URL}/v1/tiles/:tileMatrixSet/:z/:x/:y.png` },
101+
{
102+
wmts: `${BASE_URL}/v1/wmts/WMTSCapabilities.xml`,
103+
xyz: `${BASE_URL}/v1/tiles/:tileMatrixSet/:z/:x/:y.png`,
104+
root: `${BASE_URL}`,
105+
},
102106
'Started',
103107
);
104108
}

src/log.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
1-
import { Log, LogMessage, LogLevel } from 'bblog';
2-
import { PrettySimple } from 'pretty-json-log';
1+
import pino from 'pino';
2+
import { PrettyTransform } from 'pretty-json-log';
33

4-
const pretty = new PrettySimple(-1);
5-
6-
/** Should the logger output JSON or straight objects */
7-
export enum LoggerType {
8-
JSON,
9-
WEB,
10-
}
11-
export const LoggerConfig = { level: Log.TRACE };
12-
13-
export const ConsoleLogStream = {
14-
setLevel(l: LogLevel): void {
15-
LoggerConfig.level = l;
16-
},
17-
write(msg: LogMessage): void {
18-
if (msg.level < LoggerConfig.level) return;
19-
if (!process.stdout.isTTY) return console.log(JSON.stringify(msg));
20-
21-
const res = pretty.pretty(msg);
22-
if (res == null) return;
23-
process.stdout.write(res + '\n');
24-
},
25-
};
26-
export const Logger = Log.createLogger({
27-
name: 'xyz',
28-
hostname: '',
29-
streams: [ConsoleLogStream],
30-
});
4+
export const Logger = process.stdout.isTTY ? pino(PrettyTransform.stream()) : pino();

src/wmts/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2-
import { TileMatrixSet } from '@basemaps/geo/build/tile.matrix.set';
3-
import { V, VNode } from '../vdom';
2+
import { TileMatrixSet } from '@basemaps/geo';
3+
import { V, VNode } from '../vdom.js';
44

55
const XmlPrefix = `<?xml version="1.0"?>`;
66
const CapabilitiesAttrs = {

src/wmts/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import * as NZTM from '@linzjs/tile-matrix-set';
2-
import { GoogleTms } from '@basemaps/geo/build/tms/google';
3-
import { TileMatrixSet } from '@basemaps/geo';
4-
5-
const Nztm2000Tms = new TileMatrixSet(NZTM.Nztm2000);
6-
const Nztm2000QuadTms = new TileMatrixSet(NZTM.Nztm2000Quad);
1+
import { GoogleTms } from '@basemaps/geo/build/tms/google.js';
2+
import { Nztm2000Tms, Nztm2000QuadTms } from '@basemaps/geo/build/tms/nztm2000.js';
73

84
export const TileMatrixes = [Nztm2000Tms, Nztm2000QuadTms, GoogleTms];
95

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extends": "@linzjs/style/tsconfig.base.json",
33
"compilerOptions": {
44
"lib": ["ES2020"],
5+
"module": "esnext",
6+
"moduleResolution": "node",
57
"outDir": "build"
68
}
79
}

0 commit comments

Comments
 (0)
0