@unvt/charites 0.5.4 → 2.0.0

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.
Files changed (79) hide show
  1. package/.github/workflows/build.yml +3 -5
  2. package/.mocharc.json +7 -0
  3. package/README.md +5 -2
  4. package/dist/cli/build.js +13 -24
  5. package/dist/cli/convert.js +7 -9
  6. package/dist/cli/init.js +7 -9
  7. package/dist/cli/serve.js +7 -21
  8. package/dist/cli.js +18 -16
  9. package/dist/commands/build.js +25 -38
  10. package/dist/commands/convert.js +14 -21
  11. package/dist/commands/init.js +6 -10
  12. package/dist/commands/serve.js +33 -65
  13. package/dist/lib/build-sprite.js +5 -12
  14. package/dist/lib/defaultValues.js +6 -31
  15. package/dist/lib/error.js +1 -5
  16. package/dist/lib/get-sprite-slug.js +1 -5
  17. package/dist/lib/tileinfo-importer/base-importer.js +2 -5
  18. package/dist/lib/tileinfo-importer/index.js +2 -7
  19. package/dist/lib/tileinfo-importer/metadata-importer.js +4 -11
  20. package/dist/lib/tileinfo-importer/tilejson-importer.js +4 -11
  21. package/dist/lib/validate-style.js +3 -17
  22. package/dist/lib/yaml-include/file.js +23 -0
  23. package/dist/lib/yaml-include/index.js +22 -0
  24. package/dist/lib/yaml-parser.js +8 -14
  25. package/dist/lib/yaml-writer.js +17 -23
  26. package/dist/types/index.js +3 -19
  27. package/dist/types/metadatajson.js +1 -2
  28. package/dist/types/tilejson.js +1 -2
  29. package/dist/types/vector_layers.js +1 -2
  30. package/docs/source/index.rst +4 -5
  31. package/docs/source/usage/commandline_interface.rst +0 -12
  32. package/docs/source/usage/examples.rst +0 -6
  33. package/docs/source/usage/index.rst +0 -1
  34. package/eslint.config.mjs +46 -0
  35. package/mocha-register.cjs +2 -0
  36. package/package.json +40 -37
  37. package/playwright.config.ts +1 -12
  38. package/provider/{default/shared.js → app.js} +30 -0
  39. package/provider/{default/index.html → index.html} +3 -3
  40. package/src/cli/build.ts +2 -15
  41. package/src/cli/convert.ts +2 -2
  42. package/src/cli/init.ts +2 -2
  43. package/src/cli/serve.ts +2 -20
  44. package/src/cli.ts +14 -5
  45. package/src/commands/build.ts +5 -12
  46. package/src/commands/convert.ts +1 -1
  47. package/src/commands/init.ts +2 -2
  48. package/src/commands/serve.ts +10 -48
  49. package/src/lib/defaultValues.ts +8 -34
  50. package/src/lib/tileinfo-importer/index.ts +2 -2
  51. package/src/lib/tileinfo-importer/metadata-importer.ts +2 -2
  52. package/src/lib/tileinfo-importer/tilejson-importer.ts +2 -2
  53. package/src/lib/validate-style.ts +5 -13
  54. package/src/lib/yaml-include/file.ts +29 -0
  55. package/src/lib/yaml-include/index.ts +28 -0
  56. package/src/lib/yaml-parser.ts +3 -3
  57. package/test/build-sprite.spec.ts +5 -0
  58. package/test/build.spec.ts +10 -13
  59. package/test/command.build.spec.ts +2 -2
  60. package/test/convert.spec.ts +7 -1
  61. package/test/get-sprite-slug.spec.ts +4 -0
  62. package/test/init.spec.ts +5 -0
  63. package/test/playwright/provider/{default/e2e.spec.ts → e2e.spec.ts} +2 -2
  64. package/test/util/charitesCmd.ts +5 -0
  65. package/test/util/copyFixtures.ts +5 -0
  66. package/test/yaml-parser.spec.ts +4 -0
  67. package/tsconfig.json +11 -6
  68. package/.eslintignore +0 -2
  69. package/.eslintrc.js +0 -17
  70. package/docs/source/usage/global_options.rst +0 -21
  71. package/provider/default/app.js +0 -30
  72. package/provider/geolonia/app.js +0 -28
  73. package/provider/geolonia/index.html +0 -22
  74. package/provider/mapbox/app.js +0 -33
  75. package/provider/mapbox/index.html +0 -23
  76. package/test/playwright/provider/geolonia/e2e.spec.ts +0 -13
  77. package/test/playwright/provider/mapbox/e2e.spec.ts +0 -13
  78. /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
  79. /package/provider/{default/app.css → app.css} +0 -0
@@ -1,58 +1,42 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.serve = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const os_1 = __importDefault(require("os"));
10
- const http_1 = __importDefault(require("http"));
11
- const open_1 = __importDefault(require("open"));
12
- const ws_1 = require("ws");
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 = path_1.default.resolve(process.cwd(), source);
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 (!fs_1.default.existsSync(sourcePath)) {
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 fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'charites-'));
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 (0, build_sprite_1.buildSprite)(options.spriteInput, spriteOut, 'sprite', options.sdf);
34
+ await buildSprite(options.spriteInput, spriteOut, 'sprite', options.sdf);
49
35
  };
50
36
  await spriteRefresher();
51
37
  }
52
- const server = http_1.default.createServer(async (req, res) => {
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 = path_1.default.basename(url);
67
- const fsStream = fs_1.default.createReadStream(path_1.default.join(spriteOut, filename));
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 = fs_1.default.readFileSync(path_1.default.join(providerDir, 'index.html'), 'utf-8');
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 = (0, yaml_parser_1.parser)(sourcePath);
65
+ style = parser(sourcePath);
82
66
  if (typeof spriteOut !== 'undefined') {
83
67
  style.sprite = `http://${req.headers.host || `localhost:${port}`}/sprite`;
84
68
  }
85
- (0, validate_style_1.validateStyle)(style, provider);
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 = fs_1.default.readFileSync(path_1.default.join(defaultProviderDir, 'app.css'), 'utf-8');
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
- try {
112
- const app = fs_1.default.readFileSync(path_1.default.join(providerDir, 'app.js'), 'utf-8');
113
- const js = app
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
- (0, open_1.default)(`http://localhost:${port}`);
103
+ open(`http://localhost:${port}`);
135
104
  }
136
105
  });
137
- const wss = new ws_1.WebSocketServer({ server });
106
+ const wss = new WebSocketServer({ server });
138
107
  wss.on('connection', (ws) => {
139
- const watcher = (0, node_watch_1.default)(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$|\.svg$/i }, (event, file) => {
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 === null || file === void 0 ? void 0 : file.toLowerCase().endsWith('.yml')) {
111
+ if (file?.toLowerCase().endsWith('.yml')) {
143
112
  ws.send(JSON.stringify({
144
113
  event: 'styleUpdate',
145
114
  }));
146
115
  }
147
- else if ((file === null || file === void 0 ? void 0 : file.toLowerCase().endsWith('.svg')) &&
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 (e) {
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
- fs_1.default.rmSync(spriteOut, { recursive: true });
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;
@@ -1,15 +1,8 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 = path_1.default.join(publicPath, iconSlug);
12
- await (0, sprite_one_1.generateSprite)(outPath, [svgPath], pxRatios, sdf);
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defaultSettings = exports.defaultValues = void 0;
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
- "use strict";
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
- "use strict";
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 axios_1.default.get(url);
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 axios_1.default.get(url);
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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, };
@@ -1,17 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 yaml = fs_1.default.readFileSync(file, 'utf8');
13
- const obj = js_yaml_1.default.load(yaml, {
14
- schema: yamlinc.YAML_INCLUDE_SCHEMA,
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;
@@ -1,13 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 = js_yaml_1.default.dump(style);
21
- let stylePath = path_1.default.resolve(process.cwd(), destinationPath);
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
- fs_1.default.writeFileSync(stylePath, styleYAML);
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 = path_1.default.posix.join('layers', fileName);
25
+ this.value = path.posix.join('layers', fileName);
32
26
  }
33
27
  }
34
- const INC_PATH_TYPE = new js_yaml_1.default.Type('tag:yaml.org,2002:inc/file', {
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 = js_yaml_1.default.DEFAULT_SCHEMA.extend([INC_PATH_TYPE]);
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 = js_yaml_1.default.dump(layer);
40
+ const layerYml = YAML.dump(layer);
47
41
  const fileName = `${style.layers[i].id}.yml`;
48
- const layersDirName = path_1.default.join(path_1.default.dirname(destinationPath), 'layers');
49
- const filePath = path_1.default.join(layersDirName, fileName);
50
- fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
51
- fs_1.default.writeFileSync(filePath, layerYml);
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
- fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style, {
51
+ fs.writeFileSync(destinationPath, YAML.dump(style, {
58
52
  schema: INC_PATH_OUTPUT_SCHEMA,
59
53
  }));
60
54
  };
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -6,17 +6,17 @@
6
6
  Charites - Documentation
7
7
  ====================================
8
8
 
9
- :Date: 2022-12-15
9
+ :Date: 2024-08-23
10
10
  :Copyright: CC-BY-SA
11
11
  :Organization: The United Nations Vector Tile Toolkit
12
- :Version: 0.3.0
12
+ :Version: 2.0.0
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, Mapbox, Maplibre, Vectortiles, UNVT, webmapping
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 `Mapbox <https://docs.mapbox.com/mapbox-gl-js/style-spec/>`_ and `MapLibre <https://maplibre.org/maplibre-gl-js-docs/style-spec/>`_ Style Specification in YAML.
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::