@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
@@ -6,17 +6,16 @@ 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
18
+ sdf?: boolean
20
19
  }
21
20
 
22
21
  export async function serve(source: string, options: serveOptions) {
@@ -26,11 +25,6 @@ export async function serve(source: string, options: serveOptions) {
26
25
  }
27
26
  let sourcePath = path.resolve(process.cwd(), source)
28
27
 
29
- let provider = defaultValues.provider
30
- if (options.provider) {
31
- provider = options.provider
32
- }
33
-
34
28
  // The `source` is absolute path.
35
29
  if (source.match(/^\//)) {
36
30
  sourcePath = source
@@ -40,12 +34,6 @@ export async function serve(source: string, options: serveOptions) {
40
34
  throw `${sourcePath}: No such file or directory`
41
35
  }
42
36
 
43
- const mapboxAccessToken =
44
- options.mapboxAccessToken || defaultValues.mapboxAccessToken
45
- if (provider === 'mapbox' && !mapboxAccessToken) {
46
- 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)`
47
- }
48
-
49
37
  let spriteOut: string | undefined = undefined
50
38
  let spriteRefresher: (() => Promise<void>) | undefined = undefined
51
39
  if (options.spriteInput) {
@@ -57,15 +45,13 @@ export async function serve(source: string, options: serveOptions) {
57
45
  ) {
58
46
  return
59
47
  }
60
- await buildSprite(options.spriteInput, spriteOut, 'sprite')
48
+ await buildSprite(options.spriteInput, spriteOut, 'sprite', options.sdf)
61
49
  }
62
50
  await spriteRefresher()
63
51
  }
64
52
 
65
53
  const server = http.createServer(async (req, res) => {
66
54
  const url = (req.url || '').replace(/\?.*/, '')
67
- const defaultProviderDir = path.join(defaultValues.providerDir, 'default')
68
- const providerDir = path.join(defaultValues.providerDir, provider)
69
55
 
70
56
  if (
71
57
  typeof spriteOut !== 'undefined' &&
@@ -103,7 +89,7 @@ export async function serve(source: string, options: serveOptions) {
103
89
  req.headers.host || `localhost:${port}`
104
90
  }/sprite`
105
91
  }
106
- validateStyle(style, provider)
92
+ validateStyle(style)
107
93
  } catch (error) {
108
94
  console.log(error)
109
95
  }
@@ -115,37 +101,15 @@ export async function serve(source: string, options: serveOptions) {
115
101
  case '/app.css':
116
102
  res.statusCode = 200
117
103
  res.setHeader('Content-Type', 'text/css; charset=UTF-8')
118
- const css = fs.readFileSync(
119
- path.join(defaultProviderDir, 'app.css'),
120
- 'utf-8',
121
- )
104
+ const css = fs.readFileSync(path.join(providerDir, 'app.css'), 'utf-8')
122
105
  res.end(css)
123
106
  break
124
- case `/shared.js`:
125
- res.statusCode = 200
126
- res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
127
- const shared = fs.readFileSync(
128
- path.join(defaultProviderDir, 'shared.js'),
129
- 'utf-8',
130
- )
131
- const js = shared.replace('___PORT___', `${port}`)
132
- res.end(js)
133
- break
134
107
  case `/app.js`:
135
108
  res.statusCode = 200
136
109
  res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
137
- try {
138
- const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8')
139
- const js = app
140
- .replace('___PORT___', `${port}`)
141
- .replace(
142
- '___MAPBOX_ACCESS_TOKEN___',
143
- `${options.mapboxAccessToken || defaultValues.mapboxAccessToken}`,
144
- )
145
- res.end(js)
146
- } catch (e) {
147
- throw `Invalid provider: ${provider}`
148
- }
110
+ const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8')
111
+ const js = app.replace('___PORT___', `${port}`)
112
+ res.end(js)
149
113
  break
150
114
  default:
151
115
  res.statusCode = 404
@@ -156,7 +120,6 @@ export async function serve(source: string, options: serveOptions) {
156
120
  })
157
121
 
158
122
  server.listen(port, () => {
159
- console.log(`Provider: ${provider}`)
160
123
  console.log(`Loading your style: ${sourcePath}`)
161
124
  console.log(`Your map is running on http://localhost:${port}/\n`)
162
125
  if (options.open) {
@@ -191,7 +154,7 @@ export async function serve(source: string, options: serveOptions) {
191
154
  )
192
155
  })
193
156
  }
194
- } catch (e) {
157
+ } catch (_) {
195
158
  // Nothing to do
196
159
  }
197
160
  },
@@ -5,9 +5,10 @@ export async function buildSprite(
5
5
  svgPath: string,
6
6
  publicPath: string,
7
7
  iconSlug: string,
8
+ sdf = false,
8
9
  ): Promise<void> {
9
10
  const pxRatios = [1, 2]
10
11
  const outPath = path.join(publicPath, iconSlug)
11
- await generateSprite(outPath, [svgPath], pxRatios)
12
+ await generateSprite(outPath, [svgPath], pxRatios, sdf)
12
13
  return
13
14
  }
@@ -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,11 +1,15 @@
1
1
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
2
2
 
3
3
  export function getSpriteSlug(style: StyleSpecification): string | false {
4
- if (!style.hasOwnProperty('sprite')) {
4
+ if (!style.hasOwnProperty('sprite') || !style.sprite) {
5
5
  return false
6
6
  }
7
7
 
8
- const matchedUrl = style.sprite?.match(
8
+ const firstUrl = Array.isArray(style.sprite)
9
+ ? style.sprite[0].url
10
+ : style.sprite
11
+
12
+ const matchedUrl = firstUrl.match(
9
13
  /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?(?:([^?#]*\/)([^\/?#]*))?(\?[^#]*)?(?:#.*)?$/,
10
14
  )
11
15
 
@@ -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'
@@ -1,10 +1,10 @@
1
1
  import axios from 'axios'
2
- import { MetadataJSON, VectorLayer } from '../../types'
2
+ import { MetadataJSON, VectorLayer } from '../../types/index.js'
3
3
  import {
4
4
  LayerSpecification,
5
5
  VectorSourceSpecification,
6
6
  } from '@maplibre/maplibre-gl-style-spec'
7
- import { BaseImporter, TileInfoJSONResponse } from './base-importer'
7
+ import { BaseImporter, TileInfoJSONResponse } from './base-importer.js'
8
8
 
9
9
  export class MetadataJSONImporter extends BaseImporter {
10
10
  async getJSON(url: string): Promise<TileInfoJSONResponse> {
@@ -1,10 +1,10 @@
1
1
  import axios from 'axios'
2
- import { TileJSON } from '../../types'
2
+ import { TileJSON } from '../../types/index.js'
3
3
  import {
4
4
  SourceSpecification,
5
5
  LayerSpecification,
6
6
  } from '@maplibre/maplibre-gl-style-spec'
7
- import { BaseImporter, TileInfoJSONResponse } from './base-importer'
7
+ import { BaseImporter, TileInfoJSONResponse } from './base-importer.js'
8
8
 
9
9
  export class TileJSONImporter extends BaseImporter {
10
10
  async getJSON(url: string): Promise<TileInfoJSONResponse> {
@@ -1,22 +1,22 @@
1
- const maplibreStyleSpec = require('@maplibre/maplibre-gl-style-spec')
2
- const mapboxStyleSpec = require('@mapbox/mapbox-gl-style-spec')
3
- import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
1
+ import maplibreStyleSpec, {
2
+ StyleSpecification,
3
+ } from '@maplibre/maplibre-gl-style-spec'
4
4
 
5
- export function validateStyle(
6
- style: StyleSpecification,
7
- provider = 'default',
8
- ): void {
9
- let result = []
10
- if ('mapbox' === provider) {
11
- result = mapboxStyleSpec.validate(style)
12
- } else {
13
- result = maplibreStyleSpec.validate(style)
14
- }
5
+ export function validateStyle(style: StyleSpecification): void {
6
+ const result = maplibreStyleSpec.validateStyleMin(style)
15
7
 
16
8
  const errors = []
17
9
  for (let i = 0; i < result.length; i++) {
18
- if (result[i].message) {
19
- errors.push(result[i].message)
10
+ const msg = result[i].message
11
+ if (msg) {
12
+ const layerMatch = msg.match(/^layers\[([0-9]+)\]/)
13
+ if (layerMatch) {
14
+ const layerIndex = Number(layerMatch[1])
15
+ const layerId = style.layers[layerIndex].id
16
+ errors.push(`Layer "${layerId}": ${msg}`)
17
+ } else {
18
+ errors.push(msg)
19
+ }
20
20
  }
21
21
  }
22
22
 
@@ -0,0 +1,29 @@
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import yaml from 'js-yaml'
4
+ import * as yamlinc from './index.js'
5
+
6
+ function construct(data: string): unknown {
7
+ const basepath = yamlinc.getBasePath()
8
+ const fullpath = path.join(basepath, data)
9
+
10
+ yamlinc.YAML_VISITED_FILES.push(fullpath.replace(basepath + path.sep, ''))
11
+
12
+ const src = fs.readFileSync(fullpath, 'utf8')
13
+ const included = yaml.load(src, {
14
+ schema: yamlinc.YAML_INCLUDE_SCHEMA,
15
+ filename: fullpath,
16
+ })
17
+
18
+ return included
19
+ }
20
+
21
+ function resolve(data: unknown): boolean {
22
+ return typeof data === 'string'
23
+ }
24
+
25
+ export default new yaml.Type('tag:yaml.org,2002:inc/file', {
26
+ kind: 'scalar',
27
+ resolve: resolve,
28
+ construct: construct,
29
+ })
@@ -0,0 +1,28 @@
1
+ import yaml from 'js-yaml'
2
+ import path from 'path'
3
+
4
+ // import YamlIncludeDirType from './lib/dir';
5
+ import YamlIncludeFileType from './file.js'
6
+
7
+ export const YAML_VISITED_FILES: string[] = []
8
+ export const YAML_TYPES = [
9
+ // YamlIncludeDirType,
10
+ YamlIncludeFileType,
11
+ ]
12
+ export const YAML_INCLUDE_SCHEMA = yaml.DEFAULT_SCHEMA.extend(YAML_TYPES)
13
+ export let basefile = ''
14
+
15
+ // so we know where to find files referenced relative to the base file
16
+ export function setBaseFile(file: string): void {
17
+ YAML_VISITED_FILES.push(file)
18
+ basefile = file
19
+ }
20
+
21
+ export function getBasePath(): string {
22
+ return path.dirname(basefile)
23
+ }
24
+
25
+ export {
26
+ // YamlIncludeDirType,
27
+ YamlIncludeFileType,
28
+ }
@@ -1,8 +1,7 @@
1
1
  import fs from 'fs'
2
2
  import YAML from 'js-yaml'
3
3
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
4
-
5
- const yamlinc = require('yaml-include')
4
+ import * as yamlinc from './yaml-include/index.js'
6
5
 
7
6
  interface StyleObject {
8
7
  [key: string]: string
@@ -10,10 +9,11 @@ interface StyleObject {
10
9
 
11
10
  export function parser(file: string): StyleSpecification {
12
11
  yamlinc.setBaseFile(file)
12
+ const schema = yamlinc.YAML_INCLUDE_SCHEMA
13
13
  const yaml = fs.readFileSync(file, 'utf8')
14
14
 
15
15
  const obj: StyleObject = YAML.load(yaml, {
16
- schema: yamlinc.YAML_INCLUDE_SCHEMA,
16
+ schema,
17
17
  filename: file,
18
18
  json: true,
19
19
  }) as StyleObject
@@ -1,8 +1,13 @@
1
+ import { fileURLToPath } from 'url'
2
+ import { dirname } from 'path'
1
3
  import { assert } from 'chai'
2
4
  import path from 'path'
3
5
  import fs from 'fs'
4
6
  import os from 'os'
5
7
 
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = dirname(__filename)
10
+
6
11
  import { buildSprite } from '../src/lib/build-sprite'
7
12
  const iconsPath = path.join(__dirname, 'data/icons')
8
13
  let tmpdir = ''
@@ -1,15 +1,19 @@
1
- import chai from 'chai'
1
+ import { fileURLToPath } from 'url'
2
+ import { dirname } from 'path'
3
+ import * as chai from 'chai'
2
4
  import chaiAsPromised from 'chai-as-promised'
3
5
  import path from 'path'
4
6
  import fs from 'fs'
5
7
  import os from 'os'
6
8
 
7
9
  import { build, buildWatch } from '../src/commands/build'
8
- import { defaultValues } from '../src/lib/defaultValues'
10
+
11
+ const __filename = fileURLToPath(import.meta.url)
12
+ const __dirname = dirname(__filename)
9
13
 
10
14
  chai.use(chaiAsPromised)
11
15
  chai.should()
12
- const assert = chai.assert
16
+ const assert: Chai.AssertStatic = chai.assert
13
17
 
14
18
  describe('Test for the `build.ts`.', () => {
15
19
  const styleYaml = path.join(__dirname, 'data/style.yml')
@@ -39,7 +43,7 @@ describe('Test for the `build.ts`.', () => {
39
43
  })
40
44
 
41
45
  it('Should convert `data/style.yml` to JSON.', async () => {
42
- await build(styleYaml, styleJson, { provider: defaultValues.provider })
46
+ await build(styleYaml, styleJson, {})
43
47
 
44
48
  // The file should exists.
45
49
  assert.deepEqual(true, !!fs.statSync(styleJson))
@@ -53,7 +57,6 @@ describe('Test for the `build.ts`.', () => {
53
57
 
54
58
  it('Should minify `data/style.yml` to JSON.', async () => {
55
59
  await build(styleYaml, styleJson, {
56
- provider: defaultValues.provider,
57
60
  compactOutput: true,
58
61
  })
59
62
 
@@ -67,7 +70,6 @@ describe('Test for the `build.ts`.', () => {
67
70
  const expectedUrl = 'http://localhost:8080/icons'
68
71
 
69
72
  await build(styleYaml, styleJson, {
70
- provider: defaultValues.provider,
71
73
  spriteUrl: expectedUrl,
72
74
  spriteInput: iconSource,
73
75
  spriteOutput: tmpdir,
@@ -85,7 +87,6 @@ describe('Test for the `build.ts`.', () => {
85
87
  const expectedJson = path.join(tmpdir, `${expectedIconName}.json`)
86
88
 
87
89
  build(styleYaml, styleJson, {
88
- provider: defaultValues.provider,
89
90
  spriteUrl: `http://localhost:8080/${expectedIconName}`,
90
91
  spriteInput: iconSource,
91
92
  spriteOutput: tmpdir,
@@ -101,7 +102,6 @@ describe('Test for the `build.ts`.', () => {
101
102
  const expectedJson = path.join(tmpdir, `${expectedIconName}.json`)
102
103
 
103
104
  build(styleYaml, styleJson, {
104
- provider: defaultValues.provider,
105
105
  spriteInput: iconSource,
106
106
  spriteOutput: tmpdir,
107
107
  }).then(() => {
@@ -115,7 +115,6 @@ describe('Test for the `build.ts`.', () => {
115
115
  const noExistInputDir = path.join(__dirname, 'data/hellooooo')
116
116
 
117
117
  const promise = build(styleYaml, styleJson, {
118
- provider: defaultValues.provider,
119
118
  spriteInput: noExistInputDir,
120
119
  spriteOutput: tmpdir,
121
120
  })
@@ -128,15 +127,13 @@ describe('Test for the `build.ts`.', () => {
128
127
  it('Should watch `*.yml` and convert it to JSON', async () => {
129
128
  const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms))
130
129
 
131
- const watcher = buildWatch(styleYaml, styleJson, {
132
- provider: defaultValues.provider,
133
- })
130
+ const watcher = buildWatch(styleYaml, styleJson, {})
134
131
  await sleep(500)
135
132
  const yamlData1 = fs
136
133
  .readFileSync(styleYaml, 'utf-8')
137
134
  .replace('metadata: {}', 'metadata: aaa')
138
135
  fs.writeFileSync(styleYaml, yamlData1)
139
- await sleep(500)
136
+ await sleep(1000)
140
137
  await watcher.close()
141
138
  assert.deepEqual(true, !!fs.statSync(styleJson))
142
139
  assert.deepEqual(
@@ -1,4 +1,4 @@
1
- import chai from 'chai'
1
+ import * as chai from 'chai'
2
2
  import chaiAsPromised from 'chai-as-promised'
3
3
  import path from 'path'
4
4
  import fs from 'fs'
@@ -10,7 +10,7 @@ import charites from './util/charitesCmd'
10
10
  let tmpdir = ''
11
11
  chai.use(chaiAsPromised)
12
12
  chai.should()
13
- const assert = chai.assert
13
+ const assert: Chai.AssertStatic = chai.assert
14
14
 
15
15
  describe('Test for the `charites build`', () => {
16
16
  beforeEach(async function () {
@@ -6,6 +6,12 @@ import os from 'os'
6
6
  import { convert } from '../src/commands/convert'
7
7
  import { build } from '../src/commands/build'
8
8
 
9
+ import { fileURLToPath } from 'url'
10
+ import { dirname } from 'path'
11
+
12
+ const __filename = fileURLToPath(import.meta.url)
13
+ const __dirname = dirname(__filename)
14
+
9
15
  let tmp: string
10
16
 
11
17
  describe('Test for the `convert.ts`.', () => {
@@ -46,7 +52,7 @@ id: example
46
52
 
47
53
  const outJsonPath = path.join(tmp, 'converted-back.json')
48
54
  // This will throw an error if the outputted YAML was invalid
49
- await build(yamlPath, outJsonPath, { provider: 'default' })
55
+ await build(yamlPath, outJsonPath, {})
50
56
  assert.isTrue(fs.existsSync(outJsonPath))
51
57
  })
52
58
 
@@ -2,7 +2,11 @@ import { assert } from 'chai'
2
2
  import path from 'path'
3
3
  import fs from 'fs'
4
4
  import { getSpriteSlug } from '../src/lib/get-sprite-slug'
5
+ import { fileURLToPath } from 'url'
6
+ import { dirname } from 'path'
5
7
 
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = dirname(__filename)
6
10
  const stylePath = path.join(__dirname, 'data/style.json')
7
11
  const styleJson = fs.readFileSync(stylePath, 'utf-8')
8
12
 
package/test/init.spec.ts CHANGED
@@ -6,6 +6,11 @@ import YAML from 'js-yaml'
6
6
 
7
7
  import { init, initOptions } from '../src/commands/init'
8
8
 
9
+ import { fileURLToPath } from 'url'
10
+ import { dirname } from 'path'
11
+ const __filename = fileURLToPath(import.meta.url)
12
+ const __dirname = dirname(__filename)
13
+
9
14
  describe('Test for the `init.ts`.', () => {
10
15
  it('Should initialize default style.yml.', async () => {
11
16
  const tempStylePath = path.join(__dirname, 'data/init/init.yml')
@@ -1,6 +1,6 @@
1
- import { test, expect } from '@playwright/test'
1
+ import { test, expect } from '@playwright/test/index.mjs'
2
2
 
3
- test('Charites Live Preview with maplibre', async ({ page }) => {
3
+ test('Charites Live Preview', async ({ page }) => {
4
4
  // collect errors on the page
5
5
  const pageErrors: Error[] = []
6
6
  page.on('pageerror', (exception) => pageErrors.push(exception))
@@ -1,5 +1,10 @@
1
+ import { fileURLToPath } from 'url'
2
+ import { dirname } from 'path'
1
3
  import path from 'path'
2
4
 
5
+ const __filename = fileURLToPath(import.meta.url)
6
+ const __dirname = dirname(__filename)
7
+
3
8
  export const charitesCliJs = path.join(__dirname, '..', '..', 'dist', 'cli.js')
4
9
 
5
10
  export default `"${process.execPath}" "${charitesCliJs}"`
@@ -1,6 +1,11 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
3
  import fse from 'fs-extra'
4
+ import { fileURLToPath } from 'url'
5
+ import { dirname } from 'path'
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = dirname(__filename)
4
9
 
5
10
  export const copyFixturesFile = (file: string, destDir: string) => {
6
11
  fs.copyFileSync(
@@ -2,7 +2,11 @@ import { assert } from 'chai'
2
2
  import path from 'path'
3
3
 
4
4
  import { parser } from '../src/lib/yaml-parser'
5
+ import { fileURLToPath } from 'url'
6
+ import { dirname } from 'path'
5
7
 
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = dirname(__filename)
6
10
  describe('Test for the `yaml-parser.ts`.', () => {
7
11
  it('should parse `data/example.yml`.', () => {
8
12
  const yamlPath = path.join(__dirname, 'data/example.yml')
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2018",
3
+ "target": "ESNext",
4
4
  "declaration": false,
5
5
  "declarationMap": false,
6
6
  "sourceMap": false,
@@ -12,10 +12,15 @@
12
12
  "esModuleInterop": true,
13
13
  "experimentalDecorators": true,
14
14
  "emitDecoratorMetadata": true,
15
- "module": "commonjs",
16
- "outDir": "./dist"
15
+ "resolveJsonModule": true,
16
+ "module": "ESNext",
17
+ "moduleResolution": "node",
18
+ "outDir": "./dist",
19
+ "baseUrl": ".",
20
+ "paths": {
21
+ "*": ["node_modules/*", "src/types/*"]
22
+ }
17
23
  },
18
- "include": [
19
- "src/cli.ts"
20
- ]
24
+ "include": ["src/**/*"],
25
+ "exclude": ["node_modules", "dist"]
21
26
  }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- /node_modules/
2
- /dist
package/.eslintrc.js DELETED
@@ -1,17 +0,0 @@
1
- module.exports = {
2
- parser: '@typescript-eslint/parser',
3
- parserOptions: {
4
- ecmaVersion: 2020,
5
- sourceType: 'module',
6
- },
7
- extends: [
8
- 'plugin:@typescript-eslint/recommended',
9
- 'plugin:prettier/recommended',
10
- 'prettier',
11
- ],
12
- rules: {
13
- '@typescript-eslint/explicit-module-boundary-types': 0,
14
- '@typescript-eslint/ban-ts-comment': 0,
15
- '@typescript-eslint/no-var-requires': 0,
16
- },
17
- }
@@ -1,21 +0,0 @@
1
- Global configuration
2
- ====================
3
-
4
- Some options for Charites can be stored in a configuration file written in YAML.
5
-
6
- The config file will be automatically created to the following path the first time the charites command is executed.
7
-
8
- .. code-block:: bash
9
-
10
- ~/.charites/config.yml
11
-
12
-
13
- Global options can be specified as follows:
14
-
15
- .. code-block:: bash
16
-
17
- provider: mapbox
18
- mapboxAccessToken: xxxx
19
-
20
-
21
- With the example above, you get the same result as `charites serve --provider mapbox --mapbox-access-token xxxx`.