@unvt/charites 0.3.0 → 0.4.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/.eslintrc.js +1 -1
- package/.github/workflows/build-docs.yml +4 -4
- package/.github/workflows/build.yml +8 -7
- package/dist/cli/build.js +4 -4
- package/dist/cli/convert.js +2 -2
- package/dist/cli/init.js +3 -3
- package/dist/cli/serve.js +7 -3
- package/dist/commands/build.js +7 -12
- package/dist/commands/convert.js +2 -12
- package/dist/commands/init.js +1 -1
- package/dist/commands/serve.js +65 -12
- package/dist/lib/build-sprite.js +6 -8
- package/dist/lib/error.js +2 -1
- package/dist/lib/tileinfo-importer/index.js +1 -0
- package/dist/lib/yaml-writer.js +21 -12
- package/dist/types/index.js +6 -2
- package/docs/Pipfile.lock +136 -193
- package/docs/source/index.rst +2 -2
- package/docs/source/install/img/windows-guide-01.png +0 -0
- package/docs/source/install/index.rst +1 -0
- package/docs/source/install/install.rst +1 -0
- package/docs/source/install/install_on_nanban.rst +1 -1
- package/docs/source/install/installation_guide_for_windows.rst +52 -0
- package/docs/source/install/recommended_environment.rst +2 -2
- package/docs/source/usage/commandline_interface.rst +21 -8
- package/docs/source/usage/example2.rst +166 -0
- package/docs/source/usage/img/example02-001.png +0 -0
- package/docs/source/usage/img/example02-002.png +0 -0
- package/docs/source/usage/img/example02-003.png +0 -0
- package/docs/source/usage/img/example02-004.png +0 -0
- package/docs/source/usage/img/example02-005.png +0 -0
- package/docs/source/usage/img/example02-006.png +0 -0
- package/docs/source/usage/img/example02-007.png +0 -0
- package/docs/source/usage/img/example02-008.png +0 -0
- package/docs/source/usage/img/example02-009.png +0 -0
- package/docs/source/usage/img/example02-010.png +0 -0
- package/docs/source/usage/img/example02-011.png +0 -0
- package/docs/source/usage/img/example02-012.png +0 -0
- package/docs/source/usage/img/example02-013.png +0 -0
- package/docs/source/usage/img/example02-014.png +0 -0
- package/docs/source/usage/img/example02-015.png +0 -0
- package/docs/source/usage/img/example02-016.png +0 -0
- package/docs/source/usage/img/example02-017.png +0 -0
- package/docs/source/usage/img/example02-018.png +0 -0
- package/docs/source/usage/index.rst +1 -0
- package/package.json +31 -29
- package/provider/default/app.js +1 -3
- package/provider/default/index.html +2 -2
- package/provider/default/shared.js +11 -2
- package/provider/geolonia/app.js +1 -3
- package/provider/mapbox/app.js +1 -3
- package/src/cli/init.ts +1 -1
- package/src/cli/serve.ts +9 -2
- package/src/commands/build.ts +2 -6
- package/src/commands/convert.ts +2 -10
- package/src/commands/init.ts +1 -1
- package/src/commands/serve.ts +80 -11
- package/src/lib/build-sprite.ts +2 -6
- package/src/lib/get-sprite-slug.ts +1 -1
- package/src/lib/tileinfo-importer/base-importer.ts +1 -1
- package/src/lib/tileinfo-importer/metadata-importer.ts +1 -1
- package/src/lib/tileinfo-importer/tilejson-importer.ts +1 -1
- package/src/lib/validate-style.ts +1 -1
- package/src/lib/yaml-parser.ts +1 -1
- package/src/lib/yaml-writer.ts +23 -14
- package/test/build.spec.ts +2 -2
- package/test/command.serve.spec.ts +103 -0
- package/test/convert.spec.ts +24 -4
- package/test/data/convert.json +7 -0
- package/test/init.spec.ts +7 -5
- package/test/util/charitesCmd.ts +3 -1
- package/test/util/execPromise.ts +51 -1
- package/test/util/index.ts +3 -0
- package/test/validate-style.spec.ts +1 -1
package/.eslintrc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
name: Build and Deploy docs
|
|
2
2
|
|
|
3
|
-
on:
|
|
3
|
+
on:
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
6
|
- main
|
|
@@ -21,9 +21,9 @@ jobs:
|
|
|
21
21
|
TX_TOKEN: ${{ secrets.TX_TOKEN }}
|
|
22
22
|
|
|
23
23
|
steps:
|
|
24
|
-
- uses: actions/checkout@
|
|
24
|
+
- uses: actions/checkout@v3
|
|
25
25
|
- name: Set up Python 3.9
|
|
26
|
-
uses: actions/setup-python@
|
|
26
|
+
uses: actions/setup-python@v4
|
|
27
27
|
with:
|
|
28
28
|
python-version: 3.9
|
|
29
29
|
|
|
@@ -65,7 +65,7 @@ jobs:
|
|
|
65
65
|
touch ./build/html/.nojekyll
|
|
66
66
|
|
|
67
67
|
- name: Deploy 🚀
|
|
68
|
-
uses: JamesIves/github-pages-deploy-action@
|
|
68
|
+
uses: JamesIves/github-pages-deploy-action@v4
|
|
69
69
|
if: ${{ github.ref == 'refs/heads/main' }}
|
|
70
70
|
with:
|
|
71
71
|
branch: gh-pages # The branch the action should deploy to.
|
|
@@ -14,14 +14,15 @@ on:
|
|
|
14
14
|
|
|
15
15
|
jobs:
|
|
16
16
|
build:
|
|
17
|
-
runs-on: ubuntu-latest
|
|
18
17
|
strategy:
|
|
19
18
|
matrix:
|
|
20
19
|
node-version: [14.x, 16.x, 18.x]
|
|
20
|
+
os: [ubuntu-latest, windows-latest]
|
|
21
|
+
runs-on: ${{ matrix.os }}
|
|
21
22
|
steps:
|
|
22
|
-
- uses: actions/checkout@
|
|
23
|
+
- uses: actions/checkout@v3
|
|
23
24
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
24
|
-
uses: actions/setup-node@
|
|
25
|
+
uses: actions/setup-node@v3
|
|
25
26
|
with:
|
|
26
27
|
node-version: ${{ matrix.node-version }}
|
|
27
28
|
- run: npm install
|
|
@@ -34,9 +35,9 @@ jobs:
|
|
|
34
35
|
matrix:
|
|
35
36
|
node-version: [18.x]
|
|
36
37
|
steps:
|
|
37
|
-
- uses: actions/checkout@
|
|
38
|
+
- uses: actions/checkout@v3
|
|
38
39
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
39
|
-
uses: actions/setup-node@
|
|
40
|
+
uses: actions/setup-node@v3
|
|
40
41
|
with:
|
|
41
42
|
node-version: ${{ matrix.node-version }}
|
|
42
43
|
- name: Check and restore cache of playwright
|
|
@@ -61,9 +62,9 @@ jobs:
|
|
|
61
62
|
needs: build
|
|
62
63
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
63
64
|
steps:
|
|
64
|
-
- uses: actions/checkout@
|
|
65
|
+
- uses: actions/checkout@v3
|
|
65
66
|
# Setup .npmrc file to publish to npm
|
|
66
|
-
- uses: actions/setup-node@
|
|
67
|
+
- uses: actions/setup-node@v3
|
|
67
68
|
with:
|
|
68
69
|
tag_name: 'v%s'
|
|
69
70
|
node-version: '14.x'
|
package/dist/cli/build.js
CHANGED
|
@@ -40,7 +40,7 @@ program
|
|
|
40
40
|
try {
|
|
41
41
|
console.log('Start watching...');
|
|
42
42
|
await new Promise((resolve) => {
|
|
43
|
-
const watcher = build_1.buildWatch(source, destination, options);
|
|
43
|
+
const watcher = (0, build_1.buildWatch)(source, destination, options);
|
|
44
44
|
process.on('SIGINT', () => {
|
|
45
45
|
watcher.close();
|
|
46
46
|
resolve(undefined);
|
|
@@ -48,15 +48,15 @@ program
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
|
51
|
-
error_1.error(e);
|
|
51
|
+
(0, error_1.error)(e);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
try {
|
|
56
|
-
await build_1.build(source, destination, options);
|
|
56
|
+
await (0, build_1.build)(source, destination, options);
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
59
|
-
error_1.error(e);
|
|
59
|
+
(0, error_1.error)(e);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
});
|
package/dist/cli/convert.js
CHANGED
|
@@ -10,10 +10,10 @@ program
|
|
|
10
10
|
.description('convert the style JSON to YAML')
|
|
11
11
|
.action((source, destination) => {
|
|
12
12
|
try {
|
|
13
|
-
convert_1.convert(source, destination);
|
|
13
|
+
(0, convert_1.convert)(source, destination);
|
|
14
14
|
}
|
|
15
15
|
catch (e) {
|
|
16
|
-
error_1.error(e);
|
|
16
|
+
(0, error_1.error)(e);
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
exports.default = program;
|
package/dist/cli/init.js
CHANGED
|
@@ -7,7 +7,7 @@ const program = new commander_1.Command();
|
|
|
7
7
|
program
|
|
8
8
|
.name('init')
|
|
9
9
|
.arguments('<file>')
|
|
10
|
-
.description('initialize a style
|
|
10
|
+
.description('initialize a style YAML')
|
|
11
11
|
.option('-t, --tilejson-urls <tilejson_urls>', 'an URL for TileJSON. It will create empty layers from vector_layers property of TileJSON. Please use comma (,) in case multiple TileJSONs require.')
|
|
12
12
|
.option('-m, --metadatajson-urls <metadatajson_urls>', 'an URL for metadata.json. It will create empty layers from vector_layers property of metadata.json. Please use comma (,) in case multiple metadata.json require.')
|
|
13
13
|
.option('-c, --composite-layers', 'If it is true, a single YAML will be generated with multiple layers. Default is false.')
|
|
@@ -17,10 +17,10 @@ program
|
|
|
17
17
|
options.metadatajsonUrls = initOptions.metadatajsonUrls;
|
|
18
18
|
options.compositeLayers = initOptions.compositeLayers;
|
|
19
19
|
try {
|
|
20
|
-
await init_1.init(file, options);
|
|
20
|
+
await (0, init_1.init)(file, options);
|
|
21
21
|
}
|
|
22
22
|
catch (e) {
|
|
23
|
-
error_1.error(e);
|
|
23
|
+
(0, error_1.error)(e);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
exports.default = program;
|
package/dist/cli/serve.js
CHANGED
|
@@ -15,20 +15,24 @@ program
|
|
|
15
15
|
.description('serve your map locally')
|
|
16
16
|
.option('--provider [provider]', 'your map service. e.g. `mapbox`, `geolonia`')
|
|
17
17
|
.option('--mapbox-access-token [mapboxAccessToken]', 'Your Mapbox Access Token (required if using the `mapbox` provider)')
|
|
18
|
+
.option('-i, --sprite-input [<icon input directory>]', 'directory path of icon source to build icons. The default <icon source> is `icons/`')
|
|
18
19
|
.option('--port [port]', 'Specify custom port')
|
|
19
|
-
.
|
|
20
|
+
.option('--no-open', "Don't open the preview in the default browser")
|
|
21
|
+
.action(async (source, serveOptions) => {
|
|
20
22
|
const options = program.opts();
|
|
21
23
|
options.provider = serveOptions.provider;
|
|
22
24
|
options.mapboxAccessToken = serveOptions.mapboxAccessToken;
|
|
23
25
|
options.port = serveOptions.port;
|
|
26
|
+
options.spriteInput = serveOptions.spriteInput;
|
|
27
|
+
options.open = serveOptions.open;
|
|
24
28
|
if (!fs_1.default.existsSync(defaultValues_1.defaultSettings.configFile)) {
|
|
25
29
|
fs_1.default.writeFileSync(defaultValues_1.defaultSettings.configFile, `provider: ${options.provider || 'default'}`);
|
|
26
30
|
}
|
|
27
31
|
try {
|
|
28
|
-
serve_1.serve(source, program.opts());
|
|
32
|
+
await (0, serve_1.serve)(source, program.opts());
|
|
29
33
|
}
|
|
30
34
|
catch (e) {
|
|
31
|
-
error_1.error(e);
|
|
35
|
+
(0, error_1.error)(e);
|
|
32
36
|
}
|
|
33
37
|
});
|
|
34
38
|
exports.default = program;
|
package/dist/commands/build.js
CHANGED
|
@@ -40,8 +40,8 @@ async function build(source, destination, options) {
|
|
|
40
40
|
}
|
|
41
41
|
let style = '';
|
|
42
42
|
try {
|
|
43
|
-
const _style = yaml_parser_1.parser(sourcePath);
|
|
44
|
-
validate_style_1.validateStyle(_style, provider);
|
|
43
|
+
const _style = (0, yaml_parser_1.parser)(sourcePath);
|
|
44
|
+
(0, validate_style_1.validateStyle)(_style, provider);
|
|
45
45
|
if (options.spriteUrl && 'sprite' in _style) {
|
|
46
46
|
_style.sprite = options.spriteUrl;
|
|
47
47
|
}
|
|
@@ -53,14 +53,14 @@ async function build(source, destination, options) {
|
|
|
53
53
|
if (!fs_1.default.existsSync(options.spriteOutput)) {
|
|
54
54
|
throw `${options.spriteOutput}: No such directory. Please specify valid icon output directory. For more help run charites build --help`;
|
|
55
55
|
}
|
|
56
|
-
const iconSlug = get_sprite_slug_1.getSpriteSlug(JSON.parse(style));
|
|
56
|
+
const iconSlug = (0, get_sprite_slug_1.getSpriteSlug)(JSON.parse(style));
|
|
57
57
|
if (!iconSlug) {
|
|
58
58
|
throw `Invalid sprite url format.`;
|
|
59
59
|
}
|
|
60
|
-
await build_sprite_1.buildSprite(options.spriteInput, options.spriteOutput, iconSlug);
|
|
60
|
+
await (0, build_sprite_1.buildSprite)(options.spriteInput, options.spriteOutput, iconSlug);
|
|
61
61
|
}
|
|
62
62
|
if (options.compactOutput) {
|
|
63
|
-
style = jsonminify_1.default(style);
|
|
63
|
+
style = (0, jsonminify_1.default)(style);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
catch (err) {
|
|
@@ -71,12 +71,7 @@ async function build(source, destination, options) {
|
|
|
71
71
|
throw `${sourcePath}: Invalid YAML syntax`;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
fs_1.default.writeFileSync(destinationPath, style);
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
throw `${destinationPath}: Permission denied`;
|
|
79
|
-
}
|
|
74
|
+
fs_1.default.writeFileSync(destinationPath, style);
|
|
80
75
|
}
|
|
81
76
|
exports.build = build;
|
|
82
77
|
function buildWatch(source, destination, options) {
|
|
@@ -85,7 +80,7 @@ function buildWatch(source, destination, options) {
|
|
|
85
80
|
sourcePath = source;
|
|
86
81
|
}
|
|
87
82
|
console.log(path_1.default.dirname(sourcePath));
|
|
88
|
-
return node_watch_1.default(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
|
|
83
|
+
return (0, node_watch_1.default)(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
|
|
89
84
|
console.log(`${(event || '').toUpperCase()}: ${file}`);
|
|
90
85
|
try {
|
|
91
86
|
build(source, destination, options);
|
package/dist/commands/convert.js
CHANGED
|
@@ -42,12 +42,7 @@ function convert(source, destination) {
|
|
|
42
42
|
rl.on('close', () => {
|
|
43
43
|
const style = JSON.parse(lines.join(''));
|
|
44
44
|
const destinationPath = getDestinationPath(destination);
|
|
45
|
-
|
|
46
|
-
yaml_writer_1.writeYaml(destinationPath, style, false);
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
throw `${destinationPath}: Permission denied`;
|
|
50
|
-
}
|
|
45
|
+
(0, yaml_writer_1.writeYaml)(destinationPath, style, false);
|
|
51
46
|
});
|
|
52
47
|
}
|
|
53
48
|
else {
|
|
@@ -61,12 +56,7 @@ function convert(source, destination) {
|
|
|
61
56
|
}
|
|
62
57
|
style = JSON.parse(fs_1.default.readFileSync(sourcePath, 'utf-8'));
|
|
63
58
|
const destinationPath = getDestinationPath(destination, sourcePath);
|
|
64
|
-
|
|
65
|
-
yaml_writer_1.writeYaml(destinationPath, style, false);
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
throw `${destinationPath}: Permission denied`;
|
|
69
|
-
}
|
|
59
|
+
(0, yaml_writer_1.writeYaml)(destinationPath, style, false);
|
|
70
60
|
}
|
|
71
61
|
}
|
|
72
62
|
exports.convert = convert;
|
package/dist/commands/init.js
CHANGED
|
@@ -21,6 +21,6 @@ async function init(file, options) {
|
|
|
21
21
|
const metadataJSONImporter = new tileinfo_importer_1.MetadataJSONImporter(options.metadatajsonUrls);
|
|
22
22
|
styleTemplate = await metadataJSONImporter.import(styleTemplate);
|
|
23
23
|
}
|
|
24
|
-
yaml_writer_1.writeYaml(file, styleTemplate, options.compositeLayers);
|
|
24
|
+
(0, yaml_writer_1.writeYaml)(file, styleTemplate, options.compositeLayers);
|
|
25
25
|
}
|
|
26
26
|
exports.init = init;
|
package/dist/commands/serve.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.serve = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
9
10
|
const http_1 = __importDefault(require("http"));
|
|
10
11
|
const open_1 = __importDefault(require("open"));
|
|
11
12
|
const ws_1 = require("ws");
|
|
@@ -13,7 +14,8 @@ const node_watch_1 = __importDefault(require("node-watch"));
|
|
|
13
14
|
const yaml_parser_1 = require("../lib/yaml-parser");
|
|
14
15
|
const validate_style_1 = require("../lib/validate-style");
|
|
15
16
|
const defaultValues_1 = require("../lib/defaultValues");
|
|
16
|
-
|
|
17
|
+
const build_sprite_1 = require("../lib/build-sprite");
|
|
18
|
+
async function serve(source, options) {
|
|
17
19
|
let port = process.env.PORT || 8080;
|
|
18
20
|
if (options.port) {
|
|
19
21
|
port = Number(options.port);
|
|
@@ -34,10 +36,38 @@ function serve(source, options) {
|
|
|
34
36
|
if (provider === 'mapbox' && !mapboxAccessToken) {
|
|
35
37
|
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
38
|
}
|
|
37
|
-
|
|
39
|
+
let spriteOut = undefined;
|
|
40
|
+
let spriteRefresher = undefined;
|
|
41
|
+
if (options.spriteInput) {
|
|
42
|
+
spriteOut = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'charites-'));
|
|
43
|
+
spriteRefresher = async () => {
|
|
44
|
+
if (typeof options.spriteInput === 'undefined' ||
|
|
45
|
+
typeof spriteOut === 'undefined') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await (0, build_sprite_1.buildSprite)(options.spriteInput, spriteOut, 'sprite');
|
|
49
|
+
};
|
|
50
|
+
await spriteRefresher();
|
|
51
|
+
}
|
|
52
|
+
const server = http_1.default.createServer(async (req, res) => {
|
|
38
53
|
const url = (req.url || '').replace(/\?.*/, '');
|
|
39
54
|
const defaultProviderDir = path_1.default.join(defaultValues_1.defaultValues.providerDir, 'default');
|
|
40
55
|
const providerDir = path_1.default.join(defaultValues_1.defaultValues.providerDir, provider);
|
|
56
|
+
if (typeof spriteOut !== 'undefined' &&
|
|
57
|
+
url.match(/^\/sprite(@2x)?\.(json|png)/)) {
|
|
58
|
+
res.statusCode = 200;
|
|
59
|
+
if (url.endsWith('.json')) {
|
|
60
|
+
res.setHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
res.setHeader('Content-Type', 'image/png');
|
|
64
|
+
}
|
|
65
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
66
|
+
const filename = path_1.default.basename(url);
|
|
67
|
+
const fsStream = fs_1.default.createReadStream(path_1.default.join(spriteOut, filename));
|
|
68
|
+
fsStream.pipe(res);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
41
71
|
switch (url) {
|
|
42
72
|
case '/':
|
|
43
73
|
res.statusCode = 200;
|
|
@@ -48,14 +78,18 @@ function serve(source, options) {
|
|
|
48
78
|
case '/style.json':
|
|
49
79
|
let style;
|
|
50
80
|
try {
|
|
51
|
-
style = yaml_parser_1.parser(sourcePath);
|
|
52
|
-
|
|
81
|
+
style = (0, yaml_parser_1.parser)(sourcePath);
|
|
82
|
+
if (typeof spriteOut !== 'undefined') {
|
|
83
|
+
style.sprite = `http://${req.headers.host || `localhost:${port}`}/sprite`;
|
|
84
|
+
}
|
|
85
|
+
(0, validate_style_1.validateStyle)(style, provider);
|
|
53
86
|
}
|
|
54
87
|
catch (error) {
|
|
55
88
|
console.log(error);
|
|
56
89
|
}
|
|
57
90
|
res.statusCode = 200;
|
|
58
91
|
res.setHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
92
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
59
93
|
res.end(JSON.stringify(style));
|
|
60
94
|
break;
|
|
61
95
|
case '/app.css':
|
|
@@ -96,26 +130,45 @@ function serve(source, options) {
|
|
|
96
130
|
console.log(`Provider: ${provider}`);
|
|
97
131
|
console.log(`Loading your style: ${sourcePath}`);
|
|
98
132
|
console.log(`Your map is running on http://localhost:${port}/\n`);
|
|
99
|
-
|
|
133
|
+
if (options.open) {
|
|
134
|
+
(0, open_1.default)(`http://localhost:${port}`);
|
|
135
|
+
}
|
|
100
136
|
});
|
|
101
137
|
const wss = new ws_1.WebSocketServer({ server });
|
|
102
138
|
wss.on('connection', (ws) => {
|
|
103
|
-
node_watch_1.default(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
|
|
139
|
+
const watcher = (0, node_watch_1.default)(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$|\.svg$/i }, (event, file) => {
|
|
104
140
|
console.log(`${(event || '').toUpperCase()}: ${file}`);
|
|
105
141
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
142
|
+
if (file === null || file === void 0 ? void 0 : file.toLowerCase().endsWith('.yml')) {
|
|
143
|
+
ws.send(JSON.stringify({
|
|
144
|
+
event: 'styleUpdate',
|
|
145
|
+
}));
|
|
109
146
|
}
|
|
110
|
-
|
|
111
|
-
|
|
147
|
+
else if ((file === null || file === void 0 ? void 0 : file.toLowerCase().endsWith('.svg')) &&
|
|
148
|
+
typeof spriteRefresher !== 'undefined') {
|
|
149
|
+
spriteRefresher().then(() => {
|
|
150
|
+
ws.send(JSON.stringify({
|
|
151
|
+
event: 'spriteUpdate',
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
112
154
|
}
|
|
113
|
-
ws.send(JSON.stringify(style));
|
|
114
155
|
}
|
|
115
156
|
catch (e) {
|
|
116
157
|
// Nothing to do
|
|
117
158
|
}
|
|
118
159
|
});
|
|
160
|
+
ws.on('close', () => {
|
|
161
|
+
watcher.close();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
process.on('SIGINT', () => {
|
|
165
|
+
console.log('Cleaning up...');
|
|
166
|
+
server.close();
|
|
167
|
+
if (typeof spriteOut !== 'undefined') {
|
|
168
|
+
fs_1.default.rmSync(spriteOut, { recursive: true });
|
|
169
|
+
spriteOut = undefined;
|
|
170
|
+
}
|
|
171
|
+
process.exit(0);
|
|
119
172
|
});
|
|
120
173
|
return server;
|
|
121
174
|
}
|
package/dist/lib/build-sprite.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.buildSprite = void 0;
|
|
4
7
|
const sprite_one_1 = require("@unvt/sprite-one");
|
|
5
|
-
const
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
6
9
|
async function buildSprite(svgPath, publicPath, iconSlug) {
|
|
7
10
|
const pxRatios = [1, 2];
|
|
8
|
-
const outPath =
|
|
9
|
-
|
|
10
|
-
await sprite_one_1.generateSprite(outPath, [svgPath], pxRatios);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
11
|
+
const outPath = path_1.default.join(publicPath, iconSlug);
|
|
12
|
+
await (0, sprite_one_1.generateSprite)(outPath, [svgPath], pxRatios);
|
|
15
13
|
return;
|
|
16
14
|
}
|
|
17
15
|
exports.buildSprite = buildSprite;
|
package/dist/lib/error.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.error = void 0;
|
|
4
|
-
|
|
4
|
+
const error = (e) => {
|
|
5
5
|
if (e instanceof Error) {
|
|
6
6
|
console.error(e.message);
|
|
7
7
|
}
|
|
@@ -10,3 +10,4 @@ exports.error = (e) => {
|
|
|
10
10
|
}
|
|
11
11
|
process.exit(1);
|
|
12
12
|
};
|
|
13
|
+
exports.error = error;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TileJSONImporter = exports.MetadataJSONImporter = void 0;
|
|
3
4
|
var metadata_importer_1 = require("./metadata-importer");
|
|
4
5
|
Object.defineProperty(exports, "MetadataJSONImporter", { enumerable: true, get: function () { return metadata_importer_1.MetadataJSONImporter; } });
|
|
5
6
|
var tilejson_importer_1 = require("./tilejson-importer");
|
package/dist/lib/yaml-writer.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.writeYaml = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
|
-
|
|
10
|
+
const writeYaml = (destinationPath, style, composite = false) => {
|
|
11
11
|
if (composite === true) {
|
|
12
12
|
writeCompositedYaml(destinationPath, style);
|
|
13
13
|
}
|
|
@@ -15,6 +15,7 @@ exports.writeYaml = (destinationPath, style, composite = false) => {
|
|
|
15
15
|
writeDecompositedYaml(destinationPath, style);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
+
exports.writeYaml = writeYaml;
|
|
18
19
|
const writeCompositedYaml = (destinationPath, style) => {
|
|
19
20
|
const styleYAML = js_yaml_1.default.dump(style);
|
|
20
21
|
let stylePath = path_1.default.resolve(process.cwd(), destinationPath);
|
|
@@ -22,13 +23,22 @@ const writeCompositedYaml = (destinationPath, style) => {
|
|
|
22
23
|
if (destinationPath.match(/^\//)) {
|
|
23
24
|
stylePath = destinationPath;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
fs_1.default.writeFileSync(stylePath, styleYAML);
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
throw `${stylePath}: Permission denied`;
|
|
30
|
-
}
|
|
26
|
+
fs_1.default.writeFileSync(stylePath, styleYAML);
|
|
31
27
|
};
|
|
28
|
+
class IncFileTag {
|
|
29
|
+
constructor(fileName) {
|
|
30
|
+
// We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
|
|
31
|
+
this.value = path_1.default.posix.join('layers', fileName);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const INC_PATH_TYPE = new js_yaml_1.default.Type('tag:yaml.org,2002:inc/file', {
|
|
35
|
+
kind: 'scalar',
|
|
36
|
+
resolve: (data) => data,
|
|
37
|
+
construct: (data) => new IncFileTag(data),
|
|
38
|
+
instanceOf: IncFileTag,
|
|
39
|
+
represent: (tag) => tag.value,
|
|
40
|
+
});
|
|
41
|
+
const INC_PATH_OUTPUT_SCHEMA = js_yaml_1.default.DEFAULT_SCHEMA.extend([INC_PATH_TYPE]);
|
|
32
42
|
const writeDecompositedYaml = (destinationPath, style) => {
|
|
33
43
|
const layers = [];
|
|
34
44
|
for (let i = 0; i < style.layers.length; i++) {
|
|
@@ -39,13 +49,12 @@ const writeDecompositedYaml = (destinationPath, style) => {
|
|
|
39
49
|
const filePath = path_1.default.join(layersDirName, fileName);
|
|
40
50
|
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
41
51
|
fs_1.default.writeFileSync(filePath, layerYml);
|
|
42
|
-
// ts-ignore is required here because !!inc/file
|
|
43
|
-
// We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
|
|
52
|
+
// ts-ignore is required here because the !!inc/file object is not compatible with the Layer object type.
|
|
44
53
|
// @ts-ignore
|
|
45
|
-
layers.push(
|
|
54
|
+
layers.push(new IncFileTag(fileName));
|
|
46
55
|
}
|
|
47
56
|
style.layers = layers;
|
|
48
|
-
fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style
|
|
49
|
-
|
|
57
|
+
fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style, {
|
|
58
|
+
schema: INC_PATH_OUTPUT_SCHEMA,
|
|
50
59
|
}));
|
|
51
60
|
};
|
package/dist/types/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./tilejson"), exports);
|