@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.
- package/.all-contributorsrc +63 -0
- package/.devcontainer/Dockerfile +29 -0
- package/.devcontainer/README.md +34 -0
- package/.devcontainer/devcontainer.json +36 -0
- package/.github/CONTRIBUTING.md +6 -4
- package/.github/PULL_REQUEST_TEMPLATE.md +2 -1
- package/.github/release.yml +14 -0
- package/.github/workflows/build.yml +28 -3
- package/LICENSE +1 -1
- package/README.md +8 -3
- package/dist/cli/serve.js +1 -1
- package/dist/commands/serve.js +21 -4
- package/dist/lib/build-sprite.js +8 -62
- package/dist/lib/error.js +4 -1
- package/dist/lib/yaml-writer.js +7 -4
- package/docs/source/conf.py +3 -3
- package/docs/source/index.rst +2 -2
- package/docs/source/install/recommended_environment.rst +1 -1
- package/docs/source/usage/commandline_interface.rst +3 -3
- package/docs/source/usage/examples.rst +2 -2
- package/package.json +11 -4
- package/playwright.config.ts +29 -0
- package/provider/default/app.js +28 -33
- package/provider/default/index.html +4 -1
- package/provider/default/shared.js +67 -0
- package/provider/geolonia/app.js +27 -32
- package/provider/geolonia/index.html +4 -1
- package/provider/mapbox/app.js +30 -34
- package/provider/mapbox/index.html +4 -1
- package/src/cli/serve.ts +1 -1
- package/src/commands/serve.ts +32 -4
- package/src/lib/build-sprite.ts +8 -71
- package/src/lib/error.ts +3 -1
- package/src/lib/yaml-writer.ts +8 -4
- package/test/build-sprite.spec.ts +5 -5
- package/test/build.spec.ts +33 -23
- package/test/command.build.spec.ts +108 -0
- package/test/command.convert.spec.ts +24 -0
- package/test/command.init.spec.ts +45 -0
- package/test/data/style.json +4 -3
- package/test/playwright/provider/default/e2e.spec.ts +13 -0
- package/test/playwright/provider/geolonia/e2e.spec.ts +13 -0
- package/test/playwright/provider/mapbox/e2e.spec.ts +13 -0
- package/test/util/charitesCmd.ts +3 -0
- package/test/util/copyFixtures.ts +14 -0
- package/test/util/execPromise.ts +14 -0
- package/test/util/makeTempDir.ts +6 -0
- package/provider/geolonia/app.css +0 -17
- package/provider/mapbox/app.css +0 -17
package/.all-contributorsrc
CHANGED
|
@@ -13,6 +13,69 @@
|
|
|
13
13
|
"contributions": [
|
|
14
14
|
"code"
|
|
15
15
|
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"login": "naogify",
|
|
19
|
+
"name": "Naoki Ohashi",
|
|
20
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/8760841?v=4",
|
|
21
|
+
"profile": "https://naoki-is.me",
|
|
22
|
+
"contributions": [
|
|
23
|
+
"code"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"login": "ubukawa",
|
|
28
|
+
"name": "UBUKAWA Taro",
|
|
29
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/59204379?v=4",
|
|
30
|
+
"profile": "https://github.com/ubukawa",
|
|
31
|
+
"contributions": [
|
|
32
|
+
"code"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"login": "miya0001",
|
|
37
|
+
"name": "Takayuki Miyauchi",
|
|
38
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/309946?v=4",
|
|
39
|
+
"profile": "https://geolonia.com/",
|
|
40
|
+
"contributions": [
|
|
41
|
+
"code"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"login": "JinIgarashi",
|
|
46
|
+
"name": "Jin Igarashi",
|
|
47
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/2639701?v=4",
|
|
48
|
+
"profile": "https://jin-igarashi.me",
|
|
49
|
+
"contributions": [
|
|
50
|
+
"code"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"login": "smellman",
|
|
55
|
+
"name": "Taro Matsuzawa aka. btm",
|
|
56
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/135112?v=4",
|
|
57
|
+
"profile": "http://smellman.hatenablog.com/",
|
|
58
|
+
"contributions": [
|
|
59
|
+
"code"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"login": "ShinichiNishikawa",
|
|
64
|
+
"name": "Shinichi Nishikawa",
|
|
65
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/1124652?v=4",
|
|
66
|
+
"profile": "https://shinichi.blog",
|
|
67
|
+
"contributions": [
|
|
68
|
+
"doc"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"login": "yuiseki",
|
|
73
|
+
"name": "yuiseki",
|
|
74
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/25507?v=4",
|
|
75
|
+
"profile": "http://yuiseki.net/",
|
|
76
|
+
"contributions": [
|
|
77
|
+
"code"
|
|
78
|
+
]
|
|
16
79
|
}
|
|
17
80
|
],
|
|
18
81
|
"contributorsPerLine": 7,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
FROM ubuntu:22.04
|
|
2
|
+
|
|
3
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
4
|
+
RUN apt-get update && apt install -y --no-install-recommends \
|
|
5
|
+
git \
|
|
6
|
+
curl \
|
|
7
|
+
vim \
|
|
8
|
+
htop \
|
|
9
|
+
make \
|
|
10
|
+
jq
|
|
11
|
+
|
|
12
|
+
ENV DEBIAN_FRONTEND=dialog
|
|
13
|
+
|
|
14
|
+
RUN curl -Ls https://deb.nodesource.com/setup_18.x | bash
|
|
15
|
+
RUN apt update && apt install -y nodejs npm
|
|
16
|
+
RUN npm install npm@latest -g
|
|
17
|
+
|
|
18
|
+
RUN useradd -m user
|
|
19
|
+
USER user
|
|
20
|
+
|
|
21
|
+
ENV NPM_CONFIG_DIR="/home/user/.npm-global"
|
|
22
|
+
RUN mkdir -p "${NPM_CONFIG_DIR}"
|
|
23
|
+
RUN mkdir -p "${NPM_CONFIG_DIR}/bin"
|
|
24
|
+
RUN mkdir -p "${NPM_CONFIG_DIR}/lib"
|
|
25
|
+
ENV PATH="/home/user/.npm-global/bin:${PATH}"
|
|
26
|
+
|
|
27
|
+
EXPOSE 8080
|
|
28
|
+
|
|
29
|
+
CMD [ "sleep", "infinity" ]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Development Containers (DevContainer) for charites
|
|
2
|
+
|
|
3
|
+
## What is it?
|
|
4
|
+
|
|
5
|
+
- DevContainer is a Dockerfile and a configuration file for remote development in Visual Studio Code or GitHub Codespaces
|
|
6
|
+
- DevContainer allows development environments to be written and maintained as code
|
|
7
|
+
- DevContainer allows everyone to develop in a common development environment
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Visual Studio Code
|
|
12
|
+
- Docker
|
|
13
|
+
|
|
14
|
+
## How to use it?
|
|
15
|
+
|
|
16
|
+
- Fork `charites` repository (If not yet)
|
|
17
|
+
- Sync your fork from upstream (If not yet)
|
|
18
|
+
- Clone `charites` repository (If not yet)
|
|
19
|
+
- Open cloned directory
|
|
20
|
+
- At this time, you should see a message `Reopen in container`, then click `Open` button
|
|
21
|
+
- DevContainer will be built...
|
|
22
|
+
- It take a while...
|
|
23
|
+
|
|
24
|
+
### Once the DevContainer has been built and started...
|
|
25
|
+
|
|
26
|
+
- Development can be done as usual
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
npm ci
|
|
30
|
+
npm run build
|
|
31
|
+
npm install -g .
|
|
32
|
+
charites help
|
|
33
|
+
charites serve test/data/style.yml
|
|
34
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Ubuntu 22.04 Node.js",
|
|
3
|
+
"dockerFile": "./Dockerfile",
|
|
4
|
+
"forwardPorts": [8080],
|
|
5
|
+
"remoteUser": "user",
|
|
6
|
+
"overrideCommand": false,
|
|
7
|
+
"customizations": {
|
|
8
|
+
"vscode": {
|
|
9
|
+
"settings": {
|
|
10
|
+
"terminal.integrated.profiles.linux": {
|
|
11
|
+
"bash": {
|
|
12
|
+
"path": "/bin/bash"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"terminal.integrated.defaultProfile.linux": "bash",
|
|
16
|
+
"files.autoSave": "afterDelay",
|
|
17
|
+
"files.autoSaveDelay": 1000,
|
|
18
|
+
"editor.formatOnSave": true
|
|
19
|
+
},
|
|
20
|
+
"extensions": [
|
|
21
|
+
"ms-vscode-remote.vscode-remote-extensionpack",
|
|
22
|
+
"ms-vscode.vscode-typescript-next",
|
|
23
|
+
"ms-vsliveshare.vsliveshare",
|
|
24
|
+
"esbenp.prettier-vscode",
|
|
25
|
+
"usernamehw.errorlens",
|
|
26
|
+
"VisualStudioExptTeam.vscodeintellicode",
|
|
27
|
+
"VisualStudioExptTeam.intellicode-api-usage-examples",
|
|
28
|
+
"wraith13.bracket-lens",
|
|
29
|
+
"oderwat.indent-rainbow",
|
|
30
|
+
"mosapride.zenkaku",
|
|
31
|
+
"vscode-icons-team.vscode-icons",
|
|
32
|
+
"nickdemayo.vscode-json-editor"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/.github/CONTRIBUTING.md
CHANGED
|
@@ -10,7 +10,9 @@ Submit a new issue only if you are sure it is a missing feature or a bug.
|
|
|
10
10
|
|
|
11
11
|
4. Run unit tests to ensure all features work well. Run: `npm test`
|
|
12
12
|
|
|
13
|
-
5.
|
|
13
|
+
5. Please add at least one unit test if you are going to add new feature.
|
|
14
|
+
|
|
15
|
+
6. Make sure `charites` command work well after installing globally. Run:
|
|
14
16
|
|
|
15
17
|
```bash
|
|
16
18
|
npm uninstall -g .
|
|
@@ -19,11 +21,11 @@ npm install -g
|
|
|
19
21
|
charites help
|
|
20
22
|
```
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
7. Make sure you submit a change specific to exactly one issue. If you have ideas for multiple changes please create separate pull requests.
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
8. Make sure update documentation under `docs` folder if your changes affect existing documents.
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
9. Push to your fork and [submit a pull request](https://help.github.com/articles/using-pull-requests). A button should appear on your fork its github page afterwards.
|
|
27
29
|
|
|
28
30
|
## Translation of charites documentation
|
|
29
31
|
|
|
@@ -18,7 +18,8 @@ Please describe what you changed briefly.
|
|
|
18
18
|
- [ ] No build errors after `npm run build`
|
|
19
19
|
- [ ] No lint errors after `npm run lint`
|
|
20
20
|
- [ ] No errors on using `charites help` globally
|
|
21
|
-
- [ ] Make sure all the
|
|
21
|
+
- [ ] Make sure all the existing features working well
|
|
22
|
+
- [ ] Have you added at least one unit test if you are going to add new feature?
|
|
22
23
|
- [ ] Have you updated documentation?
|
|
23
24
|
<!-- ignore-task-list-end -->
|
|
24
25
|
|
|
@@ -15,11 +15,9 @@ on:
|
|
|
15
15
|
jobs:
|
|
16
16
|
build:
|
|
17
17
|
runs-on: ubuntu-latest
|
|
18
|
-
|
|
19
18
|
strategy:
|
|
20
19
|
matrix:
|
|
21
|
-
node-version: [14.x, 16.x]
|
|
22
|
-
|
|
20
|
+
node-version: [14.x, 16.x, 18.x]
|
|
23
21
|
steps:
|
|
24
22
|
- uses: actions/checkout@v2
|
|
25
23
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
@@ -30,6 +28,33 @@ jobs:
|
|
|
30
28
|
- run: npm run lint
|
|
31
29
|
- run: npm test
|
|
32
30
|
|
|
31
|
+
e2e:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
strategy:
|
|
34
|
+
matrix:
|
|
35
|
+
node-version: [18.x]
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v2
|
|
38
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
39
|
+
uses: actions/setup-node@v1
|
|
40
|
+
with:
|
|
41
|
+
node-version: ${{ matrix.node-version }}
|
|
42
|
+
- name: Check and restore cache of playwright
|
|
43
|
+
uses: actions/cache@v3
|
|
44
|
+
id: playwright-cache
|
|
45
|
+
with:
|
|
46
|
+
path: |
|
|
47
|
+
~/.cache/ms-playwright
|
|
48
|
+
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
|
|
49
|
+
- run: npm install
|
|
50
|
+
- run: npx playwright install --with-deps chromium
|
|
51
|
+
if: steps.playwright-cache.outputs.cache-hit != 'true'
|
|
52
|
+
- run: npm run build
|
|
53
|
+
- run: chmod 777 dist/cli.js
|
|
54
|
+
- run: npm run test:e2e
|
|
55
|
+
env:
|
|
56
|
+
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
|
57
|
+
|
|
33
58
|
publish:
|
|
34
59
|
name: 'Publish npm package'
|
|
35
60
|
runs-on: ubuntu-latest
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2022 The United Nations Vector Tile Toolkit
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Charites
|
|
2
2
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
3
|
-
[](#contributors-)
|
|
4
4
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
5
5
|
|
|
6
6
|
An easy, intuitive, and efficient command-line tool for writing vector map styles compatible with the [Mapbox](https://docs.mapbox.com/mapbox-gl-js/style-spec/) and [MapLibre](https://maplibre.org/maplibre-gl-js-docs/style-spec/) Style Specification in YAML.
|
|
@@ -37,14 +37,19 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
37
37
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
38
38
|
<!-- prettier-ignore-start -->
|
|
39
39
|
<!-- markdownlint-disable -->
|
|
40
|
-
|
|
41
40
|
<table>
|
|
42
41
|
<tr>
|
|
43
42
|
<td align="center"><a href="https://geolonia.com/"><img src="https://avatars.githubusercontent.com/u/42296593?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Geolonia</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=geolonia" title="Code">💻</a></td>
|
|
43
|
+
<td align="center"><a href="https://naoki-is.me"><img src="https://avatars.githubusercontent.com/u/8760841?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Naoki Ohashi</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=naogify" title="Code">💻</a></td>
|
|
44
|
+
<td align="center"><a href="https://github.com/ubukawa"><img src="https://avatars.githubusercontent.com/u/59204379?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UBUKAWA Taro</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=ubukawa" title="Code">💻</a></td>
|
|
45
|
+
<td align="center"><a href="https://geolonia.com/"><img src="https://avatars.githubusercontent.com/u/309946?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Takayuki Miyauchi</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=miya0001" title="Code">💻</a></td>
|
|
46
|
+
<td align="center"><a href="https://jin-igarashi.me"><img src="https://avatars.githubusercontent.com/u/2639701?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jin Igarashi</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=JinIgarashi" title="Code">💻</a></td>
|
|
47
|
+
<td align="center"><a href="http://smellman.hatenablog.com/"><img src="https://avatars.githubusercontent.com/u/135112?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Taro Matsuzawa aka. btm</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=smellman" title="Code">💻</a></td>
|
|
48
|
+
<td align="center"><a href="https://shinichi.blog"><img src="https://avatars.githubusercontent.com/u/1124652?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Shinichi Nishikawa</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=ShinichiNishikawa" title="Documentation">📖</a></td>
|
|
49
|
+
<td align="center"><a href="http://yuiseki.net/"><img src="https://avatars.githubusercontent.com/u/25507?v=4?s=100" width="100px;" alt=""/><br /><sub><b>yuiseki</b></sub></a><br /><a href="https://github.com/unvt/charites/commits?author=yuiseki" title="Code">💻</a></td>
|
|
44
50
|
</tr>
|
|
45
51
|
</table>
|
|
46
52
|
|
|
47
|
-
|
|
48
53
|
<!-- markdownlint-restore -->
|
|
49
54
|
<!-- prettier-ignore-end -->
|
|
50
55
|
|
package/dist/cli/serve.js
CHANGED
|
@@ -14,7 +14,7 @@ program
|
|
|
14
14
|
.arguments('<source>')
|
|
15
15
|
.description('serve your map locally')
|
|
16
16
|
.option('--provider [provider]', 'your map service. e.g. `mapbox`, `geolonia`')
|
|
17
|
-
.option('--mapbox-access-token [mapboxAccessToken]', 'Access Token
|
|
17
|
+
.option('--mapbox-access-token [mapboxAccessToken]', 'Your Mapbox Access Token (required if using the `mapbox` provider)')
|
|
18
18
|
.option('--port [port]', 'Specify custom port')
|
|
19
19
|
.action((source, serveOptions) => {
|
|
20
20
|
const options = program.opts();
|
package/dist/commands/serve.js
CHANGED
|
@@ -30,14 +30,19 @@ function serve(source, options) {
|
|
|
30
30
|
if (!fs_1.default.existsSync(sourcePath)) {
|
|
31
31
|
throw `${sourcePath}: No such file or directory`;
|
|
32
32
|
}
|
|
33
|
+
const mapboxAccessToken = options.mapboxAccessToken || defaultValues_1.defaultValues.mapboxAccessToken;
|
|
34
|
+
if (provider === 'mapbox' && !mapboxAccessToken) {
|
|
35
|
+
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)`;
|
|
36
|
+
}
|
|
33
37
|
const server = http_1.default.createServer((req, res) => {
|
|
34
38
|
const url = (req.url || '').replace(/\?.*/, '');
|
|
35
|
-
const
|
|
39
|
+
const defaultProviderDir = path_1.default.join(defaultValues_1.defaultValues.providerDir, 'default');
|
|
40
|
+
const providerDir = path_1.default.join(defaultValues_1.defaultValues.providerDir, provider);
|
|
36
41
|
switch (url) {
|
|
37
42
|
case '/':
|
|
38
43
|
res.statusCode = 200;
|
|
39
44
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
|
40
|
-
const content = fs_1.default.readFileSync(path_1.default.join(
|
|
45
|
+
const content = fs_1.default.readFileSync(path_1.default.join(providerDir, 'index.html'), 'utf-8');
|
|
41
46
|
res.end(content);
|
|
42
47
|
break;
|
|
43
48
|
case '/style.json':
|
|
@@ -56,14 +61,21 @@ function serve(source, options) {
|
|
|
56
61
|
case '/app.css':
|
|
57
62
|
res.statusCode = 200;
|
|
58
63
|
res.setHeader('Content-Type', 'text/css; charset=UTF-8');
|
|
59
|
-
const css = fs_1.default.readFileSync(path_1.default.join(
|
|
64
|
+
const css = fs_1.default.readFileSync(path_1.default.join(defaultProviderDir, 'app.css'), 'utf-8');
|
|
60
65
|
res.end(css);
|
|
61
66
|
break;
|
|
67
|
+
case `/shared.js`:
|
|
68
|
+
res.statusCode = 200;
|
|
69
|
+
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
70
|
+
const shared = fs_1.default.readFileSync(path_1.default.join(defaultProviderDir, 'shared.js'), 'utf-8');
|
|
71
|
+
const js = shared.replace('___PORT___', `${port}`);
|
|
72
|
+
res.end(js);
|
|
73
|
+
break;
|
|
62
74
|
case `/app.js`:
|
|
63
75
|
res.statusCode = 200;
|
|
64
76
|
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
65
77
|
try {
|
|
66
|
-
const app = fs_1.default.readFileSync(path_1.default.join(
|
|
78
|
+
const app = fs_1.default.readFileSync(path_1.default.join(providerDir, 'app.js'), 'utf-8');
|
|
67
79
|
const js = app
|
|
68
80
|
.replace('___PORT___', `${port}`)
|
|
69
81
|
.replace('___MAPBOX_ACCESS_TOKEN___', `${options.mapboxAccessToken || defaultValues_1.defaultValues.mapboxAccessToken}`);
|
|
@@ -73,6 +85,11 @@ function serve(source, options) {
|
|
|
73
85
|
throw `Invalid provider: ${provider}`;
|
|
74
86
|
}
|
|
75
87
|
break;
|
|
88
|
+
default:
|
|
89
|
+
res.statusCode = 404;
|
|
90
|
+
res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
|
|
91
|
+
res.end('Not found');
|
|
92
|
+
break;
|
|
76
93
|
}
|
|
77
94
|
});
|
|
78
95
|
server.listen(port, () => {
|
package/dist/lib/build-sprite.js
CHANGED
|
@@ -1,71 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildSprite = void 0;
|
|
4
|
-
const
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const glob = require('glob');
|
|
4
|
+
const sprite_one_1 = require("@unvt/sprite-one");
|
|
7
5
|
const path = require('path');
|
|
8
|
-
function generateLayoutAsync(option) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
spritezero.generateLayout(option, (err, result) => {
|
|
11
|
-
if (err)
|
|
12
|
-
reject(err);
|
|
13
|
-
else
|
|
14
|
-
resolve(result);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function generateImageAsync(option) {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
spritezero.generateImage(option, (err, result) => {
|
|
21
|
-
if (err)
|
|
22
|
-
reject(err);
|
|
23
|
-
else
|
|
24
|
-
resolve(result);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
6
|
async function buildSprite(svgPath, publicPath, iconSlug) {
|
|
29
7
|
const pxRatios = [1, 2];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
svg: fs.readFileSync(iconPath),
|
|
37
|
-
id: path.basename(iconPath).replace('.svg', ''),
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
let file = '';
|
|
41
|
-
if (pxRatio > 1) {
|
|
42
|
-
file = `@${pxRatio}x`;
|
|
43
|
-
}
|
|
44
|
-
const pngPath = path.join(publicPath, `${iconSlug}${file}.png`);
|
|
45
|
-
const jsonPath = path.join(publicPath, `${iconSlug}${file}.json`);
|
|
46
|
-
try {
|
|
47
|
-
const dataLayout = await generateLayoutAsync({
|
|
48
|
-
imgs: svgFiles,
|
|
49
|
-
pixelRatio: pxRatio,
|
|
50
|
-
format: true,
|
|
51
|
-
});
|
|
52
|
-
fs.writeFileSync(jsonPath, JSON.stringify(dataLayout));
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw `${publicPath}: No such file or directory`;
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
const imageLayout = await generateLayoutAsync({
|
|
59
|
-
imgs: svgFiles,
|
|
60
|
-
pixelRatio: pxRatio,
|
|
61
|
-
format: false,
|
|
62
|
-
});
|
|
63
|
-
const image = await generateImageAsync(imageLayout);
|
|
64
|
-
fs.writeFileSync(pngPath, image);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
throw `${publicPath}: No such file or directory`;
|
|
68
|
-
}
|
|
8
|
+
const outPath = path.join(publicPath, iconSlug);
|
|
9
|
+
try {
|
|
10
|
+
await sprite_one_1.generateSprite(outPath, [svgPath], pxRatios);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
throw error;
|
|
69
14
|
}
|
|
15
|
+
return;
|
|
70
16
|
}
|
|
71
17
|
exports.buildSprite = buildSprite;
|
package/dist/lib/error.js
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.error = void 0;
|
|
4
4
|
exports.error = (e) => {
|
|
5
|
-
if (e instanceof
|
|
5
|
+
if (e instanceof Error) {
|
|
6
6
|
console.error(e.message);
|
|
7
7
|
}
|
|
8
|
+
else {
|
|
9
|
+
console.error(String(e));
|
|
10
|
+
}
|
|
8
11
|
process.exit(1);
|
|
9
12
|
};
|
package/dist/lib/yaml-writer.js
CHANGED
|
@@ -35,11 +35,14 @@ const writeDecompositedYaml = (destinationPath, style) => {
|
|
|
35
35
|
const layer = style.layers[i];
|
|
36
36
|
const layerYml = js_yaml_1.default.dump(layer);
|
|
37
37
|
const fileName = `${style.layers[i].id}.yml`;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
fs_1.default.
|
|
38
|
+
const layersDirName = path_1.default.join(path_1.default.dirname(destinationPath), 'layers');
|
|
39
|
+
const filePath = path_1.default.join(layersDirName, fileName);
|
|
40
|
+
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
41
|
+
fs_1.default.writeFileSync(filePath, layerYml);
|
|
42
|
+
// ts-ignore is required here because !!inc/file string is not compatible with the Layer object type.
|
|
43
|
+
// We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
|
|
41
44
|
// @ts-ignore
|
|
42
|
-
layers.push(`!!inc/file ${path_1.default.join('layers', fileName)}`);
|
|
45
|
+
layers.push(`!!inc/file ${path_1.default.posix.join('layers', fileName)}`);
|
|
43
46
|
}
|
|
44
47
|
style.layers = layers;
|
|
45
48
|
fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style).replace(/'\!\!inc\/file layers\/.+\.yml'/g, function (match) {
|
package/docs/source/conf.py
CHANGED
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
# -- Project information -----------------------------------------------------
|
|
19
19
|
|
|
20
20
|
project = 'charites'
|
|
21
|
-
copyright = '
|
|
21
|
+
copyright = '2022, The United Nations Vector Tile Toolkit'
|
|
22
22
|
author = 'Jin Igarashi'
|
|
23
23
|
|
|
24
24
|
# The full version, including alpha/beta/rc tags
|
|
25
|
-
release = '0.
|
|
25
|
+
release = '0.2.0'
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
# -- General configuration ---------------------------------------------------
|
|
@@ -66,4 +66,4 @@ html_context = {
|
|
|
66
66
|
"github_repo": "charites", # Repo name
|
|
67
67
|
"github_version": "main", # Version
|
|
68
68
|
"conf_py_path": "/docs/source/", # Path in the checkout to the docs root
|
|
69
|
-
}
|
|
69
|
+
}
|
package/docs/source/index.rst
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
Charites - Documentation
|
|
7
7
|
====================================
|
|
8
8
|
|
|
9
|
-
:Date:
|
|
9
|
+
:Date: 2022-11-16
|
|
10
10
|
:Copyright: CC-BY-SA
|
|
11
11
|
:Organization: The United Nations Vector Tile Toolkit
|
|
12
|
-
:Version: 0.
|
|
12
|
+
:Version: 0.2.0
|
|
13
13
|
:Abstract: This document contains the complete documentation of Charites, an application to style vector tiles easily
|
|
14
14
|
|
|
15
15
|
.. meta::
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Recommended environment
|
|
2
2
|
=======================
|
|
3
3
|
|
|
4
|
-
Chrities may work well on OSX, Ubuntu,
|
|
4
|
+
Chrities may work well on OSX, Ubuntu, and Raspberry Pi.
|
|
5
5
|
|
|
6
6
|
Docker can be the good environment in Windows while WSL might work well.
|
|
@@ -92,11 +92,11 @@ Realtime editor on browser
|
|
|
92
92
|
|
|
93
93
|
Charites has three options for `serve` command.
|
|
94
94
|
|
|
95
|
-
-
|
|
95
|
+
- ``--provider`` - `mapbox`, `geolonia`, or `default`. When not specified, default or the value in the configuration file will be used.
|
|
96
96
|
|
|
97
97
|
- `mapbox` - The format linter runs against the Mapbox GL JS v2.x compatible specification.
|
|
98
98
|
- `geolonia` and `default` - the format linter runs against the MapLibre GL JS compatible specification.
|
|
99
99
|
|
|
100
|
-
-
|
|
100
|
+
- ``--mapbox-access-token`` - Set your access-token when styling for Mapbox.
|
|
101
101
|
|
|
102
|
-
-
|
|
102
|
+
- ``--port`` - Set http server's port number. When not specified, use 8080 port.
|
|
@@ -29,14 +29,14 @@ Build `style.json` from `style.yml`:
|
|
|
29
29
|
|
|
30
30
|
charites build style.yml style.json
|
|
31
31
|
|
|
32
|
-
Add
|
|
32
|
+
Add ``-c`` or ``--compact-output`` to minify the JSON
|
|
33
33
|
|
|
34
34
|
.. code-block:: bash
|
|
35
35
|
|
|
36
36
|
charites build style.yml style.json -c
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
Add
|
|
39
|
+
Add ``--sprite-input`` and ``--sprite-output`` to build svg files for map icons.
|
|
40
40
|
|
|
41
41
|
.. code-block:: bash
|
|
42
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvt/charites",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"bin": {
|
|
6
6
|
"charites": "dist/cli.js"
|
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
"build": "tsc -p .",
|
|
10
10
|
"watch": "tsc -w",
|
|
11
11
|
"lint": "eslint --fix .",
|
|
12
|
-
"test": "mocha -r ts-node/register test/*.ts",
|
|
12
|
+
"test": "npm run build && mocha -r ts-node/register 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
|
+
"command": "./node_modules/.bin/ts-node ./src/cli.ts"
|
|
15
16
|
},
|
|
16
17
|
"author": "",
|
|
17
18
|
"license": "MIT",
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@mapbox/mapbox-gl-style-spec": "^13.22.0",
|
|
20
|
-
"@mapbox/spritezero": "^8.0.0",
|
|
21
21
|
"@maplibre/maplibre-gl-style-spec": "^14.0.2",
|
|
22
|
+
"@unvt/sprite-one": "^0.0.8",
|
|
22
23
|
"@types/jsonminify": "^0.4.1",
|
|
23
24
|
"axios": "^0.24.0",
|
|
24
25
|
"commander": "^8.2.0",
|
|
@@ -31,7 +32,10 @@
|
|
|
31
32
|
"yaml-include": "^1.2.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
35
|
+
"@playwright/test": "^1.28.1",
|
|
34
36
|
"@types/chai": "^4.2.11",
|
|
37
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
38
|
+
"@types/fs-extra": "^9.0.13",
|
|
35
39
|
"@types/js-yaml": "^4.0.3",
|
|
36
40
|
"@types/mocha": "^7.0.2",
|
|
37
41
|
"@types/node": "^14.0.14",
|
|
@@ -39,9 +43,12 @@
|
|
|
39
43
|
"@typescript-eslint/eslint-plugin": "^4.16.1",
|
|
40
44
|
"@typescript-eslint/parser": "^4.16.1",
|
|
41
45
|
"chai": "^4.2.0",
|
|
46
|
+
"chai-as-promised": "^7.1.1",
|
|
42
47
|
"eslint": "^7.21.0",
|
|
43
48
|
"eslint-config-prettier": "^6.15.0",
|
|
44
49
|
"eslint-plugin-prettier": "^3.3.1",
|
|
50
|
+
"fs-extra": "^10.0.0",
|
|
51
|
+
"kill-port-process": "^3.0.1",
|
|
45
52
|
"mocha": "^8.0.1",
|
|
46
53
|
"prettier": "^2.5.0",
|
|
47
54
|
"ts-node": "^8.10.2",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// playwright.config.ts
|
|
2
|
+
import type { PlaywrightTestConfig } from '@playwright/test'
|
|
3
|
+
|
|
4
|
+
const config: PlaywrightTestConfig = {
|
|
5
|
+
testDir: 'test/playwright',
|
|
6
|
+
use: {
|
|
7
|
+
browserName: 'chromium',
|
|
8
|
+
headless: true,
|
|
9
|
+
},
|
|
10
|
+
workers: 3,
|
|
11
|
+
webServer: [
|
|
12
|
+
{
|
|
13
|
+
command: 'dist/cli.js serve test/data/style.yml --port 8080',
|
|
14
|
+
port: 8080,
|
|
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
|
+
],
|
|
28
|
+
}
|
|
29
|
+
export default config
|