@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.
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} +5 -5
  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
@@ -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,8 +91,6 @@ 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/`
101
96
  --sdf Allows to use SDF sprite in charites
@@ -104,13 +99,6 @@ Realtime editor on browser
104
99
 
105
100
  Charites has three options for `serve` command.
106
101
 
107
- - ``--provider`` - `mapbox`, `geolonia`, or `default`. When not specified, default or the value in the configuration file will be used.
108
-
109
- - `mapbox` - The format linter runs against the Mapbox GL JS v2.x compatible specification.
110
- - `geolonia` and `default` - the format linter runs against the MapLibre GL JS compatible specification.
111
-
112
- - ``--mapbox-access-token`` - Set your access-token when styling for Mapbox.
113
-
114
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.
115
103
 
116
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.
@@ -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.4",
3
+ "version": "2.0.2",
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": "^19.3.0",
22
- "@types/jsonminify": "^0.4.1",
20
+ "@maplibre/maplibre-gl-style-spec": "^20.3.1",
21
+ "@types/geojson": "^7946.0.14",
22
+ "@types/jsonminify": "^0.4.3",
23
23
  "@unvt/sprite-one": "^0.1.1",
24
- "axios": "^1.2.2",
25
- "commander": "^9.4.1",
26
- "glob": "^8.0.3",
27
- "js-yaml": "^4.0.0",
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
@@ -79,4 +79,34 @@
79
79
  }
80
80
  },
81
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)
82
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' />
6
- <link href='https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.css' rel='stylesheet' />
5
+ <link href='https://cdn.jsdelivr.net/npm/maplibre-gl/dist/maplibre-gl.css' rel='stylesheet' />
6
+ <link href='https://cdn.jsdelivr.net/npm/@watergis/maplibre-gl-legend@2.0.5/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>
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>
8
+ <script src='https://cdn.jsdelivr.net/npm/maplibre-gl/dist/maplibre-gl.js'></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/@watergis/maplibre-gl-legend@2.0.5/dist/maplibre-gl-legend.umd.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/pmtiles@4.3.0/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,22 +1,12 @@
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/`',
@@ -26,18 +16,10 @@ program
26
16
  .option('--no-open', "Don't open the preview in the default browser")
27
17
  .action(async (source: string, serveOptions: serveOptions) => {
28
18
  const options: serveOptions = program.opts()
29
- options.provider = serveOptions.provider
30
- options.mapboxAccessToken = serveOptions.mapboxAccessToken
31
19
  options.port = serveOptions.port
32
20
  options.spriteInput = serveOptions.spriteInput
33
21
  options.open = serveOptions.open
34
22
  options.sdf = serveOptions.sdf
35
- if (!fs.existsSync(defaultSettings.configFile)) {
36
- fs.writeFileSync(
37
- defaultSettings.configFile,
38
- `provider: ${options.provider || 'default'}`,
39
- )
40
- }
41
23
  try {
42
24
  await serve(source, program.opts())
43
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
@@ -6,14 +6,12 @@ import open from 'open'
6
6
  import { WebSocketServer } from 'ws'
7
7
  import watch from 'node-watch'
8
8
 
9
- import { parser } from '../lib/yaml-parser'
10
- import { validateStyle } from '../lib/validate-style'
11
- import { defaultValues } from '../lib/defaultValues'
12
- import { buildSprite } from '../lib/build-sprite'
9
+ import { parser } from '../lib/yaml-parser.js'
10
+ import { validateStyle } from '../lib/validate-style.js'
11
+ import { providerDir } from '../lib/defaultValues.js'
12
+ import { buildSprite } from '../lib/build-sprite.js'
13
13
 
14
14
  export interface serveOptions {
15
- provider?: string
16
- mapboxAccessToken?: string
17
15
  port?: string
18
16
  spriteInput?: string
19
17
  open?: boolean
@@ -27,11 +25,6 @@ export async function serve(source: string, options: serveOptions) {
27
25
  }
28
26
  let sourcePath = path.resolve(process.cwd(), source)
29
27
 
30
- let provider = defaultValues.provider
31
- if (options.provider) {
32
- provider = options.provider
33
- }
34
-
35
28
  // The `source` is absolute path.
36
29
  if (source.match(/^\//)) {
37
30
  sourcePath = source
@@ -41,12 +34,6 @@ export async function serve(source: string, options: serveOptions) {
41
34
  throw `${sourcePath}: No such file or directory`
42
35
  }
43
36
 
44
- const mapboxAccessToken =
45
- options.mapboxAccessToken || defaultValues.mapboxAccessToken
46
- if (provider === 'mapbox' && !mapboxAccessToken) {
47
- 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)`
48
- }
49
-
50
37
  let spriteOut: string | undefined = undefined
51
38
  let spriteRefresher: (() => Promise<void>) | undefined = undefined
52
39
  if (options.spriteInput) {
@@ -65,8 +52,6 @@ export async function serve(source: string, options: serveOptions) {
65
52
 
66
53
  const server = http.createServer(async (req, res) => {
67
54
  const url = (req.url || '').replace(/\?.*/, '')
68
- const defaultProviderDir = path.join(defaultValues.providerDir, 'default')
69
- const providerDir = path.join(defaultValues.providerDir, provider)
70
55
 
71
56
  if (
72
57
  typeof spriteOut !== 'undefined' &&
@@ -104,7 +89,7 @@ export async function serve(source: string, options: serveOptions) {
104
89
  req.headers.host || `localhost:${port}`
105
90
  }/sprite`
106
91
  }
107
- validateStyle(style, provider)
92
+ validateStyle(style)
108
93
  } catch (error) {
109
94
  console.log(error)
110
95
  }
@@ -116,37 +101,15 @@ export async function serve(source: string, options: serveOptions) {
116
101
  case '/app.css':
117
102
  res.statusCode = 200
118
103
  res.setHeader('Content-Type', 'text/css; charset=UTF-8')
119
- const css = fs.readFileSync(
120
- path.join(defaultProviderDir, 'app.css'),
121
- 'utf-8',
122
- )
104
+ const css = fs.readFileSync(path.join(providerDir, 'app.css'), 'utf-8')
123
105
  res.end(css)
124
106
  break
125
- case `/shared.js`:
126
- res.statusCode = 200
127
- res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
128
- const shared = fs.readFileSync(
129
- path.join(defaultProviderDir, 'shared.js'),
130
- 'utf-8',
131
- )
132
- const js = shared.replace('___PORT___', `${port}`)
133
- res.end(js)
134
- break
135
107
  case `/app.js`:
136
108
  res.statusCode = 200
137
109
  res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
138
- try {
139
- const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8')
140
- const js = app
141
- .replace('___PORT___', `${port}`)
142
- .replace(
143
- '___MAPBOX_ACCESS_TOKEN___',
144
- `${options.mapboxAccessToken || defaultValues.mapboxAccessToken}`,
145
- )
146
- res.end(js)
147
- } catch (e) {
148
- throw `Invalid provider: ${provider}`
149
- }
110
+ const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8')
111
+ const js = app.replace('___PORT___', `${port}`)
112
+ res.end(js)
150
113
  break
151
114
  default:
152
115
  res.statusCode = 404
@@ -157,7 +120,6 @@ export async function serve(source: string, options: serveOptions) {
157
120
  })
158
121
 
159
122
  server.listen(port, () => {
160
- console.log(`Provider: ${provider}`)
161
123
  console.log(`Loading your style: ${sourcePath}`)
162
124
  console.log(`Your map is running on http://localhost:${port}/\n`)
163
125
  if (options.open) {
@@ -192,7 +154,7 @@ export async function serve(source: string, options: serveOptions) {
192
154
  )
193
155
  })
194
156
  }
195
- } catch (e) {
157
+ } catch (_) {
196
158
  // Nothing to do
197
159
  }
198
160
  },
@@ -1,36 +1,10 @@
1
+ import { fileURLToPath } from 'url'
2
+ import { dirname } from 'path'
1
3
  import path from 'path'
2
- import os from 'os'
3
- import fs from 'fs'
4
- import YAML from 'js-yaml'
5
4
 
6
- interface Config {
7
- provider: string
8
- providerDir: string
9
- mapboxAccessToken?: string
10
- }
11
-
12
- const homedir = os.homedir()
13
- const defaultProvider = 'default'
14
-
15
- const configDir = path.join(homedir, '.charites')
16
- fs.mkdirSync(configDir, { recursive: true })
17
-
18
- const configFile = path.join(configDir, 'config.yml')
19
- let config: Config = { provider: '', providerDir: '', mapboxAccessToken: '' }
20
-
21
- try {
22
- const yaml = fs.readFileSync(configFile, 'utf-8')
23
- config = YAML.load(yaml) as Config
24
- } catch (e) {
25
- // nothing to do
26
- }
27
-
28
- export const defaultValues: Config = {
29
- provider: config.provider || defaultProvider,
30
- providerDir: path.join(path.dirname(path.dirname(__dirname)), 'provider'),
31
- mapboxAccessToken: config.mapboxAccessToken || '',
32
- }
33
-
34
- export const defaultSettings = {
35
- configFile: configFile,
36
- }
5
+ const __filename = fileURLToPath(import.meta.url)
6
+ const __dirname = dirname(__filename)
7
+ export const providerDir = path.join(
8
+ path.dirname(path.dirname(__dirname)),
9
+ 'provider',
10
+ )
@@ -1,2 +1,2 @@
1
- export { MetadataJSONImporter } from './metadata-importer'
2
- export { TileJSONImporter } from './tilejson-importer'
1
+ export { MetadataJSONImporter } from './metadata-importer.js'
2
+ export { TileJSONImporter } from './tilejson-importer.js'