@unvt/charites 0.1.4 → 0.3.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 (49) hide show
  1. package/.all-contributorsrc +63 -0
  2. package/.devcontainer/Dockerfile +29 -0
  3. package/.devcontainer/README.md +34 -0
  4. package/.devcontainer/devcontainer.json +36 -0
  5. package/.github/CONTRIBUTING.md +6 -4
  6. package/.github/PULL_REQUEST_TEMPLATE.md +2 -1
  7. package/.github/release.yml +14 -0
  8. package/.github/workflows/build.yml +28 -3
  9. package/LICENSE +1 -1
  10. package/README.md +8 -3
  11. package/dist/cli/serve.js +1 -1
  12. package/dist/commands/serve.js +21 -4
  13. package/dist/lib/build-sprite.js +8 -62
  14. package/dist/lib/error.js +4 -1
  15. package/dist/lib/yaml-writer.js +7 -4
  16. package/docs/source/conf.py +3 -3
  17. package/docs/source/index.rst +2 -2
  18. package/docs/source/install/recommended_environment.rst +1 -1
  19. package/docs/source/usage/commandline_interface.rst +3 -3
  20. package/docs/source/usage/examples.rst +2 -2
  21. package/package.json +11 -4
  22. package/playwright.config.ts +29 -0
  23. package/provider/default/app.js +28 -33
  24. package/provider/default/index.html +4 -1
  25. package/provider/default/shared.js +67 -0
  26. package/provider/geolonia/app.js +27 -32
  27. package/provider/geolonia/index.html +4 -1
  28. package/provider/mapbox/app.js +30 -34
  29. package/provider/mapbox/index.html +4 -1
  30. package/src/cli/serve.ts +1 -1
  31. package/src/commands/serve.ts +32 -4
  32. package/src/lib/build-sprite.ts +8 -71
  33. package/src/lib/error.ts +3 -1
  34. package/src/lib/yaml-writer.ts +8 -4
  35. package/test/build-sprite.spec.ts +5 -5
  36. package/test/build.spec.ts +33 -23
  37. package/test/command.build.spec.ts +108 -0
  38. package/test/command.convert.spec.ts +24 -0
  39. package/test/command.init.spec.ts +45 -0
  40. package/test/data/style.json +4 -3
  41. package/test/playwright/provider/default/e2e.spec.ts +13 -0
  42. package/test/playwright/provider/geolonia/e2e.spec.ts +13 -0
  43. package/test/playwright/provider/mapbox/e2e.spec.ts +13 -0
  44. package/test/util/charitesCmd.ts +3 -0
  45. package/test/util/copyFixtures.ts +14 -0
  46. package/test/util/execPromise.ts +14 -0
  47. package/test/util/makeTempDir.ts +6 -0
  48. package/provider/geolonia/app.css +0 -17
  49. package/provider/mapbox/app.css +0 -17
@@ -0,0 +1,108 @@
1
+ import chai from 'chai'
2
+ import chaiAsPromised from 'chai-as-promised'
3
+ import path from 'path'
4
+ import fs from 'fs'
5
+ import { copyFixturesFile, copyFixturesDir } from './util/copyFixtures'
6
+ import { exec } from './util/execPromise'
7
+ import { makeTempDir } from './util/makeTempDir'
8
+ import charites from './util/charitesCmd'
9
+
10
+ let tmpdir = ''
11
+ chai.use(chaiAsPromised)
12
+ chai.should()
13
+ const assert = chai.assert
14
+
15
+ describe('Test for the `charites build`', () => {
16
+ beforeEach(async function () {
17
+ tmpdir = makeTempDir()
18
+ copyFixturesFile('style.yml', tmpdir)
19
+ copyFixturesFile('error.yml', tmpdir)
20
+ copyFixturesDir('layers', tmpdir)
21
+ copyFixturesDir('icons', tmpdir)
22
+ })
23
+
24
+ it('charites build style.yml', async () => {
25
+ // prettier-ignore
26
+ const { stdout, stderr } = await exec(`${charites} build style.yml`, tmpdir)
27
+ assert.deepEqual(stdout, '')
28
+ assert.deepEqual(stderr, '')
29
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'style.json')))
30
+ })
31
+
32
+ it('charites build style.yml custom.json', async () => {
33
+ // prettier-ignore
34
+ const { stdout, stderr } = await exec(`${charites} build style.yml custom.json`, tmpdir)
35
+ assert.deepEqual(stdout, '')
36
+ assert.deepEqual(stderr, '')
37
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'custom.json')))
38
+ })
39
+
40
+ it('charites build style.yml --compact-output', async () => {
41
+ // prettier-ignore
42
+ const { stdout, stderr } = await exec(`${charites} build style.yml --compact-output`, tmpdir)
43
+ assert.deepEqual(stdout, '')
44
+ assert.deepEqual(stderr, '')
45
+
46
+ const contents = fs.readFileSync(path.join(tmpdir, 'style.json'), 'utf-8')
47
+ assert.isNull(contents.match(/\\n/))
48
+ })
49
+
50
+ it('charites build style.yml style.json --sprite-url http://localhost:8080/icons', async () => {
51
+ // prettier-ignore
52
+ const { stdout, stderr } = await exec(`${charites} build style.yml style.json --sprite-url http://localhost:8080/icons`, tmpdir)
53
+ assert.deepEqual(stdout, '')
54
+ assert.deepEqual(stderr, '')
55
+
56
+ const contents = fs.readFileSync(path.join(tmpdir, 'style.json'), 'utf-8')
57
+ assert.deepEqual('http://localhost:8080/icons', JSON.parse(contents).sprite)
58
+ })
59
+
60
+ it('charites build style.yml style.json --sprite-input icons --sprite-output .', async () => {
61
+ // prettier-ignore
62
+ const { stdout, stderr } = await exec(`${charites} build style.yml style.json --sprite-input icons --sprite-output .`, tmpdir)
63
+ assert.deepEqual(stdout, '')
64
+ assert.deepEqual(stderr, '')
65
+
66
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'basic-white.png')))
67
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'basic-white.json')))
68
+ })
69
+
70
+ it('charites build style.yml style.json --sprite-url http://localhost:8080', () => {
71
+ const promise = exec(
72
+ `${charites} build style.yml style.json --sprite-url http://localhost:8080`,
73
+ tmpdir,
74
+ )
75
+ return assert.isRejected(promise, /Invalid sprite url format.\n/)
76
+ })
77
+
78
+ it('charites build style.yml style.json --sprite-input noExistDirname', () => {
79
+ const promise = exec(
80
+ `${charites} build style.yml style.json --sprite-input noExistDirname`,
81
+ tmpdir,
82
+ )
83
+ return assert.isRejected(
84
+ promise,
85
+ /noExistDirname: No such directory. Please specify valid icon input directory. For more help run charites build --help\n/,
86
+ )
87
+ })
88
+
89
+ it('charites build style.yml style.json --sprite-output noExistDirname', (done) => {
90
+ const promise = exec(
91
+ `${charites} build style.yml style.json --sprite-output noExistDirname`,
92
+ tmpdir,
93
+ )
94
+ promise.should.be.rejected
95
+ .then(function () {
96
+ return assert.isRejected(
97
+ promise,
98
+ /noExistDirname: No such directory. Please specify valid icon output directory. For more help run charites build --help\n/,
99
+ )
100
+ })
101
+ .should.notify(done)
102
+ })
103
+
104
+ it('charites build print error message', () => {
105
+ const promise = exec(`${charites} build error.yml`, tmpdir)
106
+ return assert.isRejected(promise, /missing required property "sources"/)
107
+ })
108
+ })
@@ -0,0 +1,24 @@
1
+ import { assert } from 'chai'
2
+ import path from 'path'
3
+ import fs from 'fs'
4
+ import { copyFixturesFile } from './util/copyFixtures'
5
+ import { exec } from './util/execPromise'
6
+ import { makeTempDir } from './util/makeTempDir'
7
+ import charites from './util/charitesCmd'
8
+
9
+ let tmpdir = ''
10
+
11
+ describe('Test for the `charites convert`', () => {
12
+ beforeEach(async function () {
13
+ tmpdir = makeTempDir()
14
+ copyFixturesFile('style.json', tmpdir)
15
+ })
16
+
17
+ it('charites convert style.json style.yml', async () => {
18
+ // prettier-ignore
19
+ const { stdout, stderr } = await exec(`${charites} convert style.json style.yml`, tmpdir)
20
+ assert.deepEqual(stdout, '')
21
+ assert.deepEqual(stderr, '')
22
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'style.yml')))
23
+ })
24
+ })
@@ -0,0 +1,45 @@
1
+ import { assert } from 'chai'
2
+ import path from 'path'
3
+ import fs from 'fs'
4
+ import { exec } from './util/execPromise'
5
+ import { makeTempDir } from './util/makeTempDir'
6
+ import charites from './util/charitesCmd'
7
+
8
+ const tileJsonUrl =
9
+ 'https://raw.githubusercontent.com/mapbox/tilejson-spec/master/3.0.0/example/osm.json'
10
+ const metadataJsonUrl = 'https://optgeo.github.io/kokoromi-rw/zxy/metadata.json'
11
+
12
+ let tmpdir = ''
13
+
14
+ describe('Test for the `charites convert`', () => {
15
+ beforeEach(async function () {
16
+ tmpdir = makeTempDir()
17
+ })
18
+
19
+ it('charites init style.yml --tilejson-urls ${tileJsonUrl}', async () => {
20
+ // prettier-ignore
21
+ const { stdout, stderr } = await exec(`${charites} init style.yml --tilejson-urls ${tileJsonUrl}`, tmpdir)
22
+ assert.deepEqual(stdout, '')
23
+ assert.deepEqual(stderr, '')
24
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'style.yml')))
25
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'layers')))
26
+ })
27
+
28
+ it('charites init style.yml --metadatajson-urls ${metadataJsonUrl}', async () => {
29
+ // prettier-ignore
30
+ const { stdout, stderr } = await exec(`${charites} init style.yml --metadatajson-urls ${metadataJsonUrl}`, tmpdir)
31
+ assert.deepEqual(stdout, '')
32
+ assert.deepEqual(stderr, '')
33
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'style.yml')))
34
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'layers')))
35
+ })
36
+
37
+ it('charites init style.yml --tilejson-urls ${tileJsonUrl} --composite-layers', async () => {
38
+ // prettier-ignore
39
+ const { stdout, stderr } = await exec(`${charites} init style.yml --tilejson-urls ${tileJsonUrl} --composite-layers`, tmpdir)
40
+ assert.deepEqual(stdout, '')
41
+ assert.deepEqual(stderr, '')
42
+ assert.isTrue(fs.existsSync(path.join(tmpdir, 'style.yml')))
43
+ assert.isFalse(fs.existsSync(path.join(tmpdir, 'layers')))
44
+ })
45
+ })
@@ -14,8 +14,9 @@
14
14
  {
15
15
  "id": "background",
16
16
  "type": "background",
17
- "paint": null,
18
- "background-color": "rgba(19, 28, 54, 1)"
17
+ "paint": {
18
+ "background-color": "rgba(19, 28, 54, 1)"
19
+ }
19
20
  },
20
21
  {
21
22
  "id": "water",
@@ -30,4 +31,4 @@
30
31
  }
31
32
  }
32
33
  ]
33
- }
34
+ }
@@ -0,0 +1,13 @@
1
+ import { test, expect } from '@playwright/test'
2
+
3
+ test('Charites Live Preview with maplibre', async ({ page }) => {
4
+ // collect errors on the page
5
+ const pageErrors: Error[] = []
6
+ page.on('pageerror', (exception) => pageErrors.push(exception))
7
+
8
+ await page.goto('http://localhost:8080/', { waitUntil: 'networkidle' })
9
+ await page.waitForTimeout(1000)
10
+ const title = await page.title()
11
+ expect(title).toBe('Charites Live Preview')
12
+ expect(pageErrors).toMatchObject([])
13
+ })
@@ -0,0 +1,13 @@
1
+ import { test, expect } from '@playwright/test'
2
+
3
+ test('Charites Live Preview with geolonia', async ({ page }) => {
4
+ // collect errors on the page
5
+ const pageErrors: Error[] = []
6
+ page.on('pageerror', (exception) => pageErrors.push(exception))
7
+
8
+ await page.goto('http://localhost:8088/', { waitUntil: 'networkidle' })
9
+ await page.waitForTimeout(1000)
10
+ const title = await page.title()
11
+ expect(title).toBe('Charites Live Preview')
12
+ expect(pageErrors).toMatchObject([])
13
+ })
@@ -0,0 +1,13 @@
1
+ import { test, expect } from '@playwright/test'
2
+
3
+ test('Charites Live Preview with mapbox', async ({ page }) => {
4
+ // collect errors on the page
5
+ const pageErrors: Error[] = []
6
+ page.on('pageerror', (exception) => pageErrors.push(exception))
7
+
8
+ await page.goto('http://localhost:8888/', { waitUntil: 'networkidle' })
9
+ await page.waitForTimeout(1000)
10
+ const title = await page.title()
11
+ expect(title).toBe('Charites Live Preview')
12
+ expect(pageErrors).toMatchObject([])
13
+ })
@@ -0,0 +1,3 @@
1
+ import path from 'path'
2
+
3
+ export default `node ${path.join(__dirname, '..', '..', 'dist', 'cli.js')}`
@@ -0,0 +1,14 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import fse from 'fs-extra'
4
+
5
+ export const copyFixturesFile = (file: string, destDir: string) => {
6
+ fs.copyFileSync(
7
+ path.join(__dirname, '..', 'data', file),
8
+ path.join(destDir, file),
9
+ )
10
+ }
11
+
12
+ export const copyFixturesDir = (dir: string, destDir: string) => {
13
+ fse.copySync(path.join(__dirname, '..', 'data', dir), path.join(destDir, dir))
14
+ }
@@ -0,0 +1,14 @@
1
+ import child_process from 'child_process'
2
+ import util from 'util'
3
+ import { makeTempDir } from './makeTempDir'
4
+ const execSync = util.promisify(child_process.exec)
5
+
6
+ export const exec = async (cmd: string, cwd?: string) => {
7
+ const temp = cwd ? cwd : makeTempDir()
8
+ const { stdout, stderr } = await execSync(cmd, {
9
+ encoding: 'utf8',
10
+ cwd: temp,
11
+ })
12
+
13
+ return { stdout, stderr, cwd: temp }
14
+ }
@@ -0,0 +1,6 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import os from 'os'
4
+
5
+ export const makeTempDir = () =>
6
+ fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
@@ -1,17 +0,0 @@
1
- html, body, #map
2
- {
3
- width: 100vw;
4
- height: 100vh;
5
- padding: 0;
6
- margin: 0;
7
- }
8
-
9
- .overlay {
10
- width: 200px;
11
- position: absolute;
12
- top: 10;
13
- left: 10;
14
- margin: 5px;
15
- z-index: 90;
16
- background-color: rgba(255, 255, 255, 0.6);
17
- }
@@ -1,17 +0,0 @@
1
- html, body, #map
2
- {
3
- width: 100vw;
4
- height: 100vh;
5
- padding: 0;
6
- margin: 0;
7
- }
8
-
9
- .overlay {
10
- width: 200px;
11
- position: absolute;
12
- top: 10;
13
- left: 10;
14
- margin: 5px;
15
- z-index: 90;
16
- background-color: rgba(255, 255, 255, 0.6);
17
- }