locize-cli 10.3.2 → 10.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/CHANGELOG.md +3 -0
- package/README.md +2 -0
- package/add.js +49 -47
- package/bin/locize +693 -481
- package/combineSubkeyPreprocessor.js +86 -85
- package/convertToDesiredFormat.js +125 -125
- package/convertToFlatFormat.js +154 -154
- package/copyVersion.js +36 -36
- package/createBranch.js +32 -32
- package/deleteBranch.js +50 -50
- package/deleteNamespace.js +20 -20
- package/download.js +285 -283
- package/filterNamespaces.js +5 -5
- package/format.js +101 -101
- package/formats.js +10 -10
- package/get.js +40 -36
- package/getBranches.js +21 -21
- package/getJob.js +21 -21
- package/getProjectStats.js +21 -21
- package/getRemoteLanguages.js +19 -19
- package/getRemoteNamespace.js +59 -55
- package/index.js +1 -1
- package/isValidUuid.js +2 -2
- package/mergeBranch.js +53 -53
- package/migrate.js +148 -149
- package/missing.js +89 -89
- package/package.json +4 -2
- package/parseLocalLanguage.js +110 -110
- package/parseLocalLanguages.js +14 -14
- package/parseLocalReference.js +6 -6
- package/publishVersion.js +33 -33
- package/removeUndefinedFromArrays.js +8 -8
- package/removeVersion.js +33 -33
- package/request.js +32 -32
- package/shouldUnflatten.js +11 -11
- package/sortFlatResources.js +7 -7
- package/sync.js +417 -413
- package/unflatten.js +40 -40
package/download.js
CHANGED
|
@@ -1,358 +1,358 @@
|
|
|
1
|
-
const colors = require('colors')
|
|
2
|
-
const { mkdirp } = require('mkdirp')
|
|
3
|
-
const rimraf = require('rimraf')
|
|
4
|
-
const request = require('./request')
|
|
5
|
-
const fs = require('fs')
|
|
6
|
-
const path = require('path')
|
|
7
|
-
const async = require('async')
|
|
8
|
-
const flatten = require('flat')
|
|
9
|
-
const getRemoteNamespace = require('./getRemoteNamespace')
|
|
10
|
-
const getRemoteLanguages = require('./getRemoteLanguages')
|
|
11
|
-
const convertToDesiredFormat = require('./convertToDesiredFormat')
|
|
12
|
-
const formats = require('./formats')
|
|
13
|
-
const getProjectStats = require('./getProjectStats')
|
|
14
|
-
const reversedFileExtensionsMap = formats.reversedFileExtensionsMap
|
|
15
|
-
const locize2xcstrings = require('locize-xcstrings/cjs/locize2xcstrings')
|
|
16
|
-
const getBranches = require('./getBranches')
|
|
17
|
-
const isValidUuid = require('./isValidUuid')
|
|
18
|
-
|
|
19
|
-
function getInfosInUrl(download) {
|
|
20
|
-
const splitted = download.key.split('/')
|
|
21
|
-
const version = splitted[download.isPrivate ? 2 : 1]
|
|
22
|
-
const language = splitted[download.isPrivate ? 3 : 2]
|
|
23
|
-
const namespace = splitted[download.isPrivate ? 4 : 3]
|
|
24
|
-
return { version, language, namespace }
|
|
1
|
+
const colors = require('colors')
|
|
2
|
+
const { mkdirp } = require('mkdirp')
|
|
3
|
+
const rimraf = require('rimraf')
|
|
4
|
+
const request = require('./request')
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const async = require('async')
|
|
8
|
+
const flatten = require('flat')
|
|
9
|
+
const getRemoteNamespace = require('./getRemoteNamespace')
|
|
10
|
+
const getRemoteLanguages = require('./getRemoteLanguages')
|
|
11
|
+
const convertToDesiredFormat = require('./convertToDesiredFormat')
|
|
12
|
+
const formats = require('./formats')
|
|
13
|
+
const getProjectStats = require('./getProjectStats')
|
|
14
|
+
const reversedFileExtensionsMap = formats.reversedFileExtensionsMap
|
|
15
|
+
const locize2xcstrings = require('locize-xcstrings/cjs/locize2xcstrings')
|
|
16
|
+
const getBranches = require('./getBranches')
|
|
17
|
+
const isValidUuid = require('./isValidUuid')
|
|
18
|
+
|
|
19
|
+
function getInfosInUrl (download) {
|
|
20
|
+
const splitted = download.key.split('/')
|
|
21
|
+
const version = splitted[download.isPrivate ? 2 : 1]
|
|
22
|
+
const language = splitted[download.isPrivate ? 3 : 2]
|
|
23
|
+
const namespace = splitted[download.isPrivate ? 4 : 3]
|
|
24
|
+
return { version, language, namespace }
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function handleDownload(opt, url, err, res, downloads, cb) {
|
|
27
|
+
function handleDownload (opt, url, err, res, downloads, cb) {
|
|
28
28
|
if (err || (downloads && (downloads.errorMessage || downloads.message))) {
|
|
29
|
-
if (!cb) console.log(colors.red(`download failed for ${url} to ${opt.path}...`))
|
|
29
|
+
if (!cb) console.log(colors.red(`download failed for ${url} to ${opt.path}...`))
|
|
30
30
|
|
|
31
31
|
if (err) {
|
|
32
|
-
if (!cb) { console.error(colors.red(err.message)); process.exit(1)
|
|
33
|
-
if (cb) cb(err)
|
|
34
|
-
return
|
|
32
|
+
if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
|
|
33
|
+
if (cb) cb(err)
|
|
34
|
+
return
|
|
35
35
|
}
|
|
36
36
|
if (downloads && (downloads.errorMessage || downloads.message)) {
|
|
37
|
-
if (!cb) { console.error(colors.red((downloads.errorMessage || downloads.message))); process.exit(1)
|
|
38
|
-
if (cb) cb(new Error((downloads.errorMessage || downloads.message)))
|
|
39
|
-
return
|
|
37
|
+
if (!cb) { console.error(colors.red((downloads.errorMessage || downloads.message))); process.exit(1) }
|
|
38
|
+
if (cb) cb(new Error((downloads.errorMessage || downloads.message)))
|
|
39
|
+
return
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
if (res.status >= 300) {
|
|
43
|
-
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1)
|
|
44
|
-
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
|
|
45
|
-
return
|
|
43
|
+
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
|
|
44
|
+
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
|
|
45
|
+
return
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (opt.format === 'xcstrings') { // 1 file per namespace including all languages
|
|
49
|
-
const downloadsByNamespace = {}
|
|
49
|
+
const downloadsByNamespace = {}
|
|
50
50
|
downloads.forEach((download) => {
|
|
51
|
-
const { version, namespace } = getInfosInUrl(download)
|
|
52
|
-
opt.isPrivate = download.isPrivate
|
|
51
|
+
const { version, namespace } = getInfosInUrl(download)
|
|
52
|
+
opt.isPrivate = download.isPrivate
|
|
53
53
|
|
|
54
|
-
downloadsByNamespace[version] = downloadsByNamespace[version] || {}
|
|
55
|
-
downloadsByNamespace[version][namespace] = downloadsByNamespace[version][namespace] || []
|
|
56
|
-
downloadsByNamespace[version][namespace].push(download)
|
|
57
|
-
})
|
|
54
|
+
downloadsByNamespace[version] = downloadsByNamespace[version] || {}
|
|
55
|
+
downloadsByNamespace[version][namespace] = downloadsByNamespace[version][namespace] || []
|
|
56
|
+
downloadsByNamespace[version][namespace].push(download)
|
|
57
|
+
})
|
|
58
58
|
|
|
59
59
|
async.eachSeries(Object.keys(downloadsByNamespace), (version, clb) => {
|
|
60
60
|
async.eachLimit(Object.keys(downloadsByNamespace[version]), 20, (ns, clb) => {
|
|
61
|
-
if (opt.namespace && opt.namespace !== ns) return clb(null)
|
|
62
|
-
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(ns) < 0) return clb(null)
|
|
61
|
+
if (opt.namespace && opt.namespace !== ns) return clb(null)
|
|
62
|
+
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(ns) < 0) return clb(null)
|
|
63
63
|
|
|
64
64
|
const locizeData = {
|
|
65
65
|
sourceLng: opt.referenceLanguage,
|
|
66
66
|
resources: {}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
68
68
|
async.eachLimit(downloadsByNamespace[version][ns], 20, (download, clb2) => {
|
|
69
|
-
const { language } = getInfosInUrl(download)
|
|
69
|
+
const { language } = getInfosInUrl(download)
|
|
70
70
|
getRemoteNamespace(opt, language, ns, (err, ns, lastModified) => {
|
|
71
|
-
if (err) return clb2(err)
|
|
71
|
+
if (err) return clb2(err)
|
|
72
72
|
|
|
73
73
|
if (opt.skipEmpty && Object.keys(flatten(ns)).length === 0) {
|
|
74
|
-
return clb2(null)
|
|
74
|
+
return clb2(null)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
locizeData.resources[language] = ns
|
|
78
|
-
clb2()
|
|
79
|
-
})
|
|
77
|
+
locizeData.resources[language] = ns
|
|
78
|
+
clb2()
|
|
79
|
+
})
|
|
80
80
|
}, (err) => {
|
|
81
|
-
if (err) return clb(err)
|
|
81
|
+
if (err) return clb(err)
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
|
-
const converted = locize2xcstrings(locizeData)
|
|
84
|
+
const converted = locize2xcstrings(locizeData)
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const filledMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, '').replace(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`, ns) + reversedFileExtensionsMap[opt.format]
|
|
87
|
+
let mkdirPath
|
|
88
88
|
if (filledMask.lastIndexOf(path.sep) > 0) {
|
|
89
|
-
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
89
|
+
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function logAndClb(err) {
|
|
93
|
-
if (err) return clb(err)
|
|
94
|
-
if (!cb) console.log(colors.green(`downloaded ${version}/${ns} to ${opt.path}...`))
|
|
95
|
-
if (clb) clb(null)
|
|
92
|
+
function logAndClb (err) {
|
|
93
|
+
if (err) return clb(err)
|
|
94
|
+
if (!cb) console.log(colors.green(`downloaded ${version}/${ns} to ${opt.path}...`))
|
|
95
|
+
if (clb) clb(null)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
98
|
+
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
99
99
|
if (!opt.version) {
|
|
100
|
-
if (mkdirPath) mkdirp.sync(path.join(opt.path, version, mkdirPath))
|
|
101
|
-
fs.writeFile(path.join(opt.path, version, filledMask), fileContent, logAndClb)
|
|
102
|
-
return
|
|
100
|
+
if (mkdirPath) mkdirp.sync(path.join(opt.path, version, mkdirPath))
|
|
101
|
+
fs.writeFile(path.join(opt.path, version, filledMask), fileContent, logAndClb)
|
|
102
|
+
return
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
106
|
-
fs.writeFile(path.join(opt.path, filledMask), converted, logAndClb)
|
|
105
|
+
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
106
|
+
fs.writeFile(path.join(opt.path, filledMask), converted, logAndClb)
|
|
107
107
|
} catch (e) {
|
|
108
|
-
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
109
|
-
return clb(err)
|
|
108
|
+
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
109
|
+
return clb(err)
|
|
110
110
|
}
|
|
111
|
-
})
|
|
112
|
-
}, clb)
|
|
111
|
+
})
|
|
112
|
+
}, clb)
|
|
113
113
|
}, (err) => {
|
|
114
114
|
if (err) {
|
|
115
115
|
if (!cb) {
|
|
116
|
-
console.error(colors.red(err.message))
|
|
117
|
-
process.exit(1)
|
|
116
|
+
console.error(colors.red(err.message))
|
|
117
|
+
process.exit(1)
|
|
118
118
|
}
|
|
119
|
-
if (cb) cb(err)
|
|
120
|
-
return
|
|
119
|
+
if (cb) cb(err)
|
|
120
|
+
return
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
if (cb) cb(null)
|
|
124
|
-
})
|
|
123
|
+
if (cb) cb(null)
|
|
124
|
+
})
|
|
125
125
|
} else { // 1 file per namespace/lng
|
|
126
126
|
async.eachLimit(downloads, 20, (download, clb) => {
|
|
127
|
-
const { version, language, namespace } = getInfosInUrl(download)
|
|
128
|
-
opt.isPrivate = download.isPrivate
|
|
127
|
+
const { version, language, namespace } = getInfosInUrl(download)
|
|
128
|
+
opt.isPrivate = download.isPrivate
|
|
129
129
|
|
|
130
|
-
if (opt.namespace && opt.namespace !== namespace) return clb(null)
|
|
131
|
-
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(namespace) < 0) return clb(null)
|
|
130
|
+
if (opt.namespace && opt.namespace !== namespace) return clb(null)
|
|
131
|
+
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(namespace) < 0) return clb(null)
|
|
132
132
|
|
|
133
133
|
getRemoteNamespace(opt, language, namespace, (err, ns, lastModified) => {
|
|
134
|
-
if (err) return clb(err)
|
|
134
|
+
if (err) return clb(err)
|
|
135
135
|
|
|
136
136
|
if (opt.skipEmpty && Object.keys(flatten(ns)).length === 0) {
|
|
137
|
-
return clb(null)
|
|
137
|
+
return clb(null)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
convertToDesiredFormat(opt, namespace, language, ns, lastModified, (err, converted) => {
|
|
141
141
|
if (err) {
|
|
142
|
-
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
143
|
-
return clb(err)
|
|
142
|
+
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
143
|
+
return clb(err)
|
|
144
144
|
}
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
let filledMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, language).replace(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`, namespace) + reversedFileExtensionsMap[opt.format]
|
|
146
|
+
let mkdirPath
|
|
147
147
|
if (filledMask.lastIndexOf(path.sep) > 0) {
|
|
148
|
-
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
148
|
+
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
149
149
|
}
|
|
150
|
-
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
150
|
+
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
151
151
|
if (!opt.version) {
|
|
152
|
-
if (mkdirPath) mkdirp.sync(path.join(opt.path, version, mkdirPath))
|
|
153
|
-
fs.writeFile(path.join(opt.path, version, filledMask), fileContent, clb)
|
|
154
|
-
return
|
|
152
|
+
if (mkdirPath) mkdirp.sync(path.join(opt.path, version, mkdirPath))
|
|
153
|
+
fs.writeFile(path.join(opt.path, version, filledMask), fileContent, clb)
|
|
154
|
+
return
|
|
155
155
|
}
|
|
156
156
|
if (!opt.language) {
|
|
157
|
-
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
158
|
-
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
159
|
-
return
|
|
157
|
+
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
158
|
+
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
159
|
+
return
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
if (opt.languageFolderPrefix && filledMask.indexOf(path.sep) > 0) filledMask = filledMask.replace(opt.languageFolderPrefix + language, '')
|
|
162
|
+
if (opt.languageFolderPrefix && filledMask.indexOf(path.sep) > 0) filledMask = filledMask.replace(opt.languageFolderPrefix + language, '')
|
|
163
163
|
// if (opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`) > opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) && filledMask.lastIndexOf(path.sep) > 0) {
|
|
164
164
|
// mkdirp.sync(path.join(opt.path, filledMask.substring(0, filledMask.lastIndexOf(path.sep))));
|
|
165
165
|
// }
|
|
166
|
-
const parentDir = path.dirname(path.join(opt.path, filledMask))
|
|
167
|
-
mkdirp.sync(parentDir)
|
|
168
|
-
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
169
|
-
})
|
|
170
|
-
})
|
|
166
|
+
const parentDir = path.dirname(path.join(opt.path, filledMask))
|
|
167
|
+
mkdirp.sync(parentDir)
|
|
168
|
+
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
171
|
}, (err) => {
|
|
172
172
|
if (err) {
|
|
173
173
|
if (!cb) {
|
|
174
|
-
console.error(colors.red(err.message))
|
|
175
|
-
process.exit(1)
|
|
174
|
+
console.error(colors.red(err.message))
|
|
175
|
+
process.exit(1)
|
|
176
176
|
}
|
|
177
|
-
if (cb) cb(err)
|
|
178
|
-
return
|
|
177
|
+
if (cb) cb(err)
|
|
178
|
+
return
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
if (!cb) console.log(colors.green(`downloaded ${url} to ${opt.path}...`))
|
|
182
|
-
if (cb) cb(null)
|
|
183
|
-
})
|
|
181
|
+
if (!cb) console.log(colors.green(`downloaded ${url} to ${opt.path}...`))
|
|
182
|
+
if (cb) cb(null)
|
|
183
|
+
})
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
function handlePull(opt, toDownload, cb) {
|
|
188
|
-
const url = opt.apiPath + '/pull/' + opt.projectId + '/' + opt.version
|
|
187
|
+
function handlePull (opt, toDownload, cb) {
|
|
188
|
+
const url = opt.apiPath + '/pull/' + opt.projectId + '/' + opt.version
|
|
189
189
|
|
|
190
190
|
if (opt.format === 'xcstrings') { // 1 file per namespace including all languages
|
|
191
|
-
const downloadsByNamespace = {}
|
|
191
|
+
const downloadsByNamespace = {}
|
|
192
192
|
toDownload.forEach((download) => {
|
|
193
|
-
const { namespace } = download
|
|
194
|
-
downloadsByNamespace[namespace] = downloadsByNamespace[namespace] || []
|
|
195
|
-
downloadsByNamespace[namespace].push(download)
|
|
196
|
-
})
|
|
193
|
+
const { namespace } = download
|
|
194
|
+
downloadsByNamespace[namespace] = downloadsByNamespace[namespace] || []
|
|
195
|
+
downloadsByNamespace[namespace].push(download)
|
|
196
|
+
})
|
|
197
197
|
|
|
198
198
|
async.eachLimit(Object.keys(downloadsByNamespace), 5, (namespace, clb) => {
|
|
199
|
-
if (opt.namespace && opt.namespace !== namespace) return clb(null)
|
|
200
|
-
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(namespace) < 0) return clb(null)
|
|
199
|
+
if (opt.namespace && opt.namespace !== namespace) return clb(null)
|
|
200
|
+
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(namespace) < 0) return clb(null)
|
|
201
201
|
|
|
202
202
|
const locizeData = {
|
|
203
203
|
sourceLng: opt.referenceLanguage,
|
|
204
204
|
resources: {}
|
|
205
|
-
}
|
|
205
|
+
}
|
|
206
206
|
|
|
207
207
|
async.eachLimit(downloadsByNamespace[namespace], 5, (download, clb2) => {
|
|
208
|
-
const { language } = download
|
|
209
|
-
opt.raw = true
|
|
208
|
+
const { language } = download
|
|
209
|
+
opt.raw = true
|
|
210
210
|
getRemoteNamespace(opt, language, namespace, (err, ns, lastModified) => {
|
|
211
|
-
if (err) return clb2(err)
|
|
211
|
+
if (err) return clb2(err)
|
|
212
212
|
|
|
213
213
|
if (opt.skipEmpty && Object.keys(flatten(ns)).length === 0) {
|
|
214
|
-
return clb2(null)
|
|
214
|
+
return clb2(null)
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
locizeData.resources[language] = ns
|
|
218
|
-
clb2()
|
|
219
|
-
})
|
|
217
|
+
locizeData.resources[language] = ns
|
|
218
|
+
clb2()
|
|
219
|
+
})
|
|
220
220
|
}, (err) => {
|
|
221
|
-
if (err) return clb(err)
|
|
221
|
+
if (err) return clb(err)
|
|
222
222
|
|
|
223
223
|
try {
|
|
224
|
-
const result = locize2xcstrings(locizeData)
|
|
225
|
-
const converted = JSON.stringify(result, null, 2)
|
|
224
|
+
const result = locize2xcstrings(locizeData)
|
|
225
|
+
const converted = JSON.stringify(result, null, 2)
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
const filledMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, '').replace(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`, namespace) + reversedFileExtensionsMap[opt.format]
|
|
228
|
+
let mkdirPath
|
|
229
229
|
if (filledMask.lastIndexOf(path.sep) > 0) {
|
|
230
|
-
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
230
|
+
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
function logAndClb(err) {
|
|
234
|
-
if (err) return clb(err)
|
|
235
|
-
if (!cb) console.log(colors.green(`downloaded ${opt.version}/${namespace} to ${opt.path}...`))
|
|
236
|
-
if (clb) clb(null)
|
|
233
|
+
function logAndClb (err) {
|
|
234
|
+
if (err) return clb(err)
|
|
235
|
+
if (!cb) console.log(colors.green(`downloaded ${opt.version}/${namespace} to ${opt.path}...`))
|
|
236
|
+
if (clb) clb(null)
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
240
|
-
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
241
|
-
fs.writeFile(path.join(opt.path, filledMask), fileContent, logAndClb)
|
|
239
|
+
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
240
|
+
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
241
|
+
fs.writeFile(path.join(opt.path, filledMask), fileContent, logAndClb)
|
|
242
242
|
} catch (e) {
|
|
243
|
-
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
244
|
-
return clb(err)
|
|
243
|
+
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
244
|
+
return clb(err)
|
|
245
245
|
}
|
|
246
|
-
})
|
|
246
|
+
})
|
|
247
247
|
}, (err) => {
|
|
248
248
|
if (err) {
|
|
249
249
|
if (!cb) {
|
|
250
|
-
console.error(colors.red(err.message))
|
|
251
|
-
process.exit(1)
|
|
250
|
+
console.error(colors.red(err.message))
|
|
251
|
+
process.exit(1)
|
|
252
252
|
}
|
|
253
|
-
if (cb) cb(err)
|
|
254
|
-
return
|
|
253
|
+
if (cb) cb(err)
|
|
254
|
+
return
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
if (cb) cb(null)
|
|
258
|
-
})
|
|
257
|
+
if (cb) cb(null)
|
|
258
|
+
})
|
|
259
259
|
} else { // 1 file per namespace/lng
|
|
260
260
|
async.eachLimit(toDownload, 5, (download, clb) => {
|
|
261
|
-
const lng = download.language
|
|
262
|
-
const namespace = download.namespace
|
|
261
|
+
const lng = download.language
|
|
262
|
+
const namespace = download.namespace
|
|
263
263
|
|
|
264
|
-
if (opt.namespace && opt.namespace !== namespace) return clb(null)
|
|
265
|
-
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(namespace) < 0) return clb(null)
|
|
264
|
+
if (opt.namespace && opt.namespace !== namespace) return clb(null)
|
|
265
|
+
if (opt.namespaces && opt.namespaces.length > 0 && opt.namespaces.indexOf(namespace) < 0) return clb(null)
|
|
266
266
|
|
|
267
267
|
getRemoteNamespace(opt, lng, namespace, (err, ns, lastModified) => {
|
|
268
|
-
if (err) return clb(err)
|
|
268
|
+
if (err) return clb(err)
|
|
269
269
|
|
|
270
270
|
if (opt.skipEmpty && Object.keys(flatten(ns)).length === 0) {
|
|
271
|
-
return clb(null)
|
|
271
|
+
return clb(null)
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
convertToDesiredFormat(opt, namespace, lng, ns, lastModified, (err, converted) => {
|
|
275
275
|
if (err) {
|
|
276
|
-
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
277
|
-
return clb(err)
|
|
276
|
+
err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
|
|
277
|
+
return clb(err)
|
|
278
278
|
}
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
let filledMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, lng).replace(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`, namespace) + reversedFileExtensionsMap[opt.format]
|
|
280
|
+
let mkdirPath
|
|
281
281
|
if (filledMask.lastIndexOf(path.sep) > 0) {
|
|
282
|
-
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
282
|
+
mkdirPath = filledMask.substring(0, filledMask.lastIndexOf(path.sep))
|
|
283
283
|
}
|
|
284
|
-
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
284
|
+
const fileContent = (opt.format !== 'xlsx' && !converted.endsWith('\n')) ? (converted + '\n') : converted
|
|
285
285
|
if (!opt.language) {
|
|
286
|
-
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
287
|
-
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
288
|
-
return
|
|
286
|
+
if (mkdirPath) mkdirp.sync(path.join(opt.path, mkdirPath))
|
|
287
|
+
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
288
|
+
return
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
if (opt.languageFolderPrefix && filledMask.indexOf(path.sep) > 0) filledMask = filledMask.replace(opt.languageFolderPrefix + lng, '')
|
|
291
|
+
if (opt.languageFolderPrefix && filledMask.indexOf(path.sep) > 0) filledMask = filledMask.replace(opt.languageFolderPrefix + lng, '')
|
|
292
292
|
// if (opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`) > opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) && filledMask.lastIndexOf(path.sep) > 0) {
|
|
293
293
|
// mkdirp.sync(path.join(opt.path, filledMask.substring(0, filledMask.lastIndexOf(path.sep))));
|
|
294
294
|
// }
|
|
295
|
-
const parentDir = path.dirname(path.join(opt.path, filledMask))
|
|
296
|
-
mkdirp.sync(parentDir)
|
|
297
|
-
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
298
|
-
})
|
|
299
|
-
})
|
|
295
|
+
const parentDir = path.dirname(path.join(opt.path, filledMask))
|
|
296
|
+
mkdirp.sync(parentDir)
|
|
297
|
+
fs.writeFile(path.join(opt.path, filledMask), fileContent, clb)
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
300
|
}, (err) => {
|
|
301
301
|
if (err) {
|
|
302
302
|
if (!cb) {
|
|
303
|
-
console.error(colors.red(err.message))
|
|
304
|
-
process.exit(1)
|
|
303
|
+
console.error(colors.red(err.message))
|
|
304
|
+
process.exit(1)
|
|
305
305
|
}
|
|
306
|
-
if (cb) cb(err)
|
|
307
|
-
return
|
|
306
|
+
if (cb) cb(err)
|
|
307
|
+
return
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
if (!cb) console.log(colors.green(`downloaded ${url} to ${opt.path}...`))
|
|
311
|
-
if (cb) cb(null)
|
|
312
|
-
})
|
|
310
|
+
if (!cb) console.log(colors.green(`downloaded ${url} to ${opt.path}...`))
|
|
311
|
+
if (cb) cb(null)
|
|
312
|
+
})
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
const handleError = (err, cb) => {
|
|
317
317
|
if (!cb && err) {
|
|
318
|
-
console.error(colors.red(err.message))
|
|
319
|
-
process.exit(1)
|
|
318
|
+
console.error(colors.red(err.message))
|
|
319
|
+
process.exit(1)
|
|
320
320
|
}
|
|
321
|
-
if (cb) cb(err)
|
|
322
|
-
}
|
|
321
|
+
if (cb) cb(err)
|
|
322
|
+
}
|
|
323
323
|
|
|
324
324
|
const filterDownloadsLanguages = (opt, downloads) => {
|
|
325
325
|
if (opt.languages) {
|
|
326
326
|
downloads = downloads.filter((d) => {
|
|
327
|
-
const splitted = d.key.split('/')
|
|
327
|
+
const splitted = d.key.split('/')
|
|
328
328
|
// const p = splitted[d.isPrivate ? 1 : 0];
|
|
329
329
|
// const v = splitted[d.isPrivate ? 2 : 1];
|
|
330
|
-
const l = splitted[d.isPrivate ? 3 : 2]
|
|
331
|
-
const n = splitted[d.isPrivate ? 4 : 3]
|
|
332
|
-
return opt.languages.indexOf(l) > -1 && (!opt.namespace || opt.namespace === n)
|
|
333
|
-
})
|
|
330
|
+
const l = splitted[d.isPrivate ? 3 : 2]
|
|
331
|
+
const n = splitted[d.isPrivate ? 4 : 3]
|
|
332
|
+
return opt.languages.indexOf(l) > -1 && (!opt.namespace || opt.namespace === n)
|
|
333
|
+
})
|
|
334
334
|
}
|
|
335
|
-
return downloads
|
|
336
|
-
}
|
|
335
|
+
return downloads
|
|
336
|
+
}
|
|
337
337
|
|
|
338
338
|
const filterDownloads = (opt, downloads) => {
|
|
339
|
-
if (opt.skipEmpty) return filterDownloadsLanguages(opt, downloads.filter((d) => d.size > 2))
|
|
340
|
-
if (downloads.length < 1) return downloads
|
|
339
|
+
if (opt.skipEmpty) return filterDownloadsLanguages(opt, downloads.filter((d) => d.size > 2))
|
|
340
|
+
if (downloads.length < 1) return downloads
|
|
341
341
|
|
|
342
|
-
const allNamespaces = []
|
|
343
|
-
const downloadMap = {}
|
|
342
|
+
const allNamespaces = []
|
|
343
|
+
const downloadMap = {}
|
|
344
344
|
downloads.forEach((d) => {
|
|
345
|
-
const splitted = d.key.split('/')
|
|
346
|
-
const p = splitted[d.isPrivate ? 1 : 0]
|
|
347
|
-
const v = splitted[d.isPrivate ? 2 : 1]
|
|
348
|
-
const l = splitted[d.isPrivate ? 3 : 2]
|
|
349
|
-
const n = splitted[d.isPrivate ? 4 : 3]
|
|
350
|
-
downloadMap[p] = downloadMap[p] || {}
|
|
351
|
-
downloadMap[p][v] = downloadMap[p][v] || {}
|
|
352
|
-
downloadMap[p][v][l] = downloadMap[p][v][l] || {}
|
|
353
|
-
downloadMap[p][v][l][n] = d
|
|
354
|
-
if (allNamespaces.indexOf(n) < 0) allNamespaces.push(n)
|
|
355
|
-
})
|
|
345
|
+
const splitted = d.key.split('/')
|
|
346
|
+
const p = splitted[d.isPrivate ? 1 : 0]
|
|
347
|
+
const v = splitted[d.isPrivate ? 2 : 1]
|
|
348
|
+
const l = splitted[d.isPrivate ? 3 : 2]
|
|
349
|
+
const n = splitted[d.isPrivate ? 4 : 3]
|
|
350
|
+
downloadMap[p] = downloadMap[p] || {}
|
|
351
|
+
downloadMap[p][v] = downloadMap[p][v] || {}
|
|
352
|
+
downloadMap[p][v][l] = downloadMap[p][v][l] || {}
|
|
353
|
+
downloadMap[p][v][l][n] = d
|
|
354
|
+
if (allNamespaces.indexOf(n) < 0) allNamespaces.push(n)
|
|
355
|
+
})
|
|
356
356
|
Object.keys(downloadMap).forEach((projectId) => {
|
|
357
357
|
Object.keys(downloadMap[projectId]).forEach((version) => {
|
|
358
358
|
Object.keys(downloadMap[projectId][version]).forEach((language) => {
|
|
@@ -363,152 +363,154 @@ const filterDownloads = (opt, downloads) => {
|
|
|
363
363
|
key: `${projectId}/${version}/${language}/${namespace}`,
|
|
364
364
|
lastModified: '1960-01-01T00:00:00.000Z',
|
|
365
365
|
size: 0
|
|
366
|
-
})
|
|
366
|
+
})
|
|
367
367
|
}
|
|
368
|
-
})
|
|
369
|
-
})
|
|
370
|
-
})
|
|
371
|
-
})
|
|
372
|
-
return filterDownloadsLanguages(opt, downloads)
|
|
373
|
-
}
|
|
368
|
+
})
|
|
369
|
+
})
|
|
370
|
+
})
|
|
371
|
+
})
|
|
372
|
+
return filterDownloadsLanguages(opt, downloads)
|
|
373
|
+
}
|
|
374
374
|
|
|
375
375
|
const continueToDownload = (opt, cb) => {
|
|
376
|
-
|
|
376
|
+
let url = opt.apiPath + '/download/' + opt.projectId
|
|
377
377
|
|
|
378
378
|
if (opt.namespace && opt.namespace.indexOf(',') > 0 && opt.namespace.indexOf(' ') < 0) {
|
|
379
|
-
opt.namespaces = opt.namespace.split(',')
|
|
380
|
-
delete opt.namespace
|
|
379
|
+
opt.namespaces = opt.namespace.split(',')
|
|
380
|
+
delete opt.namespace
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
if (opt.version) {
|
|
384
|
-
url += '/' + opt.version
|
|
384
|
+
url += '/' + opt.version
|
|
385
385
|
if (!opt.languages && opt.language) {
|
|
386
|
-
url += '/' + opt.language
|
|
386
|
+
url += '/' + opt.language
|
|
387
387
|
if (opt.namespace) {
|
|
388
|
-
url += '/' + opt.namespace
|
|
388
|
+
url += '/' + opt.namespace
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
if (opt.clean) rimraf.sync(path.join(opt.path, '*'))
|
|
393
|
+
if (opt.clean) rimraf.sync(path.join(opt.path, '*'))
|
|
394
394
|
|
|
395
|
-
mkdirp.sync(opt.path)
|
|
395
|
+
mkdirp.sync(opt.path)
|
|
396
396
|
|
|
397
|
-
if (!cb) console.log(colors.yellow(`downloading ${url} to ${opt.path}...`))
|
|
397
|
+
if (!cb) console.log(colors.yellow(`downloading ${url} to ${opt.path}...`))
|
|
398
398
|
|
|
399
399
|
getRemoteLanguages(opt, (err) => {
|
|
400
|
-
if (err) return handleError(err, cb)
|
|
400
|
+
if (err) return handleError(err, cb)
|
|
401
401
|
|
|
402
402
|
if (!opt.unpublished) {
|
|
403
403
|
request(url, {
|
|
404
404
|
method: 'get',
|
|
405
|
-
headers: opt.apiKey
|
|
406
|
-
|
|
407
|
-
|
|
405
|
+
headers: opt.apiKey
|
|
406
|
+
? {
|
|
407
|
+
Authorization: opt.apiKey
|
|
408
|
+
}
|
|
409
|
+
: undefined
|
|
408
410
|
}, (err, res, obj) => {
|
|
409
411
|
if (res && res.status === 401) {
|
|
410
|
-
opt.apiKey = null
|
|
412
|
+
opt.apiKey = null
|
|
411
413
|
request(url, {
|
|
412
414
|
method: 'get',
|
|
413
415
|
}, (err, res, obj) => {
|
|
414
|
-
obj = filterDownloads(opt, obj || [])
|
|
415
|
-
handleDownload(opt, url, err, res, obj, cb)
|
|
416
|
-
})
|
|
417
|
-
return
|
|
416
|
+
obj = filterDownloads(opt, obj || [])
|
|
417
|
+
handleDownload(opt, url, err, res, obj, cb)
|
|
418
|
+
})
|
|
419
|
+
return
|
|
418
420
|
}
|
|
419
421
|
|
|
420
422
|
if (obj.length > 0) {
|
|
421
|
-
obj = filterDownloads(opt, obj || [])
|
|
422
|
-
return handleDownload(opt, url, err, res, obj, cb)
|
|
423
|
+
obj = filterDownloads(opt, obj || [])
|
|
424
|
+
return handleDownload(opt, url, err, res, obj, cb)
|
|
423
425
|
}
|
|
424
426
|
|
|
425
427
|
getProjectStats(opt, (err, res) => {
|
|
426
|
-
if (err) return handleError(err, cb)
|
|
427
|
-
if (!res) return handleError(new Error('Nothing found!'), cb)
|
|
428
|
-
if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb)
|
|
429
|
-
|
|
430
|
-
obj = filterDownloads(opt, obj || [])
|
|
431
|
-
return handleDownload(opt, url, err, res, obj, cb)
|
|
432
|
-
})
|
|
433
|
-
})
|
|
434
|
-
return
|
|
428
|
+
if (err) return handleError(err, cb)
|
|
429
|
+
if (!res) return handleError(new Error('Nothing found!'), cb)
|
|
430
|
+
if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb)
|
|
431
|
+
|
|
432
|
+
obj = filterDownloads(opt, obj || [])
|
|
433
|
+
return handleDownload(opt, url, err, res, obj, cb)
|
|
434
|
+
})
|
|
435
|
+
})
|
|
436
|
+
return
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
getProjectStats(opt, (err, res) => {
|
|
438
|
-
if (err) return handleError(err, cb)
|
|
439
|
-
if (!res) return handleError(new Error('Nothing found!'), cb)
|
|
440
|
-
if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb)
|
|
440
|
+
if (err) return handleError(err, cb)
|
|
441
|
+
if (!res) return handleError(new Error('Nothing found!'), cb)
|
|
442
|
+
if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb)
|
|
441
443
|
|
|
442
|
-
const toDownload = []
|
|
443
|
-
const lngsToCheck = opt.language ? [opt.language] : Object.keys(res[opt.version])
|
|
444
|
+
const toDownload = []
|
|
445
|
+
const lngsToCheck = opt.language ? [opt.language] : Object.keys(res[opt.version])
|
|
444
446
|
lngsToCheck.forEach((l) => {
|
|
445
447
|
if (opt.namespaces) {
|
|
446
448
|
opt.namespaces.forEach((n) => {
|
|
447
|
-
if (!res[opt.version][l][n]) return
|
|
448
|
-
if (opt.skipEmpty && res[opt.version][l][n].segmentsTranslated === 0) return
|
|
449
|
-
toDownload.push({ language: l, namespace: n })
|
|
450
|
-
})
|
|
449
|
+
if (!res[opt.version][l][n]) return
|
|
450
|
+
if (opt.skipEmpty && res[opt.version][l][n].segmentsTranslated === 0) return
|
|
451
|
+
toDownload.push({ language: l, namespace: n })
|
|
452
|
+
})
|
|
451
453
|
} else if (opt.namespace) {
|
|
452
|
-
if (!res[opt.version][l][opt.namespace]) return
|
|
453
|
-
if (opt.skipEmpty && res[opt.version][l][opt.namespace].segmentsTranslated === 0) return
|
|
454
|
-
toDownload.push({ language: l, namespace: opt.namespace })
|
|
454
|
+
if (!res[opt.version][l][opt.namespace]) return
|
|
455
|
+
if (opt.skipEmpty && res[opt.version][l][opt.namespace].segmentsTranslated === 0) return
|
|
456
|
+
toDownload.push({ language: l, namespace: opt.namespace })
|
|
455
457
|
} else {
|
|
456
458
|
Object.keys(res[opt.version][l]).forEach((n) => {
|
|
457
|
-
if (opt.skipEmpty && res[opt.version][l][n].segmentsTranslated === 0) return
|
|
458
|
-
toDownload.push({ language: l, namespace: n })
|
|
459
|
-
})
|
|
459
|
+
if (opt.skipEmpty && res[opt.version][l][n].segmentsTranslated === 0) return
|
|
460
|
+
toDownload.push({ language: l, namespace: n })
|
|
461
|
+
})
|
|
460
462
|
}
|
|
461
|
-
})
|
|
462
|
-
handlePull(opt, toDownload, cb)
|
|
463
|
-
})
|
|
464
|
-
})
|
|
465
|
-
}
|
|
463
|
+
})
|
|
464
|
+
handlePull(opt, toDownload, cb)
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
}
|
|
466
468
|
|
|
467
469
|
const download = (opt, cb) => {
|
|
468
|
-
opt.format = opt.format || 'json'
|
|
470
|
+
opt.format = opt.format || 'json'
|
|
469
471
|
if (!reversedFileExtensionsMap[opt.format]) {
|
|
470
|
-
return handleError(new Error(`${opt.format} is not a valid format!`), cb)
|
|
472
|
+
return handleError(new Error(`${opt.format} is not a valid format!`), cb)
|
|
471
473
|
}
|
|
472
474
|
|
|
473
|
-
if (opt.skipEmpty === undefined) opt.skipEmpty = true
|
|
474
|
-
opt.apiPath = opt.apiPath || 'https://api.locize.app'
|
|
475
|
-
opt.version = opt.version || 'latest'
|
|
476
|
-
opt.languageFolderPrefix = opt.languageFolderPrefix || ''
|
|
477
|
-
opt.path = opt.path || opt.target
|
|
478
|
-
opt.pathMaskInterpolationPrefix = opt.pathMaskInterpolationPrefix || '{{'
|
|
479
|
-
opt.pathMaskInterpolationSuffix = opt.pathMaskInterpolationSuffix || '}}'
|
|
480
|
-
opt.pathMask = opt.pathMask || `${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}${path.sep}${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}
|
|
481
|
-
opt.pathMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, `${opt.languageFolderPrefix}${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`)
|
|
475
|
+
if (opt.skipEmpty === undefined) opt.skipEmpty = true
|
|
476
|
+
opt.apiPath = opt.apiPath || 'https://api.locize.app'
|
|
477
|
+
opt.version = opt.version || 'latest'
|
|
478
|
+
opt.languageFolderPrefix = opt.languageFolderPrefix || ''
|
|
479
|
+
opt.path = opt.path || opt.target
|
|
480
|
+
opt.pathMaskInterpolationPrefix = opt.pathMaskInterpolationPrefix || '{{'
|
|
481
|
+
opt.pathMaskInterpolationSuffix = opt.pathMaskInterpolationSuffix || '}}'
|
|
482
|
+
opt.pathMask = opt.pathMask || `${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}${path.sep}${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`
|
|
483
|
+
opt.pathMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, `${opt.languageFolderPrefix}${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`)
|
|
482
484
|
if (opt.overriddenOnly) {
|
|
483
|
-
opt.unpublished = true
|
|
485
|
+
opt.unpublished = true
|
|
484
486
|
}
|
|
485
487
|
if (opt.unpublished && !opt.apiKey) {
|
|
486
|
-
return handleError(new Error('Please provide also an api-key!'), cb)
|
|
488
|
+
return handleError(new Error('Please provide also an api-key!'), cb)
|
|
487
489
|
}
|
|
488
490
|
|
|
489
491
|
if (opt.branch === '') {
|
|
490
|
-
return handleError(new Error('The branch name seems invalid!'), cb)
|
|
492
|
+
return handleError(new Error('The branch name seems invalid!'), cb)
|
|
491
493
|
}
|
|
492
494
|
|
|
493
495
|
if (opt.branch) {
|
|
494
496
|
getBranches(opt, (err, branches) => {
|
|
495
|
-
if (err) return handleError(err, cb)
|
|
497
|
+
if (err) return handleError(err, cb)
|
|
496
498
|
|
|
497
|
-
let b
|
|
498
|
-
if (isValidUuid(opt.branch)) b = branches.find((br) => br.id === opt.branch)
|
|
499
|
-
if (!b) b = branches.find((br) => br.name === opt.branch)
|
|
499
|
+
let b
|
|
500
|
+
if (isValidUuid(opt.branch)) b = branches.find((br) => br.id === opt.branch)
|
|
501
|
+
if (!b) b = branches.find((br) => br.name === opt.branch)
|
|
500
502
|
if (!b) {
|
|
501
|
-
return handleError(new Error(`Branch ${opt.branch} not found!`), cb)
|
|
503
|
+
return handleError(new Error(`Branch ${opt.branch} not found!`), cb)
|
|
502
504
|
}
|
|
503
|
-
opt.projectId = b.id
|
|
504
|
-
opt.version = b.version
|
|
505
|
+
opt.projectId = b.id
|
|
506
|
+
opt.version = b.version
|
|
505
507
|
|
|
506
|
-
continueToDownload(opt, cb)
|
|
507
|
-
})
|
|
508
|
-
return
|
|
508
|
+
continueToDownload(opt, cb)
|
|
509
|
+
})
|
|
510
|
+
return
|
|
509
511
|
}
|
|
510
512
|
|
|
511
|
-
continueToDownload(opt, cb)
|
|
512
|
-
}
|
|
513
|
+
continueToDownload(opt, cb)
|
|
514
|
+
}
|
|
513
515
|
|
|
514
|
-
module.exports = download
|
|
516
|
+
module.exports = download
|