-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·56 lines (48 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const argv = require('yargs/yargs')(process.argv.slice(2))
.demandOption(['owner', 'style'])
.argv
const deepMap = require('deep-map')
const MapboxStyles = require('@mapbox/mapbox-sdk/services/styles')
const accessToken = argv['access-token'] || process.env.MapboxAccessToken
if (!accessToken) {
console.error(`Mapbox Access Token must be supplied as either --access-token sk.XXX as a command line argument or via the MapboxAccessToken environment variable`)
}
const stylesService = MapboxStyles({ accessToken })
// https://docs.mapbox.com/vector-tiles/reference/mapbox-streets-v8/#name-text--name_lang-code-text
const languages = ['ar', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'zh-Hans', 'zh-Hant', 'ja', 'ko', 'vi']
stylesService.getStyle({
styleId: argv.style,
ownerId: argv.owner,
metadata: true,
draft: false,
fresh: true,
})
.send()
.then(res => {
const canonicalStyle = res.body
languages.map(language => {
console.log(language)
const localisedStyle = deepMap(canonicalStyle, value => {
if (value === 'name_en') {
return `name_${language}`
} else {
return value
}
})
localisedStyle.name = `${canonicalStyle.name} ${language}`
stylesService.createStyle({
ownerId: argv.owner,
style: localisedStyle
})
.send()
.then(res => {
const createdStyle = res.body
console.log(`"${createdStyle.name}" ${createdStyle.owner}/${createdStyle.id}`)
}, err => {
console.error(`Error publishing ${language}`, err)
})
})
}, err => {
console.error(`Error retrieving ${argv.owner}/${argv.style}`)
})