@unvt/charites 0.5.4 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +3 -5
- package/.mocharc.json +7 -0
- package/README.md +5 -2
- package/dist/cli/build.js +13 -24
- package/dist/cli/convert.js +7 -9
- package/dist/cli/init.js +7 -9
- package/dist/cli/serve.js +7 -21
- package/dist/cli.js +18 -16
- package/dist/commands/build.js +25 -38
- package/dist/commands/convert.js +14 -21
- package/dist/commands/init.js +6 -10
- package/dist/commands/serve.js +33 -65
- package/dist/lib/build-sprite.js +5 -12
- package/dist/lib/defaultValues.js +6 -31
- package/dist/lib/error.js +1 -5
- package/dist/lib/get-sprite-slug.js +1 -5
- package/dist/lib/tileinfo-importer/base-importer.js +2 -5
- package/dist/lib/tileinfo-importer/index.js +2 -7
- package/dist/lib/tileinfo-importer/metadata-importer.js +4 -11
- package/dist/lib/tileinfo-importer/tilejson-importer.js +4 -11
- package/dist/lib/validate-style.js +3 -17
- package/dist/lib/yaml-include/file.js +23 -0
- package/dist/lib/yaml-include/index.js +22 -0
- package/dist/lib/yaml-parser.js +8 -14
- package/dist/lib/yaml-writer.js +17 -23
- package/dist/types/index.js +3 -19
- package/dist/types/metadatajson.js +1 -2
- package/dist/types/tilejson.js +1 -2
- package/dist/types/vector_layers.js +1 -2
- package/docs/source/index.rst +4 -5
- package/docs/source/usage/commandline_interface.rst +0 -12
- package/docs/source/usage/examples.rst +0 -6
- package/docs/source/usage/index.rst +0 -1
- package/eslint.config.mjs +46 -0
- package/mocha-register.cjs +2 -0
- package/package.json +40 -37
- package/playwright.config.ts +1 -12
- package/provider/{default/shared.js → app.js} +30 -0
- package/provider/{default/index.html → index.html} +5 -5
- package/src/cli/build.ts +2 -15
- package/src/cli/convert.ts +2 -2
- package/src/cli/init.ts +2 -2
- package/src/cli/serve.ts +2 -20
- package/src/cli.ts +14 -5
- package/src/commands/build.ts +5 -12
- package/src/commands/convert.ts +1 -1
- package/src/commands/init.ts +2 -2
- package/src/commands/serve.ts +10 -48
- package/src/lib/defaultValues.ts +8 -34
- package/src/lib/tileinfo-importer/index.ts +2 -2
- package/src/lib/tileinfo-importer/metadata-importer.ts +2 -2
- package/src/lib/tileinfo-importer/tilejson-importer.ts +2 -2
- package/src/lib/validate-style.ts +5 -13
- package/src/lib/yaml-include/file.ts +29 -0
- package/src/lib/yaml-include/index.ts +28 -0
- package/src/lib/yaml-parser.ts +3 -3
- package/test/build-sprite.spec.ts +5 -0
- package/test/build.spec.ts +10 -13
- package/test/command.build.spec.ts +2 -2
- package/test/convert.spec.ts +7 -1
- package/test/get-sprite-slug.spec.ts +4 -0
- package/test/init.spec.ts +5 -0
- package/test/playwright/provider/{default/e2e.spec.ts → e2e.spec.ts} +2 -2
- package/test/util/charitesCmd.ts +5 -0
- package/test/util/copyFixtures.ts +5 -0
- package/test/yaml-parser.spec.ts +4 -0
- package/tsconfig.json +11 -6
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -17
- package/docs/source/usage/global_options.rst +0 -21
- package/provider/default/app.js +0 -30
- package/provider/geolonia/app.js +0 -28
- package/provider/geolonia/index.html +0 -22
- package/provider/mapbox/app.js +0 -33
- package/provider/mapbox/index.html +0 -23
- package/test/playwright/provider/geolonia/e2e.spec.ts +0 -13
- package/test/playwright/provider/mapbox/e2e.spec.ts +0 -13
- /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
- /package/provider/{default/app.css → app.css} +0 -0
package/dist/commands/serve.js
CHANGED
|
@@ -1,58 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const node_watch_1 = __importDefault(require("node-watch"));
|
|
14
|
-
const yaml_parser_1 = require("../lib/yaml-parser");
|
|
15
|
-
const validate_style_1 = require("../lib/validate-style");
|
|
16
|
-
const defaultValues_1 = require("../lib/defaultValues");
|
|
17
|
-
const build_sprite_1 = require("../lib/build-sprite");
|
|
18
|
-
async function serve(source, options) {
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
import open from 'open';
|
|
6
|
+
import { WebSocketServer } from 'ws';
|
|
7
|
+
import watch from 'node-watch';
|
|
8
|
+
import { parser } from '../lib/yaml-parser.js';
|
|
9
|
+
import { validateStyle } from '../lib/validate-style.js';
|
|
10
|
+
import { providerDir } from '../lib/defaultValues.js';
|
|
11
|
+
import { buildSprite } from '../lib/build-sprite.js';
|
|
12
|
+
export async function serve(source, options) {
|
|
19
13
|
let port = process.env.PORT || 8080;
|
|
20
14
|
if (options.port) {
|
|
21
15
|
port = Number(options.port);
|
|
22
16
|
}
|
|
23
|
-
let sourcePath =
|
|
24
|
-
let provider = defaultValues_1.defaultValues.provider;
|
|
25
|
-
if (options.provider) {
|
|
26
|
-
provider = options.provider;
|
|
27
|
-
}
|
|
17
|
+
let sourcePath = path.resolve(process.cwd(), source);
|
|
28
18
|
// The `source` is absolute path.
|
|
29
19
|
if (source.match(/^\//)) {
|
|
30
20
|
sourcePath = source;
|
|
31
21
|
}
|
|
32
|
-
if (!
|
|
22
|
+
if (!fs.existsSync(sourcePath)) {
|
|
33
23
|
throw `${sourcePath}: No such file or directory`;
|
|
34
24
|
}
|
|
35
|
-
const mapboxAccessToken = options.mapboxAccessToken || defaultValues_1.defaultValues.mapboxAccessToken;
|
|
36
|
-
if (provider === 'mapbox' && !mapboxAccessToken) {
|
|
37
|
-
throw `Provider is mapbox, but the Mapbox Access Token is not set. Please provide it using --mapbox-access-token, or set it in \`~/.charites/config.yml\` (see the Global configuration section of the documentation for more information)`;
|
|
38
|
-
}
|
|
39
25
|
let spriteOut = undefined;
|
|
40
26
|
let spriteRefresher = undefined;
|
|
41
27
|
if (options.spriteInput) {
|
|
42
|
-
spriteOut = await
|
|
28
|
+
spriteOut = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'charites-'));
|
|
43
29
|
spriteRefresher = async () => {
|
|
44
30
|
if (typeof options.spriteInput === 'undefined' ||
|
|
45
31
|
typeof spriteOut === 'undefined') {
|
|
46
32
|
return;
|
|
47
33
|
}
|
|
48
|
-
await
|
|
34
|
+
await buildSprite(options.spriteInput, spriteOut, 'sprite', options.sdf);
|
|
49
35
|
};
|
|
50
36
|
await spriteRefresher();
|
|
51
37
|
}
|
|
52
|
-
const server =
|
|
38
|
+
const server = http.createServer(async (req, res) => {
|
|
53
39
|
const url = (req.url || '').replace(/\?.*/, '');
|
|
54
|
-
const defaultProviderDir = path_1.default.join(defaultValues_1.defaultValues.providerDir, 'default');
|
|
55
|
-
const providerDir = path_1.default.join(defaultValues_1.defaultValues.providerDir, provider);
|
|
56
40
|
if (typeof spriteOut !== 'undefined' &&
|
|
57
41
|
url.match(/^\/sprite(@2x)?\.(json|png)/)) {
|
|
58
42
|
res.statusCode = 200;
|
|
@@ -63,8 +47,8 @@ async function serve(source, options) {
|
|
|
63
47
|
res.setHeader('Content-Type', 'image/png');
|
|
64
48
|
}
|
|
65
49
|
res.setHeader('Cache-Control', 'no-store');
|
|
66
|
-
const filename =
|
|
67
|
-
const fsStream =
|
|
50
|
+
const filename = path.basename(url);
|
|
51
|
+
const fsStream = fs.createReadStream(path.join(spriteOut, filename));
|
|
68
52
|
fsStream.pipe(res);
|
|
69
53
|
return;
|
|
70
54
|
}
|
|
@@ -72,17 +56,17 @@ async function serve(source, options) {
|
|
|
72
56
|
case '/':
|
|
73
57
|
res.statusCode = 200;
|
|
74
58
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
|
75
|
-
const content =
|
|
59
|
+
const content = fs.readFileSync(path.join(providerDir, 'index.html'), 'utf-8');
|
|
76
60
|
res.end(content);
|
|
77
61
|
break;
|
|
78
62
|
case '/style.json':
|
|
79
63
|
let style;
|
|
80
64
|
try {
|
|
81
|
-
style =
|
|
65
|
+
style = parser(sourcePath);
|
|
82
66
|
if (typeof spriteOut !== 'undefined') {
|
|
83
67
|
style.sprite = `http://${req.headers.host || `localhost:${port}`}/sprite`;
|
|
84
68
|
}
|
|
85
|
-
|
|
69
|
+
validateStyle(style);
|
|
86
70
|
}
|
|
87
71
|
catch (error) {
|
|
88
72
|
console.log(error);
|
|
@@ -95,29 +79,15 @@ async function serve(source, options) {
|
|
|
95
79
|
case '/app.css':
|
|
96
80
|
res.statusCode = 200;
|
|
97
81
|
res.setHeader('Content-Type', 'text/css; charset=UTF-8');
|
|
98
|
-
const css =
|
|
82
|
+
const css = fs.readFileSync(path.join(providerDir, 'app.css'), 'utf-8');
|
|
99
83
|
res.end(css);
|
|
100
84
|
break;
|
|
101
|
-
case `/shared.js`:
|
|
102
|
-
res.statusCode = 200;
|
|
103
|
-
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
104
|
-
const shared = fs_1.default.readFileSync(path_1.default.join(defaultProviderDir, 'shared.js'), 'utf-8');
|
|
105
|
-
const js = shared.replace('___PORT___', `${port}`);
|
|
106
|
-
res.end(js);
|
|
107
|
-
break;
|
|
108
85
|
case `/app.js`:
|
|
109
86
|
res.statusCode = 200;
|
|
110
87
|
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.replace('___PORT___', `${port}`)
|
|
115
|
-
.replace('___MAPBOX_ACCESS_TOKEN___', `${options.mapboxAccessToken || defaultValues_1.defaultValues.mapboxAccessToken}`);
|
|
116
|
-
res.end(js);
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
throw `Invalid provider: ${provider}`;
|
|
120
|
-
}
|
|
88
|
+
const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8');
|
|
89
|
+
const js = app.replace('___PORT___', `${port}`);
|
|
90
|
+
res.end(js);
|
|
121
91
|
break;
|
|
122
92
|
default:
|
|
123
93
|
res.statusCode = 404;
|
|
@@ -127,24 +97,23 @@ async function serve(source, options) {
|
|
|
127
97
|
}
|
|
128
98
|
});
|
|
129
99
|
server.listen(port, () => {
|
|
130
|
-
console.log(`Provider: ${provider}`);
|
|
131
100
|
console.log(`Loading your style: ${sourcePath}`);
|
|
132
101
|
console.log(`Your map is running on http://localhost:${port}/\n`);
|
|
133
102
|
if (options.open) {
|
|
134
|
-
(
|
|
103
|
+
open(`http://localhost:${port}`);
|
|
135
104
|
}
|
|
136
105
|
});
|
|
137
|
-
const wss = new
|
|
106
|
+
const wss = new WebSocketServer({ server });
|
|
138
107
|
wss.on('connection', (ws) => {
|
|
139
|
-
const watcher = (
|
|
108
|
+
const watcher = watch(path.dirname(sourcePath), { recursive: true, filter: /\.yml$|\.svg$/i }, (event, file) => {
|
|
140
109
|
console.log(`${(event || '').toUpperCase()}: ${file}`);
|
|
141
110
|
try {
|
|
142
|
-
if (file
|
|
111
|
+
if (file?.toLowerCase().endsWith('.yml')) {
|
|
143
112
|
ws.send(JSON.stringify({
|
|
144
113
|
event: 'styleUpdate',
|
|
145
114
|
}));
|
|
146
115
|
}
|
|
147
|
-
else if (
|
|
116
|
+
else if (file?.toLowerCase().endsWith('.svg') &&
|
|
148
117
|
typeof spriteRefresher !== 'undefined') {
|
|
149
118
|
spriteRefresher().then(() => {
|
|
150
119
|
ws.send(JSON.stringify({
|
|
@@ -153,7 +122,7 @@ async function serve(source, options) {
|
|
|
153
122
|
});
|
|
154
123
|
}
|
|
155
124
|
}
|
|
156
|
-
catch (
|
|
125
|
+
catch (_) {
|
|
157
126
|
// Nothing to do
|
|
158
127
|
}
|
|
159
128
|
});
|
|
@@ -165,11 +134,10 @@ async function serve(source, options) {
|
|
|
165
134
|
console.log('Cleaning up...');
|
|
166
135
|
server.close();
|
|
167
136
|
if (typeof spriteOut !== 'undefined') {
|
|
168
|
-
|
|
137
|
+
fs.rmSync(spriteOut, { recursive: true });
|
|
169
138
|
spriteOut = undefined;
|
|
170
139
|
}
|
|
171
140
|
process.exit(0);
|
|
172
141
|
});
|
|
173
142
|
return server;
|
|
174
143
|
}
|
|
175
|
-
exports.serve = serve;
|
package/dist/lib/build-sprite.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildSprite = void 0;
|
|
7
|
-
const sprite_one_1 = require("@unvt/sprite-one");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
async function buildSprite(svgPath, publicPath, iconSlug, sdf = false) {
|
|
1
|
+
import { generateSprite } from '@unvt/sprite-one';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export async function buildSprite(svgPath, publicPath, iconSlug, sdf = false) {
|
|
10
4
|
const pxRatios = [1, 2];
|
|
11
|
-
const outPath =
|
|
12
|
-
await
|
|
5
|
+
const outPath = path.join(publicPath, iconSlug);
|
|
6
|
+
await generateSprite(outPath, [svgPath], pxRatios, sdf);
|
|
13
7
|
return;
|
|
14
8
|
}
|
|
15
|
-
exports.buildSprite = buildSprite;
|
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const os_1 = __importDefault(require("os"));
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
11
|
-
const homedir = os_1.default.homedir();
|
|
12
|
-
const defaultProvider = 'default';
|
|
13
|
-
const configDir = path_1.default.join(homedir, '.charites');
|
|
14
|
-
fs_1.default.mkdirSync(configDir, { recursive: true });
|
|
15
|
-
const configFile = path_1.default.join(configDir, 'config.yml');
|
|
16
|
-
let config = { provider: '', providerDir: '', mapboxAccessToken: '' };
|
|
17
|
-
try {
|
|
18
|
-
const yaml = fs_1.default.readFileSync(configFile, 'utf-8');
|
|
19
|
-
config = js_yaml_1.default.load(yaml);
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
// nothing to do
|
|
23
|
-
}
|
|
24
|
-
exports.defaultValues = {
|
|
25
|
-
provider: config.provider || defaultProvider,
|
|
26
|
-
providerDir: path_1.default.join(path_1.default.dirname(path_1.default.dirname(__dirname)), 'provider'),
|
|
27
|
-
mapboxAccessToken: config.mapboxAccessToken || '',
|
|
28
|
-
};
|
|
29
|
-
exports.defaultSettings = {
|
|
30
|
-
configFile: configFile,
|
|
31
|
-
};
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
export const providerDir = path.join(path.dirname(path.dirname(__dirname)), 'provider');
|
package/dist/lib/error.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.error = void 0;
|
|
4
|
-
const error = (e) => {
|
|
1
|
+
export const error = (e) => {
|
|
5
2
|
if (e instanceof Error) {
|
|
6
3
|
console.error(e.message);
|
|
7
4
|
}
|
|
@@ -10,4 +7,3 @@ const error = (e) => {
|
|
|
10
7
|
}
|
|
11
8
|
process.exit(1);
|
|
12
9
|
};
|
|
13
|
-
exports.error = error;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpriteSlug = void 0;
|
|
4
|
-
function getSpriteSlug(style) {
|
|
1
|
+
export function getSpriteSlug(style) {
|
|
5
2
|
if (!style.hasOwnProperty('sprite') || !style.sprite) {
|
|
6
3
|
return false;
|
|
7
4
|
}
|
|
@@ -15,4 +12,3 @@ function getSpriteSlug(style) {
|
|
|
15
12
|
// icon slug
|
|
16
13
|
return matchedUrl[2];
|
|
17
14
|
}
|
|
18
|
-
exports.getSpriteSlug = getSpriteSlug;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BaseImporter = void 0;
|
|
4
|
-
class BaseImporter {
|
|
1
|
+
export class BaseImporter {
|
|
2
|
+
urls;
|
|
5
3
|
constructor(original_urls) {
|
|
6
4
|
const temp_urls = original_urls + '';
|
|
7
5
|
this.urls = temp_urls.split(',');
|
|
@@ -38,4 +36,3 @@ class BaseImporter {
|
|
|
38
36
|
return layers;
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
exports.BaseImporter = BaseImporter;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TileJSONImporter = exports.MetadataJSONImporter = void 0;
|
|
4
|
-
var metadata_importer_1 = require("./metadata-importer");
|
|
5
|
-
Object.defineProperty(exports, "MetadataJSONImporter", { enumerable: true, get: function () { return metadata_importer_1.MetadataJSONImporter; } });
|
|
6
|
-
var tilejson_importer_1 = require("./tilejson-importer");
|
|
7
|
-
Object.defineProperty(exports, "TileJSONImporter", { enumerable: true, get: function () { return tilejson_importer_1.TileJSONImporter; } });
|
|
1
|
+
export { MetadataJSONImporter } from './metadata-importer.js';
|
|
2
|
+
export { TileJSONImporter } from './tilejson-importer.js';
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MetadataJSONImporter = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const base_importer_1 = require("./base-importer");
|
|
9
|
-
class MetadataJSONImporter extends base_importer_1.BaseImporter {
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { BaseImporter } from './base-importer.js';
|
|
3
|
+
export class MetadataJSONImporter extends BaseImporter {
|
|
10
4
|
async getJSON(url) {
|
|
11
|
-
const res = await
|
|
5
|
+
const res = await axios.get(url);
|
|
12
6
|
const matadataJSON = res.data;
|
|
13
7
|
const metadataName = matadataJSON.name
|
|
14
8
|
? matadataJSON.name
|
|
@@ -35,4 +29,3 @@ class MetadataJSONImporter extends base_importer_1.BaseImporter {
|
|
|
35
29
|
return { sources, layers };
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
exports.MetadataJSONImporter = MetadataJSONImporter;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TileJSONImporter = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const base_importer_1 = require("./base-importer");
|
|
9
|
-
class TileJSONImporter extends base_importer_1.BaseImporter {
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { BaseImporter } from './base-importer.js';
|
|
3
|
+
export class TileJSONImporter extends BaseImporter {
|
|
10
4
|
async getJSON(url) {
|
|
11
|
-
const res = await
|
|
5
|
+
const res = await axios.get(url);
|
|
12
6
|
const tilejson = res.data;
|
|
13
7
|
const tilesetName = tilejson.name
|
|
14
8
|
? tilejson.name
|
|
@@ -22,4 +16,3 @@ class TileJSONImporter extends base_importer_1.BaseImporter {
|
|
|
22
16
|
return { sources, layers };
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
|
-
exports.TileJSONImporter = TileJSONImporter;
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateStyle = void 0;
|
|
7
|
-
const maplibre_gl_style_spec_1 = __importDefault(require("@maplibre/maplibre-gl-style-spec"));
|
|
8
|
-
const mapboxStyleSpec = require('@mapbox/mapbox-gl-style-spec');
|
|
9
|
-
function validateStyle(style, provider = 'default') {
|
|
10
|
-
let result = [];
|
|
11
|
-
if ('mapbox' === provider) {
|
|
12
|
-
result = mapboxStyleSpec.validate(style);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
result = maplibre_gl_style_spec_1.default.validateStyleMin(style);
|
|
16
|
-
}
|
|
1
|
+
import maplibreStyleSpec from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
+
export function validateStyle(style) {
|
|
3
|
+
const result = maplibreStyleSpec.validateStyleMin(style);
|
|
17
4
|
const errors = [];
|
|
18
5
|
for (let i = 0; i < result.length; i++) {
|
|
19
6
|
const msg = result[i].message;
|
|
@@ -33,4 +20,3 @@ function validateStyle(style, provider = 'default') {
|
|
|
33
20
|
throw `\u001b[31mError:\u001b[0m ${errors.join('\n\u001b[31mError:\u001b[0m ')}`;
|
|
34
21
|
}
|
|
35
22
|
}
|
|
36
|
-
exports.validateStyle = validateStyle;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import * as yamlinc from './index.js';
|
|
5
|
+
function construct(data) {
|
|
6
|
+
const basepath = yamlinc.getBasePath();
|
|
7
|
+
const fullpath = path.join(basepath, data);
|
|
8
|
+
yamlinc.YAML_VISITED_FILES.push(fullpath.replace(basepath + path.sep, ''));
|
|
9
|
+
const src = fs.readFileSync(fullpath, 'utf8');
|
|
10
|
+
const included = yaml.load(src, {
|
|
11
|
+
schema: yamlinc.YAML_INCLUDE_SCHEMA,
|
|
12
|
+
filename: fullpath,
|
|
13
|
+
});
|
|
14
|
+
return included;
|
|
15
|
+
}
|
|
16
|
+
function resolve(data) {
|
|
17
|
+
return typeof data === 'string';
|
|
18
|
+
}
|
|
19
|
+
export default new yaml.Type('tag:yaml.org,2002:inc/file', {
|
|
20
|
+
kind: 'scalar',
|
|
21
|
+
resolve: resolve,
|
|
22
|
+
construct: construct,
|
|
23
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import yaml from 'js-yaml';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
// import YamlIncludeDirType from './lib/dir';
|
|
4
|
+
import YamlIncludeFileType from './file.js';
|
|
5
|
+
export const YAML_VISITED_FILES = [];
|
|
6
|
+
export const YAML_TYPES = [
|
|
7
|
+
// YamlIncludeDirType,
|
|
8
|
+
YamlIncludeFileType,
|
|
9
|
+
];
|
|
10
|
+
export const YAML_INCLUDE_SCHEMA = yaml.DEFAULT_SCHEMA.extend(YAML_TYPES);
|
|
11
|
+
export let basefile = '';
|
|
12
|
+
// so we know where to find files referenced relative to the base file
|
|
13
|
+
export function setBaseFile(file) {
|
|
14
|
+
YAML_VISITED_FILES.push(file);
|
|
15
|
+
basefile = file;
|
|
16
|
+
}
|
|
17
|
+
export function getBasePath() {
|
|
18
|
+
return path.dirname(basefile);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
// YamlIncludeDirType,
|
|
22
|
+
YamlIncludeFileType, };
|
package/dist/lib/yaml-parser.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parser = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
-
const yamlinc = require('yaml-include');
|
|
10
|
-
function parser(file) {
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import YAML from 'js-yaml';
|
|
3
|
+
import * as yamlinc from './yaml-include/index.js';
|
|
4
|
+
export function parser(file) {
|
|
11
5
|
yamlinc.setBaseFile(file);
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
6
|
+
const schema = yamlinc.YAML_INCLUDE_SCHEMA;
|
|
7
|
+
const yaml = fs.readFileSync(file, 'utf8');
|
|
8
|
+
const obj = YAML.load(yaml, {
|
|
9
|
+
schema,
|
|
15
10
|
filename: file,
|
|
16
11
|
json: true,
|
|
17
12
|
});
|
|
@@ -43,4 +38,3 @@ function parser(file) {
|
|
|
43
38
|
}
|
|
44
39
|
return JSON.parse(style);
|
|
45
40
|
}
|
|
46
|
-
exports.parser = parser;
|
package/dist/lib/yaml-writer.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeYaml = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
|
-
const writeYaml = (destinationPath, style, composite = false) => {
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import YAML from 'js-yaml';
|
|
4
|
+
export const writeYaml = (destinationPath, style, composite = false) => {
|
|
11
5
|
if (composite === true) {
|
|
12
6
|
writeCompositedYaml(destinationPath, style);
|
|
13
7
|
}
|
|
@@ -15,46 +9,46 @@ const writeYaml = (destinationPath, style, composite = false) => {
|
|
|
15
9
|
writeDecompositedYaml(destinationPath, style);
|
|
16
10
|
}
|
|
17
11
|
};
|
|
18
|
-
exports.writeYaml = writeYaml;
|
|
19
12
|
const writeCompositedYaml = (destinationPath, style) => {
|
|
20
|
-
const styleYAML =
|
|
21
|
-
let stylePath =
|
|
13
|
+
const styleYAML = YAML.dump(style);
|
|
14
|
+
let stylePath = path.resolve(process.cwd(), destinationPath);
|
|
22
15
|
// The `source` is absolute path.
|
|
23
16
|
if (destinationPath.match(/^\//)) {
|
|
24
17
|
stylePath = destinationPath;
|
|
25
18
|
}
|
|
26
|
-
|
|
19
|
+
fs.writeFileSync(stylePath, styleYAML);
|
|
27
20
|
};
|
|
28
21
|
class IncFileTag {
|
|
22
|
+
value;
|
|
29
23
|
constructor(fileName) {
|
|
30
24
|
// We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
|
|
31
|
-
this.value =
|
|
25
|
+
this.value = path.posix.join('layers', fileName);
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
|
-
const INC_PATH_TYPE = new
|
|
28
|
+
const INC_PATH_TYPE = new YAML.Type('tag:yaml.org,2002:inc/file', {
|
|
35
29
|
kind: 'scalar',
|
|
36
30
|
resolve: (data) => data,
|
|
37
31
|
construct: (data) => new IncFileTag(data),
|
|
38
32
|
instanceOf: IncFileTag,
|
|
39
33
|
represent: (tag) => tag.value,
|
|
40
34
|
});
|
|
41
|
-
const INC_PATH_OUTPUT_SCHEMA =
|
|
35
|
+
const INC_PATH_OUTPUT_SCHEMA = YAML.DEFAULT_SCHEMA.extend([INC_PATH_TYPE]);
|
|
42
36
|
const writeDecompositedYaml = (destinationPath, style) => {
|
|
43
37
|
const layers = [];
|
|
44
38
|
for (let i = 0; i < style.layers.length; i++) {
|
|
45
39
|
const layer = style.layers[i];
|
|
46
|
-
const layerYml =
|
|
40
|
+
const layerYml = YAML.dump(layer);
|
|
47
41
|
const fileName = `${style.layers[i].id}.yml`;
|
|
48
|
-
const layersDirName =
|
|
49
|
-
const filePath =
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
const layersDirName = path.join(path.dirname(destinationPath), 'layers');
|
|
43
|
+
const filePath = path.join(layersDirName, fileName);
|
|
44
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
45
|
+
fs.writeFileSync(filePath, layerYml);
|
|
52
46
|
// ts-ignore is required here because the !!inc/file object is not compatible with the Layer object type.
|
|
53
47
|
// @ts-ignore
|
|
54
48
|
layers.push(new IncFileTag(fileName));
|
|
55
49
|
}
|
|
56
50
|
style.layers = layers;
|
|
57
|
-
|
|
51
|
+
fs.writeFileSync(destinationPath, YAML.dump(style, {
|
|
58
52
|
schema: INC_PATH_OUTPUT_SCHEMA,
|
|
59
53
|
}));
|
|
60
54
|
};
|
package/dist/types/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./tilejson"), exports);
|
|
18
|
-
__exportStar(require("./metadatajson"), exports);
|
|
19
|
-
__exportStar(require("./vector_layers"), exports);
|
|
1
|
+
export * from './tilejson';
|
|
2
|
+
export * from './metadatajson';
|
|
3
|
+
export * from './vector_layers';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/types/tilejson.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/docs/source/index.rst
CHANGED
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
Charites - Documentation
|
|
7
7
|
====================================
|
|
8
8
|
|
|
9
|
-
:Date:
|
|
9
|
+
:Date: 2024-08-23
|
|
10
10
|
:Copyright: CC-BY-SA
|
|
11
11
|
:Organization: The United Nations Vector Tile Toolkit
|
|
12
|
-
:Version: 0.
|
|
12
|
+
:Version: 2.0.2
|
|
13
13
|
:Abstract: This document contains the complete documentation of Charites, an application to style vector tiles easily
|
|
14
14
|
|
|
15
15
|
.. meta::
|
|
16
16
|
:description lang=en: This document contains the complete documentation of Charites, an application to style vector tiles easily
|
|
17
|
-
:keywords: Charites,
|
|
17
|
+
:keywords: Charites, Maplibre, Vectortiles, UNVT, webmapping
|
|
18
18
|
|
|
19
|
-
An easy, intuitive, and efficient command-line tool for writing vector map styles compatible with the `
|
|
19
|
+
An easy, intuitive, and efficient command-line tool for writing vector map styles compatible with the `MapLibre <https://maplibre.org/maplibre-style-spec/>`_ Style Specification in YAML.
|
|
20
20
|
With YAML format's readability, JSON compiler, linter, and live style viewer on a local browser, you can simplify your map styling workflow.
|
|
21
21
|
|
|
22
22
|
.. note::
|
|
@@ -30,7 +30,6 @@ Features
|
|
|
30
30
|
- Divide groups of layers in to multiple files for better readability and mantainability. `!!inc/file <relative-path-to-the-file>`
|
|
31
31
|
- Use variables like `$backgroundColor` and `$waterColor` to style effectively.
|
|
32
32
|
- Compile YAML to a single style.json file, with a format linter.
|
|
33
|
-
- Use `--provider mapbox` to validate your style against Mapbox GL JS v2.x
|
|
34
33
|
- Run `charites serve <source>` to preview your style live while you make changes in a browser.
|
|
35
34
|
|
|
36
35
|
.. toctree::
|