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/publishVersion.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
const colors = require('colors')
|
|
2
|
-
const request = require('./request')
|
|
3
|
-
const getJob = require('./getJob')
|
|
1
|
+
const colors = require('colors')
|
|
2
|
+
const request = require('./request')
|
|
3
|
+
const getJob = require('./getJob')
|
|
4
4
|
|
|
5
5
|
const publishVersion = (opt, cb) => {
|
|
6
6
|
request(opt.apiPath + '/publish/' + opt.projectId + '/' + opt.version + (opt.tenants ? '?tenants=true' : ''), {
|
|
7
7
|
method: 'post',
|
|
8
8
|
headers: {
|
|
9
|
-
|
|
9
|
+
Authorization: opt.apiKey
|
|
10
10
|
}
|
|
11
11
|
}, (err, res, obj) => {
|
|
12
12
|
if (err || (obj && (obj.errorMessage || obj.message))) {
|
|
13
|
-
if (!cb) console.log(colors.red(`publishing failed for ${opt.version}...`))
|
|
13
|
+
if (!cb) console.log(colors.red(`publishing failed for ${opt.version}...`))
|
|
14
14
|
|
|
15
15
|
if (err) {
|
|
16
|
-
if (!cb) { console.error(colors.red(err.message)); process.exit(1)
|
|
17
|
-
if (cb) cb(err)
|
|
18
|
-
return
|
|
16
|
+
if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
|
|
17
|
+
if (cb) cb(err)
|
|
18
|
+
return
|
|
19
19
|
}
|
|
20
20
|
if (obj && (obj.errorMessage || obj.message)) {
|
|
21
|
-
if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1)
|
|
22
|
-
if (cb) cb(new Error((obj.errorMessage || obj.message)))
|
|
23
|
-
return
|
|
21
|
+
if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
|
|
22
|
+
if (cb) cb(new Error((obj.errorMessage || obj.message)))
|
|
23
|
+
return
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
if (res.status >= 300) {
|
|
27
|
-
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1)
|
|
28
|
-
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
|
|
29
|
-
return
|
|
27
|
+
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
|
|
28
|
+
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
|
|
29
|
+
return
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (!obj || !obj.jobId) {
|
|
33
|
-
if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1)
|
|
34
|
-
if (cb) cb(new Error('No jobId! Something went wrong!'))
|
|
35
|
-
return
|
|
33
|
+
if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1) }
|
|
34
|
+
if (cb) cb(new Error('No jobId! Something went wrong!'))
|
|
35
|
+
return
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
(function waitForJob() {
|
|
38
|
+
(function waitForJob () {
|
|
39
39
|
getJob(opt, obj.jobId, (err, job) => {
|
|
40
40
|
if (err) {
|
|
41
|
-
if (!cb) { console.error(colors.red(err.message)); process.exit(1)
|
|
42
|
-
if (cb) cb(err)
|
|
43
|
-
return
|
|
41
|
+
if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
|
|
42
|
+
if (cb) cb(err)
|
|
43
|
+
return
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (job && !job.timeouted) {
|
|
47
|
-
setTimeout(waitForJob, 2000)
|
|
48
|
-
return
|
|
47
|
+
setTimeout(waitForJob, 2000)
|
|
48
|
+
return
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (job && job.timeouted) {
|
|
52
|
-
if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1)
|
|
53
|
-
if (cb) cb(new Error('Job timeouted!'))
|
|
54
|
-
return
|
|
52
|
+
if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1) }
|
|
53
|
+
if (cb) cb(new Error('Job timeouted!'))
|
|
54
|
+
return
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (!cb) console.log(colors.green(`publishing for ${opt.version} succesfully requested`))
|
|
58
|
-
if (cb) cb(null)
|
|
59
|
-
})
|
|
60
|
-
})()
|
|
61
|
-
})
|
|
62
|
-
}
|
|
57
|
+
if (!cb) console.log(colors.green(`publishing for ${opt.version} succesfully requested`))
|
|
58
|
+
if (cb) cb(null)
|
|
59
|
+
})
|
|
60
|
+
})()
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
module.exports = publishVersion
|
|
64
|
+
module.exports = publishVersion
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// rails seems to start date relevant information in an array with 1 instead of 0
|
|
2
|
-
function removeUndefinedFromArrays(obj) {
|
|
3
|
-
if (!obj) return obj
|
|
2
|
+
function removeUndefinedFromArrays (obj) {
|
|
3
|
+
if (!obj) return obj
|
|
4
4
|
|
|
5
|
-
const propNames = Object.keys(obj)
|
|
5
|
+
const propNames = Object.keys(obj)
|
|
6
6
|
propNames.forEach((propName) => {
|
|
7
7
|
if (Array.isArray(obj[propName]) && obj[propName][0] === undefined) {
|
|
8
|
-
obj[propName].shift()
|
|
8
|
+
obj[propName].shift()
|
|
9
9
|
} else if (typeof obj[propName] === 'object') {
|
|
10
|
-
removeUndefinedFromArrays(obj[propName])
|
|
10
|
+
removeUndefinedFromArrays(obj[propName])
|
|
11
11
|
}
|
|
12
|
-
})
|
|
12
|
+
})
|
|
13
13
|
|
|
14
|
-
return obj
|
|
14
|
+
return obj
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
module.exports = removeUndefinedFromArrays
|
|
17
|
+
module.exports = removeUndefinedFromArrays
|
package/removeVersion.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
const colors = require('colors')
|
|
2
|
-
const request = require('./request')
|
|
3
|
-
const getJob = require('./getJob')
|
|
1
|
+
const colors = require('colors')
|
|
2
|
+
const request = require('./request')
|
|
3
|
+
const getJob = require('./getJob')
|
|
4
4
|
|
|
5
5
|
const removeVersion = (opt, cb) => {
|
|
6
6
|
request(opt.apiPath + '/version/' + opt.projectId + '/' + opt.version, {
|
|
7
7
|
method: 'delete',
|
|
8
8
|
headers: {
|
|
9
|
-
|
|
9
|
+
Authorization: opt.apiKey
|
|
10
10
|
}
|
|
11
11
|
}, (err, res, obj) => {
|
|
12
12
|
if (err || (obj && (obj.errorMessage || obj.message))) {
|
|
13
|
-
if (!cb) console.log(colors.red(`remove failed for version ${opt.version}...`))
|
|
13
|
+
if (!cb) console.log(colors.red(`remove failed for version ${opt.version}...`))
|
|
14
14
|
|
|
15
15
|
if (err) {
|
|
16
|
-
if (!cb) { console.error(colors.red(err.message)); process.exit(1)
|
|
17
|
-
if (cb) cb(err)
|
|
18
|
-
return
|
|
16
|
+
if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
|
|
17
|
+
if (cb) cb(err)
|
|
18
|
+
return
|
|
19
19
|
}
|
|
20
20
|
if (obj && (obj.errorMessage || obj.message)) {
|
|
21
|
-
if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1)
|
|
22
|
-
if (cb) cb(new Error((obj.errorMessage || obj.message)))
|
|
23
|
-
return
|
|
21
|
+
if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
|
|
22
|
+
if (cb) cb(new Error((obj.errorMessage || obj.message)))
|
|
23
|
+
return
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
if (res.status >= 300) {
|
|
27
|
-
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1)
|
|
28
|
-
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
|
|
29
|
-
return
|
|
27
|
+
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
|
|
28
|
+
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
|
|
29
|
+
return
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (!obj || !obj.jobId) {
|
|
33
|
-
if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1)
|
|
34
|
-
if (cb) cb(new Error('No jobId! Something went wrong!'))
|
|
35
|
-
return
|
|
33
|
+
if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1) }
|
|
34
|
+
if (cb) cb(new Error('No jobId! Something went wrong!'))
|
|
35
|
+
return
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
(function waitForJob() {
|
|
38
|
+
(function waitForJob () {
|
|
39
39
|
getJob(opt, obj.jobId, (err, job) => {
|
|
40
40
|
if (err) {
|
|
41
|
-
if (!cb) { console.error(colors.red(err.message)); process.exit(1)
|
|
42
|
-
if (cb) cb(err)
|
|
43
|
-
return
|
|
41
|
+
if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
|
|
42
|
+
if (cb) cb(err)
|
|
43
|
+
return
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (job && !job.timeouted) {
|
|
47
|
-
setTimeout(waitForJob, 2000)
|
|
48
|
-
return
|
|
47
|
+
setTimeout(waitForJob, 2000)
|
|
48
|
+
return
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (job && job.timeouted) {
|
|
52
|
-
if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1)
|
|
53
|
-
if (cb) cb(new Error('Job timeouted!'))
|
|
54
|
-
return
|
|
52
|
+
if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1) }
|
|
53
|
+
if (cb) cb(new Error('Job timeouted!'))
|
|
54
|
+
return
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (!cb) console.log(colors.green(`remove version ${opt.version} succesfully requested`))
|
|
58
|
-
if (cb) cb(null)
|
|
59
|
-
})
|
|
60
|
-
})()
|
|
61
|
-
})
|
|
62
|
-
}
|
|
57
|
+
if (!cb) console.log(colors.green(`remove version ${opt.version} succesfully requested`))
|
|
58
|
+
if (cb) cb(null)
|
|
59
|
+
})
|
|
60
|
+
})()
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
module.exports = removeVersion
|
|
64
|
+
module.exports = removeVersion
|
package/request.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const
|
|
2
|
-
const fetch = require('node-fetch')
|
|
3
|
-
const { HttpsProxyAgent } = require('https-proxy-agent')
|
|
4
|
-
const https = require('https')
|
|
5
|
-
const CacheableLookup = require('cacheable-lookup')
|
|
6
|
-
const cacheable = new CacheableLookup()
|
|
7
|
-
cacheable.install(https.globalAgent)
|
|
1
|
+
const pkg = require('./package.json')
|
|
2
|
+
const fetch = require('node-fetch')
|
|
3
|
+
const { HttpsProxyAgent } = require('https-proxy-agent')
|
|
4
|
+
const https = require('https')
|
|
5
|
+
const CacheableLookup = require('cacheable-lookup')
|
|
6
|
+
const cacheable = new CacheableLookup()
|
|
7
|
+
cacheable.install(https.globalAgent)
|
|
8
8
|
|
|
9
|
-
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || process.env.https_proxy || process.env.HTTPS_PROXY
|
|
9
|
+
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || process.env.https_proxy || process.env.HTTPS_PROXY
|
|
10
10
|
|
|
11
11
|
const isRetriableError = (err) => {
|
|
12
12
|
return err && err.message && (
|
|
@@ -17,48 +17,48 @@ const isRetriableError = (err) => {
|
|
|
17
17
|
err.message.indexOf('ENOTFOUND') > -1 ||
|
|
18
18
|
err.message.indexOf('ENODATA') > -1 ||
|
|
19
19
|
err.message.indexOf('ENOENT') > -1 // Windows: name exists, but not this record type
|
|
20
|
-
)
|
|
21
|
-
}
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
const isJSONResponse = (res) => res.headers.get('content-type') && res.headers.get('content-type').indexOf('json') > 0
|
|
23
|
+
const isJSONResponse = (res) => res.headers.get('content-type') && res.headers.get('content-type').indexOf('json') > 0
|
|
24
24
|
|
|
25
25
|
const handleResponse = (res) => {
|
|
26
26
|
if (isJSONResponse(res)) {
|
|
27
|
-
return new Promise((resolve, reject) => res.json().then((obj) => resolve({ res, obj })).catch(reject))
|
|
27
|
+
return new Promise((resolve, reject) => res.json().then((obj) => resolve({ res, obj })).catch(reject))
|
|
28
28
|
} else {
|
|
29
|
-
return { res }
|
|
29
|
+
return { res }
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
const handleSuccessful = (callback) => (ret) => callback(null, ret.res, ret.obj)
|
|
33
|
+
const handleSuccessful = (callback) => (ret) => callback(null, ret.res, ret.obj)
|
|
34
34
|
|
|
35
35
|
module.exports = (url, options, callback) => {
|
|
36
36
|
if (httpProxy) {
|
|
37
|
-
const httpsProxyAgent = new HttpsProxyAgent(httpProxy)
|
|
38
|
-
cacheable.install(httpsProxyAgent)
|
|
39
|
-
options.agent = httpsProxyAgent
|
|
37
|
+
const httpsProxyAgent = new HttpsProxyAgent(httpProxy)
|
|
38
|
+
cacheable.install(httpsProxyAgent)
|
|
39
|
+
options.agent = httpsProxyAgent
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
options.headers = options.headers || {}
|
|
43
|
-
options.headers['User-Agent'] = `${
|
|
44
|
-
options.headers['X-User-Agent'] = options.headers['User-Agent']
|
|
45
|
-
if (options.body || options.method !== 'get') options.headers['Content-Type'] = 'application/json'
|
|
42
|
+
options.headers = options.headers || {}
|
|
43
|
+
options.headers['User-Agent'] = `${pkg.name}/v${pkg.version} (node/${process.version}; ${process.platform} ${process.arch})`
|
|
44
|
+
options.headers['X-User-Agent'] = options.headers['User-Agent']
|
|
45
|
+
if (options.body || options.method !== 'get') options.headers['Content-Type'] = 'application/json'
|
|
46
46
|
if (options.body) {
|
|
47
47
|
if (typeof options.body !== 'string') {
|
|
48
|
-
options.body = JSON.stringify(options.body)
|
|
48
|
+
options.body = JSON.stringify(options.body)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
if (options.headers['Authorization'] === undefined) delete options.headers['Authorization']
|
|
51
|
+
if (options.headers['Authorization'] === undefined) delete options.headers['Authorization']
|
|
52
52
|
|
|
53
|
-
function retriableFetch(maxRetries) {
|
|
53
|
+
function retriableFetch (maxRetries) {
|
|
54
54
|
fetch(url, options).then(handleResponse).then(handleSuccessful(callback)).catch((err) => {
|
|
55
|
-
if (maxRetries < 1) return callback(err)
|
|
56
|
-
if (!isRetriableError(err)) return callback(err)
|
|
55
|
+
if (maxRetries < 1) return callback(err)
|
|
56
|
+
if (!isRetriableError(err)) return callback(err)
|
|
57
57
|
setTimeout(() => {
|
|
58
|
-
retriableFetch(--maxRetries)
|
|
59
|
-
}, 5000)
|
|
60
|
-
})
|
|
58
|
+
retriableFetch(--maxRetries)
|
|
59
|
+
}, 5000)
|
|
60
|
+
})
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
retriableFetch(3)
|
|
64
|
-
}
|
|
63
|
+
retriableFetch(3)
|
|
64
|
+
}
|
package/shouldUnflatten.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
const shouldUnflatten = (json) => {
|
|
2
|
-
const keys = Object.keys(json)
|
|
3
|
-
|
|
4
|
-
for (
|
|
5
|
-
|
|
2
|
+
const keys = Object.keys(json)
|
|
3
|
+
let shouldUnflatten = true
|
|
4
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
5
|
+
const key = keys[i]
|
|
6
6
|
|
|
7
7
|
if (shouldUnflatten && /( |,|\?)/.test(key)) {
|
|
8
|
-
shouldUnflatten = false
|
|
9
|
-
return shouldUnflatten
|
|
8
|
+
shouldUnflatten = false
|
|
9
|
+
return shouldUnflatten
|
|
10
10
|
} else if (shouldUnflatten && key.indexOf('.') > -1 && keys.indexOf(key.substring(0, key.lastIndexOf('.'))) > -1) {
|
|
11
|
-
shouldUnflatten = false
|
|
12
|
-
return shouldUnflatten
|
|
11
|
+
shouldUnflatten = false
|
|
12
|
+
return shouldUnflatten
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
return shouldUnflatten
|
|
17
|
-
}
|
|
16
|
+
return shouldUnflatten
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
module.exports = shouldUnflatten
|
|
19
|
+
module.exports = shouldUnflatten
|
package/sortFlatResources.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module.exports = (resources) => {
|
|
2
|
-
const keys = Object.keys(resources).sort()
|
|
3
|
-
|
|
4
|
-
for (
|
|
5
|
-
|
|
6
|
-
cleaned[key] = resources[key]
|
|
2
|
+
const keys = Object.keys(resources).sort()
|
|
3
|
+
const cleaned = {}
|
|
4
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
5
|
+
const key = keys[i]
|
|
6
|
+
cleaned[key] = resources[key]
|
|
7
7
|
}
|
|
8
|
-
return cleaned
|
|
9
|
-
}
|
|
8
|
+
return cleaned
|
|
9
|
+
}
|