@unvt/charites 0.5.4 → 2.0.2
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/.github/workflows/build.yml +3 -5
- package/.mocharc.json +7 -0
- package/README.md +5 -2
- package/dist/cli/build.js +13 -24
- package/dist/cli/convert.js +7 -9
- package/dist/cli/init.js +7 -9
- package/dist/cli/serve.js +7 -21
- package/dist/cli.js +18 -16
- package/dist/commands/build.js +25 -38
- package/dist/commands/convert.js +14 -21
- package/dist/commands/init.js +6 -10
- package/dist/commands/serve.js +33 -65
- package/dist/lib/build-sprite.js +5 -12
- package/dist/lib/defaultValues.js +6 -31
- package/dist/lib/error.js +1 -5
- package/dist/lib/get-sprite-slug.js +1 -5
- package/dist/lib/tileinfo-importer/base-importer.js +2 -5
- package/dist/lib/tileinfo-importer/index.js +2 -7
- package/dist/lib/tileinfo-importer/metadata-importer.js +4 -11
- package/dist/lib/tileinfo-importer/tilejson-importer.js +4 -11
- package/dist/lib/validate-style.js +3 -17
- package/dist/lib/yaml-include/file.js +23 -0
- package/dist/lib/yaml-include/index.js +22 -0
- package/dist/lib/yaml-parser.js +8 -14
- package/dist/lib/yaml-writer.js +17 -23
- package/dist/types/index.js +3 -19
- package/dist/types/metadatajson.js +1 -2
- package/dist/types/tilejson.js +1 -2
- package/dist/types/vector_layers.js +1 -2
- package/docs/source/index.rst +4 -5
- package/docs/source/usage/commandline_interface.rst +0 -12
- package/docs/source/usage/examples.rst +0 -6
- package/docs/source/usage/index.rst +0 -1
- package/eslint.config.mjs +46 -0
- package/mocha-register.cjs +2 -0
- package/package.json +40 -37
- package/playwright.config.ts +1 -12
- package/provider/{default/shared.js → app.js} +30 -0
- package/provider/{default/index.html → index.html} +5 -5
- package/src/cli/build.ts +2 -15
- package/src/cli/convert.ts +2 -2
- package/src/cli/init.ts +2 -2
- package/src/cli/serve.ts +2 -20
- package/src/cli.ts +14 -5
- package/src/commands/build.ts +5 -12
- package/src/commands/convert.ts +1 -1
- package/src/commands/init.ts +2 -2
- package/src/commands/serve.ts +10 -48
- package/src/lib/defaultValues.ts +8 -34
- package/src/lib/tileinfo-importer/index.ts +2 -2
- package/src/lib/tileinfo-importer/metadata-importer.ts +2 -2
- package/src/lib/tileinfo-importer/tilejson-importer.ts +2 -2
- package/src/lib/validate-style.ts +5 -13
- package/src/lib/yaml-include/file.ts +29 -0
- package/src/lib/yaml-include/index.ts +28 -0
- package/src/lib/yaml-parser.ts +3 -3
- package/test/build-sprite.spec.ts +5 -0
- package/test/build.spec.ts +10 -13
- package/test/command.build.spec.ts +2 -2
- package/test/convert.spec.ts +7 -1
- package/test/get-sprite-slug.spec.ts +4 -0
- package/test/init.spec.ts +5 -0
- package/test/playwright/provider/{default/e2e.spec.ts → e2e.spec.ts} +2 -2
- package/test/util/charitesCmd.ts +5 -0
- package/test/util/copyFixtures.ts +5 -0
- package/test/yaml-parser.spec.ts +4 -0
- package/tsconfig.json +11 -6
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -17
- package/docs/source/usage/global_options.rst +0 -21
- package/provider/default/app.js +0 -30
- package/provider/geolonia/app.js +0 -28
- package/provider/geolonia/index.html +0 -22
- package/provider/mapbox/app.js +0 -33
- package/provider/mapbox/index.html +0 -23
- package/test/playwright/provider/geolonia/e2e.spec.ts +0 -13
- package/test/playwright/provider/mapbox/e2e.spec.ts +0 -13
- /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
- /package/provider/{default/app.css → app.css} +0 -0
|
@@ -16,7 +16,7 @@ jobs:
|
|
|
16
16
|
build:
|
|
17
17
|
strategy:
|
|
18
18
|
matrix:
|
|
19
|
-
node-version: [
|
|
19
|
+
node-version: [20.x, 22.x]
|
|
20
20
|
os: [ubuntu-latest]
|
|
21
21
|
runs-on: ${{ matrix.os }}
|
|
22
22
|
steps:
|
|
@@ -33,7 +33,7 @@ jobs:
|
|
|
33
33
|
runs-on: ubuntu-latest
|
|
34
34
|
strategy:
|
|
35
35
|
matrix:
|
|
36
|
-
node-version: [
|
|
36
|
+
node-version: [22.x]
|
|
37
37
|
steps:
|
|
38
38
|
- uses: actions/checkout@v3
|
|
39
39
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
@@ -53,8 +53,6 @@ jobs:
|
|
|
53
53
|
- run: npm run build
|
|
54
54
|
- run: chmod 777 dist/cli.js
|
|
55
55
|
- run: npm run test:e2e
|
|
56
|
-
env:
|
|
57
|
-
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
|
58
56
|
|
|
59
57
|
publish:
|
|
60
58
|
name: 'Publish npm package'
|
|
@@ -67,7 +65,7 @@ jobs:
|
|
|
67
65
|
- uses: actions/setup-node@v3
|
|
68
66
|
with:
|
|
69
67
|
tag_name: 'v%s'
|
|
70
|
-
node-version: '
|
|
68
|
+
node-version: '22.x'
|
|
71
69
|
registry-url: 'https://registry.npmjs.org'
|
|
72
70
|
scope: '@unvt'
|
|
73
71
|
- run: npm install
|
package/.mocharc.json
ADDED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](#contributors-)
|
|
4
4
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
5
5
|
|
|
6
|
-
An easy, intuitive, and efficient command-line tool for writing vector map styles compatible with the [
|
|
6
|
+
An easy, intuitive, and efficient command-line tool for writing vector map styles compatible with the [MapLibre](https://maplibre.org/maplibre-style-spec/) Style Specification in YAML.
|
|
7
7
|
With YAML format's readability, JSON compiler, linter, and live style viewer on a local browser, you can simplify your map styling workflow.
|
|
8
8
|
|
|
9
9
|
In Greek mythology, the [Charites](https://en.wikipedia.org/wiki/Charites) are the three goddesses of charm, beauty, and human creativity. They are believed to have been worshipped not only by artists but also by those who aspired to technology to infuse them with a creative spirit.
|
|
@@ -15,7 +15,6 @@ In Greek mythology, the [Charites](https://en.wikipedia.org/wiki/Charites) are t
|
|
|
15
15
|
- Divide groups of layers in to multiple files for better readability and mantainability. `!!inc/file <relative-path-to-the-file>`
|
|
16
16
|
- Use variables like `$backgroundColor` and `$waterColor` to style effectively.
|
|
17
17
|
- Compile YAML to a single style.json file, with a format linter.
|
|
18
|
-
- Use `--provider mapbox` to validate your style against Mapbox GL JS v2.x
|
|
19
18
|
- Run `charites serve <source>` to preview your style live while you make changes in a browser.
|
|
20
19
|
|
|
21
20
|
## Documentation
|
|
@@ -30,6 +29,10 @@ see [CONTRIBUTING.md](./.github/CONTRIBUTING.md)
|
|
|
30
29
|
|
|
31
30
|
MIT
|
|
32
31
|
|
|
32
|
+
## Rquirements
|
|
33
|
+
|
|
34
|
+
- Node.js v20 or later
|
|
35
|
+
|
|
33
36
|
## Contributors ✨
|
|
34
37
|
|
|
35
38
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
package/dist/cli/build.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const build_1 = require("../commands/build");
|
|
8
|
-
const error_1 = require("../lib/error");
|
|
9
|
-
const defaultValues_1 = require("../lib/defaultValues");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const program = new commander_1.Command();
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { build, buildWatch } from '../commands/build.js';
|
|
3
|
+
import { error } from '../lib/error.js';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
const program = new Command();
|
|
13
7
|
program
|
|
14
8
|
.name('build')
|
|
15
9
|
.arguments('<source> [destination]')
|
|
@@ -19,28 +13,23 @@ program
|
|
|
19
13
|
.option('-u, --sprite-url [<sprite url>]', 'url to set as the sprite in style.json')
|
|
20
14
|
.option('-i, --sprite-input [<icon input directory>]', 'directory path of icon source to build icons. The default <icon source> is `icons/`')
|
|
21
15
|
.option('-o, --sprite-output [<icon output directory>]', 'directory path to output icon files. The default <icons destination> is the current directory')
|
|
22
|
-
.option('--provider [provider]', 'your map service. e.g. `mapbox`, `geolonia`')
|
|
23
16
|
.action(async (source, destination, buildOptions) => {
|
|
24
17
|
const options = program.opts();
|
|
25
|
-
options.provider = buildOptions.provider;
|
|
26
18
|
options.compactOutput = buildOptions.compactOutput;
|
|
27
19
|
options.spriteUrl = buildOptions.spriteUrl;
|
|
28
20
|
options.spriteOutput = buildOptions.spriteOutput || process.cwd();
|
|
29
|
-
const spriteInputDefault =
|
|
21
|
+
const spriteInputDefault = path.resolve(process.cwd(), 'icons');
|
|
30
22
|
if (buildOptions.spriteInput) {
|
|
31
23
|
options.spriteInput = buildOptions.spriteInput;
|
|
32
24
|
}
|
|
33
|
-
else if (
|
|
25
|
+
else if (fs.existsSync(spriteInputDefault)) {
|
|
34
26
|
options.spriteInput = spriteInputDefault;
|
|
35
27
|
}
|
|
36
|
-
if (!fs_1.default.existsSync(defaultValues_1.defaultSettings.configFile)) {
|
|
37
|
-
fs_1.default.writeFileSync(defaultValues_1.defaultSettings.configFile, `provider: ${options.provider || 'default'}`);
|
|
38
|
-
}
|
|
39
28
|
if (buildOptions.watch) {
|
|
40
29
|
try {
|
|
41
30
|
console.log('Start watching...');
|
|
42
31
|
await new Promise((resolve) => {
|
|
43
|
-
const watcher =
|
|
32
|
+
const watcher = buildWatch(source, destination, options);
|
|
44
33
|
process.on('SIGINT', () => {
|
|
45
34
|
watcher.close();
|
|
46
35
|
resolve(undefined);
|
|
@@ -48,16 +37,16 @@ program
|
|
|
48
37
|
});
|
|
49
38
|
}
|
|
50
39
|
catch (e) {
|
|
51
|
-
|
|
40
|
+
error(e);
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
43
|
else {
|
|
55
44
|
try {
|
|
56
|
-
await
|
|
45
|
+
await build(source, destination, options);
|
|
57
46
|
}
|
|
58
47
|
catch (e) {
|
|
59
|
-
|
|
48
|
+
error(e);
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
});
|
|
63
|
-
|
|
52
|
+
export default program;
|
package/dist/cli/convert.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const error_1 = require("../lib/error");
|
|
6
|
-
const program = new commander_1.Command();
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { convert } from '../commands/convert.js';
|
|
3
|
+
import { error } from '../lib/error.js';
|
|
4
|
+
const program = new Command();
|
|
7
5
|
program
|
|
8
6
|
.name('convert')
|
|
9
7
|
.arguments('<source> [destination]')
|
|
10
8
|
.description('convert the style JSON to YAML')
|
|
11
9
|
.action((source, destination) => {
|
|
12
10
|
try {
|
|
13
|
-
|
|
11
|
+
convert(source, destination);
|
|
14
12
|
}
|
|
15
13
|
catch (e) {
|
|
16
|
-
|
|
14
|
+
error(e);
|
|
17
15
|
}
|
|
18
16
|
});
|
|
19
|
-
|
|
17
|
+
export default program;
|
package/dist/cli/init.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const error_1 = require("../lib/error");
|
|
6
|
-
const program = new commander_1.Command();
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { init } from '../commands/init.js';
|
|
3
|
+
import { error } from '../lib/error.js';
|
|
4
|
+
const program = new Command();
|
|
7
5
|
program
|
|
8
6
|
.name('init')
|
|
9
7
|
.arguments('<file>')
|
|
@@ -17,10 +15,10 @@ program
|
|
|
17
15
|
options.metadatajsonUrls = initOptions.metadatajsonUrls;
|
|
18
16
|
options.compositeLayers = initOptions.compositeLayers;
|
|
19
17
|
try {
|
|
20
|
-
await
|
|
18
|
+
await init(file, options);
|
|
21
19
|
}
|
|
22
20
|
catch (e) {
|
|
23
|
-
|
|
21
|
+
error(e);
|
|
24
22
|
}
|
|
25
23
|
});
|
|
26
|
-
|
|
24
|
+
export default program;
|
package/dist/cli/serve.js
CHANGED
|
@@ -1,40 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const commander_1 = require("commander");
|
|
7
|
-
const serve_1 = require("../commands/serve");
|
|
8
|
-
const error_1 = require("../lib/error");
|
|
9
|
-
const defaultValues_1 = require("../lib/defaultValues");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const program = new commander_1.Command();
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { serve } from '../commands/serve.js';
|
|
3
|
+
import { error } from '../lib/error.js';
|
|
4
|
+
const program = new Command();
|
|
12
5
|
program
|
|
13
6
|
.name('serve')
|
|
14
7
|
.arguments('<source>')
|
|
15
8
|
.description('serve your map locally')
|
|
16
|
-
.option('--provider [provider]', 'your map service. e.g. `mapbox`, `geolonia`')
|
|
17
|
-
.option('--mapbox-access-token [mapboxAccessToken]', 'Your Mapbox Access Token (required if using the `mapbox` provider)')
|
|
18
9
|
.option('-i, --sprite-input [<icon input directory>]', 'directory path of icon source to build icons. The default <icon source> is `icons/`')
|
|
19
10
|
.option('--sdf', 'Allows to use SDF sprite in charites')
|
|
20
11
|
.option('--port [port]', 'Specify custom port')
|
|
21
12
|
.option('--no-open', "Don't open the preview in the default browser")
|
|
22
13
|
.action(async (source, serveOptions) => {
|
|
23
14
|
const options = program.opts();
|
|
24
|
-
options.provider = serveOptions.provider;
|
|
25
|
-
options.mapboxAccessToken = serveOptions.mapboxAccessToken;
|
|
26
15
|
options.port = serveOptions.port;
|
|
27
16
|
options.spriteInput = serveOptions.spriteInput;
|
|
28
17
|
options.open = serveOptions.open;
|
|
29
18
|
options.sdf = serveOptions.sdf;
|
|
30
|
-
if (!fs_1.default.existsSync(defaultValues_1.defaultSettings.configFile)) {
|
|
31
|
-
fs_1.default.writeFileSync(defaultValues_1.defaultSettings.configFile, `provider: ${options.provider || 'default'}`);
|
|
32
|
-
}
|
|
33
19
|
try {
|
|
34
|
-
await
|
|
20
|
+
await serve(source, program.opts());
|
|
35
21
|
}
|
|
36
22
|
catch (e) {
|
|
37
|
-
|
|
23
|
+
error(e);
|
|
38
24
|
}
|
|
39
25
|
});
|
|
40
|
-
|
|
26
|
+
export default program;
|
package/dist/cli.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import init from './cli/init.js';
|
|
4
|
+
import convert from './cli/convert.js';
|
|
5
|
+
import build from './cli/build.js';
|
|
6
|
+
import serve from './cli/serve.js';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
9
|
+
import { readFileSync } from 'fs';
|
|
10
|
+
// ESMの__dirnameの代わり
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
const program = new Command();
|
|
14
|
+
const packageJson = readFileSync(join(__dirname, '../package.json'), 'utf-8');
|
|
15
|
+
const { version } = JSON.parse(packageJson);
|
|
14
16
|
program
|
|
15
17
|
.version(version, '-v, --version', 'output the version number')
|
|
16
|
-
.addCommand(
|
|
17
|
-
.addCommand(
|
|
18
|
-
.addCommand(
|
|
19
|
-
.addCommand(
|
|
18
|
+
.addCommand(init)
|
|
19
|
+
.addCommand(convert)
|
|
20
|
+
.addCommand(build)
|
|
21
|
+
.addCommand(serve);
|
|
20
22
|
program.parse(process.argv);
|
package/dist/commands/build.js
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const build_sprite_1 = require("../lib/build-sprite");
|
|
12
|
-
const get_sprite_slug_1 = require("../lib/get-sprite-slug");
|
|
13
|
-
const defaultValues_1 = require("../lib/defaultValues");
|
|
14
|
-
const jsonminify_1 = __importDefault(require("jsonminify"));
|
|
15
|
-
const node_watch_1 = __importDefault(require("node-watch"));
|
|
16
|
-
async function build(source, destination, options) {
|
|
17
|
-
let sourcePath = path_1.default.resolve(process.cwd(), source);
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { parser } from '../lib/yaml-parser.js';
|
|
4
|
+
import { validateStyle } from '../lib/validate-style.js';
|
|
5
|
+
import { buildSprite } from '../lib/build-sprite.js';
|
|
6
|
+
import { getSpriteSlug } from '../lib/get-sprite-slug.js';
|
|
7
|
+
import jsonminify from 'jsonminify';
|
|
8
|
+
import watch from 'node-watch';
|
|
9
|
+
export async function build(source, destination, options) {
|
|
10
|
+
let sourcePath = path.resolve(process.cwd(), source);
|
|
18
11
|
// The `source` is absolute path.
|
|
19
12
|
if (source.match(/^\//)) {
|
|
20
13
|
sourcePath = source;
|
|
21
14
|
}
|
|
22
|
-
if (!
|
|
15
|
+
if (!fs.existsSync(sourcePath)) {
|
|
23
16
|
throw `${sourcePath}: No such file or directory`;
|
|
24
17
|
}
|
|
25
18
|
let destinationPath = '';
|
|
@@ -28,39 +21,35 @@ async function build(source, destination, options) {
|
|
|
28
21
|
destinationPath = destination;
|
|
29
22
|
}
|
|
30
23
|
else {
|
|
31
|
-
destinationPath =
|
|
24
|
+
destinationPath = path.resolve(process.cwd(), destination);
|
|
32
25
|
}
|
|
33
26
|
}
|
|
34
27
|
else {
|
|
35
|
-
destinationPath =
|
|
36
|
-
}
|
|
37
|
-
let provider = defaultValues_1.defaultValues.provider;
|
|
38
|
-
if (options.provider) {
|
|
39
|
-
provider = options.provider;
|
|
28
|
+
destinationPath = path.join(path.dirname(sourcePath), `${path.basename(source, '.yml')}.json`);
|
|
40
29
|
}
|
|
41
30
|
let style = '';
|
|
42
31
|
try {
|
|
43
|
-
const _style =
|
|
44
|
-
|
|
32
|
+
const _style = parser(sourcePath);
|
|
33
|
+
validateStyle(_style);
|
|
45
34
|
if (options.spriteUrl && 'sprite' in _style) {
|
|
46
35
|
_style.sprite = options.spriteUrl;
|
|
47
36
|
}
|
|
48
37
|
style = JSON.stringify(_style, null, ' ');
|
|
49
38
|
if (options.spriteInput && options.spriteOutput) {
|
|
50
|
-
if (!
|
|
39
|
+
if (!fs.existsSync(options.spriteInput)) {
|
|
51
40
|
throw `${options.spriteInput}: No such directory. Please specify valid icon input directory. For more help run charites build --help`;
|
|
52
41
|
}
|
|
53
|
-
if (!
|
|
42
|
+
if (!fs.existsSync(options.spriteOutput)) {
|
|
54
43
|
throw `${options.spriteOutput}: No such directory. Please specify valid icon output directory. For more help run charites build --help`;
|
|
55
44
|
}
|
|
56
|
-
const iconSlug =
|
|
45
|
+
const iconSlug = getSpriteSlug(JSON.parse(style));
|
|
57
46
|
if (!iconSlug) {
|
|
58
47
|
throw `Invalid sprite url format.`;
|
|
59
48
|
}
|
|
60
|
-
await
|
|
49
|
+
await buildSprite(options.spriteInput, options.spriteOutput, iconSlug);
|
|
61
50
|
}
|
|
62
51
|
if (options.compactOutput) {
|
|
63
|
-
style = (
|
|
52
|
+
style = jsonminify(style);
|
|
64
53
|
}
|
|
65
54
|
}
|
|
66
55
|
catch (err) {
|
|
@@ -71,15 +60,14 @@ async function build(source, destination, options) {
|
|
|
71
60
|
throw `${sourcePath}: Invalid YAML syntax`;
|
|
72
61
|
}
|
|
73
62
|
}
|
|
74
|
-
|
|
63
|
+
fs.writeFileSync(destinationPath, style);
|
|
75
64
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
let sourcePath = path_1.default.resolve(process.cwd(), source);
|
|
65
|
+
export function buildWatch(source, destination, options) {
|
|
66
|
+
let sourcePath = path.resolve(process.cwd(), source);
|
|
79
67
|
if (source.match(/^\//)) {
|
|
80
68
|
sourcePath = source;
|
|
81
69
|
}
|
|
82
|
-
console.log(
|
|
70
|
+
console.log(path.dirname(sourcePath));
|
|
83
71
|
const watchCallback = async (event, file) => {
|
|
84
72
|
console.log(`${(event || '').toUpperCase()}: ${file}`);
|
|
85
73
|
try {
|
|
@@ -92,6 +80,5 @@ function buildWatch(source, destination, options) {
|
|
|
92
80
|
};
|
|
93
81
|
// Trigger the watch callback first manually, so the user doesn't need to save the file to create the initial file.
|
|
94
82
|
watchCallback('update', sourcePath);
|
|
95
|
-
return (
|
|
83
|
+
return watch(path.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, watchCallback);
|
|
96
84
|
}
|
|
97
|
-
exports.buildWatch = buildWatch;
|
package/dist/commands/convert.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.convert = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const readline_1 = __importDefault(require("readline"));
|
|
10
|
-
const yaml_writer_1 = require("../lib/yaml-writer");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import readline from 'readline';
|
|
4
|
+
import { writeYaml } from '../lib/yaml-writer.js';
|
|
11
5
|
const getDestinationPath = (destination, sourcePath = '') => {
|
|
12
6
|
let destinationPath;
|
|
13
7
|
if (destination) {
|
|
@@ -15,23 +9,23 @@ const getDestinationPath = (destination, sourcePath = '') => {
|
|
|
15
9
|
destinationPath = destination;
|
|
16
10
|
}
|
|
17
11
|
else {
|
|
18
|
-
destinationPath =
|
|
12
|
+
destinationPath = path.resolve(process.cwd(), destination);
|
|
19
13
|
}
|
|
20
14
|
}
|
|
21
15
|
else {
|
|
22
16
|
if (sourcePath) {
|
|
23
|
-
destinationPath =
|
|
17
|
+
destinationPath = path.join(path.dirname(sourcePath), `${path.basename(sourcePath, '.json')}.yml`);
|
|
24
18
|
}
|
|
25
19
|
else {
|
|
26
|
-
destinationPath =
|
|
20
|
+
destinationPath = path.join(process.cwd(), 'style.yml');
|
|
27
21
|
}
|
|
28
22
|
}
|
|
29
23
|
return destinationPath;
|
|
30
24
|
};
|
|
31
|
-
function convert(source, destination) {
|
|
25
|
+
export function convert(source, destination) {
|
|
32
26
|
let style, sourcePath;
|
|
33
27
|
if ('-' === source) {
|
|
34
|
-
const rl =
|
|
28
|
+
const rl = readline.createInterface({
|
|
35
29
|
input: process.stdin,
|
|
36
30
|
terminal: false,
|
|
37
31
|
});
|
|
@@ -42,21 +36,20 @@ function convert(source, destination) {
|
|
|
42
36
|
rl.on('close', () => {
|
|
43
37
|
const style = JSON.parse(lines.join(''));
|
|
44
38
|
const destinationPath = getDestinationPath(destination);
|
|
45
|
-
|
|
39
|
+
writeYaml(destinationPath, style, false);
|
|
46
40
|
});
|
|
47
41
|
}
|
|
48
42
|
else {
|
|
49
|
-
sourcePath =
|
|
43
|
+
sourcePath = path.resolve(process.cwd(), source);
|
|
50
44
|
// The `source` is absolute path.
|
|
51
45
|
if (source.match(/^\//)) {
|
|
52
46
|
sourcePath = source;
|
|
53
47
|
}
|
|
54
|
-
if (!
|
|
48
|
+
if (!fs.existsSync(sourcePath)) {
|
|
55
49
|
throw `${sourcePath}: No such file or directory`;
|
|
56
50
|
}
|
|
57
|
-
style = JSON.parse(
|
|
51
|
+
style = JSON.parse(fs.readFileSync(sourcePath, 'utf-8'));
|
|
58
52
|
const destinationPath = getDestinationPath(destination, sourcePath);
|
|
59
|
-
|
|
53
|
+
writeYaml(destinationPath, style, false);
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
|
-
exports.convert = convert;
|
package/dist/commands/init.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.init = void 0;
|
|
4
|
-
const yaml_writer_1 = require("../lib/yaml-writer");
|
|
5
|
-
const tileinfo_importer_1 = require("../lib/tileinfo-importer");
|
|
1
|
+
import { writeYaml } from '../lib/yaml-writer.js';
|
|
2
|
+
import { TileJSONImporter, MetadataJSONImporter, } from '../lib/tileinfo-importer/index.js';
|
|
6
3
|
const styleRoot = {
|
|
7
4
|
version: 8,
|
|
8
5
|
name: 'My Style',
|
|
@@ -11,16 +8,15 @@ const styleRoot = {
|
|
|
11
8
|
sources: {},
|
|
12
9
|
layers: [],
|
|
13
10
|
};
|
|
14
|
-
async function init(file, options) {
|
|
11
|
+
export async function init(file, options) {
|
|
15
12
|
let styleTemplate = JSON.parse(JSON.stringify(styleRoot));
|
|
16
13
|
if (options.tilejsonUrls) {
|
|
17
|
-
const tileJSONImporter = new
|
|
14
|
+
const tileJSONImporter = new TileJSONImporter(options.tilejsonUrls);
|
|
18
15
|
styleTemplate = await tileJSONImporter.import(styleTemplate);
|
|
19
16
|
}
|
|
20
17
|
if (options.metadatajsonUrls) {
|
|
21
|
-
const metadataJSONImporter = new
|
|
18
|
+
const metadataJSONImporter = new MetadataJSONImporter(options.metadatajsonUrls);
|
|
22
19
|
styleTemplate = await metadataJSONImporter.import(styleTemplate);
|
|
23
20
|
}
|
|
24
|
-
|
|
21
|
+
writeYaml(file, styleTemplate, options.compositeLayers);
|
|
25
22
|
}
|
|
26
|
-
exports.init = init;
|