@unvt/charites 0.5.4 → 2.0.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 (79) hide show
  1. package/.github/workflows/build.yml +3 -5
  2. package/.mocharc.json +7 -0
  3. package/README.md +5 -2
  4. package/dist/cli/build.js +13 -24
  5. package/dist/cli/convert.js +7 -9
  6. package/dist/cli/init.js +7 -9
  7. package/dist/cli/serve.js +7 -21
  8. package/dist/cli.js +18 -16
  9. package/dist/commands/build.js +25 -38
  10. package/dist/commands/convert.js +14 -21
  11. package/dist/commands/init.js +6 -10
  12. package/dist/commands/serve.js +33 -65
  13. package/dist/lib/build-sprite.js +5 -12
  14. package/dist/lib/defaultValues.js +6 -31
  15. package/dist/lib/error.js +1 -5
  16. package/dist/lib/get-sprite-slug.js +1 -5
  17. package/dist/lib/tileinfo-importer/base-importer.js +2 -5
  18. package/dist/lib/tileinfo-importer/index.js +2 -7
  19. package/dist/lib/tileinfo-importer/metadata-importer.js +4 -11
  20. package/dist/lib/tileinfo-importer/tilejson-importer.js +4 -11
  21. package/dist/lib/validate-style.js +3 -17
  22. package/dist/lib/yaml-include/file.js +23 -0
  23. package/dist/lib/yaml-include/index.js +22 -0
  24. package/dist/lib/yaml-parser.js +8 -14
  25. package/dist/lib/yaml-writer.js +17 -23
  26. package/dist/types/index.js +3 -19
  27. package/dist/types/metadatajson.js +1 -2
  28. package/dist/types/tilejson.js +1 -2
  29. package/dist/types/vector_layers.js +1 -2
  30. package/docs/source/index.rst +4 -5
  31. package/docs/source/usage/commandline_interface.rst +0 -12
  32. package/docs/source/usage/examples.rst +0 -6
  33. package/docs/source/usage/index.rst +0 -1
  34. package/eslint.config.mjs +46 -0
  35. package/mocha-register.cjs +2 -0
  36. package/package.json +40 -37
  37. package/playwright.config.ts +1 -12
  38. package/provider/{default/shared.js → app.js} +30 -0
  39. package/provider/{default/index.html → index.html} +3 -3
  40. package/src/cli/build.ts +2 -15
  41. package/src/cli/convert.ts +2 -2
  42. package/src/cli/init.ts +2 -2
  43. package/src/cli/serve.ts +2 -20
  44. package/src/cli.ts +14 -5
  45. package/src/commands/build.ts +5 -12
  46. package/src/commands/convert.ts +1 -1
  47. package/src/commands/init.ts +2 -2
  48. package/src/commands/serve.ts +10 -48
  49. package/src/lib/defaultValues.ts +8 -34
  50. package/src/lib/tileinfo-importer/index.ts +2 -2
  51. package/src/lib/tileinfo-importer/metadata-importer.ts +2 -2
  52. package/src/lib/tileinfo-importer/tilejson-importer.ts +2 -2
  53. package/src/lib/validate-style.ts +5 -13
  54. package/src/lib/yaml-include/file.ts +29 -0
  55. package/src/lib/yaml-include/index.ts +28 -0
  56. package/src/lib/yaml-parser.ts +3 -3
  57. package/test/build-sprite.spec.ts +5 -0
  58. package/test/build.spec.ts +10 -13
  59. package/test/command.build.spec.ts +2 -2
  60. package/test/convert.spec.ts +7 -1
  61. package/test/get-sprite-slug.spec.ts +4 -0
  62. package/test/init.spec.ts +5 -0
  63. package/test/playwright/provider/{default/e2e.spec.ts → e2e.spec.ts} +2 -2
  64. package/test/util/charitesCmd.ts +5 -0
  65. package/test/util/copyFixtures.ts +5 -0
  66. package/test/yaml-parser.spec.ts +4 -0
  67. package/tsconfig.json +11 -6
  68. package/.eslintignore +0 -2
  69. package/.eslintrc.js +0 -17
  70. package/docs/source/usage/global_options.rst +0 -21
  71. package/provider/default/app.js +0 -30
  72. package/provider/geolonia/app.js +0 -28
  73. package/provider/geolonia/index.html +0 -22
  74. package/provider/mapbox/app.js +0 -33
  75. package/provider/mapbox/index.html +0 -23
  76. package/test/playwright/provider/geolonia/e2e.spec.ts +0 -13
  77. package/test/playwright/provider/mapbox/e2e.spec.ts +0 -13
  78. /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
  79. /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: [18.x, 20.x, 21.x]
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: [18.x]
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: '18.x'
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
@@ -0,0 +1,7 @@
1
+ {
2
+ "loader": "ts-node/esm",
3
+ "require": ["./mocha-register.cjs"],
4
+ "extensions": ["ts"],
5
+ "spec": "test/*.ts",
6
+ "timeout": 5000
7
+ }
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#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 [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.
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const commander_1 = require("commander");
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 = path_1.default.resolve(process.cwd(), 'icons');
21
+ const spriteInputDefault = path.resolve(process.cwd(), 'icons');
30
22
  if (buildOptions.spriteInput) {
31
23
  options.spriteInput = buildOptions.spriteInput;
32
24
  }
33
- else if (fs_1.default.existsSync(spriteInputDefault)) {
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 = (0, build_1.buildWatch)(source, destination, options);
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
- (0, error_1.error)(e);
40
+ error(e);
52
41
  }
53
42
  }
54
43
  else {
55
44
  try {
56
- await (0, build_1.build)(source, destination, options);
45
+ await build(source, destination, options);
57
46
  }
58
47
  catch (e) {
59
- (0, error_1.error)(e);
48
+ error(e);
60
49
  }
61
50
  }
62
51
  });
63
- exports.default = program;
52
+ export default program;
@@ -1,19 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const commander_1 = require("commander");
4
- const convert_1 = require("../commands/convert");
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
- (0, convert_1.convert)(source, destination);
11
+ convert(source, destination);
14
12
  }
15
13
  catch (e) {
16
- (0, error_1.error)(e);
14
+ error(e);
17
15
  }
18
16
  });
19
- exports.default = program;
17
+ export default program;
package/dist/cli/init.js CHANGED
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const commander_1 = require("commander");
4
- const init_1 = require("../commands/init");
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 (0, init_1.init)(file, options);
18
+ await init(file, options);
21
19
  }
22
20
  catch (e) {
23
- (0, error_1.error)(e);
21
+ error(e);
24
22
  }
25
23
  });
26
- exports.default = program;
24
+ export default program;
package/dist/cli/serve.js CHANGED
@@ -1,40 +1,26 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 (0, serve_1.serve)(source, program.opts());
20
+ await serve(source, program.opts());
35
21
  }
36
22
  catch (e) {
37
- (0, error_1.error)(e);
23
+ error(e);
38
24
  }
39
25
  });
40
- exports.default = program;
26
+ export default program;
package/dist/cli.js CHANGED
@@ -1,20 +1,22 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const init_1 = __importDefault(require("./cli/init"));
9
- const convert_1 = __importDefault(require("./cli/convert"));
10
- const build_1 = __importDefault(require("./cli/build"));
11
- const serve_1 = __importDefault(require("./cli/serve"));
12
- const program = new commander_1.Command();
13
- const version = require('../package.json').version;
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(init_1.default)
17
- .addCommand(convert_1.default)
18
- .addCommand(build_1.default)
19
- .addCommand(serve_1.default);
18
+ .addCommand(init)
19
+ .addCommand(convert)
20
+ .addCommand(build)
21
+ .addCommand(serve);
20
22
  program.parse(process.argv);
@@ -1,25 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildWatch = exports.build = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const yaml_parser_1 = require("../lib/yaml-parser");
10
- const validate_style_1 = require("../lib/validate-style");
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 (!fs_1.default.existsSync(sourcePath)) {
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 = path_1.default.resolve(process.cwd(), destination);
24
+ destinationPath = path.resolve(process.cwd(), destination);
32
25
  }
33
26
  }
34
27
  else {
35
- destinationPath = path_1.default.join(path_1.default.dirname(sourcePath), `${path_1.default.basename(source, '.yml')}.json`);
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 = (0, yaml_parser_1.parser)(sourcePath);
44
- (0, validate_style_1.validateStyle)(_style, provider);
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 (!fs_1.default.existsSync(options.spriteInput)) {
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 (!fs_1.default.existsSync(options.spriteOutput)) {
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 = (0, get_sprite_slug_1.getSpriteSlug)(JSON.parse(style));
45
+ const iconSlug = getSpriteSlug(JSON.parse(style));
57
46
  if (!iconSlug) {
58
47
  throw `Invalid sprite url format.`;
59
48
  }
60
- await (0, build_sprite_1.buildSprite)(options.spriteInput, options.spriteOutput, iconSlug);
49
+ await buildSprite(options.spriteInput, options.spriteOutput, iconSlug);
61
50
  }
62
51
  if (options.compactOutput) {
63
- style = (0, jsonminify_1.default)(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
- fs_1.default.writeFileSync(destinationPath, style);
63
+ fs.writeFileSync(destinationPath, style);
75
64
  }
76
- exports.build = build;
77
- function buildWatch(source, destination, options) {
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(path_1.default.dirname(sourcePath));
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 (0, node_watch_1.default)(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, watchCallback);
83
+ return watch(path.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, watchCallback);
96
84
  }
97
- exports.buildWatch = buildWatch;
@@ -1,13 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 = path_1.default.resolve(process.cwd(), destination);
12
+ destinationPath = path.resolve(process.cwd(), destination);
19
13
  }
20
14
  }
21
15
  else {
22
16
  if (sourcePath) {
23
- destinationPath = path_1.default.join(path_1.default.dirname(sourcePath), `${path_1.default.basename(sourcePath, '.json')}.yml`);
17
+ destinationPath = path.join(path.dirname(sourcePath), `${path.basename(sourcePath, '.json')}.yml`);
24
18
  }
25
19
  else {
26
- destinationPath = path_1.default.join(process.cwd(), 'style.yml');
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 = readline_1.default.createInterface({
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
- (0, yaml_writer_1.writeYaml)(destinationPath, style, false);
39
+ writeYaml(destinationPath, style, false);
46
40
  });
47
41
  }
48
42
  else {
49
- sourcePath = path_1.default.resolve(process.cwd(), source);
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 (!fs_1.default.existsSync(sourcePath)) {
48
+ if (!fs.existsSync(sourcePath)) {
55
49
  throw `${sourcePath}: No such file or directory`;
56
50
  }
57
- style = JSON.parse(fs_1.default.readFileSync(sourcePath, 'utf-8'));
51
+ style = JSON.parse(fs.readFileSync(sourcePath, 'utf-8'));
58
52
  const destinationPath = getDestinationPath(destination, sourcePath);
59
- (0, yaml_writer_1.writeYaml)(destinationPath, style, false);
53
+ writeYaml(destinationPath, style, false);
60
54
  }
61
55
  }
62
- exports.convert = convert;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 tileinfo_importer_1.TileJSONImporter(options.tilejsonUrls);
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 tileinfo_importer_1.MetadataJSONImporter(options.metadatajsonUrls);
18
+ const metadataJSONImporter = new MetadataJSONImporter(options.metadatajsonUrls);
22
19
  styleTemplate = await metadataJSONImporter.import(styleTemplate);
23
20
  }
24
- (0, yaml_writer_1.writeYaml)(file, styleTemplate, options.compositeLayers);
21
+ writeYaml(file, styleTemplate, options.compositeLayers);
25
22
  }
26
- exports.init = init;