@unvt/charites 0.1.1 → 0.1.4
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 +24 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +17 -0
- package/.github/CONTRIBUTING.md +30 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
- package/.github/workflows/build-docs.yml +72 -0
- package/.github/workflows/build.yml +1 -0
- package/.prettierrc.js +6 -0
- package/LICENSE +1 -1
- package/README.md +23 -106
- package/dist/cli/build.js +63 -0
- package/dist/cli/convert.js +19 -0
- package/dist/cli/init.js +26 -0
- package/dist/cli/serve.js +34 -0
- package/dist/cli.js +10 -66
- package/dist/commands/build.js +39 -3
- package/dist/commands/convert.js +6 -23
- package/dist/commands/init.js +15 -22
- package/dist/commands/serve.js +8 -3
- package/dist/lib/build-sprite.js +71 -0
- package/dist/lib/defaultValues.js +3 -3
- package/dist/lib/error.js +9 -0
- package/dist/lib/get-sprite-slug.js +16 -0
- package/dist/lib/tileinfo-importer/base-importer.js +41 -0
- package/dist/lib/tileinfo-importer/index.js +6 -0
- package/dist/lib/tileinfo-importer/metadata-importer.js +38 -0
- package/dist/lib/tileinfo-importer/tilejson-importer.js +25 -0
- package/dist/lib/validate-style.js +2 -2
- package/dist/lib/yaml-parser.js +2 -2
- package/dist/lib/yaml-writer.js +48 -0
- package/dist/types/index.js +15 -0
- package/dist/types/metadatajson.js +2 -0
- package/dist/types/tilejson.js +2 -0
- package/dist/types/vector_layers.js +2 -0
- package/docs/.tx/config +62 -0
- package/docs/Makefile +170 -0
- package/docs/Pipfile +20 -0
- package/docs/Pipfile.lock +429 -0
- package/docs/README.md +43 -0
- package/docs/make.bat +35 -0
- package/docs/source/_static/.gitkeep +0 -0
- package/docs/source/_templates/.gitkeep +0 -0
- package/docs/source/conf.py +69 -0
- package/docs/source/development/index.rst +40 -0
- package/docs/source/index.rst +61 -0
- package/docs/source/install/index.rst +10 -0
- package/docs/source/install/install.rst +7 -0
- package/docs/source/install/install_on_nanban.rst +9 -0
- package/docs/source/install/recommended_environment.rst +6 -0
- package/docs/source/usage/commandline_interface.rst +102 -0
- package/docs/source/usage/examples.rst +74 -0
- package/docs/source/usage/global_options.rst +21 -0
- package/docs/source/usage/index.rst +10 -0
- package/package.json +12 -4
- package/provider/default/app.css +10 -0
- package/provider/default/app.js +31 -5
- package/provider/default/index.html +7 -0
- package/provider/geolonia/app.css +10 -0
- package/provider/geolonia/app.js +29 -5
- package/provider/geolonia/index.html +7 -0
- package/provider/mapbox/app.css +10 -0
- package/provider/mapbox/app.js +31 -5
- package/provider/mapbox/index.html +7 -0
- package/src/cli/build.ts +77 -0
- package/src/cli/convert.ts +18 -0
- package/src/cli/init.ts +34 -0
- package/src/cli/serve.ts +39 -0
- package/src/cli.ts +12 -76
- package/src/commands/build.ts +71 -9
- package/src/commands/convert.ts +16 -35
- package/src/commands/init.ts +28 -21
- package/src/commands/serve.ts +70 -57
- package/src/lib/build-sprite.ts +80 -0
- package/src/lib/defaultValues.ts +6 -6
- package/src/lib/error.ts +6 -0
- package/src/lib/get-sprite-slug.ts +18 -0
- package/src/lib/tileinfo-importer/base-importer.ts +57 -0
- package/src/lib/tileinfo-importer/index.ts +2 -0
- package/src/lib/tileinfo-importer/metadata-importer.ts +44 -0
- package/src/lib/tileinfo-importer/tilejson-importer.ts +29 -0
- package/src/lib/validate-style.ts +8 -2
- package/src/lib/yaml-parser.ts +9 -8
- package/src/lib/yaml-writer.ts +68 -0
- package/src/types/index.ts +3 -0
- package/src/types/metadatajson.ts +16 -0
- package/src/types/tilejson.ts +25 -0
- package/src/types/vector_layers.ts +11 -0
- package/test/build-sprite.spec.ts +24 -0
- package/test/build.spec.ts +121 -16
- package/test/convert.spec.ts +7 -7
- package/test/data/icons/aerialway.svg +4 -0
- package/test/data/init/init.yml +6 -0
- package/test/data/init/init_metadata.yml +60 -0
- package/test/data/init/init_tilejson.yml +28 -0
- package/test/data/init/init_tilejson_without_layers.yml +9 -0
- package/test/data/init/tilejson/init_decomposite.yml +13 -0
- package/test/data/init/tilejson/layers/bicycle_parking.yml +6 -0
- package/test/data/init/tilejson/layers/showers.yml +6 -0
- package/test/data/init/tilejson/layers/telephone.yml +6 -0
- package/test/get-sprite-slug.spec.ts +34 -0
- package/test/init.spec.ts +151 -0
- package/test/validate-style.spec.ts +7 -5
- package/test/yaml-parser.spec.ts +15 -15
- package/tsconfig.json +3 -1
package/dist/commands/build.js
CHANGED
|
@@ -3,14 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.build = void 0;
|
|
6
|
+
exports.buildWatch = exports.build = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const yaml_parser_1 = require("../lib/yaml-parser");
|
|
10
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");
|
|
11
13
|
const defaultValues_1 = require("../lib/defaultValues");
|
|
12
14
|
const jsonminify_1 = __importDefault(require("jsonminify"));
|
|
13
|
-
|
|
15
|
+
const node_watch_1 = __importDefault(require("node-watch"));
|
|
16
|
+
async function build(source, destination, options) {
|
|
14
17
|
let sourcePath = path_1.default.resolve(process.cwd(), source);
|
|
15
18
|
// The `source` is absolute path.
|
|
16
19
|
if (source.match(/^\//)) {
|
|
@@ -19,7 +22,7 @@ function build(source, destination, options) {
|
|
|
19
22
|
if (!fs_1.default.existsSync(sourcePath)) {
|
|
20
23
|
throw `${sourcePath}: No such file or directory`;
|
|
21
24
|
}
|
|
22
|
-
let destinationPath =
|
|
25
|
+
let destinationPath = '';
|
|
23
26
|
if (destination) {
|
|
24
27
|
if (destination.match(/^\//)) {
|
|
25
28
|
destinationPath = destination;
|
|
@@ -39,7 +42,23 @@ function build(source, destination, options) {
|
|
|
39
42
|
try {
|
|
40
43
|
const _style = yaml_parser_1.parser(sourcePath);
|
|
41
44
|
validate_style_1.validateStyle(_style, provider);
|
|
45
|
+
if (options.spriteUrl && 'sprite' in _style) {
|
|
46
|
+
_style.sprite = options.spriteUrl;
|
|
47
|
+
}
|
|
42
48
|
style = JSON.stringify(_style, null, ' ');
|
|
49
|
+
if (options.spriteInput && options.spriteOutput) {
|
|
50
|
+
if (!fs_1.default.existsSync(options.spriteInput)) {
|
|
51
|
+
throw `${options.spriteInput}: No such directory. Please specify valid icon input directory. For more help run charites build --help`;
|
|
52
|
+
}
|
|
53
|
+
if (!fs_1.default.existsSync(options.spriteOutput)) {
|
|
54
|
+
throw `${options.spriteOutput}: No such directory. Please specify valid icon output directory. For more help run charites build --help`;
|
|
55
|
+
}
|
|
56
|
+
const iconSlug = get_sprite_slug_1.getSpriteSlug(JSON.parse(style));
|
|
57
|
+
if (!iconSlug) {
|
|
58
|
+
throw `Invalid sprite url format.`;
|
|
59
|
+
}
|
|
60
|
+
await build_sprite_1.buildSprite(options.spriteInput, options.spriteOutput, iconSlug);
|
|
61
|
+
}
|
|
43
62
|
if (options.compactOutput) {
|
|
44
63
|
style = jsonminify_1.default(style);
|
|
45
64
|
}
|
|
@@ -60,3 +79,20 @@ function build(source, destination, options) {
|
|
|
60
79
|
}
|
|
61
80
|
}
|
|
62
81
|
exports.build = build;
|
|
82
|
+
function buildWatch(source, destination, options) {
|
|
83
|
+
let sourcePath = path_1.default.resolve(process.cwd(), source);
|
|
84
|
+
if (source.match(/^\//)) {
|
|
85
|
+
sourcePath = source;
|
|
86
|
+
}
|
|
87
|
+
console.log(path_1.default.dirname(sourcePath));
|
|
88
|
+
return node_watch_1.default(path_1.default.dirname(sourcePath), { recursive: true, filter: /\.yml$/ }, (event, file) => {
|
|
89
|
+
console.log(`${(event || '').toUpperCase()}: ${file}`);
|
|
90
|
+
try {
|
|
91
|
+
build(source, destination, options);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
// Nothing to do
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.buildWatch = buildWatch;
|
package/dist/commands/convert.js
CHANGED
|
@@ -6,25 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.convert = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
9
|
const readline_1 = __importDefault(require("readline"));
|
|
11
|
-
|
|
12
|
-
const writeYaml = (destinationPath, style) => {
|
|
13
|
-
const layers = [];
|
|
14
|
-
for (let i = 0; i < style.layers.length; i++) {
|
|
15
|
-
const layer = style.layers[i];
|
|
16
|
-
const layerYml = js_yaml_1.default.dump(layer);
|
|
17
|
-
const fileName = `${style.layers[i].id}.yml`;
|
|
18
|
-
const dirName = path_1.default.join(path_1.default.dirname(destinationPath), 'layers');
|
|
19
|
-
fs_1.default.mkdirSync(dirName, { recursive: true });
|
|
20
|
-
fs_1.default.writeFileSync(path_1.default.join(dirName, fileName), layerYml);
|
|
21
|
-
layers.push(`!!inc/file ${path_1.default.join('layers', fileName)}`);
|
|
22
|
-
}
|
|
23
|
-
style.layers = layers;
|
|
24
|
-
fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style).replace(/'\!\!inc\/file layers\/.+\.yml'/g, function (match) {
|
|
25
|
-
return match.replace(/'/g, '');
|
|
26
|
-
}));
|
|
27
|
-
};
|
|
10
|
+
const yaml_writer_1 = require("../lib/yaml-writer");
|
|
28
11
|
const getDestinationPath = (destination, sourcePath = '') => {
|
|
29
12
|
let destinationPath;
|
|
30
13
|
if (destination) {
|
|
@@ -50,17 +33,17 @@ function convert(source, destination) {
|
|
|
50
33
|
if ('-' === source) {
|
|
51
34
|
const rl = readline_1.default.createInterface({
|
|
52
35
|
input: process.stdin,
|
|
53
|
-
terminal: false
|
|
36
|
+
terminal: false,
|
|
54
37
|
});
|
|
55
38
|
const lines = [];
|
|
56
|
-
rl.on(
|
|
39
|
+
rl.on('line', (line) => {
|
|
57
40
|
lines.push(line);
|
|
58
41
|
});
|
|
59
|
-
rl.on(
|
|
42
|
+
rl.on('close', () => {
|
|
60
43
|
const style = JSON.parse(lines.join(''));
|
|
61
44
|
const destinationPath = getDestinationPath(destination);
|
|
62
45
|
try {
|
|
63
|
-
writeYaml(destinationPath, style);
|
|
46
|
+
yaml_writer_1.writeYaml(destinationPath, style, false);
|
|
64
47
|
}
|
|
65
48
|
catch (err) {
|
|
66
49
|
throw `${destinationPath}: Permission denied`;
|
|
@@ -79,7 +62,7 @@ function convert(source, destination) {
|
|
|
79
62
|
style = JSON.parse(fs_1.default.readFileSync(sourcePath, 'utf-8'));
|
|
80
63
|
const destinationPath = getDestinationPath(destination, sourcePath);
|
|
81
64
|
try {
|
|
82
|
-
writeYaml(destinationPath, style);
|
|
65
|
+
yaml_writer_1.writeYaml(destinationPath, style, false);
|
|
83
66
|
}
|
|
84
67
|
catch (err) {
|
|
85
68
|
throw `${destinationPath}: Permission denied`;
|
package/dist/commands/init.js
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.init = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
|
-
// TODO: We need type definition for style.
|
|
4
|
+
const yaml_writer_1 = require("../lib/yaml-writer");
|
|
5
|
+
const tileinfo_importer_1 = require("../lib/tileinfo-importer");
|
|
11
6
|
const styleRoot = {
|
|
12
7
|
version: 8,
|
|
13
|
-
name:
|
|
14
|
-
sprite:
|
|
15
|
-
glyphs:
|
|
8
|
+
name: 'My Style',
|
|
9
|
+
sprite: '',
|
|
10
|
+
glyphs: '',
|
|
16
11
|
sources: {},
|
|
17
|
-
layers: []
|
|
12
|
+
layers: [],
|
|
18
13
|
};
|
|
19
|
-
function init(file) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
stylePath = file;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
fs_1.default.writeFileSync(stylePath, styleYAML);
|
|
14
|
+
async function init(file, options) {
|
|
15
|
+
let styleTemplate = JSON.parse(JSON.stringify(styleRoot));
|
|
16
|
+
if (options.tilejsonUrls) {
|
|
17
|
+
const tileJSONImporter = new tileinfo_importer_1.TileJSONImporter(options.tilejsonUrls);
|
|
18
|
+
styleTemplate = await tileJSONImporter.import(styleTemplate);
|
|
28
19
|
}
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
if (options.metadatajsonUrls) {
|
|
21
|
+
const metadataJSONImporter = new tileinfo_importer_1.MetadataJSONImporter(options.metadatajsonUrls);
|
|
22
|
+
styleTemplate = await metadataJSONImporter.import(styleTemplate);
|
|
31
23
|
}
|
|
24
|
+
yaml_writer_1.writeYaml(file, styleTemplate, options.compositeLayers);
|
|
32
25
|
}
|
|
33
26
|
exports.init = init;
|
package/dist/commands/serve.js
CHANGED
|
@@ -14,7 +14,10 @@ const yaml_parser_1 = require("../lib/yaml-parser");
|
|
|
14
14
|
const validate_style_1 = require("../lib/validate-style");
|
|
15
15
|
const defaultValues_1 = require("../lib/defaultValues");
|
|
16
16
|
function serve(source, options) {
|
|
17
|
-
|
|
17
|
+
let port = process.env.PORT || 8080;
|
|
18
|
+
if (options.port) {
|
|
19
|
+
port = Number(options.port);
|
|
20
|
+
}
|
|
18
21
|
let sourcePath = path_1.default.resolve(process.cwd(), source);
|
|
19
22
|
let provider = defaultValues_1.defaultValues.provider;
|
|
20
23
|
if (options.provider) {
|
|
@@ -38,8 +41,9 @@ function serve(source, options) {
|
|
|
38
41
|
res.end(content);
|
|
39
42
|
break;
|
|
40
43
|
case '/style.json':
|
|
41
|
-
|
|
44
|
+
let style;
|
|
42
45
|
try {
|
|
46
|
+
style = yaml_parser_1.parser(sourcePath);
|
|
43
47
|
validate_style_1.validateStyle(style, provider);
|
|
44
48
|
}
|
|
45
49
|
catch (error) {
|
|
@@ -60,7 +64,8 @@ function serve(source, options) {
|
|
|
60
64
|
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
61
65
|
try {
|
|
62
66
|
const app = fs_1.default.readFileSync(path_1.default.join(dir, 'app.js'), 'utf-8');
|
|
63
|
-
const js = app
|
|
67
|
+
const js = app
|
|
68
|
+
.replace('___PORT___', `${port}`)
|
|
64
69
|
.replace('___MAPBOX_ACCESS_TOKEN___', `${options.mapboxAccessToken || defaultValues_1.defaultValues.mapboxAccessToken}`);
|
|
65
70
|
res.end(js);
|
|
66
71
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSprite = void 0;
|
|
4
|
+
const spritezero = require('@mapbox/spritezero');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const glob = require('glob');
|
|
7
|
+
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
|
+
async function buildSprite(svgPath, publicPath, iconSlug) {
|
|
29
|
+
const pxRatios = [1, 2];
|
|
30
|
+
for (let i = 0; i < pxRatios.length; i++) {
|
|
31
|
+
const pxRatio = pxRatios[i];
|
|
32
|
+
const svgFiles = glob
|
|
33
|
+
.sync(path.join(svgPath, `*.svg`))
|
|
34
|
+
.map(function (iconPath) {
|
|
35
|
+
return {
|
|
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
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.buildSprite = buildSprite;
|
|
@@ -9,7 +9,7 @@ const os_1 = __importDefault(require("os"));
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
11
11
|
const homedir = os_1.default.homedir();
|
|
12
|
-
const defaultProvider =
|
|
12
|
+
const defaultProvider = 'default';
|
|
13
13
|
const configDir = path_1.default.join(homedir, '.charites');
|
|
14
14
|
fs_1.default.mkdirSync(configDir, { recursive: true });
|
|
15
15
|
const configFile = path_1.default.join(configDir, 'config.yml');
|
|
@@ -24,8 +24,8 @@ catch (e) {
|
|
|
24
24
|
exports.defaultValues = {
|
|
25
25
|
provider: config.provider || defaultProvider,
|
|
26
26
|
providerDir: path_1.default.join(path_1.default.dirname(path_1.default.dirname(__dirname)), 'provider'),
|
|
27
|
-
mapboxAccessToken: config.mapboxAccessToken || ''
|
|
27
|
+
mapboxAccessToken: config.mapboxAccessToken || '',
|
|
28
28
|
};
|
|
29
29
|
exports.defaultSettings = {
|
|
30
|
-
configFile: configFile
|
|
30
|
+
configFile: configFile,
|
|
31
31
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSpriteSlug = void 0;
|
|
4
|
+
function getSpriteSlug(style) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (!style.hasOwnProperty('sprite')) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const matchedUrl = (_a = style.sprite) === null || _a === void 0 ? void 0 : _a.match(/^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?(?:([^?#]*\/)([^\/?#]*))?(\?[^#]*)?(?:#.*)?$/);
|
|
10
|
+
if (!matchedUrl || !matchedUrl[2]) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
// icon slug
|
|
14
|
+
return matchedUrl[2];
|
|
15
|
+
}
|
|
16
|
+
exports.getSpriteSlug = getSpriteSlug;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseImporter = void 0;
|
|
4
|
+
class BaseImporter {
|
|
5
|
+
constructor(original_urls) {
|
|
6
|
+
const temp_urls = original_urls + '';
|
|
7
|
+
this.urls = temp_urls.split(',');
|
|
8
|
+
}
|
|
9
|
+
async import(style) {
|
|
10
|
+
if (this.urls.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
const responses = await Promise.all(this.urls.map((url) => this.getJSON(url)));
|
|
13
|
+
responses.forEach((res) => {
|
|
14
|
+
Object.keys(res.sources).forEach((sourceName) => {
|
|
15
|
+
style.sources[sourceName] = res.sources[sourceName];
|
|
16
|
+
});
|
|
17
|
+
if (res.layers.length > 0) {
|
|
18
|
+
style.layers = style.layers.concat(res.layers);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return style;
|
|
22
|
+
}
|
|
23
|
+
getVectorLayers(name, vector_layers) {
|
|
24
|
+
const layers = [];
|
|
25
|
+
if (vector_layers) {
|
|
26
|
+
vector_layers.forEach((layer) => {
|
|
27
|
+
const layerStyle = {
|
|
28
|
+
id: layer.id,
|
|
29
|
+
type: 'fill',
|
|
30
|
+
source: name,
|
|
31
|
+
'source-layer': layer.id,
|
|
32
|
+
layout: {},
|
|
33
|
+
paint: {},
|
|
34
|
+
};
|
|
35
|
+
layers.push(layerStyle);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return layers;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.BaseImporter = BaseImporter;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var metadata_importer_1 = require("./metadata-importer");
|
|
4
|
+
Object.defineProperty(exports, "MetadataJSONImporter", { enumerable: true, get: function () { return metadata_importer_1.MetadataJSONImporter; } });
|
|
5
|
+
var tilejson_importer_1 = require("./tilejson-importer");
|
|
6
|
+
Object.defineProperty(exports, "TileJSONImporter", { enumerable: true, get: function () { return tilejson_importer_1.TileJSONImporter; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
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.MetadataJSONImporter = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const base_importer_1 = require("./base-importer");
|
|
9
|
+
class MetadataJSONImporter extends base_importer_1.BaseImporter {
|
|
10
|
+
async getJSON(url) {
|
|
11
|
+
const res = await axios_1.default.get(url);
|
|
12
|
+
const matadataJSON = res.data;
|
|
13
|
+
const metadataName = matadataJSON.name
|
|
14
|
+
? matadataJSON.name
|
|
15
|
+
: Math.random().toString(32).substring(2);
|
|
16
|
+
const sources = {};
|
|
17
|
+
const urlSplited = url.split('/');
|
|
18
|
+
sources[metadataName] = {
|
|
19
|
+
type: 'vector',
|
|
20
|
+
tiles: [
|
|
21
|
+
url.replace(new RegExp(urlSplited[urlSplited.length - 1], 'g'), '{z}/{x}/{y}.pbf'),
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
if (matadataJSON.minzoom) {
|
|
25
|
+
sources[metadataName].minzoom = matadataJSON.minzoom;
|
|
26
|
+
}
|
|
27
|
+
if (matadataJSON.maxzoom) {
|
|
28
|
+
sources[metadataName].maxzoom = matadataJSON.maxzoom;
|
|
29
|
+
}
|
|
30
|
+
let layers = [];
|
|
31
|
+
if (matadataJSON.json) {
|
|
32
|
+
const vector_layers = JSON.parse(matadataJSON.json).vector_layers;
|
|
33
|
+
layers = this.getVectorLayers(metadataName, vector_layers);
|
|
34
|
+
}
|
|
35
|
+
return { sources, layers };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.MetadataJSONImporter = MetadataJSONImporter;
|
|
@@ -0,0 +1,25 @@
|
|
|
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.TileJSONImporter = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const base_importer_1 = require("./base-importer");
|
|
9
|
+
class TileJSONImporter extends base_importer_1.BaseImporter {
|
|
10
|
+
async getJSON(url) {
|
|
11
|
+
const res = await axios_1.default.get(url);
|
|
12
|
+
const tilejson = res.data;
|
|
13
|
+
const tilesetName = tilejson.name
|
|
14
|
+
? tilejson.name
|
|
15
|
+
: Math.random().toString(32).substring(2);
|
|
16
|
+
const sources = {};
|
|
17
|
+
sources[tilesetName] = {
|
|
18
|
+
type: 'vector',
|
|
19
|
+
url: url,
|
|
20
|
+
};
|
|
21
|
+
const layers = this.getVectorLayers(tilesetName, tilejson.vector_layers);
|
|
22
|
+
return { sources, layers };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.TileJSONImporter = TileJSONImporter;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validateStyle = void 0;
|
|
4
4
|
const maplibreStyleSpec = require('@maplibre/maplibre-gl-style-spec');
|
|
5
5
|
const mapboxStyleSpec = require('@mapbox/mapbox-gl-style-spec');
|
|
6
|
-
function validateStyle(style, provider =
|
|
6
|
+
function validateStyle(style, provider = 'default') {
|
|
7
7
|
let result = [];
|
|
8
8
|
if ('mapbox' === provider) {
|
|
9
9
|
result = mapboxStyleSpec.validate(style);
|
|
@@ -18,7 +18,7 @@ function validateStyle(style, provider = "default") {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
if (errors.length) {
|
|
21
|
-
throw `\u001b[31mError:\u001b[0m ${errors.join(
|
|
21
|
+
throw `\u001b[31mError:\u001b[0m ${errors.join('\n\u001b[31mError:\u001b[0m ')}`;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.validateStyle = validateStyle;
|
package/dist/lib/yaml-parser.js
CHANGED
|
@@ -13,10 +13,10 @@ function parser(file) {
|
|
|
13
13
|
const obj = js_yaml_1.default.load(yaml, {
|
|
14
14
|
schema: yamlinc.YAML_INCLUDE_SCHEMA,
|
|
15
15
|
filename: file,
|
|
16
|
-
json: true
|
|
16
|
+
json: true,
|
|
17
17
|
});
|
|
18
18
|
const styleObj = {};
|
|
19
|
-
|
|
19
|
+
const variables = {};
|
|
20
20
|
for (const key in obj) {
|
|
21
21
|
if (key.match(/^\$/)) {
|
|
22
22
|
variables[key] = obj[key];
|
|
@@ -0,0 +1,48 @@
|
|
|
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.writeYaml = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
|
+
exports.writeYaml = (destinationPath, style, composite = false) => {
|
|
11
|
+
if (composite === true) {
|
|
12
|
+
writeCompositedYaml(destinationPath, style);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
writeDecompositedYaml(destinationPath, style);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const writeCompositedYaml = (destinationPath, style) => {
|
|
19
|
+
const styleYAML = js_yaml_1.default.dump(style);
|
|
20
|
+
let stylePath = path_1.default.resolve(process.cwd(), destinationPath);
|
|
21
|
+
// The `source` is absolute path.
|
|
22
|
+
if (destinationPath.match(/^\//)) {
|
|
23
|
+
stylePath = destinationPath;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
fs_1.default.writeFileSync(stylePath, styleYAML);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw `${stylePath}: Permission denied`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const writeDecompositedYaml = (destinationPath, style) => {
|
|
33
|
+
const layers = [];
|
|
34
|
+
for (let i = 0; i < style.layers.length; i++) {
|
|
35
|
+
const layer = style.layers[i];
|
|
36
|
+
const layerYml = js_yaml_1.default.dump(layer);
|
|
37
|
+
const fileName = `${style.layers[i].id}.yml`;
|
|
38
|
+
const dirName = path_1.default.join(path_1.default.dirname(destinationPath), 'layers');
|
|
39
|
+
fs_1.default.mkdirSync(dirName, { recursive: true });
|
|
40
|
+
fs_1.default.writeFileSync(path_1.default.join(dirName, fileName), layerYml);
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
layers.push(`!!inc/file ${path_1.default.join('layers', fileName)}`);
|
|
43
|
+
}
|
|
44
|
+
style.layers = layers;
|
|
45
|
+
fs_1.default.writeFileSync(destinationPath, js_yaml_1.default.dump(style).replace(/'\!\!inc\/file layers\/.+\.yml'/g, function (match) {
|
|
46
|
+
return match.replace(/'/g, '');
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./tilejson"), exports);
|
|
14
|
+
__exportStar(require("./metadatajson"), exports);
|
|
15
|
+
__exportStar(require("./vector_layers"), exports);
|
package/docs/.tx/config
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[main]
|
|
2
|
+
host = https://www.transifex.com
|
|
3
|
+
|
|
4
|
+
[charites-docs.index]
|
|
5
|
+
file_filter = i18n/<lang>/LC_MESSAGES/index.po
|
|
6
|
+
source_file = i18n/pot/index.pot
|
|
7
|
+
source_lang = en
|
|
8
|
+
type = PO
|
|
9
|
+
|
|
10
|
+
[charites-docs.development--index]
|
|
11
|
+
file_filter = i18n/<lang>/LC_MESSAGES/development/index.po
|
|
12
|
+
source_file = i18n/pot/development/index.pot
|
|
13
|
+
source_lang = en
|
|
14
|
+
type = PO
|
|
15
|
+
|
|
16
|
+
[charites-docs.install--index]
|
|
17
|
+
file_filter = i18n/<lang>/LC_MESSAGES/install/index.po
|
|
18
|
+
source_file = i18n/pot/install/index.pot
|
|
19
|
+
source_lang = en
|
|
20
|
+
type = PO
|
|
21
|
+
|
|
22
|
+
[charites-docs.install--install]
|
|
23
|
+
file_filter = i18n/<lang>/LC_MESSAGES/install/install.po
|
|
24
|
+
source_file = i18n/pot/install/install.pot
|
|
25
|
+
source_lang = en
|
|
26
|
+
type = PO
|
|
27
|
+
|
|
28
|
+
[charites-docs.install--install_on_nanban]
|
|
29
|
+
file_filter = i18n/<lang>/LC_MESSAGES/install/install_on_nanban.po
|
|
30
|
+
source_file = i18n/pot/install/install_on_nanban.pot
|
|
31
|
+
source_lang = en
|
|
32
|
+
type = PO
|
|
33
|
+
|
|
34
|
+
[charites-docs.install--recommended_environment]
|
|
35
|
+
file_filter = i18n/<lang>/LC_MESSAGES/install/recommended_environment.po
|
|
36
|
+
source_file = i18n/pot/install/recommended_environment.pot
|
|
37
|
+
source_lang = en
|
|
38
|
+
type = PO
|
|
39
|
+
|
|
40
|
+
[charites-docs.usage--commandline_interface]
|
|
41
|
+
file_filter = i18n/<lang>/LC_MESSAGES/usage/commandline_interface.po
|
|
42
|
+
source_file = i18n/pot/usage/commandline_interface.pot
|
|
43
|
+
source_lang = en
|
|
44
|
+
type = PO
|
|
45
|
+
|
|
46
|
+
[charites-docs.usage--examples]
|
|
47
|
+
file_filter = i18n/<lang>/LC_MESSAGES/usage/examples.po
|
|
48
|
+
source_file = i18n/pot/usage/examples.pot
|
|
49
|
+
source_lang = en
|
|
50
|
+
type = PO
|
|
51
|
+
|
|
52
|
+
[charites-docs.usage--global_options]
|
|
53
|
+
file_filter = i18n/<lang>/LC_MESSAGES/usage/global_options.po
|
|
54
|
+
source_file = i18n/pot/usage/global_options.pot
|
|
55
|
+
source_lang = en
|
|
56
|
+
type = PO
|
|
57
|
+
|
|
58
|
+
[charites-docs.usage--index]
|
|
59
|
+
file_filter = i18n/<lang>/LC_MESSAGES/usage/index.po
|
|
60
|
+
source_file = i18n/pot/usage/index.pot
|
|
61
|
+
source_lang = en
|
|
62
|
+
type = PO
|