@unvt/charites 0.1.1 → 0.1.4
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.
- package/.all-contributorsrc +24 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +17 -0
- package/.github/CONTRIBUTING.md +30 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
- package/.github/workflows/build-docs.yml +72 -0
- package/.github/workflows/build.yml +1 -0
- package/.prettierrc.js +6 -0
- package/LICENSE +1 -1
- package/README.md +23 -106
- package/dist/cli/build.js +63 -0
- package/dist/cli/convert.js +19 -0
- package/dist/cli/init.js +26 -0
- package/dist/cli/serve.js +34 -0
- package/dist/cli.js +10 -66
- package/dist/commands/build.js +39 -3
- package/dist/commands/convert.js +6 -23
- package/dist/commands/init.js +15 -22
- package/dist/commands/serve.js +8 -3
- package/dist/lib/build-sprite.js +71 -0
- package/dist/lib/defaultValues.js +3 -3
- package/dist/lib/error.js +9 -0
- package/dist/lib/get-sprite-slug.js +16 -0
- package/dist/lib/tileinfo-importer/base-importer.js +41 -0
- package/dist/lib/tileinfo-importer/index.js +6 -0
- package/dist/lib/tileinfo-importer/metadata-importer.js +38 -0
- package/dist/lib/tileinfo-importer/tilejson-importer.js +25 -0
- package/dist/lib/validate-style.js +2 -2
- package/dist/lib/yaml-parser.js +2 -2
- package/dist/lib/yaml-writer.js +48 -0
- package/dist/types/index.js +15 -0
- package/dist/types/metadatajson.js +2 -0
- package/dist/types/tilejson.js +2 -0
- package/dist/types/vector_layers.js +2 -0
- package/docs/.tx/config +62 -0
- package/docs/Makefile +170 -0
- package/docs/Pipfile +20 -0
- package/docs/Pipfile.lock +429 -0
- package/docs/README.md +43 -0
- package/docs/make.bat +35 -0
- package/docs/source/_static/.gitkeep +0 -0
- package/docs/source/_templates/.gitkeep +0 -0
- package/docs/source/conf.py +69 -0
- package/docs/source/development/index.rst +40 -0
- package/docs/source/index.rst +61 -0
- package/docs/source/install/index.rst +10 -0
- package/docs/source/install/install.rst +7 -0
- package/docs/source/install/install_on_nanban.rst +9 -0
- package/docs/source/install/recommended_environment.rst +6 -0
- package/docs/source/usage/commandline_interface.rst +102 -0
- package/docs/source/usage/examples.rst +74 -0
- package/docs/source/usage/global_options.rst +21 -0
- package/docs/source/usage/index.rst +10 -0
- package/package.json +12 -4
- package/provider/default/app.css +10 -0
- package/provider/default/app.js +31 -5
- package/provider/default/index.html +7 -0
- package/provider/geolonia/app.css +10 -0
- package/provider/geolonia/app.js +29 -5
- package/provider/geolonia/index.html +7 -0
- package/provider/mapbox/app.css +10 -0
- package/provider/mapbox/app.js +31 -5
- package/provider/mapbox/index.html +7 -0
- package/src/cli/build.ts +77 -0
- package/src/cli/convert.ts +18 -0
- package/src/cli/init.ts +34 -0
- package/src/cli/serve.ts +39 -0
- package/src/cli.ts +12 -76
- package/src/commands/build.ts +71 -9
- package/src/commands/convert.ts +16 -35
- package/src/commands/init.ts +28 -21
- package/src/commands/serve.ts +70 -57
- package/src/lib/build-sprite.ts +80 -0
- package/src/lib/defaultValues.ts +6 -6
- package/src/lib/error.ts +6 -0
- package/src/lib/get-sprite-slug.ts +18 -0
- package/src/lib/tileinfo-importer/base-importer.ts +57 -0
- package/src/lib/tileinfo-importer/index.ts +2 -0
- package/src/lib/tileinfo-importer/metadata-importer.ts +44 -0
- package/src/lib/tileinfo-importer/tilejson-importer.ts +29 -0
- package/src/lib/validate-style.ts +8 -2
- package/src/lib/yaml-parser.ts +9 -8
- package/src/lib/yaml-writer.ts +68 -0
- package/src/types/index.ts +3 -0
- package/src/types/metadatajson.ts +16 -0
- package/src/types/tilejson.ts +25 -0
- package/src/types/vector_layers.ts +11 -0
- package/test/build-sprite.spec.ts +24 -0
- package/test/build.spec.ts +121 -16
- package/test/convert.spec.ts +7 -7
- package/test/data/icons/aerialway.svg +4 -0
- package/test/data/init/init.yml +6 -0
- package/test/data/init/init_metadata.yml +60 -0
- package/test/data/init/init_tilejson.yml +28 -0
- package/test/data/init/init_tilejson_without_layers.yml +9 -0
- package/test/data/init/tilejson/init_decomposite.yml +13 -0
- package/test/data/init/tilejson/layers/bicycle_parking.yml +6 -0
- package/test/data/init/tilejson/layers/showers.yml +6 -0
- package/test/data/init/tilejson/layers/telephone.yml +6 -0
- package/test/get-sprite-slug.spec.ts +34 -0
- package/test/init.spec.ts +151 -0
- package/test/validate-style.spec.ts +7 -5
- package/test/yaml-parser.spec.ts +15 -15
- package/tsconfig.json +3 -1
package/test/build.spec.ts
CHANGED
|
@@ -3,34 +3,139 @@ import path from 'path'
|
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import os from 'os'
|
|
5
5
|
|
|
6
|
-
import { build } from '../src/commands/build'
|
|
6
|
+
import { build, buildWatch } from '../src/commands/build'
|
|
7
7
|
import { defaultValues } from '../src/lib/defaultValues'
|
|
8
8
|
|
|
9
9
|
describe('Test for the `build.ts`.', () => {
|
|
10
|
+
const styleYaml = path.join(__dirname, 'data/style.yml')
|
|
11
|
+
const iconSource = path.join(__dirname, 'data/icons')
|
|
12
|
+
let tmpdir = ''
|
|
13
|
+
let styleJson = ''
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
beforeEach(function () {
|
|
16
|
+
tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
17
|
+
styleJson = path.join(tmpdir, 'style.json')
|
|
18
|
+
})
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
20
|
+
afterEach(function () {
|
|
21
|
+
const cleanup = [
|
|
22
|
+
'style.json',
|
|
23
|
+
'basic-white.png',
|
|
24
|
+
'basic-white.json',
|
|
25
|
+
'basic-white@2x.png',
|
|
26
|
+
'basic-white@2x.json',
|
|
27
|
+
'icons',
|
|
28
|
+
]
|
|
29
|
+
cleanup.forEach((fileName) => {
|
|
30
|
+
if (fs.existsSync(fileName)) {
|
|
31
|
+
fs.rmSync(path.join(__dirname, '..', fileName), { recursive: true })
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
})
|
|
16
35
|
|
|
17
|
-
|
|
36
|
+
it('Should convert `data/style.yml` to JSON.', async () => {
|
|
37
|
+
await build(styleYaml, styleJson, { provider: defaultValues.provider })
|
|
18
38
|
|
|
19
39
|
// The file should exists.
|
|
20
|
-
assert.deepEqual(true, !!
|
|
40
|
+
assert.deepEqual(true, !!fs.statSync(styleJson))
|
|
21
41
|
assert.deepEqual(8, JSON.parse(fs.readFileSync(styleJson, 'utf-8')).version)
|
|
22
|
-
})
|
|
42
|
+
})
|
|
23
43
|
|
|
24
|
-
it('Should minify `data/style.yml` to JSON.', () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
build(stylePath, styleJson, {provider: defaultValues.provider, compactOutput: true})
|
|
44
|
+
it('Should minify `data/style.yml` to JSON.', async () => {
|
|
45
|
+
await build(styleYaml, styleJson, {
|
|
46
|
+
provider: defaultValues.provider,
|
|
47
|
+
compactOutput: true,
|
|
48
|
+
})
|
|
30
49
|
|
|
31
50
|
const contents = fs.readFileSync(styleJson, 'utf-8')
|
|
32
51
|
const lines = contents.split('\n').length
|
|
33
52
|
|
|
34
53
|
assert.deepEqual(lines, 1)
|
|
35
|
-
})
|
|
36
|
-
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('Should build command replace sprite url with the option `--sprite-url`.', async () => {
|
|
57
|
+
const expectedUrl = 'http://localhost:8080/icons'
|
|
58
|
+
|
|
59
|
+
await build(styleYaml, styleJson, {
|
|
60
|
+
provider: defaultValues.provider,
|
|
61
|
+
spriteUrl: expectedUrl,
|
|
62
|
+
spriteInput: iconSource,
|
|
63
|
+
spriteOutput: tmpdir,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
assert.deepEqual(
|
|
67
|
+
expectedUrl,
|
|
68
|
+
JSON.parse(fs.readFileSync(styleJson, 'utf-8')).sprite,
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('Should build icons with the option `--sprite-url`. Icon file name is set by spriteUrl', async () => {
|
|
73
|
+
const expectedIconName = 'dark'
|
|
74
|
+
const expectedPng = path.join(tmpdir, `${expectedIconName}.png`)
|
|
75
|
+
const expectedJson = path.join(tmpdir, `${expectedIconName}.json`)
|
|
76
|
+
|
|
77
|
+
await build(styleYaml, styleJson, {
|
|
78
|
+
provider: defaultValues.provider,
|
|
79
|
+
spriteUrl: `http://localhost:8080/${expectedIconName}`,
|
|
80
|
+
spriteInput: iconSource,
|
|
81
|
+
spriteOutput: tmpdir,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
assert.deepEqual(true, !!fs.statSync(expectedPng))
|
|
85
|
+
assert.deepEqual(true, !!fs.statSync(expectedJson))
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('Use sprite name that specified in style.json with no --sprite-url option', async () => {
|
|
89
|
+
const expectedIconName = 'basic-white' // from test/data/style.yml
|
|
90
|
+
const expectedPng = path.join(tmpdir, `${expectedIconName}.png`)
|
|
91
|
+
const expectedJson = path.join(tmpdir, `${expectedIconName}.json`)
|
|
92
|
+
|
|
93
|
+
await build(styleYaml, styleJson, {
|
|
94
|
+
provider: defaultValues.provider,
|
|
95
|
+
spriteInput: iconSource,
|
|
96
|
+
spriteOutput: tmpdir,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// The file should exists.
|
|
100
|
+
assert.deepEqual(true, !!fs.statSync(expectedPng))
|
|
101
|
+
assert.deepEqual(true, !!fs.statSync(expectedJson))
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('Should not create sprite when input directory is not exist.', async () => {
|
|
105
|
+
const noExistInputDir = path.join(__dirname, 'data/hellooooo')
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
await build(styleYaml, styleJson, {
|
|
109
|
+
provider: defaultValues.provider,
|
|
110
|
+
spriteInput: noExistInputDir,
|
|
111
|
+
spriteOutput: tmpdir,
|
|
112
|
+
})
|
|
113
|
+
} catch (error) {
|
|
114
|
+
assert.deepEqual(true, !!error) // It should have something error.
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('Should watch `*.yml` and convert it to JSON', async () => {
|
|
119
|
+
const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms))
|
|
120
|
+
|
|
121
|
+
const watcher = buildWatch(styleYaml, styleJson, {
|
|
122
|
+
provider: defaultValues.provider,
|
|
123
|
+
})
|
|
124
|
+
await sleep(500)
|
|
125
|
+
const yamlData1 = fs
|
|
126
|
+
.readFileSync(styleYaml, 'utf-8')
|
|
127
|
+
.replace('metadata: {}', 'metadata: aaa')
|
|
128
|
+
fs.writeFileSync(styleYaml, yamlData1)
|
|
129
|
+
await sleep(500)
|
|
130
|
+
await watcher.close()
|
|
131
|
+
assert.deepEqual(true, !!fs.statSync(styleJson))
|
|
132
|
+
assert.deepEqual(
|
|
133
|
+
'aaa',
|
|
134
|
+
JSON.parse(fs.readFileSync(styleJson, 'utf-8')).metadata,
|
|
135
|
+
)
|
|
136
|
+
const yamlData2 = fs
|
|
137
|
+
.readFileSync(styleYaml, 'utf-8')
|
|
138
|
+
.replace('metadata: aaa', 'metadata: {}')
|
|
139
|
+
fs.writeFileSync(styleYaml, yamlData2)
|
|
140
|
+
})
|
|
141
|
+
})
|
package/test/convert.spec.ts
CHANGED
|
@@ -6,18 +6,17 @@ import os from 'os'
|
|
|
6
6
|
import { convert } from '../src/commands/convert'
|
|
7
7
|
|
|
8
8
|
describe('Test for the `convert.ts`.', () => {
|
|
9
|
-
|
|
10
9
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
11
10
|
const jsonPath = path.join(__dirname, 'data/convert.json')
|
|
12
11
|
const yamlPath = path.join(tmp, 'convert.yml')
|
|
13
12
|
const layerPath = path.join(tmp, 'layers/background.yml')
|
|
14
13
|
|
|
15
14
|
it('Should convert `data/convert.json` to YAML.', () => {
|
|
16
|
-
|
|
17
15
|
convert(jsonPath, yamlPath)
|
|
18
16
|
const yml = fs.readFileSync(yamlPath, 'utf-8')
|
|
19
17
|
|
|
20
|
-
assert.equal(
|
|
18
|
+
assert.equal(
|
|
19
|
+
`version: 8
|
|
21
20
|
name: example
|
|
22
21
|
metadata: {}
|
|
23
22
|
sources:
|
|
@@ -29,15 +28,16 @@ glyphs: https://glyphs.geolonia.com/{fontstack}/{range}.pbf
|
|
|
29
28
|
layers:
|
|
30
29
|
- !!inc/file layers/background.yml
|
|
31
30
|
id: example
|
|
32
|
-
`,
|
|
33
|
-
|
|
31
|
+
`,
|
|
32
|
+
yml,
|
|
33
|
+
)
|
|
34
|
+
})
|
|
34
35
|
|
|
35
36
|
it('Should create layers directory.', () => {
|
|
36
|
-
|
|
37
37
|
convert(jsonPath, yamlPath)
|
|
38
38
|
|
|
39
39
|
const result = fs.existsSync(layerPath)
|
|
40
40
|
|
|
41
41
|
assert.equal(true, result)
|
|
42
42
|
})
|
|
43
|
-
})
|
|
43
|
+
})
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17 17" height="17" width="17"><title>aerialway-11.svg</title><rect fill="none" x="0" y="0" width="17" height="17"></rect><rect x="1" y="1" rx="4" ry="4" width="15" height="15" stroke="#ffffff" style="stroke-linejoin:round;stroke-miterlimit:4;" fill="#ffffff" stroke-width="2"></rect><rect x="1" y="1" width="15" height="15" rx="4" ry="4" fill="#415cbd"></rect><path fill="#ffffff" transform="translate(3 3)" d="M9,4.5H6V3.1c0.1992-0.1183,0.3512-0.3021,0.43-0.52L9.5,2C9.7761,2,10,1.7761,10,1.5S9.7761,1,9.5,1
|
|
2
|
+
L6.25,1.61C5.8847,1.1957,5.2528,1.156,4.8386,1.5213C4.713,1.6321,4.6172,1.7726,4.56,1.93L1.5,2.5C1.2239,2.5,1,2.7239,1,3
|
|
3
|
+
s0.2239,0.5,0.5,0.5l3.25-0.61C4.8213,2.9732,4.9057,3.0442,5,3.1v1.4H2c-0.5523,0-1,0.4477-1,1V9c0,0.5523,0.4477,1,1,1h7
|
|
4
|
+
c0.5523,0,1-0.4477,1-1V5.5C10,4.9477,9.5523,4.5,9,4.5z M5,8.5H2.5v-3H5V8.5z M8.5,8.5H6v-3h2.5V8.5z"></path></svg>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
version: 8
|
|
2
|
+
name: My Style
|
|
3
|
+
sprite: ''
|
|
4
|
+
glyphs: ''
|
|
5
|
+
sources:
|
|
6
|
+
tiles.mbtiles:
|
|
7
|
+
type: vector
|
|
8
|
+
tiles:
|
|
9
|
+
- https://optgeo.github.io/kokoromi-rw/zxy/{z}/{x}/{y}.pbf
|
|
10
|
+
minzoom: '0'
|
|
11
|
+
maxzoom: '15'
|
|
12
|
+
layers:
|
|
13
|
+
- id: boundary
|
|
14
|
+
type: fill
|
|
15
|
+
source: tiles.mbtiles
|
|
16
|
+
source-layer: boundary
|
|
17
|
+
layout: {}
|
|
18
|
+
paint: {}
|
|
19
|
+
- id: building
|
|
20
|
+
type: fill
|
|
21
|
+
source: tiles.mbtiles
|
|
22
|
+
source-layer: building
|
|
23
|
+
layout: {}
|
|
24
|
+
paint: {}
|
|
25
|
+
- id: nature
|
|
26
|
+
type: fill
|
|
27
|
+
source: tiles.mbtiles
|
|
28
|
+
source-layer: nature
|
|
29
|
+
layout: {}
|
|
30
|
+
paint: {}
|
|
31
|
+
- id: place
|
|
32
|
+
type: fill
|
|
33
|
+
source: tiles.mbtiles
|
|
34
|
+
source-layer: place
|
|
35
|
+
layout: {}
|
|
36
|
+
paint: {}
|
|
37
|
+
- id: road
|
|
38
|
+
type: fill
|
|
39
|
+
source: tiles.mbtiles
|
|
40
|
+
source-layer: road
|
|
41
|
+
layout: {}
|
|
42
|
+
paint: {}
|
|
43
|
+
- id: route
|
|
44
|
+
type: fill
|
|
45
|
+
source: tiles.mbtiles
|
|
46
|
+
source-layer: route
|
|
47
|
+
layout: {}
|
|
48
|
+
paint: {}
|
|
49
|
+
- id: structure
|
|
50
|
+
type: fill
|
|
51
|
+
source: tiles.mbtiles
|
|
52
|
+
source-layer: structure
|
|
53
|
+
layout: {}
|
|
54
|
+
paint: {}
|
|
55
|
+
- id: water
|
|
56
|
+
type: fill
|
|
57
|
+
source: tiles.mbtiles
|
|
58
|
+
source-layer: water
|
|
59
|
+
layout: {}
|
|
60
|
+
paint: {}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
version: 8
|
|
2
|
+
name: My Style
|
|
3
|
+
sprite: ''
|
|
4
|
+
glyphs: ''
|
|
5
|
+
sources:
|
|
6
|
+
OpenStreetMap:
|
|
7
|
+
type: vector
|
|
8
|
+
url: >-
|
|
9
|
+
https://raw.githubusercontent.com/mapbox/tilejson-spec/master/3.0.0/example/osm.json
|
|
10
|
+
layers:
|
|
11
|
+
- id: telephone
|
|
12
|
+
type: fill
|
|
13
|
+
source: OpenStreetMap
|
|
14
|
+
source-layer: telephone
|
|
15
|
+
layout: {}
|
|
16
|
+
paint: {}
|
|
17
|
+
- id: bicycle_parking
|
|
18
|
+
type: fill
|
|
19
|
+
source: OpenStreetMap
|
|
20
|
+
source-layer: bicycle_parking
|
|
21
|
+
layout: {}
|
|
22
|
+
paint: {}
|
|
23
|
+
- id: showers
|
|
24
|
+
type: fill
|
|
25
|
+
source: OpenStreetMap
|
|
26
|
+
source-layer: showers
|
|
27
|
+
layout: {}
|
|
28
|
+
paint: {}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
version: 8
|
|
2
|
+
name: My Style
|
|
3
|
+
sprite: ''
|
|
4
|
+
glyphs: ''
|
|
5
|
+
sources:
|
|
6
|
+
OpenStreetMap:
|
|
7
|
+
type: vector
|
|
8
|
+
url: >-
|
|
9
|
+
https://raw.githubusercontent.com/mapbox/tilejson-spec/master/3.0.0/example/osm.json
|
|
10
|
+
layers:
|
|
11
|
+
- !!inc/file layers/telephone.yml
|
|
12
|
+
- !!inc/file layers/bicycle_parking.yml
|
|
13
|
+
- !!inc/file layers/showers.yml
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { assert } from 'chai'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import { getSpriteSlug } from '../src/lib/get-sprite-slug'
|
|
5
|
+
|
|
6
|
+
const stylePath = path.join(__dirname, 'data/style.json')
|
|
7
|
+
const styleJson = fs.readFileSync(stylePath, 'utf-8')
|
|
8
|
+
|
|
9
|
+
describe('Test for the `get-sprite-slug.ts`.', () => {
|
|
10
|
+
it('should get sprite slug from style.json', async () => {
|
|
11
|
+
const spriteSlug = getSpriteSlug(JSON.parse(styleJson))
|
|
12
|
+
|
|
13
|
+
// the test/data/style.json sprit slug is basic-white
|
|
14
|
+
assert.deepEqual('basic-white', spriteSlug)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it("should return false with no icon's slug in url", async () => {
|
|
18
|
+
const styleObject = JSON.parse(styleJson)
|
|
19
|
+
const styleObject1 = styleObject
|
|
20
|
+
const styleObject2 = styleObject
|
|
21
|
+
|
|
22
|
+
styleObject.sprite = 'http://localhost:8080'
|
|
23
|
+
styleObject1.sprite = 'http://localhost:8080/'
|
|
24
|
+
styleObject2.sprite = ''
|
|
25
|
+
|
|
26
|
+
const spriteSlug = getSpriteSlug(styleObject)
|
|
27
|
+
const spriteSlug1 = getSpriteSlug(styleObject1)
|
|
28
|
+
const spriteSlug2 = getSpriteSlug(styleObject2)
|
|
29
|
+
|
|
30
|
+
assert.isFalse(spriteSlug)
|
|
31
|
+
assert.isFalse(spriteSlug1)
|
|
32
|
+
assert.isFalse(spriteSlug2)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { assert } from 'chai'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
import YAML from 'js-yaml'
|
|
6
|
+
|
|
7
|
+
import { init, initOptions } from '../src/commands/init'
|
|
8
|
+
|
|
9
|
+
describe('Test for the `init.ts`.', () => {
|
|
10
|
+
it('Should initialize default style.yml.', async () => {
|
|
11
|
+
const tempStylePath = path.join(__dirname, 'data/init/init.yml')
|
|
12
|
+
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
13
|
+
const styleYaml = path.join(tmpdir, 'style.yml')
|
|
14
|
+
|
|
15
|
+
await init(styleYaml, {})
|
|
16
|
+
|
|
17
|
+
// The file should exists.
|
|
18
|
+
assert.deepEqual(true, !!fs.statSync(styleYaml))
|
|
19
|
+
// the file should be the same with init.yml
|
|
20
|
+
assert.deepEqual(
|
|
21
|
+
YAML.load(fs.readFileSync(styleYaml, 'utf8')),
|
|
22
|
+
YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('Should initialize default composited style.yml from tilejson provided', async () => {
|
|
27
|
+
const tempStylePath = path.join(__dirname, 'data/init/init_tilejson.yml')
|
|
28
|
+
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
29
|
+
const styleYaml = path.join(tmpdir, 'style.yml')
|
|
30
|
+
|
|
31
|
+
const options: initOptions = {
|
|
32
|
+
tilejsonUrls:
|
|
33
|
+
'https://raw.githubusercontent.com/mapbox/tilejson-spec/master/3.0.0/example/osm.json',
|
|
34
|
+
compositeLayers: true,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await init(styleYaml, options)
|
|
38
|
+
|
|
39
|
+
// The file should exists.
|
|
40
|
+
assert.deepEqual(true, !!fs.statSync(styleYaml))
|
|
41
|
+
// the file should be the same with init_tilejson.yml
|
|
42
|
+
assert.deepEqual(
|
|
43
|
+
YAML.load(fs.readFileSync(styleYaml, 'utf8')),
|
|
44
|
+
YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('Should produce composited style.yml without layers if tilejson without vector_layers is specified', async () => {
|
|
49
|
+
const tempStylePath = path.join(
|
|
50
|
+
__dirname,
|
|
51
|
+
'data/init/init_tilejson_without_layers.yml',
|
|
52
|
+
)
|
|
53
|
+
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
54
|
+
const styleYaml = path.join(tmpdir, 'style.yml')
|
|
55
|
+
|
|
56
|
+
const options: initOptions = {
|
|
57
|
+
tilejsonUrls: 'https://a.tiles.mapbox.com/v3/aj.1x1-degrees.json',
|
|
58
|
+
compositeLayers: true,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await init(styleYaml, options)
|
|
62
|
+
|
|
63
|
+
// The file should exists.
|
|
64
|
+
assert.deepEqual(true, !!fs.statSync(styleYaml))
|
|
65
|
+
assert.deepEqual(
|
|
66
|
+
YAML.load(fs.readFileSync(styleYaml, 'utf8')),
|
|
67
|
+
YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
|
|
68
|
+
)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('Should initialize default decomposited style.yml from tilejson provided', async () => {
|
|
72
|
+
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
73
|
+
const styleYaml = path.join(tmpdir, 'style.yml')
|
|
74
|
+
|
|
75
|
+
const options: initOptions = {
|
|
76
|
+
tilejsonUrls:
|
|
77
|
+
'https://raw.githubusercontent.com/mapbox/tilejson-spec/master/3.0.0/example/osm.json',
|
|
78
|
+
compositeLayers: false,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
await init(styleYaml, options)
|
|
82
|
+
|
|
83
|
+
// The file should exists.
|
|
84
|
+
assert.deepEqual(true, !!fs.statSync(styleYaml))
|
|
85
|
+
// the file should be the same with init_tilejson.yml
|
|
86
|
+
assert.deepEqual(
|
|
87
|
+
fs.readFileSync(styleYaml, 'utf8'),
|
|
88
|
+
fs.readFileSync(
|
|
89
|
+
path.join(__dirname, 'data/init/tilejson/init_decomposite.yml'),
|
|
90
|
+
'utf-8',
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
assert.deepEqual(
|
|
94
|
+
YAML.load(
|
|
95
|
+
fs.readFileSync(
|
|
96
|
+
path.join(tmpdir, 'layers/bicycle_parking.yml'),
|
|
97
|
+
'utf8',
|
|
98
|
+
),
|
|
99
|
+
),
|
|
100
|
+
YAML.load(
|
|
101
|
+
fs.readFileSync(
|
|
102
|
+
path.join(__dirname, 'data/init/tilejson/layers/bicycle_parking.yml'),
|
|
103
|
+
'utf-8',
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
assert.deepEqual(
|
|
108
|
+
YAML.load(
|
|
109
|
+
fs.readFileSync(path.join(tmpdir, 'layers/showers.yml'), 'utf8'),
|
|
110
|
+
),
|
|
111
|
+
YAML.load(
|
|
112
|
+
fs.readFileSync(
|
|
113
|
+
path.join(__dirname, 'data/init/tilejson/layers/showers.yml'),
|
|
114
|
+
'utf-8',
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
assert.deepEqual(
|
|
119
|
+
YAML.load(
|
|
120
|
+
fs.readFileSync(path.join(tmpdir, 'layers/telephone.yml'), 'utf8'),
|
|
121
|
+
),
|
|
122
|
+
YAML.load(
|
|
123
|
+
fs.readFileSync(
|
|
124
|
+
path.join(__dirname, 'data/init/tilejson/layers/telephone.yml'),
|
|
125
|
+
'utf-8',
|
|
126
|
+
),
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('Should initialize default decomposited style.yml from metadatajson provided', async () => {
|
|
132
|
+
const tempStylePath = path.join(__dirname, 'data/init/init_metadata.yml')
|
|
133
|
+
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
|
|
134
|
+
const styleYaml = path.join(tmpdir, 'init_metadata.yml')
|
|
135
|
+
|
|
136
|
+
const options: initOptions = {
|
|
137
|
+
metadatajsonUrls:
|
|
138
|
+
'https://optgeo.github.io/kokoromi-rw/zxy/metadata.json',
|
|
139
|
+
compositeLayers: true,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
await init(styleYaml, options)
|
|
143
|
+
|
|
144
|
+
// The file should exists.
|
|
145
|
+
assert.deepEqual(true, !!fs.statSync(styleYaml))
|
|
146
|
+
assert.deepEqual(
|
|
147
|
+
YAML.load(fs.readFileSync(styleYaml, 'utf8')),
|
|
148
|
+
YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
|
|
149
|
+
)
|
|
150
|
+
})
|
|
151
|
+
})
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { assert } from 'chai'
|
|
2
|
+
import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec/types'
|
|
2
3
|
|
|
3
4
|
import { validateStyle } from '../src/lib/validate-style'
|
|
4
5
|
|
|
5
6
|
describe('Test for the `validate-style.ts`.', () => {
|
|
6
7
|
it('should validate as expected.', (done) => {
|
|
7
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const style: StyleSpecification = {
|
|
8
10
|
version: 8,
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
try {
|
|
12
14
|
validateStyle(style)
|
|
13
|
-
} catch(error) {
|
|
14
|
-
assert.deepEqual(true, !!
|
|
15
|
+
} catch (error) {
|
|
16
|
+
assert.deepEqual(true, !!error) // It should have something error.
|
|
15
17
|
done()
|
|
16
18
|
}
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
+
})
|
|
20
|
+
})
|
package/test/yaml-parser.spec.ts
CHANGED
|
@@ -8,18 +8,18 @@ describe('Test for the `yaml-parser.ts`.', () => {
|
|
|
8
8
|
const yamlPath = path.join(__dirname, 'data/example.yml')
|
|
9
9
|
const style = parser(yamlPath)
|
|
10
10
|
|
|
11
|
-
assert.deepEqual(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
25
|
-
})
|
|
11
|
+
assert.deepEqual(
|
|
12
|
+
{
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
color: '#ff0000',
|
|
15
|
+
'stroke-width': 2,
|
|
16
|
+
background: '#ff0000',
|
|
17
|
+
backgroundColor: '#ffff00',
|
|
18
|
+
alias: '#ff0000',
|
|
19
|
+
fruits: ['apple', 'banana', '#ff0000'],
|
|
20
|
+
names: ['John', '花子', '#ff0000'],
|
|
21
|
+
},
|
|
22
|
+
style,
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
})
|