locize-cli 11.0.0 → 12.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 (108) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -0
  4. package/dist/cjs/add.js +90 -0
  5. package/{bin/locize → dist/cjs/cli.js} +390 -670
  6. package/dist/cjs/combineSubkeyPreprocessor.js +155 -0
  7. package/dist/cjs/convertToDesiredFormat.js +205 -0
  8. package/dist/cjs/convertToFlatFormat.js +231 -0
  9. package/dist/cjs/copyVersion.js +60 -0
  10. package/dist/cjs/createBranch.js +59 -0
  11. package/dist/cjs/deleteBranch.js +89 -0
  12. package/dist/cjs/deleteNamespace.js +37 -0
  13. package/dist/cjs/download.js +376 -0
  14. package/dist/cjs/filterNamespaces.js +13 -0
  15. package/dist/cjs/format.js +156 -0
  16. package/dist/cjs/formats.js +33 -0
  17. package/dist/cjs/get.js +66 -0
  18. package/dist/cjs/getBranches.js +37 -0
  19. package/dist/cjs/getJob.js +37 -0
  20. package/dist/cjs/getProjectStats.js +37 -0
  21. package/dist/cjs/getRemoteLanguages.js +38 -0
  22. package/dist/cjs/getRemoteNamespace.js +125 -0
  23. package/dist/cjs/index.js +37 -0
  24. package/dist/cjs/isValidUuid.js +6 -0
  25. package/dist/cjs/lngs.js +215 -0
  26. package/dist/cjs/mapLimit.js +22 -0
  27. package/dist/cjs/mergeBranch.js +80 -0
  28. package/dist/cjs/migrate.js +239 -0
  29. package/dist/cjs/missing.js +162 -0
  30. package/dist/cjs/package.json +5 -0
  31. package/{parseLocalLanguage.js → dist/cjs/parseLocalLanguage.js} +135 -142
  32. package/dist/cjs/parseLocalLanguages.js +18 -0
  33. package/dist/cjs/parseLocalReference.js +11 -0
  34. package/dist/cjs/publishVersion.js +42 -0
  35. package/dist/cjs/removeUndefinedFromArrays.js +19 -0
  36. package/dist/cjs/removeVersion.js +42 -0
  37. package/dist/cjs/request.js +66 -0
  38. package/dist/cjs/shouldUnflatten.js +21 -0
  39. package/dist/cjs/sortFlatResources.js +13 -0
  40. package/dist/cjs/sync.js +772 -0
  41. package/dist/cjs/unflatten.js +81 -0
  42. package/dist/esm/add.js +88 -0
  43. package/dist/esm/cli.js +1020 -0
  44. package/{combineSubkeyPreprocessor.js → dist/esm/combineSubkeyPreprocessor.js} +70 -73
  45. package/dist/esm/convertToDesiredFormat.js +203 -0
  46. package/dist/esm/convertToFlatFormat.js +229 -0
  47. package/dist/esm/copyVersion.js +58 -0
  48. package/dist/esm/createBranch.js +57 -0
  49. package/dist/esm/deleteBranch.js +87 -0
  50. package/dist/esm/deleteNamespace.js +35 -0
  51. package/dist/esm/download.js +374 -0
  52. package/{filterNamespaces.js → dist/esm/filterNamespaces.js} +4 -4
  53. package/dist/esm/format.js +154 -0
  54. package/{formats.js → dist/esm/formats.js} +7 -11
  55. package/dist/esm/get.js +64 -0
  56. package/dist/esm/getBranches.js +35 -0
  57. package/dist/esm/getJob.js +35 -0
  58. package/dist/esm/getProjectStats.js +35 -0
  59. package/dist/esm/getRemoteLanguages.js +36 -0
  60. package/dist/esm/getRemoteNamespace.js +123 -0
  61. package/dist/esm/index.js +16 -0
  62. package/dist/esm/isValidUuid.js +4 -0
  63. package/dist/esm/lngs.js +213 -0
  64. package/dist/esm/mapLimit.js +20 -0
  65. package/dist/esm/mergeBranch.js +78 -0
  66. package/dist/esm/migrate.js +237 -0
  67. package/dist/esm/missing.js +160 -0
  68. package/dist/esm/parseLocalLanguage.js +194 -0
  69. package/dist/esm/parseLocalLanguages.js +16 -0
  70. package/dist/esm/parseLocalReference.js +9 -0
  71. package/dist/esm/publishVersion.js +40 -0
  72. package/{removeUndefinedFromArrays.js → dist/esm/removeUndefinedFromArrays.js} +5 -5
  73. package/dist/esm/removeVersion.js +40 -0
  74. package/dist/esm/request.js +64 -0
  75. package/{shouldUnflatten.js → dist/esm/shouldUnflatten.js} +7 -7
  76. package/dist/esm/sortFlatResources.js +11 -0
  77. package/dist/esm/sync.js +770 -0
  78. package/{unflatten.js → dist/esm/unflatten.js} +36 -34
  79. package/package.json +39 -18
  80. package/rollup.config.js +57 -0
  81. package/add.js +0 -105
  82. package/convertToDesiredFormat.js +0 -268
  83. package/convertToFlatFormat.js +0 -322
  84. package/copyVersion.js +0 -69
  85. package/createBranch.js +0 -61
  86. package/deleteBranch.js +0 -97
  87. package/deleteNamespace.js +0 -39
  88. package/download.js +0 -516
  89. package/format.js +0 -206
  90. package/get.js +0 -81
  91. package/getBranches.js +0 -40
  92. package/getJob.js +0 -40
  93. package/getProjectStats.js +0 -40
  94. package/getRemoteLanguages.js +0 -40
  95. package/getRemoteNamespace.js +0 -122
  96. package/index.js +0 -9
  97. package/isValidUuid.js +0 -2
  98. package/lngs.json +0 -211
  99. package/mergeBranch.js +0 -102
  100. package/migrate.js +0 -314
  101. package/missing.js +0 -169
  102. package/parseLocalLanguages.js +0 -22
  103. package/parseLocalReference.js +0 -10
  104. package/publishVersion.js +0 -64
  105. package/removeVersion.js +0 -64
  106. package/request.js +0 -64
  107. package/sortFlatResources.js +0 -9
  108. package/sync.js +0 -786
@@ -1,322 +0,0 @@
1
- const po2i18next = require('gettext-converter/cjs/po2i18next')
2
- const csvjson = require('csvjson')
3
- const xlsx = require('xlsx')
4
- const yaml = require('yaml')
5
- const asr2js = require('android-string-resource/cjs/asr2js')
6
- const stringsFile = require('strings-file')
7
- const xliff2js = require('xliff/cjs/xliff2js')
8
- const xliff12ToJs = require('xliff/cjs/xliff12ToJs')
9
- const targetOfjs = require('xliff/cjs/targetOfjs')
10
- const sourceOfjs = require('xliff/cjs/sourceOfjs')
11
- const resx2js = require('resx/cjs/resx2js')
12
- const ftl2js = require('fluent_conv/cjs/ftl2js')
13
- const tmx2js = require('tmexchange/cjs/tmx2js')
14
- const laravel2js = require('laravelphp/cjs/laravel2js')
15
- const javaProperties = require('@js.properties/properties')
16
- const xcstrings2locize = require('locize-xcstrings/cjs/xcstrings2locize')
17
- const flatten = require('flat')
18
- const prepareCombinedImport = require('./combineSubkeyPreprocessor').prepareImport
19
-
20
- const convertToFlatFormat = (opt, data, lng, cb) => {
21
- if (!cb) {
22
- cb = lng
23
- lng = undefined
24
- }
25
- try {
26
- if (opt.format === 'json' || opt.format === 'nested' || opt.format === 'flat') {
27
- const dataString = data.toString().trim()
28
- if (dataString[0] !== '{' && dataString[0] !== '[') {
29
- return cb(new Error(`Not a valid json file: Content starts with "${dataString[0]}" but should start with "{"`))
30
- }
31
- try {
32
- const jsonParsed = JSON.parse(dataString)
33
- cb(null, flatten(jsonParsed))
34
- } catch (err) {
35
- return cb(err)
36
- }
37
- return
38
- }
39
- if (opt.format === 'po' || opt.format === 'gettext') {
40
- try {
41
- const ret = po2i18next(data.toString(), {
42
- persistMsgIdPlural: true,
43
- ignoreCtx: true
44
- })
45
- cb(null, flatten(ret))
46
- } catch (err) {
47
- cb(err)
48
- }
49
- return
50
- }
51
- if (opt.format === 'po_i18next' || opt.format === 'gettext_i18next') {
52
- try {
53
- const potxt = data.toString()
54
- const compatibilityJSON = /msgctxt "(zero|one|two|few|many|other)"/.test(potxt) && 'v4'
55
- const ret = po2i18next(potxt, { compatibilityJSON })
56
- cb(null, flatten(ret))
57
- } catch (err) {
58
- cb(err)
59
- }
60
- return
61
- }
62
- if (opt.format === 'csv') {
63
- const options = {
64
- delimiter: ',',
65
- quote: '"'
66
- }
67
-
68
- // CRLF => LF
69
- let text = data.toString().replace(/\r\n/g, '\n')
70
-
71
- // handle multiline stuff
72
- const lines = text.split('\n')
73
- const toHandle = []
74
- lines.forEach((l) => {
75
- const amountOfOccurrencies = l.split('"').length - 1
76
- if (amountOfOccurrencies % 2 === 1) toHandle.push(l)
77
- })
78
- while (toHandle.length > 1) {
79
- let firstToHandle = toHandle.shift()
80
- const secondToHandle = toHandle.shift()
81
- const indexOfFirst = lines.indexOf(firstToHandle)
82
- const indexOfSecond = lines.indexOf(secondToHandle)
83
- let handlingIndex = indexOfFirst
84
- while (handlingIndex < indexOfSecond) {
85
- firstToHandle += `\\NeWlInE\\${lines[handlingIndex + 1]}`
86
- handlingIndex++
87
- }
88
- lines[indexOfFirst] = firstToHandle
89
- lines.splice(indexOfFirst + 1, indexOfSecond - indexOfFirst)
90
- }
91
- text = lines.join('\n')
92
-
93
- // https://en.wikipedia.org/wiki/Delimiter-separated_values
94
- // temporary replace "" with \_\" so we can revert this 3 lines after
95
- const jsonData = csvjson.toObject(text.replace(/""/g, '\\_\\"'), options)
96
- data = jsonData.reduce((mem, entry) => {
97
- if (entry.key && typeof entry[opt.referenceLanguage] === 'string') {
98
- mem[
99
- entry.key.replace(/\\_\\"/g, '"').replace(/\\NeWlInE\\/g, '\n')
100
- ] = entry[opt.referenceLanguage]
101
- .replace(/\\_\\"/g, '"')
102
- .replace(/\\NeWlInE\\/g, '\n')
103
- }
104
- return mem
105
- }, {})
106
- cb(null, data)
107
- return
108
- }
109
- if (opt.format === 'xlsx') {
110
- const wb = xlsx.read(data, { type: 'buffer' })
111
- const jsonData = xlsx.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
112
- data = jsonData.reduce((mem, entry) => {
113
- if (entry.key && typeof entry[opt.referenceLanguage] === 'string') {
114
- mem[entry.key] = entry[opt.referenceLanguage]
115
- }
116
- return mem
117
- }, {})
118
- cb(null, data)
119
- return
120
- }
121
- if (
122
- opt.format === 'yaml' ||
123
- opt.format === 'yml'
124
- ) {
125
- const d = data.toString()
126
- if (!d || d === '' || d === '\n') return cb(null, {})
127
- cb(null, flatten(yaml.parse(d)))
128
- return
129
- }
130
- if (
131
- opt.format === 'yaml-nested' ||
132
- opt.format === 'yml-nested'
133
- ) {
134
- const d = data.toString()
135
- if (!d || d === '' || d === '\n') return cb(null, {})
136
- cb(null, flatten(yaml.parse(d)))
137
- return
138
- }
139
- if (
140
- opt.format === 'yaml-rails' ||
141
- opt.format === 'yml-rails'
142
- ) {
143
- const d = data.toString()
144
- if (!d || d.trim() === '') return cb(null, {})
145
- const jsObj = yaml.parse(d)
146
- cb(
147
- null,
148
- flatten(
149
- jsObj[Object.keys(jsObj)[0]]
150
- )
151
- )
152
- return
153
- }
154
- if (
155
- opt.format === 'yaml-rails-ns' ||
156
- opt.format === 'yml-rails-ns'
157
- ) {
158
- const dn = data.toString()
159
- if (!dn || dn.trim() === '') return cb(null, {})
160
- const jsObjn = yaml.parse(dn)
161
- cb(
162
- null,
163
- flatten(
164
- jsObjn[Object.keys(jsObjn)[0]][
165
- Object.keys(jsObjn[Object.keys(jsObjn)[0]])[0]
166
- ]
167
- )
168
- )
169
- return
170
- }
171
- if (opt.format === 'android') {
172
- asr2js(data.toString(), { comment: 'right' }, (err, res) => {
173
- if (err) return cb(err)
174
- Object.keys(res).forEach((k) => {
175
- if (res[k] !== 'string' && typeof res[k].comment === 'string') {
176
- res[k] = {
177
- value: res[k].value,
178
- context: {
179
- text: res[k].comment,
180
- },
181
- }
182
- } else {
183
- res[k] = { value: res[k].value || res[k] }
184
- }
185
- })
186
- cb(null, res)
187
- })
188
- return
189
- }
190
- if (opt.format === 'strings') {
191
- // CRLF => LF
192
- data = stringsFile.parse(data.toString().replace(/\r\n/g, '\n'), false)
193
- cb(null, data)
194
- return
195
- }
196
- if (
197
- opt.format === 'xliff2' ||
198
- opt.format === 'xliff12' ||
199
- opt.format === 'xlf2' ||
200
- opt.format === 'xlf12'
201
- ) {
202
- const fn =
203
- opt.format === 'xliff12' || opt.format === 'xlf12'
204
- ? xliff12ToJs
205
- : xliff2js
206
- fn(data.toString(), (err, res) => {
207
- if (err) return cb(err)
208
- res.resources = res.resources || {}
209
- const ns = Object.keys(res.resources)[0]
210
- const orgRes = res.resources[ns] || res.resources
211
- function checkForPostProcessing (nsRes) {
212
- Object.keys(nsRes).forEach((k) => {
213
- if (orgRes[k].note && (typeof nsRes[k] === 'string' || !nsRes[k])) {
214
- nsRes[k] = {
215
- value: nsRes[k],
216
- context: {
217
- text: orgRes[k].note,
218
- }
219
- }
220
- }
221
- })
222
- return prepareCombinedImport(nsRes)
223
- }
224
- if (!res.targetLanguage) {
225
- sourceOfjs(res, (err, ret) => {
226
- if (err) return cb(err)
227
- cb(null, checkForPostProcessing(ret))
228
- })
229
- } else {
230
- let ret = targetOfjs(res)
231
- if (lng !== opt.referenceLanguage) return cb(null, checkForPostProcessing(ret))
232
- ret = ret || {}
233
- const keys = Object.keys(ret)
234
- if (keys.length === 0) return cb(null, checkForPostProcessing(ret))
235
- const allEmpty = keys.filter((k) => ret[k] !== '').length === 0
236
- if (!allEmpty) return cb(null, checkForPostProcessing(ret))
237
- ret = sourceOfjs(res)
238
- cb(null, checkForPostProcessing(ret))
239
- }
240
- })
241
- return
242
- }
243
- if (opt.format === 'resx') {
244
- resx2js(data.toString(), (err, res) => {
245
- if (err) return cb(err)
246
- res = Object.keys(res).reduce((mem, k) => {
247
- const value = res[k]
248
- if (typeof value === 'string') {
249
- mem[k] = value
250
- } else if (value.value) {
251
- mem[k] = {
252
- value: value.value,
253
- context: value.comment ? { text: value.comment } : null,
254
- }
255
- }
256
- return mem
257
- }, {})
258
- cb(null, res)
259
- })
260
- return
261
- }
262
- if (opt.format === 'fluent') {
263
- const fluentJS = ftl2js(
264
- data
265
- .toString()
266
- .replace(
267
- new RegExp(String.fromCharCode(160), 'g'),
268
- String.fromCharCode(32)
269
- )
270
- )
271
- const comments = {}
272
- Object.keys(fluentJS).forEach((prop) => {
273
- if (fluentJS[prop] && fluentJS[prop].comment) {
274
- comments[prop] = fluentJS[prop].comment
275
- delete fluentJS[prop].comment
276
- }
277
- })
278
- const res = flatten(fluentJS)
279
- if (res && comments) {
280
- Object.keys(comments).forEach((prop) => {
281
- res[`${prop}.val`] = {
282
- value: res[`${prop}.val`],
283
- context: comments[prop] ? { text: comments[prop] } : null,
284
- }
285
- })
286
- }
287
- cb(null, res)
288
- return
289
- }
290
- if (opt.format === 'tmx') {
291
- tmx2js(data.toString(), (err, jsonData) => {
292
- if (err) return cb(err)
293
- const tmxJsRes = jsonData.resources[Object.keys(jsonData.resources)[0]]
294
- const res = {}
295
- if (tmxJsRes) {
296
- Object.keys(tmxJsRes).forEach((k) => {
297
- res[k] = tmxJsRes[k][opt.referenceLanguage]
298
- })
299
- }
300
- cb(null, res)
301
- })
302
- return
303
- }
304
- if (opt.format === 'laravel') {
305
- laravel2js(data.toString(), (err, res) => cb(err, flatten(res)))
306
- return
307
- }
308
- if (opt.format === 'properties') {
309
- cb(null, javaProperties.parseToProperties(data.toString()))
310
- return
311
- }
312
- if (opt.format === 'xcstrings') {
313
- cb(null, xcstrings2locize(data.toString()))
314
- return
315
- }
316
- cb(new Error(`${opt.format} is not a valid format!`))
317
- } catch (err) {
318
- cb(err)
319
- }
320
- }
321
-
322
- module.exports = convertToFlatFormat
package/copyVersion.js DELETED
@@ -1,69 +0,0 @@
1
- const colors = require('colors')
2
- const request = require('./request')
3
- const getJob = require('./getJob')
4
-
5
- const copyVersion = (opt, cb) => {
6
- const queryParams = new URLSearchParams()
7
- if (opt.ignoreIfVersionExists) {
8
- queryParams.append('ignoreIfVersionExists', 'true')
9
- }
10
- const queryString = queryParams.size > 0 ? '?' + queryParams.toString() : ''
11
- request(opt.apiEndpoint + '/copy/' + opt.projectId + '/version/' + opt.fromVersion + '/' + opt.toVersion + queryString, {
12
- method: 'post',
13
- headers: {
14
- Authorization: opt.apiKey
15
- }
16
- }, (err, res, obj) => {
17
- if (err || (obj && (obj.errorMessage || obj.message))) {
18
- if (!cb) console.log(colors.red(`copy failed from ${opt.fromVersion} to ${opt.toVersion}...`))
19
-
20
- if (err) {
21
- if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
22
- if (cb) cb(err)
23
- return
24
- }
25
- if (obj && (obj.errorMessage || obj.message)) {
26
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
27
- if (cb) cb(new Error((obj.errorMessage || obj.message)))
28
- return
29
- }
30
- }
31
- if (res.status >= 300) {
32
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
33
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
34
- return
35
- }
36
-
37
- if (!obj || !obj.jobId) {
38
- if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1) }
39
- if (cb) cb(new Error('No jobId! Something went wrong!'))
40
- return
41
- }
42
-
43
- (function waitForJob () {
44
- getJob(opt, obj.jobId, (err, job) => {
45
- if (err) {
46
- if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
47
- if (cb) cb(err)
48
- return
49
- }
50
-
51
- if (job && !job.timeouted) {
52
- setTimeout(waitForJob, 2000)
53
- return
54
- }
55
-
56
- if (job && job.timeouted) {
57
- if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1) }
58
- if (cb) cb(new Error('Job timeouted!'))
59
- return
60
- }
61
-
62
- if (!cb) console.log(colors.green(`copy from ${opt.fromVersion} to ${opt.toVersion} succesfully requested`))
63
- if (cb) cb(null)
64
- })
65
- })()
66
- })
67
- }
68
-
69
- module.exports = copyVersion
package/createBranch.js DELETED
@@ -1,61 +0,0 @@
1
- const colors = require('colors')
2
- const request = require('./request')
3
- const getBranches = require('./getBranches')
4
-
5
- const handleError = (err, cb) => {
6
- if (!cb && err) {
7
- console.error(colors.red(err.stack))
8
- process.exit(1)
9
- }
10
- if (cb) cb(err)
11
- }
12
-
13
- const createBranch = (opt, cb) => {
14
- getBranches(opt, (err, branches) => {
15
- if (err) return handleError(err, cb)
16
-
17
- const b = branches.find((br) => br.name === opt.branch)
18
- if (b) {
19
- if (!cb) console.log(colors.green('creating branch "' + b.name + '" (' + b.id + ') not necessary, because already existing'))
20
- if (cb) cb(null, b)
21
- return
22
- }
23
-
24
- request(opt.apiEndpoint + '/branch/create/' + opt.projectId + '/' + opt.version, {
25
- method: 'post',
26
- headers: {
27
- Authorization: opt.apiKey
28
- },
29
- body: { name: opt.branch }
30
- }, (err, res, obj) => {
31
- if (err || (obj && (obj.errorMessage || obj.message))) {
32
- if (!cb) console.log(colors.red('creating branch failed...'))
33
-
34
- if (err) {
35
- if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
36
- if (cb) cb(err)
37
- return
38
- }
39
- if (obj && (obj.errorMessage || obj.message)) {
40
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
41
- if (cb) cb(new Error((obj.errorMessage || obj.message)))
42
- return
43
- }
44
- }
45
- if (res.status === 404) {
46
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1) }
47
- if (cb) cb(null, null)
48
- return
49
- }
50
- if (res.status >= 300) {
51
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
52
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
53
- return
54
- }
55
- if (!cb) console.log(colors.green('creating branch "' + obj.name + '" (' + obj.id + ') successful'))
56
- if (cb) cb(null, obj)
57
- })
58
- })
59
- }
60
-
61
- module.exports = createBranch
package/deleteBranch.js DELETED
@@ -1,97 +0,0 @@
1
- const colors = require('colors')
2
- const request = require('./request')
3
- const getBranches = require('./getBranches')
4
- const getJob = require('./getJob')
5
- const isValidUuid = require('./isValidUuid')
6
-
7
- const handleError = (err, cb) => {
8
- if (!cb && err) {
9
- console.error(colors.red(err.stack))
10
- process.exit(1)
11
- }
12
- if (cb) cb(err)
13
- }
14
-
15
- const deleteBranch = (opt, cb) => {
16
- request(opt.apiEndpoint + '/branch/' + opt.branch, {
17
- method: 'delete',
18
- headers: {
19
- Authorization: opt.apiKey
20
- }
21
- }, (err, res, obj) => {
22
- if (err || (obj && (obj.errorMessage || obj.message))) {
23
- if (!cb) console.log(colors.red('deleting branch failed...'))
24
-
25
- if (err) {
26
- if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
27
- if (cb) cb(err)
28
- return
29
- }
30
- if (obj && (obj.errorMessage || obj.message)) {
31
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
32
- if (cb) cb(new Error((obj.errorMessage || obj.message)))
33
- return
34
- }
35
- }
36
- if (res.status === 404) {
37
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1) }
38
- if (cb) cb(null, null)
39
- return
40
- }
41
- if (res.status >= 300) {
42
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
43
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
44
- return
45
- }
46
-
47
- if (!obj || !obj.jobId) {
48
- if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1) }
49
- if (cb) cb(new Error('No jobId! Something went wrong!'))
50
- return
51
- }
52
-
53
- (function waitForJob () {
54
- getJob({
55
- apiEndpoint: opt.apiEndpoint,
56
- apiKey: opt.apiKey,
57
- projectId: opt.branch
58
- }, obj.jobId, (err, job) => {
59
- if (err) {
60
- if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
61
- if (cb) cb(err)
62
- return
63
- }
64
-
65
- if (job && !job.timeouted) {
66
- setTimeout(waitForJob, 2000)
67
- return
68
- }
69
-
70
- if (job && job.timeouted) {
71
- if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1) }
72
- if (cb) cb(new Error('Job timeouted!'))
73
- return
74
- }
75
-
76
- if (!cb) console.log(colors.green(`deleting branch "${opt.branch}" succesfully requested`))
77
- if (cb) cb(null)
78
- })
79
- })()
80
- })
81
- }
82
-
83
- module.exports = (opt, cb) => {
84
- getBranches(opt, (err, branches) => {
85
- if (err) return handleError(err, cb)
86
-
87
- let b
88
- if (isValidUuid(opt.branch)) b = branches.find((br) => br.id === opt.branch)
89
- if (!b) b = branches.find((br) => br.name === opt.branch)
90
- if (!b) {
91
- return handleError(new Error(`Branch ${opt.branch} not found!`), cb)
92
- }
93
- opt.branch = b.id
94
-
95
- deleteBranch(opt, cb)
96
- })
97
- }
@@ -1,39 +0,0 @@
1
- const colors = require('colors')
2
- const request = require('./request')
3
-
4
- const deleteNamespace = (opt, cb) => {
5
- const url = opt.apiEndpoint + '/delete/' + opt.projectId + '/' + opt.version + '/' + opt.namespace
6
-
7
- if (!cb) console.log(colors.yellow(`deleting ${opt.namespace} from ${opt.version}...`))
8
-
9
- request(url, {
10
- method: 'delete',
11
- headers: {
12
- Authorization: opt.apiKey
13
- }
14
- }, (err, res, obj) => {
15
- if (err || (obj && (obj.errorMessage || obj.message))) {
16
- if (!cb) console.log(colors.red(`delete failed for ${opt.namespace} from ${opt.version}...`))
17
-
18
- if (err) {
19
- if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
20
- if (cb) cb(err)
21
- return
22
- }
23
- if (obj && (obj.errorMessage || obj.message)) {
24
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
25
- if (cb) cb(new Error((obj.errorMessage || obj.message)))
26
- return
27
- }
28
- }
29
- if (res.status >= 300) {
30
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
31
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
32
- return
33
- }
34
- if (!cb) console.log(colors.green(`deleted ${opt.namespace} from ${opt.version}...`))
35
- if (cb) cb(null)
36
- })
37
- }
38
-
39
- module.exports = deleteNamespace