@unvt/charites 0.2.0 → 0.4.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 (90) hide show
  1. package/.devcontainer/README.md +1 -1
  2. package/.eslintrc.js +1 -1
  3. package/.github/PULL_REQUEST_TEMPLATE.md +1 -1
  4. package/.github/release.yml +14 -0
  5. package/.github/workflows/build-docs.yml +4 -4
  6. package/.github/workflows/build.yml +33 -7
  7. package/LICENSE +1 -1
  8. package/dist/cli/build.js +4 -4
  9. package/dist/cli/convert.js +2 -2
  10. package/dist/cli/init.js +3 -3
  11. package/dist/cli/serve.js +8 -4
  12. package/dist/commands/build.js +7 -12
  13. package/dist/commands/convert.js +2 -12
  14. package/dist/commands/init.js +1 -1
  15. package/dist/commands/serve.js +81 -16
  16. package/dist/lib/build-sprite.js +6 -8
  17. package/dist/lib/error.js +2 -1
  18. package/dist/lib/tileinfo-importer/index.js +1 -0
  19. package/dist/lib/yaml-writer.js +25 -13
  20. package/dist/types/index.js +6 -2
  21. package/docs/Pipfile.lock +136 -193
  22. package/docs/source/conf.py +3 -3
  23. package/docs/source/index.rst +2 -2
  24. package/docs/source/install/img/windows-guide-01.png +0 -0
  25. package/docs/source/install/index.rst +1 -0
  26. package/docs/source/install/install.rst +1 -0
  27. package/docs/source/install/install_on_nanban.rst +1 -1
  28. package/docs/source/install/installation_guide_for_windows.rst +52 -0
  29. package/docs/source/install/recommended_environment.rst +2 -2
  30. package/docs/source/usage/commandline_interface.rst +23 -10
  31. package/docs/source/usage/example2.rst +166 -0
  32. package/docs/source/usage/examples.rst +2 -2
  33. package/docs/source/usage/img/example02-001.png +0 -0
  34. package/docs/source/usage/img/example02-002.png +0 -0
  35. package/docs/source/usage/img/example02-003.png +0 -0
  36. package/docs/source/usage/img/example02-004.png +0 -0
  37. package/docs/source/usage/img/example02-005.png +0 -0
  38. package/docs/source/usage/img/example02-006.png +0 -0
  39. package/docs/source/usage/img/example02-007.png +0 -0
  40. package/docs/source/usage/img/example02-008.png +0 -0
  41. package/docs/source/usage/img/example02-009.png +0 -0
  42. package/docs/source/usage/img/example02-010.png +0 -0
  43. package/docs/source/usage/img/example02-011.png +0 -0
  44. package/docs/source/usage/img/example02-012.png +0 -0
  45. package/docs/source/usage/img/example02-013.png +0 -0
  46. package/docs/source/usage/img/example02-014.png +0 -0
  47. package/docs/source/usage/img/example02-015.png +0 -0
  48. package/docs/source/usage/img/example02-016.png +0 -0
  49. package/docs/source/usage/img/example02-017.png +0 -0
  50. package/docs/source/usage/img/example02-018.png +0 -0
  51. package/docs/source/usage/index.rst +1 -0
  52. package/package.json +34 -28
  53. package/playwright.config.ts +29 -0
  54. package/provider/default/app.js +26 -46
  55. package/provider/default/index.html +4 -3
  56. package/provider/default/shared.js +76 -0
  57. package/provider/geolonia/app.js +25 -32
  58. package/provider/geolonia/index.html +4 -1
  59. package/provider/mapbox/app.js +33 -53
  60. package/provider/mapbox/index.html +2 -1
  61. package/src/cli/init.ts +1 -1
  62. package/src/cli/serve.ts +10 -3
  63. package/src/commands/build.ts +2 -6
  64. package/src/commands/convert.ts +2 -10
  65. package/src/commands/init.ts +1 -1
  66. package/src/commands/serve.ts +107 -15
  67. package/src/lib/build-sprite.ts +2 -6
  68. package/src/lib/get-sprite-slug.ts +1 -1
  69. package/src/lib/tileinfo-importer/base-importer.ts +1 -1
  70. package/src/lib/tileinfo-importer/metadata-importer.ts +1 -1
  71. package/src/lib/tileinfo-importer/tilejson-importer.ts +1 -1
  72. package/src/lib/validate-style.ts +1 -1
  73. package/src/lib/yaml-parser.ts +1 -1
  74. package/src/lib/yaml-writer.ts +28 -15
  75. package/test/build.spec.ts +22 -12
  76. package/test/command.build.spec.ts +39 -31
  77. package/test/command.serve.spec.ts +103 -0
  78. package/test/convert.spec.ts +24 -4
  79. package/test/data/convert.json +7 -0
  80. package/test/data/style.json +4 -3
  81. package/test/init.spec.ts +7 -5
  82. package/test/playwright/provider/default/e2e.spec.ts +13 -0
  83. package/test/playwright/provider/geolonia/e2e.spec.ts +13 -0
  84. package/test/playwright/provider/mapbox/e2e.spec.ts +13 -0
  85. package/test/util/charitesCmd.ts +3 -1
  86. package/test/util/execPromise.ts +51 -1
  87. package/test/util/index.ts +3 -0
  88. package/test/validate-style.spec.ts +1 -1
  89. package/provider/geolonia/app.css +0 -17
  90. package/provider/mapbox/app.css +0 -17
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## What is it?
4
4
 
5
- - DevContainer is a Dockerfike and configuration file for remote development in Visual Studio Code or GitHub Codespaces
5
+ - DevContainer is a Dockerfile and a configuration file for remote development in Visual Studio Code or GitHub Codespaces
6
6
  - DevContainer allows development environments to be written and maintained as code
7
7
  - DevContainer allows everyone to develop in a common development environment
8
8
 
package/.eslintrc.js CHANGED
@@ -6,8 +6,8 @@ module.exports = {
6
6
  },
7
7
  extends: [
8
8
  'plugin:@typescript-eslint/recommended',
9
- 'prettier/@typescript-eslint',
10
9
  'plugin:prettier/recommended',
10
+ 'prettier',
11
11
  ],
12
12
  rules: {
13
13
  '@typescript-eslint/explicit-module-boundary-types': 0,
@@ -18,7 +18,7 @@ Please describe what you changed briefly.
18
18
  - [ ] No build errors after `npm run build`
19
19
  - [ ] No lint errors after `npm run lint`
20
20
  - [ ] No errors on using `charites help` globally
21
- - [ ] Make sure all the exsiting features working well
21
+ - [ ] Make sure all the existing features working well
22
22
  - [ ] Have you added at least one unit test if you are going to add new feature?
23
23
  - [ ] Have you updated documentation?
24
24
  <!-- ignore-task-list-end -->
@@ -0,0 +1,14 @@
1
+ changelog:
2
+ exclude:
3
+ labels:
4
+ - ignore-for-release
5
+ categories:
6
+ - title: Breaking Changes 🛠
7
+ labels:
8
+ - breaking-change
9
+ - title: Exciting New Features 🎉
10
+ labels:
11
+ - enhancement
12
+ - title: Other Changes
13
+ labels:
14
+ - '*'
@@ -1,6 +1,6 @@
1
1
  name: Build and Deploy docs
2
2
 
3
- on:
3
+ on:
4
4
  push:
5
5
  branches:
6
6
  - main
@@ -21,9 +21,9 @@ jobs:
21
21
  TX_TOKEN: ${{ secrets.TX_TOKEN }}
22
22
 
23
23
  steps:
24
- - uses: actions/checkout@v1
24
+ - uses: actions/checkout@v3
25
25
  - name: Set up Python 3.9
26
- uses: actions/setup-python@v1
26
+ uses: actions/setup-python@v4
27
27
  with:
28
28
  python-version: 3.9
29
29
 
@@ -65,7 +65,7 @@ jobs:
65
65
  touch ./build/html/.nojekyll
66
66
 
67
67
  - name: Deploy 🚀
68
- uses: JamesIves/github-pages-deploy-action@4.1.7
68
+ uses: JamesIves/github-pages-deploy-action@v4
69
69
  if: ${{ github.ref == 'refs/heads/main' }}
70
70
  with:
71
71
  branch: gh-pages # The branch the action should deploy to.
@@ -14,31 +14,57 @@ on:
14
14
 
15
15
  jobs:
16
16
  build:
17
- runs-on: ubuntu-latest
18
-
19
17
  strategy:
20
18
  matrix:
21
19
  node-version: [14.x, 16.x, 18.x]
22
-
20
+ os: [ubuntu-latest, windows-latest]
21
+ runs-on: ${{ matrix.os }}
23
22
  steps:
24
- - uses: actions/checkout@v2
23
+ - uses: actions/checkout@v3
25
24
  - name: Use Node.js ${{ matrix.node-version }}
26
- uses: actions/setup-node@v1
25
+ uses: actions/setup-node@v3
27
26
  with:
28
27
  node-version: ${{ matrix.node-version }}
29
28
  - run: npm install
30
29
  - run: npm run lint
31
30
  - run: npm test
32
31
 
32
+ e2e:
33
+ runs-on: ubuntu-latest
34
+ strategy:
35
+ matrix:
36
+ node-version: [18.x]
37
+ steps:
38
+ - uses: actions/checkout@v3
39
+ - name: Use Node.js ${{ matrix.node-version }}
40
+ uses: actions/setup-node@v3
41
+ with:
42
+ node-version: ${{ matrix.node-version }}
43
+ - name: Check and restore cache of playwright
44
+ uses: actions/cache@v3
45
+ id: playwright-cache
46
+ with:
47
+ path: |
48
+ ~/.cache/ms-playwright
49
+ key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
50
+ - run: npm install
51
+ - run: npx playwright install --with-deps chromium
52
+ if: steps.playwright-cache.outputs.cache-hit != 'true'
53
+ - run: npm run build
54
+ - run: chmod 777 dist/cli.js
55
+ - run: npm run test:e2e
56
+ env:
57
+ MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
58
+
33
59
  publish:
34
60
  name: 'Publish npm package'
35
61
  runs-on: ubuntu-latest
36
62
  needs: build
37
63
  if: startsWith(github.ref, 'refs/tags/v')
38
64
  steps:
39
- - uses: actions/checkout@v2
65
+ - uses: actions/checkout@v3
40
66
  # Setup .npmrc file to publish to npm
41
- - uses: actions/setup-node@v1
67
+ - uses: actions/setup-node@v3
42
68
  with:
43
69
  tag_name: 'v%s'
44
70
  node-version: '14.x'
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 The United Nations Vector Tile Toolkit
3
+ Copyright (c) 2022 The United Nations Vector Tile Toolkit
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/cli/build.js CHANGED
@@ -40,7 +40,7 @@ program
40
40
  try {
41
41
  console.log('Start watching...');
42
42
  await new Promise((resolve) => {
43
- const watcher = build_1.buildWatch(source, destination, options);
43
+ const watcher = (0, build_1.buildWatch)(source, destination, options);
44
44
  process.on('SIGINT', () => {
45
45
  watcher.close();
46
46
  resolve(undefined);
@@ -48,15 +48,15 @@ program
48
48
  });
49
49
  }
50
50
  catch (e) {
51
- error_1.error(e);
51
+ (0, error_1.error)(e);
52
52
  }
53
53
  }
54
54
  else {
55
55
  try {
56
- await build_1.build(source, destination, options);
56
+ await (0, build_1.build)(source, destination, options);
57
57
  }
58
58
  catch (e) {
59
- error_1.error(e);
59
+ (0, error_1.error)(e);
60
60
  }
61
61
  }
62
62
  });
@@ -10,10 +10,10 @@ program
10
10
  .description('convert the style JSON to YAML')
11
11
  .action((source, destination) => {
12
12
  try {
13
- convert_1.convert(source, destination);
13
+ (0, convert_1.convert)(source, destination);
14
14
  }
15
15
  catch (e) {
16
- error_1.error(e);
16
+ (0, error_1.error)(e);
17
17
  }
18
18
  });
19
19
  exports.default = program;
package/dist/cli/init.js CHANGED
@@ -7,7 +7,7 @@ const program = new commander_1.Command();
7
7
  program
8
8
  .name('init')
9
9
  .arguments('<file>')
10
- .description('initialize a style JSON')
10
+ .description('initialize a style YAML')
11
11
  .option('-t, --tilejson-urls <tilejson_urls>', 'an URL for TileJSON. It will create empty layers from vector_layers property of TileJSON. Please use comma (,) in case multiple TileJSONs require.')
12
12
  .option('-m, --metadatajson-urls <metadatajson_urls>', 'an URL for metadata.json. It will create empty layers from vector_layers property of metadata.json. Please use comma (,) in case multiple metadata.json require.')
13
13
  .option('-c, --composite-layers', 'If it is true, a single YAML will be generated with multiple layers. Default is false.')
@@ -17,10 +17,10 @@ program
17
17
  options.metadatajsonUrls = initOptions.metadatajsonUrls;
18
18
  options.compositeLayers = initOptions.compositeLayers;
19
19
  try {
20
- await init_1.init(file, options);
20
+ await (0, init_1.init)(file, options);
21
21
  }
22
22
  catch (e) {
23
- error_1.error(e);
23
+ (0, error_1.error)(e);
24
24
  }
25
25
  });
26
26
  exports.default = program;
package/dist/cli/serve.js CHANGED
@@ -14,21 +14,25 @@ program
14
14
  .arguments('<source>')
15
15
  .description('serve your map locally')
16
16
  .option('--provider [provider]', 'your map service. e.g. `mapbox`, `geolonia`')
17
- .option('--mapbox-access-token [mapboxAccessToken]', 'Access Token for the Mapbox')
17
+ .option('--mapbox-access-token [mapboxAccessToken]', 'Your Mapbox Access Token (required if using the `mapbox` provider)')
18
+ .option('-i, --sprite-input [<icon input directory>]', 'directory path of icon source to build icons. The default <icon source> is `icons/`')
18
19
  .option('--port [port]', 'Specify custom port')
19
- .action((source, serveOptions) => {
20
+ .option('--no-open', "Don't open the preview in the default browser")
21
+ .action(async (source, serveOptions) => {
20
22
  const options = program.opts();
21
23
  options.provider = serveOptions.provider;
22
24
  options.mapboxAccessToken = serveOptions.mapboxAccessToken;
23
25
  options.port = serveOptions.port;
26
+ options.spriteInput = serveOptions.spriteInput;
27
+ options.open = serveOptions.open;
24
28
  if (!fs_1.default.existsSync(defaultValues_1.defaultSettings.configFile)) {
25
29
  fs_1.default.writeFileSync(defaultValues_1.defaultSettings.configFile, `provider: ${options.provider || 'default'}`);
26
30
  }
27
31
  try {
28
- serve_1.serve(source, program.opts());
32
+ await (0, serve_1.serve)(source, program.opts());
29
33
  }
30
34
  catch (e) {
31
- error_1.error(e);
35
+ (0, error_1.error)(e);
32
36
  }
33
37
  });
34
38
  exports.default = program;
@@ -40,8 +40,8 @@ async function build(source, destination, options) {
40
40
  }
41
41
  let style = '';
42
42
  try {
43
- const _style = yaml_parser_1.parser(sourcePath);
44
- validate_style_1.validateStyle(_style, provider);
43
+ const _style = (0, yaml_parser_1.parser)(sourcePath);
44
+ (0, validate_style_1.validateStyle)(_style, provider);
45
45
  if (options.spriteUrl && 'sprite' in _style) {
46
46
  _style.sprite = options.spriteUrl;
47
47
  }
@@ -53,14 +53,14 @@ async function build(source, destination, options) {
53
53
  if (!fs_1.default.existsSync(options.spriteOutput)) {
54
54
  throw `${options.spriteOutput}: No such directory. Please specify valid icon output directory. For more help run charites build --help`;
55
55
  }
56
- const iconSlug = get_sprite_slug_1.getSpriteSlug(JSON.parse(style));
56
+ const iconSlug = (0, get_sprite_slug_1.getSpriteSlug)(JSON.parse(style));
57
57
  if (!iconSlug) {
58
58
  throw `Invalid sprite url format.`;
59
59
  }
60
- await build_sprite_1.buildSprite(options.spriteInput, options.spriteOutput, iconSlug);
60
+ await (0, build_sprite_1.buildSprite)(options.spriteInput, options.spriteOutput, iconSlug);
61
61
  }
62
62
  if (options.compactOutput) {
63
- style = jsonminify_1.default(style);
63
+ style = (0, jsonminify_1.default)(style);
64
64
  }
65
65
  }
66
66
  catch (err) {
@@ -71,12 +71,7 @@ async function build(source, destination, options) {
71
71
  throw `${sourcePath}: Invalid YAML syntax`;
72
72
  }
73
73
  }
74
- try {
75
- fs_1.default.writeFileSync(destinationPath, style);
76
- }
77
- catch (err) {
78
- throw `${destinationPath}: Permission denied`;
79
- }
74
+ fs_1.default.writeFileSync(destinationPath, style);
80
75
  }
81
76
  exports.build = build;
82
77
  function buildWatch(source, destination, options) {
@@ -85,7 +80,7 @@ function buildWatch(source, destination, options) {
85
80
  sourcePath = source;
86
81
  }
87
82
  console.log(path_1.default.dirname(sourcePath));
88
- return node_watch_1.default(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
83
+ return (0, node_watch_1.default)(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
89
84
  console.log(`${(event || '').toUpperCase()}: ${file}`);
90
85
  try {
91
86
  build(source, destination, options);
@@ -42,12 +42,7 @@ function convert(source, destination) {
42
42
  rl.on('close', () => {
43
43
  const style = JSON.parse(lines.join(''));
44
44
  const destinationPath = getDestinationPath(destination);
45
- try {
46
- yaml_writer_1.writeYaml(destinationPath, style, false);
47
- }
48
- catch (err) {
49
- throw `${destinationPath}: Permission denied`;
50
- }
45
+ (0, yaml_writer_1.writeYaml)(destinationPath, style, false);
51
46
  });
52
47
  }
53
48
  else {
@@ -61,12 +56,7 @@ function convert(source, destination) {
61
56
  }
62
57
  style = JSON.parse(fs_1.default.readFileSync(sourcePath, 'utf-8'));
63
58
  const destinationPath = getDestinationPath(destination, sourcePath);
64
- try {
65
- yaml_writer_1.writeYaml(destinationPath, style, false);
66
- }
67
- catch (err) {
68
- throw `${destinationPath}: Permission denied`;
69
- }
59
+ (0, yaml_writer_1.writeYaml)(destinationPath, style, false);
70
60
  }
71
61
  }
72
62
  exports.convert = convert;
@@ -21,6 +21,6 @@ async function init(file, options) {
21
21
  const metadataJSONImporter = new tileinfo_importer_1.MetadataJSONImporter(options.metadatajsonUrls);
22
22
  styleTemplate = await metadataJSONImporter.import(styleTemplate);
23
23
  }
24
- yaml_writer_1.writeYaml(file, styleTemplate, options.compositeLayers);
24
+ (0, yaml_writer_1.writeYaml)(file, styleTemplate, options.compositeLayers);
25
25
  }
26
26
  exports.init = init;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.serve = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
+ const os_1 = __importDefault(require("os"));
9
10
  const http_1 = __importDefault(require("http"));
10
11
  const open_1 = __importDefault(require("open"));
11
12
  const ws_1 = require("ws");
@@ -13,7 +14,8 @@ const node_watch_1 = __importDefault(require("node-watch"));
13
14
  const yaml_parser_1 = require("../lib/yaml-parser");
14
15
  const validate_style_1 = require("../lib/validate-style");
15
16
  const defaultValues_1 = require("../lib/defaultValues");
16
- function serve(source, options) {
17
+ const build_sprite_1 = require("../lib/build-sprite");
18
+ async function serve(source, options) {
17
19
  let port = process.env.PORT || 8080;
18
20
  if (options.port) {
19
21
  port = Number(options.port);
@@ -30,40 +32,84 @@ function serve(source, options) {
30
32
  if (!fs_1.default.existsSync(sourcePath)) {
31
33
  throw `${sourcePath}: No such file or directory`;
32
34
  }
33
- const server = http_1.default.createServer((req, res) => {
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
+ let spriteOut = undefined;
40
+ let spriteRefresher = undefined;
41
+ if (options.spriteInput) {
42
+ spriteOut = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'charites-'));
43
+ spriteRefresher = async () => {
44
+ if (typeof options.spriteInput === 'undefined' ||
45
+ typeof spriteOut === 'undefined') {
46
+ return;
47
+ }
48
+ await (0, build_sprite_1.buildSprite)(options.spriteInput, spriteOut, 'sprite');
49
+ };
50
+ await spriteRefresher();
51
+ }
52
+ const server = http_1.default.createServer(async (req, res) => {
34
53
  const url = (req.url || '').replace(/\?.*/, '');
35
- const dir = path_1.default.join(defaultValues_1.defaultValues.providerDir, provider);
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
+ if (typeof spriteOut !== 'undefined' &&
57
+ url.match(/^\/sprite(@2x)?\.(json|png)/)) {
58
+ res.statusCode = 200;
59
+ if (url.endsWith('.json')) {
60
+ res.setHeader('Content-Type', 'application/json; charset=UTF-8');
61
+ }
62
+ else {
63
+ res.setHeader('Content-Type', 'image/png');
64
+ }
65
+ 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));
68
+ fsStream.pipe(res);
69
+ return;
70
+ }
36
71
  switch (url) {
37
72
  case '/':
38
73
  res.statusCode = 200;
39
74
  res.setHeader('Content-Type', 'text/html; charset=UTF-8');
40
- const content = fs_1.default.readFileSync(path_1.default.join(dir, 'index.html'), 'utf-8');
75
+ const content = fs_1.default.readFileSync(path_1.default.join(providerDir, 'index.html'), 'utf-8');
41
76
  res.end(content);
42
77
  break;
43
78
  case '/style.json':
44
79
  let style;
45
80
  try {
46
- style = yaml_parser_1.parser(sourcePath);
47
- validate_style_1.validateStyle(style, provider);
81
+ style = (0, yaml_parser_1.parser)(sourcePath);
82
+ if (typeof spriteOut !== 'undefined') {
83
+ style.sprite = `http://${req.headers.host || `localhost:${port}`}/sprite`;
84
+ }
85
+ (0, validate_style_1.validateStyle)(style, provider);
48
86
  }
49
87
  catch (error) {
50
88
  console.log(error);
51
89
  }
52
90
  res.statusCode = 200;
53
91
  res.setHeader('Content-Type', 'application/json; charset=UTF-8');
92
+ res.setHeader('Cache-Control', 'no-store');
54
93
  res.end(JSON.stringify(style));
55
94
  break;
56
95
  case '/app.css':
57
96
  res.statusCode = 200;
58
97
  res.setHeader('Content-Type', 'text/css; charset=UTF-8');
59
- const css = fs_1.default.readFileSync(path_1.default.join(dir, 'app.css'), 'utf-8');
98
+ const css = fs_1.default.readFileSync(path_1.default.join(defaultProviderDir, 'app.css'), 'utf-8');
60
99
  res.end(css);
61
100
  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;
62
108
  case `/app.js`:
63
109
  res.statusCode = 200;
64
110
  res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
65
111
  try {
66
- const app = fs_1.default.readFileSync(path_1.default.join(dir, 'app.js'), 'utf-8');
112
+ const app = fs_1.default.readFileSync(path_1.default.join(providerDir, 'app.js'), 'utf-8');
67
113
  const js = app
68
114
  .replace('___PORT___', `${port}`)
69
115
  .replace('___MAPBOX_ACCESS_TOKEN___', `${options.mapboxAccessToken || defaultValues_1.defaultValues.mapboxAccessToken}`);
@@ -84,26 +130,45 @@ function serve(source, options) {
84
130
  console.log(`Provider: ${provider}`);
85
131
  console.log(`Loading your style: ${sourcePath}`);
86
132
  console.log(`Your map is running on http://localhost:${port}/\n`);
87
- open_1.default(`http://localhost:${port}`);
133
+ if (options.open) {
134
+ (0, open_1.default)(`http://localhost:${port}`);
135
+ }
88
136
  });
89
137
  const wss = new ws_1.WebSocketServer({ server });
90
138
  wss.on('connection', (ws) => {
91
- node_watch_1.default(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
139
+ const watcher = (0, node_watch_1.default)(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$|\.svg$/i }, (event, file) => {
92
140
  console.log(`${(event || '').toUpperCase()}: ${file}`);
93
141
  try {
94
- const style = yaml_parser_1.parser(sourcePath);
95
- try {
96
- validate_style_1.validateStyle(style, provider);
142
+ if (file === null || file === void 0 ? void 0 : file.toLowerCase().endsWith('.yml')) {
143
+ ws.send(JSON.stringify({
144
+ event: 'styleUpdate',
145
+ }));
97
146
  }
98
- catch (error) {
99
- console.log(error);
147
+ else if ((file === null || file === void 0 ? void 0 : file.toLowerCase().endsWith('.svg')) &&
148
+ typeof spriteRefresher !== 'undefined') {
149
+ spriteRefresher().then(() => {
150
+ ws.send(JSON.stringify({
151
+ event: 'spriteUpdate',
152
+ }));
153
+ });
100
154
  }
101
- ws.send(JSON.stringify(style));
102
155
  }
103
156
  catch (e) {
104
157
  // Nothing to do
105
158
  }
106
159
  });
160
+ ws.on('close', () => {
161
+ watcher.close();
162
+ });
163
+ });
164
+ process.on('SIGINT', () => {
165
+ console.log('Cleaning up...');
166
+ server.close();
167
+ if (typeof spriteOut !== 'undefined') {
168
+ fs_1.default.rmSync(spriteOut, { recursive: true });
169
+ spriteOut = undefined;
170
+ }
171
+ process.exit(0);
107
172
  });
108
173
  return server;
109
174
  }
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.buildSprite = void 0;
4
7
  const sprite_one_1 = require("@unvt/sprite-one");
5
- const path = require('path');
8
+ const path_1 = __importDefault(require("path"));
6
9
  async function buildSprite(svgPath, publicPath, iconSlug) {
7
10
  const pxRatios = [1, 2];
8
- const outPath = path.join(publicPath, iconSlug);
9
- try {
10
- await sprite_one_1.generateSprite(outPath, [svgPath], pxRatios);
11
- }
12
- catch (error) {
13
- throw error;
14
- }
11
+ const outPath = path_1.default.join(publicPath, iconSlug);
12
+ await (0, sprite_one_1.generateSprite)(outPath, [svgPath], pxRatios);
15
13
  return;
16
14
  }
17
15
  exports.buildSprite = buildSprite;
package/dist/lib/error.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.error = void 0;
4
- exports.error = (e) => {
4
+ const error = (e) => {
5
5
  if (e instanceof Error) {
6
6
  console.error(e.message);
7
7
  }
@@ -10,3 +10,4 @@ exports.error = (e) => {
10
10
  }
11
11
  process.exit(1);
12
12
  };
13
+ exports.error = error;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TileJSONImporter = exports.MetadataJSONImporter = void 0;
3
4
  var metadata_importer_1 = require("./metadata-importer");
4
5
  Object.defineProperty(exports, "MetadataJSONImporter", { enumerable: true, get: function () { return metadata_importer_1.MetadataJSONImporter; } });
5
6
  var tilejson_importer_1 = require("./tilejson-importer");
@@ -7,7 +7,7 @@ exports.writeYaml = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const js_yaml_1 = __importDefault(require("js-yaml"));
10
- exports.writeYaml = (destinationPath, style, composite = false) => {
10
+ const writeYaml = (destinationPath, style, composite = false) => {
11
11
  if (composite === true) {
12
12
  writeCompositedYaml(destinationPath, style);
13
13
  }
@@ -15,6 +15,7 @@ exports.writeYaml = (destinationPath, style, composite = false) => {
15
15
  writeDecompositedYaml(destinationPath, style);
16
16
  }
17
17
  };
18
+ exports.writeYaml = writeYaml;
18
19
  const writeCompositedYaml = (destinationPath, style) => {
19
20
  const styleYAML = js_yaml_1.default.dump(style);
20
21
  let stylePath = path_1.default.resolve(process.cwd(), destinationPath);
@@ -22,27 +23,38 @@ const writeCompositedYaml = (destinationPath, style) => {
22
23
  if (destinationPath.match(/^\//)) {
23
24
  stylePath = destinationPath;
24
25
  }
25
- try {
26
- fs_1.default.writeFileSync(stylePath, styleYAML);
27
- }
28
- catch (err) {
29
- throw `${stylePath}: Permission denied`;
30
- }
26
+ fs_1.default.writeFileSync(stylePath, styleYAML);
31
27
  };
28
+ class IncFileTag {
29
+ constructor(fileName) {
30
+ // 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);
32
+ }
33
+ }
34
+ const INC_PATH_TYPE = new js_yaml_1.default.Type('tag:yaml.org,2002:inc/file', {
35
+ kind: 'scalar',
36
+ resolve: (data) => data,
37
+ construct: (data) => new IncFileTag(data),
38
+ instanceOf: IncFileTag,
39
+ represent: (tag) => tag.value,
40
+ });
41
+ const INC_PATH_OUTPUT_SCHEMA = js_yaml_1.default.DEFAULT_SCHEMA.extend([INC_PATH_TYPE]);
32
42
  const writeDecompositedYaml = (destinationPath, style) => {
33
43
  const layers = [];
34
44
  for (let i = 0; i < style.layers.length; i++) {
35
45
  const layer = style.layers[i];
36
46
  const layerYml = js_yaml_1.default.dump(layer);
37
47
  const fileName = `${style.layers[i].id}.yml`;
38
- const dirName = path_1.default.join(path_1.default.dirname(destinationPath), 'layers');
39
- fs_1.default.mkdirSync(dirName, { recursive: true });
40
- fs_1.default.writeFileSync(path_1.default.join(dirName, fileName), layerYml);
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);
52
+ // ts-ignore is required here because the !!inc/file object is not compatible with the Layer object type.
41
53
  // @ts-ignore
42
- layers.push(`!!inc/file ${path_1.default.join('layers', fileName)}`);
54
+ layers.push(new IncFileTag(fileName));
43
55
  }
44
56
  style.layers = layers;
45
- fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style).replace(/'\!\!inc\/file layers\/.+\.yml'/g, function (match) {
46
- return match.replace(/'/g, '');
57
+ fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style, {
58
+ schema: INC_PATH_OUTPUT_SCHEMA,
47
59
  }));
48
60
  };
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
8
12
  }));
9
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
17
  __exportStar(require("./tilejson"), exports);