@unvt/charites 0.5.2 → 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 (84) 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 +9 -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 +6 -8
  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 +14 -16
  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/install/install.rst +1 -1
  32. package/docs/source/install/installation_guide_for_windows.rst +4 -4
  33. package/docs/source/install/recommended_environment.rst +1 -1
  34. package/docs/source/usage/commandline_interface.rst +3 -12
  35. package/docs/source/usage/examples.rst +0 -6
  36. package/docs/source/usage/index.rst +0 -1
  37. package/eslint.config.mjs +46 -0
  38. package/mocha-register.cjs +2 -0
  39. package/package.json +41 -38
  40. package/playwright.config.ts +1 -12
  41. package/provider/{default/shared.js → app.js} +36 -2
  42. package/provider/{default/index.html → index.html} +3 -3
  43. package/src/cli/build.ts +2 -15
  44. package/src/cli/convert.ts +2 -2
  45. package/src/cli/init.ts +2 -2
  46. package/src/cli/serve.ts +4 -20
  47. package/src/cli.ts +14 -5
  48. package/src/commands/build.ts +5 -12
  49. package/src/commands/convert.ts +1 -1
  50. package/src/commands/init.ts +2 -2
  51. package/src/commands/serve.ts +12 -49
  52. package/src/lib/build-sprite.ts +2 -1
  53. package/src/lib/defaultValues.ts +8 -34
  54. package/src/lib/get-sprite-slug.ts +6 -2
  55. package/src/lib/tileinfo-importer/index.ts +2 -2
  56. package/src/lib/tileinfo-importer/metadata-importer.ts +2 -2
  57. package/src/lib/tileinfo-importer/tilejson-importer.ts +2 -2
  58. package/src/lib/validate-style.ts +15 -15
  59. package/src/lib/yaml-include/file.ts +29 -0
  60. package/src/lib/yaml-include/index.ts +28 -0
  61. package/src/lib/yaml-parser.ts +3 -3
  62. package/test/build-sprite.spec.ts +5 -0
  63. package/test/build.spec.ts +10 -13
  64. package/test/command.build.spec.ts +2 -2
  65. package/test/convert.spec.ts +7 -1
  66. package/test/get-sprite-slug.spec.ts +4 -0
  67. package/test/init.spec.ts +5 -0
  68. package/test/playwright/provider/{default/e2e.spec.ts → e2e.spec.ts} +2 -2
  69. package/test/util/charitesCmd.ts +5 -0
  70. package/test/util/copyFixtures.ts +5 -0
  71. package/test/yaml-parser.spec.ts +4 -0
  72. package/tsconfig.json +11 -6
  73. package/.eslintignore +0 -2
  74. package/.eslintrc.js +0 -17
  75. package/docs/source/usage/global_options.rst +0 -21
  76. package/provider/default/app.js +0 -30
  77. package/provider/geolonia/app.js +0 -28
  78. package/provider/geolonia/index.html +0 -22
  79. package/provider/mapbox/app.js +0 -33
  80. package/provider/mapbox/index.html +0 -23
  81. package/test/playwright/provider/geolonia/e2e.spec.ts +0 -13
  82. package/test/playwright/provider/mapbox/e2e.spec.ts +0 -13
  83. /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
  84. /package/provider/{default/app.css → app.css} +0 -0
@@ -15,13 +15,13 @@ Steps
15
15
 
16
16
  Step 1. Installation of nodejs (if it is not installed yet)
17
17
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18
- Check if nodejs is installed. If not, visit `nodejs <https://nodejs.org/en/>`_ to install them. Version 14 or later version is recommended. Installation will fail with the older version of nodejs than 12.20.0.
18
+ Check if nodejs is installed. If not, visit `nodejs <https://nodejs.org/en/>`_ to install them. Version 18 or later version is recommended. Installation will fail with the older version of nodejs than 12.20.0.
19
19
 
20
20
  Step 2. Open Windows PowerShell
21
21
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22
22
  Open Windows PowerShell and confirm if nodejs and npm works.
23
23
 
24
- .. code-block::
24
+ .. code-block::
25
25
 
26
26
  npm --version
27
27
  node --version
@@ -30,7 +30,7 @@ Step 3. Install @unvt/charites as a npm package
30
30
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31
31
  Just rung the following command to install the charites.
32
32
 
33
- .. code-block::
33
+ .. code-block::
34
34
 
35
35
  npm install -g @unvt/charites
36
36
 
@@ -39,7 +39,7 @@ Step 4. Confirm if charites is properly installed
39
39
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
40
  If you can see the charites version and command lits with the following command. It seems that your installation has done successfully.
41
41
 
42
- .. code-block::
42
+ .. code-block::
43
43
 
44
44
  charites --version
45
45
  charites --help
@@ -3,4 +3,4 @@ Recommended environment
3
3
 
4
4
  Chrities may work well on OSX, Ubuntu, Windows 10 and Raspberry Pi.
5
5
 
6
- Nodejs and npm are needed to install charites. Docker can also be a good environment in Windows while WSL might work well. For charites version 0.3.0 released in December 2022, nodejs ver 14. or later version is recommended.
6
+ Nodejs and npm are needed to install charites. Docker can also be a good environment in Windows while WSL might work well. For charites version 0.3.0 released in December 2022, nodejs ver 18. or later version is recommended.
@@ -78,11 +78,8 @@ Build `style.json` from `style.yml`
78
78
  -u, --sprite-url [<sprite url>] url to set as the sprite in style.json
79
79
  -i, --sprite-input [<icon input directory>] directory path of icon source to build icons. The default <icon source> is `icons/`
80
80
  -o, --sprite-output [<icon output directory>] directory path to output icon files. The default <icons destination> is the current directory
81
- --provider [provider] your map service. e.g. `mapbox`, `geolonia`
82
81
  -h, --help display help for command
83
82
 
84
- if you use mapbox v2 for your style, please use `--provider mapbox` to specify mapbox service rather than default. Please see `--provider` option at `serve` command section.
85
-
86
83
  Realtime editor on browser
87
84
  --------------------------
88
85
 
@@ -94,22 +91,16 @@ Realtime editor on browser
94
91
  serve your map locally
95
92
 
96
93
  Options:
97
- --provider [provider] your map service. e.g. `mapbox`, `geolonia`
98
- --mapbox-access-token [mapboxAccessToken] Access Token for the Mapbox
99
94
  -i, --sprite-input [<icon input directory>] directory path of icon source to build icons. The default <icon
100
95
  source> is `icons/`
96
+ --sdf Allows to use SDF sprite in charites
101
97
  --port [port] Specify custom port
102
98
  -h, --help display help for command
103
99
 
104
100
  Charites has three options for `serve` command.
105
101
 
106
- - ``--provider`` - `mapbox`, `geolonia`, or `default`. When not specified, default or the value in the configuration file will be used.
107
-
108
- - `mapbox` - The format linter runs against the Mapbox GL JS v2.x compatible specification.
109
- - `geolonia` and `default` - the format linter runs against the MapLibre GL JS compatible specification.
110
-
111
- - ``--mapbox-access-token`` - Set your access-token when styling for Mapbox.
112
-
113
102
  - ``--sprite-input`` - If you are building icon spritesheets with Charites, you can specify the directory of SVG files to compile here. See the ``build`` command for more information.
114
103
 
104
+ - ``--sdf`` - if this option is used together with ``--sprite-input``, the viewer will generate SDF sprite. If the option is not specified, non SDF sprite will be generated.
105
+
115
106
  - ``--port`` - Set http server's port number. When not specified, the default is 8080.
@@ -66,9 +66,3 @@ Launch a live preview of your map style in your local environment:
66
66
 
67
67
  charites serve style.yml
68
68
 
69
-
70
- For Mapbox users:
71
-
72
- .. code-block:: bash
73
-
74
- charites serve style.yml --provider mapbox --mapbox-access-token xxxx
@@ -6,6 +6,5 @@ Usage
6
6
  :maxdepth: 1
7
7
 
8
8
  commandline_interface
9
- global_options
10
9
  examples
11
10
  example2
@@ -0,0 +1,46 @@
1
+ import tsParser from '@typescript-eslint/parser'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import js from '@eslint/js'
5
+ import { FlatCompat } from '@eslint/eslintrc'
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = path.dirname(__filename)
9
+ const compat = new FlatCompat({
10
+ baseDirectory: __dirname,
11
+ recommendedConfig: js.configs.recommended,
12
+ allConfig: js.configs.all,
13
+ })
14
+
15
+ export default [
16
+ {
17
+ ignores: ['node_modules/', 'dist', 'mocha-register.cjs'],
18
+ },
19
+ ...compat.extends(
20
+ 'plugin:@typescript-eslint/recommended',
21
+ 'plugin:prettier/recommended',
22
+ 'prettier',
23
+ ),
24
+ {
25
+ languageOptions: {
26
+ parser: tsParser,
27
+ ecmaVersion: 2020,
28
+ sourceType: 'module',
29
+ },
30
+
31
+ rules: {
32
+ '@typescript-eslint/explicit-module-boundary-types': 0,
33
+ '@typescript-eslint/ban-ts-comment': 0,
34
+ '@typescript-eslint/no-var-requires': 0,
35
+ '@typescript-eslint/no-unused-vars': [
36
+ 'error',
37
+ {
38
+ argsIgnorePattern: '^_',
39
+ varsIgnorePattern: '^_',
40
+ caughtErrorsIgnorePattern: '^_',
41
+ destructuredArrayIgnorePattern: '^_',
42
+ },
43
+ ],
44
+ },
45
+ },
46
+ ]
@@ -0,0 +1,2 @@
1
+ require('ts-node/register')
2
+ require('tsconfig-paths/register')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unvt/charites",
3
- "version": "0.5.2",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "charites": "dist/cli.js"
@@ -9,7 +9,7 @@
9
9
  "build": "tsc -p .",
10
10
  "watch": "tsc -w",
11
11
  "lint": "eslint --fix .",
12
- "test": "npm run build && mocha --timeout 5000 -r ts-node/register test/*.ts",
12
+ "test": "npm run build && NODE_OPTIONS='--experimental-specifier-resolution=node' mocha --timeout 5000 'test/*.ts'",
13
13
  "test:watch": "npm test -- --watch --watch-files src/**/*.ts --watch-files test/**/*.ts",
14
14
  "test:e2e": "npx playwright test",
15
15
  "command": "./node_modules/.bin/ts-node ./src/cli.ts"
@@ -17,43 +17,46 @@
17
17
  "author": "",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@mapbox/mapbox-gl-style-spec": "^13.27.0",
21
- "@maplibre/maplibre-gl-style-spec": "^17.0.2",
22
- "@types/jsonminify": "^0.4.1",
23
- "@unvt/sprite-one": "^0.0.9",
24
- "axios": "^1.2.2",
25
- "commander": "^9.4.1",
26
- "glob": "^8.0.3",
27
- "js-yaml": "^4.0.0",
20
+ "@maplibre/maplibre-gl-style-spec": "^20.3.1",
21
+ "@types/geojson": "^7946.0.14",
22
+ "@types/jsonminify": "^0.4.3",
23
+ "@unvt/sprite-one": "^0.1.1",
24
+ "axios": "^1.7.5",
25
+ "commander": "^12.1.0",
26
+ "glob": "^11.0.0",
27
+ "js-yaml": "^4.1.0",
28
28
  "jsonminify": "^0.4.2",
29
- "node-watch": "^0.7.3",
30
- "open": "^8.2.1",
31
- "ws": "^8.11.0",
32
- "yaml-include": "^1.2.1"
29
+ "node-watch": "^0.7.4",
30
+ "open": "^10.1.0",
31
+ "ws": "^8.18.0"
33
32
  },
34
33
  "devDependencies": {
35
- "@playwright/test": "^1.29.1",
36
- "@types/chai": "^4.3.4",
37
- "@types/chai-as-promised": "^7.1.5",
38
- "@types/fs-extra": "^9.0.13",
39
- "@types/js-yaml": "^4.0.5",
40
- "@types/mapbox__point-geometry": "^0.1.2",
41
- "@types/mocha": "^10.0.1",
42
- "@types/node": "^18.11.18",
43
- "@types/ws": "^8.5.4",
44
- "@typescript-eslint/eslint-plugin": "^5.47.1",
45
- "@typescript-eslint/parser": "^5.47.1",
46
- "chai": "^4.3.7",
47
- "chai-as-promised": "^7.1.1",
48
- "eslint": "^8.31.0",
49
- "eslint-config-prettier": "^8.5.0",
50
- "eslint-plugin-prettier": "^4.2.1",
51
- "fs-extra": "^11.1.0",
52
- "kill-port-process": "^3.1.0",
53
- "mocha": "^10.2.0",
54
- "node-abort-controller": "^3.0.1",
55
- "prettier": "^2.8.1",
56
- "ts-node": "^10.9.1",
57
- "typescript": "^4.9.4"
58
- }
34
+ "@eslint/eslintrc": "^3.1.0",
35
+ "@eslint/js": "^9.9.1",
36
+ "@playwright/test": "^1.46.1",
37
+ "@types/chai": "^4.3.19",
38
+ "@types/chai-as-promised": "^7.1.8",
39
+ "@types/fs-extra": "^11.0.4",
40
+ "@types/js-yaml": "^4.0.9",
41
+ "@types/mapbox__point-geometry": "^0.1.4",
42
+ "@types/mocha": "^10.0.7",
43
+ "@types/node": "^22.5.0",
44
+ "@types/ws": "^8.5.12",
45
+ "@typescript-eslint/eslint-plugin": "^8.3.0",
46
+ "@typescript-eslint/parser": "^8.3.0",
47
+ "chai": "^5.1.1",
48
+ "chai-as-promised": "^8.0.0",
49
+ "eslint": "^9.9.1",
50
+ "eslint-config-prettier": "^9.1.0",
51
+ "eslint-plugin-prettier": "^5.2.1",
52
+ "fs-extra": "^11.2.0",
53
+ "kill-port-process": "^3.2.1",
54
+ "mocha": "^10.7.3",
55
+ "node-abort-controller": "^3.1.1",
56
+ "prettier": "^3.3.3",
57
+ "ts-node": "^10.9.2",
58
+ "tsconfig-paths": "^4.2.0",
59
+ "typescript": "^5.5.4"
60
+ },
61
+ "type": "module"
59
62
  }
@@ -7,23 +7,12 @@ const config: PlaywrightTestConfig = {
7
7
  browserName: 'chromium',
8
8
  headless: true,
9
9
  },
10
- workers: 3,
10
+ workers: 1,
11
11
  webServer: [
12
12
  {
13
13
  command: 'dist/cli.js serve test/data/style.yml --port 8080',
14
14
  port: 8080,
15
15
  },
16
- {
17
- command:
18
- 'dist/cli.js serve test/data/style.yml --provider geolonia --port 8088',
19
- port: 8088,
20
- },
21
- {
22
- command:
23
- 'dist/cli.js serve test/data/style.yml --provider mapbox --port 8888 --mapbox-access-token ' +
24
- process.env.MAPBOX_ACCESS_TOKEN,
25
- port: 8888,
26
- },
27
16
  ],
28
17
  }
29
18
  export default config
@@ -42,8 +42,12 @@
42
42
  if (center === undefined) {
43
43
  const bounds = mapTileJson.bounds
44
44
  center = mapTileJson.center
45
- ? mapTileJson.center
46
- : [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2]
45
+ if (!center && bounds) {
46
+ center = [
47
+ (bounds[0] + bounds[2]) / 2,
48
+ (bounds[1] + bounds[3]) / 2,
49
+ ]
50
+ }
47
51
  }
48
52
  if (zoom === undefined) {
49
53
  zoom = (mapTileJson.minzoom + mapTileJson.maxzoom) / 2
@@ -75,4 +79,34 @@
75
79
  }
76
80
  },
77
81
  }
82
+
83
+ const { style, center, zoom } = await window._charites.parseMapStyle()
84
+ const options = {
85
+ container: 'map',
86
+ hash: true,
87
+ maxPitch: 85,
88
+ style,
89
+ }
90
+ if (center) options.center = center
91
+ if (zoom) options.zoom = zoom
92
+ const map = new maplibregl.Map(options)
93
+
94
+ window._charites.initializeWebSocket(map)
95
+
96
+ map.addControl(new maplibregl.NavigationControl(), 'top-right')
97
+
98
+ map.addControl(
99
+ new MaplibreLegendControl.MaplibreLegendControl(
100
+ {},
101
+ {
102
+ showDefault: true,
103
+ showCheckbox: true,
104
+ onlyRendered: true,
105
+ reverseOrder: true,
106
+ },
107
+ ),
108
+ 'bottom-left',
109
+ )
110
+
111
+ window._charites.setupDebugCheckboxes(map)
78
112
  })()
@@ -2,12 +2,12 @@
2
2
  <html id="charites-default">
3
3
  <head>
4
4
  <link rel="stylesheet" href="/app.css" />
5
- <link href='https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css' rel='stylesheet' />
5
+ <link href='https://unpkg.com/maplibre-gl/dist/maplibre-gl.css' rel='stylesheet' />
6
6
  <link href='https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.css' rel='stylesheet' />
7
7
  <title>Charites Live Preview</title>
8
- <script src='https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js'></script>
8
+ <script src='https://unpkg.com/maplibre-gl/dist/maplibre-gl.js'></script>
9
9
  <script src="https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.umd.js"></script>
10
- <script src="https://unpkg.com/pmtiles@2.7.0/dist/index.js"></script>
10
+ <script src="https://unpkg.com/pmtiles@3.0.7/dist/pmtiles.js"></script>
11
11
  </head>
12
12
  <body>
13
13
  <div class="overlay">
package/src/cli/build.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Command } from 'commander'
2
- import { build, buildOptions, buildWatch } from '../commands/build'
3
- import { error } from '../lib/error'
4
- import { defaultSettings } from '../lib/defaultValues'
2
+ import { build, buildOptions, buildWatch } from '../commands/build.js'
3
+ import { error } from '../lib/error.js'
5
4
  import fs from 'fs'
6
5
  import path from 'path'
7
6
 
@@ -24,14 +23,9 @@ program
24
23
  '-o, --sprite-output [<icon output directory>]',
25
24
  'directory path to output icon files. The default <icons destination> is the current directory',
26
25
  )
27
- .option(
28
- '--provider [provider]',
29
- 'your map service. e.g. `mapbox`, `geolonia`',
30
- )
31
26
  .action(
32
27
  async (source: string, destination: string, buildOptions: buildOptions) => {
33
28
  const options = program.opts()
34
- options.provider = buildOptions.provider
35
29
  options.compactOutput = buildOptions.compactOutput
36
30
  options.spriteUrl = buildOptions.spriteUrl
37
31
  options.spriteOutput = buildOptions.spriteOutput || process.cwd()
@@ -44,13 +38,6 @@ program
44
38
  options.spriteInput = spriteInputDefault
45
39
  }
46
40
 
47
- if (!fs.existsSync(defaultSettings.configFile)) {
48
- fs.writeFileSync(
49
- defaultSettings.configFile,
50
- `provider: ${options.provider || 'default'}`,
51
- )
52
- }
53
-
54
41
  if (buildOptions.watch) {
55
42
  try {
56
43
  console.log('Start watching...')
@@ -1,6 +1,6 @@
1
1
  import { Command } from 'commander'
2
- import { convert } from '../commands/convert'
3
- import { error } from '../lib/error'
2
+ import { convert } from '../commands/convert.js'
3
+ import { error } from '../lib/error.js'
4
4
 
5
5
  const program = new Command()
6
6
  program
package/src/cli/init.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Command } from 'commander'
2
- import { init, initOptions } from '../commands/init'
3
- import { error } from '../lib/error'
2
+ import { init, initOptions } from '../commands/init.js'
3
+ import { error } from '../lib/error.js'
4
4
 
5
5
  const program = new Command()
6
6
  program
package/src/cli/serve.ts CHANGED
@@ -1,41 +1,25 @@
1
1
  import { Command } from 'commander'
2
- import { serve, serveOptions } from '../commands/serve'
3
- import { error } from '../lib/error'
4
- import { defaultSettings } from '../lib/defaultValues'
5
- import fs from 'fs'
2
+ import { serve, serveOptions } from '../commands/serve.js'
3
+ import { error } from '../lib/error.js'
6
4
 
7
5
  const program = new Command()
8
6
  program
9
7
  .name('serve')
10
8
  .arguments('<source>')
11
9
  .description('serve your map locally')
12
- .option(
13
- '--provider [provider]',
14
- 'your map service. e.g. `mapbox`, `geolonia`',
15
- )
16
- .option(
17
- '--mapbox-access-token [mapboxAccessToken]',
18
- 'Your Mapbox Access Token (required if using the `mapbox` provider)',
19
- )
20
10
  .option(
21
11
  '-i, --sprite-input [<icon input directory>]',
22
12
  'directory path of icon source to build icons. The default <icon source> is `icons/`',
23
13
  )
14
+ .option('--sdf', 'Allows to use SDF sprite in charites')
24
15
  .option('--port [port]', 'Specify custom port')
25
16
  .option('--no-open', "Don't open the preview in the default browser")
26
17
  .action(async (source: string, serveOptions: serveOptions) => {
27
18
  const options: serveOptions = program.opts()
28
- options.provider = serveOptions.provider
29
- options.mapboxAccessToken = serveOptions.mapboxAccessToken
30
19
  options.port = serveOptions.port
31
20
  options.spriteInput = serveOptions.spriteInput
32
21
  options.open = serveOptions.open
33
- if (!fs.existsSync(defaultSettings.configFile)) {
34
- fs.writeFileSync(
35
- defaultSettings.configFile,
36
- `provider: ${options.provider || 'default'}`,
37
- )
38
- }
22
+ options.sdf = serveOptions.sdf
39
23
  try {
40
24
  await serve(source, program.opts())
41
25
  } catch (e) {
package/src/cli.ts CHANGED
@@ -2,13 +2,22 @@
2
2
 
3
3
  import { Command } from 'commander'
4
4
 
5
- import init from './cli/init'
6
- import convert from './cli/convert'
7
- import build from './cli/build'
8
- import serve from './cli/serve'
5
+ import init from './cli/init.js'
6
+ import convert from './cli/convert.js'
7
+ import build from './cli/build.js'
8
+ import serve from './cli/serve.js'
9
+ import { fileURLToPath } from 'url'
10
+ import { dirname, join } from 'path'
11
+ import { readFileSync } from 'fs'
12
+
13
+ // ESMの__dirnameの代わり
14
+ const __filename = fileURLToPath(import.meta.url)
15
+ const __dirname = dirname(__filename)
9
16
 
10
17
  const program = new Command()
11
- const version = require('../package.json').version
18
+
19
+ const packageJson = readFileSync(join(__dirname, '../package.json'), 'utf-8')
20
+ const { version } = JSON.parse(packageJson)
12
21
  program
13
22
  .version(version, '-v, --version', 'output the version number')
14
23
  .addCommand(init)
@@ -1,16 +1,14 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
- import { parser } from '../lib/yaml-parser'
4
- import { validateStyle } from '../lib/validate-style'
5
- import { buildSprite } from '../lib/build-sprite'
6
- import { getSpriteSlug } from '../lib/get-sprite-slug'
7
- import { defaultValues } from '../lib/defaultValues'
3
+ import { parser } from '../lib/yaml-parser.js'
4
+ import { validateStyle } from '../lib/validate-style.js'
5
+ import { buildSprite } from '../lib/build-sprite.js'
6
+ import { getSpriteSlug } from '../lib/get-sprite-slug.js'
8
7
  import jsonminify from 'jsonminify'
9
8
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
10
9
  import watch from 'node-watch'
11
10
 
12
11
  export interface buildOptions {
13
- provider?: string
14
12
  compactOutput?: boolean
15
13
  watch?: boolean
16
14
  spriteUrl?: string
@@ -49,16 +47,11 @@ export async function build(
49
47
  )
50
48
  }
51
49
 
52
- let provider = defaultValues.provider
53
- if (options.provider) {
54
- provider = options.provider
55
- }
56
-
57
50
  let style = ''
58
51
 
59
52
  try {
60
53
  const _style: StyleSpecification = parser(sourcePath)
61
- validateStyle(_style, provider)
54
+ validateStyle(_style)
62
55
 
63
56
  if (options.spriteUrl && 'sprite' in _style) {
64
57
  _style.sprite = options.spriteUrl
@@ -1,7 +1,7 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
3
  import readline from 'readline'
4
- import { writeYaml } from '../lib/yaml-writer'
4
+ import { writeYaml } from '../lib/yaml-writer.js'
5
5
 
6
6
  const getDestinationPath = (destination: string, sourcePath = '') => {
7
7
  let destinationPath
@@ -1,9 +1,9 @@
1
1
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
2
- import { writeYaml } from '../lib/yaml-writer'
2
+ import { writeYaml } from '../lib/yaml-writer.js'
3
3
  import {
4
4
  TileJSONImporter,
5
5
  MetadataJSONImporter,
6
- } from '../lib/tileinfo-importer'
6
+ } from '../lib/tileinfo-importer/index.js'
7
7
 
8
8
  export interface initOptions {
9
9
  tilejsonUrls?: string