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
@@ -0,0 +1,1020 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import colors from 'colors';
4
+ import path from 'node:path';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import ini from 'ini';
8
+ import migrate from './migrate.js';
9
+ import add from './add.js';
10
+ import download from './download.js';
11
+ import get from './get.js';
12
+ import sync from './sync.js';
13
+ import missing from './missing.js';
14
+ import copyVersion from './copyVersion.js';
15
+ import removeVersion from './removeVersion.js';
16
+ import publishVersion from './publishVersion.js';
17
+ import deleteNamespace from './deleteNamespace.js';
18
+ import format from './format.js';
19
+ import createBranch from './createBranch.js';
20
+ import mergeBranch from './mergeBranch.js';
21
+ import deleteBranchEntry from './deleteBranch.js';
22
+ import 'dotenv/config';
23
+
24
+ const configInHome = path.join(os.homedir(), '.locize');
25
+ const configInWorkingDirectory = path.join(process.cwd(), '.locize');
26
+ const defaultCdnType = 'standard';
27
+
28
+ const fixApiPath = (p, cdnType) => {
29
+ if (p.indexOf('.locize.app') < 0) return p
30
+ if (p.indexOf('.lite.locize.app') > 0) {
31
+ return p.replace('.lite.locize.app', `${(cdnType || defaultCdnType) === 'standard' ? '.lite' : ''}.locize.app`)
32
+ } else {
33
+ return p.replace('.locize.app', `${(cdnType || defaultCdnType) === 'standard' ? '.lite' : ''}.locize.app`)
34
+ }
35
+ };
36
+ const defaultApiEndpoint = fixApiPath('https://api.locize.app', defaultCdnType);
37
+
38
+ let config = {};
39
+ try {
40
+ config = ini.parse(fs.readFileSync(configInWorkingDirectory, 'utf-8'));
41
+ } catch (e) {
42
+ try {
43
+ config = ini.parse(fs.readFileSync(configInHome, 'utf-8'));
44
+ } catch (e) {}
45
+ }
46
+
47
+ const program = new Command();
48
+
49
+ program
50
+ .description('The official locize CLI.')
51
+ .version('12.0.0'); // This string is replaced with the actual version at build time by rollup
52
+ // .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
53
+ // .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`);
54
+
55
+ program
56
+ .command('migrate')
57
+ .alias('m')
58
+ .description('migration of existing translation files')
59
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
60
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
61
+ .option('-l, --language <lng>', 'Found namespaces will be matched to this language')
62
+ .option('-v, --ver <version>', 'Found namespaces will be matched to this version (default: latest)')
63
+ .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
64
+ .option('-L, --parse-language <true|false>', 'Parse folders as language (default: true)', 'true')
65
+ .option('-f, --format <json>', 'File format of namespaces (default: json)', 'json')
66
+ .option('-r, --replace <true|false>', 'This will empty the optionally existing namespace before saving the new translations. (default: false)', 'false')
67
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
68
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
69
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
70
+ .action((options) => {
71
+ try {
72
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
73
+ } catch (e) {}
74
+
75
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
76
+
77
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
78
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
79
+
80
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
81
+ if (!apiKey) {
82
+ console.error(colors.red(' error: missing required argument `apiKey`'));
83
+ process.exit(1);
84
+ return
85
+ }
86
+
87
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
88
+ if (!projectId) {
89
+ console.error(colors.red(' error: missing required argument `projectId`'));
90
+ process.exit(1);
91
+ return
92
+ }
93
+
94
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
95
+
96
+ if (!path.isAbsolute(options.path)) {
97
+ options.path = path.join(process.cwd(), options.path);
98
+ }
99
+
100
+ migrate({
101
+ cdnType: cdnType || defaultCdnType,
102
+ apiKey,
103
+ projectId,
104
+ apiEndpoint,
105
+ path: options.path,
106
+ language: options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG,
107
+ version,
108
+ parseLanguage: options.parseLanguage === 'true',
109
+ format: options.format,
110
+ replace: options.replace === 'true'
111
+ });
112
+ })
113
+ .on('--help', () => {
114
+ console.log(' Examples:');
115
+ console.log();
116
+ console.log(' $ locize migrate');
117
+ console.log(' $ locize migrate --path ./en --language en');
118
+ console.log(' $ locize migrate --api-key <apiKey> --project-id <projectId> --path ./en --language en');
119
+ console.log();
120
+ });
121
+
122
+ program
123
+ .command('add <namespace> <key> <value>')
124
+ .alias('a')
125
+ .description('add a new key')
126
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
127
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
128
+ .option('-l, --language <lng>', 'The language that should be targeted')
129
+ .option('-v, --ver <version>', 'The version that should be targeted (default: latest)')
130
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
131
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
132
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
133
+ .action((namespace, key, value, options) => {
134
+ try {
135
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
136
+ } catch (e) {}
137
+
138
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
139
+
140
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
141
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
142
+
143
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
144
+ if (!apiKey) {
145
+ console.error(colors.red(' error: missing required argument `apiKey`'));
146
+ process.exit(1);
147
+ return
148
+ }
149
+
150
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
151
+ if (!projectId) {
152
+ console.error(colors.red(' error: missing required argument `projectId`'));
153
+ process.exit(1);
154
+ return
155
+ }
156
+
157
+ const language = options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG;
158
+ if (!language) {
159
+ console.error(colors.red(' error: missing required argument `language`'));
160
+ process.exit(1);
161
+ return
162
+ }
163
+
164
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
165
+
166
+ add({
167
+ cdnType: cdnType || defaultCdnType,
168
+ apiKey,
169
+ projectId,
170
+ apiEndpoint,
171
+ language,
172
+ version,
173
+ namespace,
174
+ key,
175
+ value
176
+ });
177
+ })
178
+ .on('--help', () => {
179
+ console.log(' Examples:');
180
+ console.log();
181
+ console.log(' $ locize add common title "the title of my cool app"');
182
+ console.log(' $ locize add common title "the title of my cool app" --language en');
183
+ console.log(' $ locize add common title "the title of my cool app" --api-key <apiKey> --project-id <projectId> --language en');
184
+ console.log();
185
+ });
186
+
187
+ program
188
+ .command('remove <namespace> <key>')
189
+ .alias('rm')
190
+ .description('remove a key')
191
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
192
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
193
+ .option('-l, --language <lng>', 'The language that should be targeted (omitting this attribute will result in removing the key from all languages)')
194
+ .option('-v, --ver <version>', 'The version that should be targeted (default: latest)')
195
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
196
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
197
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
198
+ .action((namespace, key, options) => {
199
+ try {
200
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
201
+ } catch (e) {}
202
+
203
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
204
+
205
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
206
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
207
+
208
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
209
+ if (!apiKey) {
210
+ console.error(colors.red(' error: missing required argument `apiKey`'));
211
+ process.exit(1);
212
+ return
213
+ }
214
+
215
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
216
+ if (!projectId) {
217
+ console.error(colors.red(' error: missing required argument `projectId`'));
218
+ process.exit(1);
219
+ return
220
+ }
221
+
222
+ const language = options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG;
223
+ // if (!language) {
224
+ // console.error(colors.red(' error: missing required argument `language`');
225
+ // process.exit(1);
226
+ // return;
227
+ // }
228
+
229
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
230
+
231
+ add({
232
+ cdnType: cdnType || defaultCdnType,
233
+ apiKey,
234
+ projectId,
235
+ apiEndpoint,
236
+ language,
237
+ version,
238
+ namespace,
239
+ key
240
+ });
241
+ })
242
+ .on('--help', () => {
243
+ console.log(' Examples:');
244
+ console.log();
245
+ console.log(' $ locize remove common title');
246
+ console.log(' $ locize remove common title --language en');
247
+ console.log(' $ locize remove common title --api-key <apiKey> --project-id <projectId> --language en');
248
+ console.log();
249
+ });
250
+
251
+ program
252
+ .command('download')
253
+ .alias('dl')
254
+ .description('download namespaces')
255
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
256
+ .option('-v, --ver <version>', 'The version that should be targeted (default: latest)')
257
+ .option('-l, --language <lng>', 'The language that should be targeted')
258
+ .option('--ls, --languages <lng1,lng2>', 'The languages that should be targeted')
259
+ .option('-n, --namespace <ns>', 'The namespace that should be targeted')
260
+ .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
261
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
262
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-rails-ns, yaml-nested, yml, yml-rails, yml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties, xcstrings])', 'json')
263
+ .option('-s, --skip-empty <true|false>', 'Skips to download empty files (default: true)', 'true')
264
+ .option('-P, --language-folder-prefix <prefix>', 'This will be added as a local folder name prefix in front of the language.', '')
265
+ .option('-m, --path-mask <mask>', 'This will define the folder and file structure; do not add a file extension (default: {{language}}/{{namespace}})', `{{language}}${path.sep}{{namespace}}`)
266
+ .option('-c, --clean <true|false>', 'Removes all local files by removing the whole folder (default: false)', 'false')
267
+ .option('--up, --unpublished <true|false>', 'Downloads the current (unpublished) translations. This will generate private download costs (default: false)', 'false')
268
+ .option('--oo, --overridden-only <true|false>', 'Downloads only the current overridden (unpublished) translations of a tenant or branch project. This will generate private download costs (default: false)', 'false')
269
+ .option('-b, --branch <branch>', 'The branch name (or id) that should be targeted')
270
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
271
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
272
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
273
+ .action((options) => {
274
+ try {
275
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
276
+ } catch (e) {}
277
+
278
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
279
+
280
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
281
+
282
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
283
+
284
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
285
+ if (!projectId) {
286
+ console.error(colors.red(' error: missing required argument `projectId`'));
287
+ process.exit(1);
288
+ return
289
+ }
290
+
291
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
292
+
293
+ const language = options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG;
294
+ const languages = options.languages || config.languages || config.lngs || process.env.LOCIZE_LANGUAGES || process.env.LOCIZE_LANGS || process.env.LOCIZE_LNGS;
295
+
296
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
297
+
298
+ const namespace = options.namespace;
299
+
300
+ const format = options.format;
301
+
302
+ const skipEmpty = options.skipEmpty === 'true';
303
+
304
+ const clean = options.clean === 'true';
305
+
306
+ const unpublished = options.unpublished === 'true';
307
+
308
+ const overriddenOnly = options.overriddenOnly === 'true';
309
+
310
+ const languageFolderPrefix = options.languageFolderPrefix || '';
311
+
312
+ const pathMask = options.pathMask;
313
+
314
+ const branch = options.branch;
315
+
316
+ download({
317
+ cdnType: cdnType || defaultCdnType,
318
+ apiKey,
319
+ projectId,
320
+ apiEndpoint,
321
+ language,
322
+ languages: languages && languages.split(','),
323
+ version,
324
+ namespace,
325
+ path: options.path,
326
+ format,
327
+ skipEmpty,
328
+ clean,
329
+ languageFolderPrefix,
330
+ pathMask,
331
+ unpublished,
332
+ branch,
333
+ overriddenOnly
334
+ });
335
+ })
336
+ .on('--help', () => {
337
+ console.log(' Examples:');
338
+ console.log();
339
+ console.log(' $ locize download');
340
+ console.log(' $ locize download --ver latest');
341
+ console.log(' $ locize download --project-id <projectId> --ver latest --language en --namespace common');
342
+ console.log(' $ locize download --project-id <projectId> --ver latest --language en --namespace common --format flat');
343
+ console.log();
344
+ });
345
+
346
+ program
347
+ .command('get <namespace> <key>')
348
+ .alias('g')
349
+ .description('get a key')
350
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
351
+ .option('-l, --language <lng>', 'The language that should be targeted')
352
+ .option('-v, --ver <version>', 'The version that should be targeted (default: latest)')
353
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
354
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
355
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
356
+ .action((namespace, key, options) => {
357
+ try {
358
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
359
+ } catch (e) {}
360
+
361
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
362
+
363
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
364
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
365
+
366
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
367
+ if (!projectId) {
368
+ console.error(colors.red(' error: missing required argument `projectId`'));
369
+ process.exit(1);
370
+ return
371
+ }
372
+
373
+ const language = options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG;
374
+ if (!language) {
375
+ console.error(colors.red(' error: missing required argument `language`'));
376
+ process.exit(1);
377
+ return
378
+ }
379
+
380
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
381
+
382
+ get({
383
+ cdnType: cdnType || defaultCdnType,
384
+ apiEndpoint,
385
+ projectId,
386
+ language,
387
+ version,
388
+ namespace,
389
+ key
390
+ });
391
+ })
392
+ .on('--help', () => {
393
+ console.log(' Examples:');
394
+ console.log();
395
+ console.log(' $ locize get common title');
396
+ console.log(' $ locize get common title --language en');
397
+ console.log(' $ locize get common title --api-key <apiKey> --project-id <projectId> --language en');
398
+ console.log();
399
+ });
400
+
401
+ program
402
+ .command('sync')
403
+ .alias('s')
404
+ .description('synchronizes locize with your repository (or any other local directory)')
405
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
406
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
407
+ .option('-v, --ver <version>', 'Found namespaces will be matched to this version (default: latest)')
408
+ .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
409
+ .option('-B, --backup-deleted-path <path>', 'Saves the segments that will be deleted in this path')
410
+ .option('-A, --auto-create-path <true|false>', 'This will automatically make sure the --path is created. (default: true)', 'true')
411
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-rails-ns, yaml-nested, yml, yml-rails, yml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties, xcstrings])', 'json')
412
+ .option('-s, --skip-empty <true|false>', 'Skips to download empty files (default: false)', 'false')
413
+ .option('-c, --clean <true|false>', 'Removes all local files by removing the whole folder (default: false)', 'false')
414
+ .option('--cf, --clean-local-files <true|false>', 'Removes all local files without removing any folder (default: false)', 'false')
415
+ .option('-u, --update-values <true|false>', 'This will update values of existing translations. (default: false)', 'false')
416
+ .option('--auto-translate <true|false>', 'This will trigger auto-translation of updated translations. (default: false)', 'false')
417
+ .option('-S, --skip-delete <true|false>', 'This will skip the removal of keys on locize. (default: false)', 'false')
418
+ .option('-D, --delete-remote-namespace <true|false>', 'This will delete a complete namespace on locize, if a local file in reference language was deleted. (default: false)', 'false')
419
+ .option('-m, --path-mask <mask>', 'This will define the folder and file structure; do not add a file extension (default: {{language}}/{{namespace}})', `{{language}}${path.sep}{{namespace}}`)
420
+ .option('-P, --language-folder-prefix <prefix>', 'This will be added as a local folder name prefix in front of the language.', '')
421
+ .option('-d, --dry <true|false>', 'Dry run (default: false)', 'false')
422
+ .option('-R, --reference-language-only <true|false>', 'Check for changes in reference language only. (default: true)', 'true')
423
+ .option('-t, --compare-modification-time <true|false>', 'while comparing the namespace content between local and remote, take the modification time of the local file and the last modified time of the remote namespace into account. (default: false)', 'false')
424
+ .option('-l, --language <lng>', 'The language that should be targeted')
425
+ .option('--ls, --languages <lng1,lng2>', 'The languages that should be targeted')
426
+ .option('-n, --namespace <ns>', 'The namespace that should be targeted (you can also pass a comma separated list)')
427
+ .option('--up, --unpublished <true|false>', 'Downloads the current (unpublished) translations. This will generate private download costs (default: false)', 'false')
428
+ .option('--oo, --overridden-only <true|false>', 'Downloads only the current overridden (unpublished) translations of a tenant or branch project. This will generate private download costs (default: false)', 'false')
429
+ .option('-b, --branch <branch>', 'The branch name (or id) that should be targeted')
430
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
431
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
432
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
433
+ .action((options) => {
434
+ try {
435
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
436
+ } catch (e) {}
437
+
438
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
439
+
440
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
441
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
442
+
443
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
444
+ if (!apiKey) {
445
+ console.error(colors.red(' error: missing required argument `apiKey`'));
446
+ process.exit(1);
447
+ return
448
+ }
449
+
450
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
451
+ if (!projectId) {
452
+ console.error(colors.red(' error: missing required argument `projectId`'));
453
+ process.exit(1);
454
+ return
455
+ }
456
+
457
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
458
+
459
+ const language = options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG;
460
+ const languages = options.languages || config.languages || config.lngs || process.env.LOCIZE_LANGUAGES || process.env.LOCIZE_LANGS || process.env.LOCIZE_LNGS;
461
+
462
+ const namespace = options.namespace;
463
+
464
+ if (!path.isAbsolute(options.path)) {
465
+ options.path = path.join(process.cwd(), options.path);
466
+ }
467
+
468
+ const clean = options.clean === 'true';
469
+ const cleanLocalFiles = options.cleanLocalFiles === 'true';
470
+ const dry = options.dry === 'true';
471
+ const updateValues = options.updateValues === 'true';
472
+ const autoTranslate = options.autoTranslate === 'true';
473
+ const skipDelete = options.skipDelete === 'true';
474
+ const deleteRemoteNamespace = options.deleteRemoteNamespace === 'true';
475
+ const languageFolderPrefix = options.languageFolderPrefix || '';
476
+ const skipEmpty = options.skipEmpty === 'true';
477
+ const referenceLanguageOnly = options.referenceLanguageOnly !== 'false';
478
+ const compareModificationTime = options.compareModificationTime === 'true';
479
+ const pathMask = options.pathMask;
480
+ const unpublished = options.unpublished === 'true';
481
+ const overriddenOnly = options.overriddenOnly === 'true';
482
+ const autoCreatePath = options.autoCreatePath === 'true';
483
+ const backupDeletedPath = options.backupDeletedPath;
484
+ const branch = options.branch;
485
+
486
+ sync({
487
+ cdnType: cdnType || defaultCdnType,
488
+ apiEndpoint,
489
+ apiKey,
490
+ projectId,
491
+ version,
492
+ path: options.path,
493
+ format: options.format,
494
+ updateValues,
495
+ autoTranslate,
496
+ skipDelete,
497
+ deleteRemoteNamespace,
498
+ languageFolderPrefix,
499
+ clean,
500
+ cleanLocalFiles,
501
+ skipEmpty,
502
+ referenceLanguageOnly,
503
+ compareModificationTime,
504
+ language,
505
+ languages: languages && languages.split(','),
506
+ namespace,
507
+ dry,
508
+ pathMask,
509
+ unpublished,
510
+ autoCreatePath,
511
+ backupDeletedPath,
512
+ branch,
513
+ overriddenOnly
514
+ });
515
+ })
516
+ .on('--help', () => {
517
+ console.log(' Examples:');
518
+ console.log();
519
+ console.log(' $ locize sync');
520
+ console.log(' $ locize sync --path ./locales --version production');
521
+ console.log(' $ locize sync --api-key <apiKey> --project-id <projectId> --path ./locales --version production --format flat');
522
+ console.log();
523
+ });
524
+
525
+ program
526
+ .command('save-missing')
527
+ .alias('sm')
528
+ .description('saves missing keys to locize from your repository (or any other local directory)')
529
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
530
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
531
+ .option('-v, --ver <version>', 'Found namespaces will be matched to this version (default: latest)')
532
+ .option('-p, --path <path>', `Specify the path that should be used (default: ${process.cwd()})`, process.cwd())
533
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-rails-ns, yaml-nested, yml, yml-rails, yml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties, xcstrings])', 'json')
534
+ .option('-m, --path-mask <mask>', 'This will define the folder and file structure; do not add a file extension (default: {{language}}/{{namespace}})', `{{language}}${path.sep}{{namespace}}`)
535
+ .option('-P, --language-folder-prefix <prefix>', 'This will be added as a local folder name prefix in front of the language.', '')
536
+ .option('-d, --dry <true|false>', 'Dry run (default: false)', 'false')
537
+ .option('-R, --reference-language-only <true|false>', 'Check for changes in reference language only. (default: true)', 'true')
538
+ .option('-l, --language <lng>', 'The language that should be targeted')
539
+ .option('-n, --namespace <ns>', 'The namespace that should be targeted (you can also pass a comma separated list)')
540
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
541
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
542
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
543
+ .action((options) => {
544
+ try {
545
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
546
+ } catch (e) {}
547
+
548
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
549
+
550
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
551
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
552
+
553
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
554
+ if (!apiKey) {
555
+ console.error(colors.red(' error: missing required argument `apiKey`'));
556
+ process.exit(1);
557
+ return
558
+ }
559
+
560
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
561
+ if (!projectId) {
562
+ console.error(colors.red(' error: missing required argument `projectId`'));
563
+ process.exit(1);
564
+ return
565
+ }
566
+
567
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
568
+
569
+ const language = options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG;
570
+
571
+ const namespace = options.namespace;
572
+
573
+ if (!path.isAbsolute(options.path)) {
574
+ options.path = path.join(process.cwd(), options.path);
575
+ }
576
+
577
+ const dry = options.dry === 'true';
578
+ const updateValues = options.updateValues === 'true';
579
+ const skipDelete = options.skipDelete === 'true';
580
+ const languageFolderPrefix = options.languageFolderPrefix || '';
581
+ const referenceLanguageOnly = options.referenceLanguageOnly !== 'false';
582
+ const pathMask = options.pathMask;
583
+
584
+ missing({
585
+ cdnType: cdnType || defaultCdnType,
586
+ apiEndpoint,
587
+ apiKey,
588
+ projectId,
589
+ version,
590
+ path: options.path,
591
+ format: options.format,
592
+ updateValues,
593
+ skipDelete,
594
+ languageFolderPrefix,
595
+ referenceLanguageOnly,
596
+ language,
597
+ namespace,
598
+ dry,
599
+ pathMask
600
+ });
601
+ })
602
+ .on('--help', () => {
603
+ console.log(' Examples:');
604
+ console.log();
605
+ console.log(' $ locize save-missing');
606
+ console.log(' $ locize save-missing --path ./locales --version production');
607
+ console.log(' $ locize save-missing --api-key <apiKey> --project-id <projectId> --path ./locales --version production --format flat');
608
+ console.log();
609
+ });
610
+
611
+ program
612
+ .command('copy-version <fromVersion>')
613
+ .alias('cv')
614
+ .description('copy version')
615
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
616
+ .option('-v, --ver <version>', 'The target version to be used to copy to (default: latest)')
617
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
618
+ .option('--iv, --ignore-if-version-exists <true|false>', 'The project-id that should be used (default: false)', 'false')
619
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
620
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
621
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
622
+ .action((fromVersion, options) => {
623
+ try {
624
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
625
+ } catch (e) {}
626
+
627
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
628
+
629
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
630
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
631
+
632
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
633
+ if (!apiKey) {
634
+ console.error(colors.red(' error: missing required argument `apiKey`'));
635
+ process.exit(1);
636
+ return
637
+ }
638
+
639
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
640
+ if (!projectId) {
641
+ console.error(colors.red(' error: missing required argument `projectId`'));
642
+ process.exit(1);
643
+ return
644
+ }
645
+
646
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
647
+
648
+ const ignoreIfVersionExists = options.ignoreIfVersionExists === 'true';
649
+
650
+ copyVersion({
651
+ apiKey,
652
+ projectId,
653
+ apiEndpoint,
654
+ fromVersion,
655
+ toVersion: version,
656
+ ignoreIfVersionExists
657
+ });
658
+ })
659
+ .on('--help', () => {
660
+ console.log(' Examples:');
661
+ console.log();
662
+ console.log(' $ locize copy-version latest');
663
+ console.log(' $ locize copy-version latest --ver production');
664
+ console.log(' $ locize copy-version latest --api-key <apiKey> --project-id <projectId> --ver <version>');
665
+ console.log();
666
+ });
667
+
668
+ program
669
+ .command('remove-version <version>')
670
+ .alias('rv')
671
+ .description('remove version')
672
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
673
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
674
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
675
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
676
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
677
+ .action((version, options) => {
678
+ try {
679
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
680
+ } catch (e) {}
681
+
682
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
683
+
684
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
685
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
686
+
687
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
688
+ if (!apiKey) {
689
+ console.error(colors.red(' error: missing required argument `apiKey`'));
690
+ process.exit(1);
691
+ return
692
+ }
693
+
694
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
695
+ if (!projectId) {
696
+ console.error(colors.red(' error: missing required argument `projectId`'));
697
+ process.exit(1);
698
+ return
699
+ }
700
+
701
+ removeVersion({
702
+ apiKey,
703
+ projectId,
704
+ apiEndpoint,
705
+ version
706
+ });
707
+ })
708
+ .on('--help', () => {
709
+ console.log(' Examples:');
710
+ console.log();
711
+ console.log(' $ locize remove-version tmp-ver');
712
+ console.log(' $ locize remove-version tmp-ver --api-key <apiKey> --project-id <projectId>');
713
+ console.log();
714
+ });
715
+
716
+ program
717
+ .command('publish-version')
718
+ .alias('pv')
719
+ .description('publish version')
720
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
721
+ .option('-v, --ver <version>', 'The version to be used to publish (default: latest)')
722
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
723
+ .option('-t, --tenants <true|false>', 'Publish also tenants (if using multi-tenant setup) (default: false)', 'false')
724
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
725
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
726
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
727
+ .action((options) => {
728
+ try {
729
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
730
+ } catch (e) {}
731
+
732
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
733
+
734
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
735
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
736
+
737
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
738
+ if (!apiKey) {
739
+ console.error(colors.red(' error: missing required argument `apiKey`'));
740
+ process.exit(1);
741
+ return
742
+ }
743
+
744
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
745
+ if (!projectId) {
746
+ console.error(colors.red(' error: missing required argument `projectId`'));
747
+ process.exit(1);
748
+ return
749
+ }
750
+
751
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
752
+
753
+ const tenants = options.tenants === 'true';
754
+
755
+ publishVersion({
756
+ apiKey,
757
+ projectId,
758
+ apiEndpoint,
759
+ version,
760
+ tenants
761
+ });
762
+ })
763
+ .on('--help', () => {
764
+ console.log(' Examples:');
765
+ console.log();
766
+ console.log(' $ locize publish-version');
767
+ console.log(' $ locize publish-version --ver production');
768
+ console.log(' $ locize publish-version --api-key <apiKey> --project-id <projectId> --ver <version>');
769
+ console.log();
770
+ });
771
+
772
+ program
773
+ .command('delete-namespace <namespace>')
774
+ .alias('dn')
775
+ .description('delete a namespace')
776
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
777
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
778
+ .option('-v, --ver <version>', 'The version that should be targeted (default: latest)')
779
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
780
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
781
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
782
+ .action((namespace, options) => {
783
+ try {
784
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
785
+ } catch (e) {}
786
+
787
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
788
+
789
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
790
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
791
+
792
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
793
+ if (!apiKey) {
794
+ console.error(colors.red(' error: missing required argument `apiKey`'));
795
+ process.exit(1);
796
+ return
797
+ }
798
+
799
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
800
+ if (!projectId) {
801
+ console.error(colors.red(' error: missing required argument `projectId`'));
802
+ process.exit(1);
803
+ return
804
+ }
805
+
806
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
807
+
808
+ deleteNamespace({
809
+ apiKey,
810
+ projectId,
811
+ apiEndpoint,
812
+ version,
813
+ namespace
814
+ });
815
+ })
816
+ .on('--help', () => {
817
+ console.log(' Examples:');
818
+ console.log();
819
+ console.log(' $ locize delete-namespace common');
820
+ console.log(' $ locize delete-namespace common --api-key <apiKey> --project-id <projectId>');
821
+ console.log();
822
+ });
823
+
824
+ program
825
+ .command('format [fileOrDirectory]')
826
+ .alias('ft')
827
+ .description('format local files')
828
+ .option('-f, --format <json>', 'File format of namespaces (default: json; [nested, flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-rails-ns, yaml-nested, yml, yml-rails, yml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties, xcstrings])', 'json')
829
+ .option('-l, --reference-language <lng>', 'Some format conversions need to know the reference language.', 'en')
830
+ .option('-d, --dry <true|false>', 'Dry run (default: false)', 'false')
831
+ .action((fileOrDirectory, options) => {
832
+ fileOrDirectory = fileOrDirectory || '.';
833
+
834
+ if (!path.isAbsolute(fileOrDirectory)) {
835
+ fileOrDirectory = path.join(process.cwd(), fileOrDirectory);
836
+ }
837
+
838
+ const format$1 = options.format;
839
+ const dry = options.dry === 'true';
840
+ const referenceLanguage = options.referenceLanguage;
841
+
842
+ format({
843
+ fileOrDirectory,
844
+ format: format$1,
845
+ referenceLanguage,
846
+ dry
847
+ });
848
+ })
849
+ .on('--help', () => {
850
+ console.log(' Examples:');
851
+ console.log();
852
+ console.log(' $ locize format');
853
+ console.log(' $ locize format path/to/file');
854
+ console.log(' $ locize format path/to/dictionary');
855
+ console.log(' $ locize format path/to/dictionary --format android');
856
+ console.log(' $ locize format path/to/dictionary --format android --dry true');
857
+ console.log(' $ locize format path/to/dictionary --format xliff2 --reference-language en');
858
+ console.log();
859
+ });
860
+
861
+ program
862
+ .command('create-branch <branch>')
863
+ .alias('cb')
864
+ .description('create branch')
865
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
866
+ .option('-v, --ver <version>', 'The target version to be used to copy to (default: latest)')
867
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
868
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
869
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
870
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
871
+ .action((branch, options) => {
872
+ try {
873
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
874
+ } catch (e) {}
875
+
876
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
877
+
878
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
879
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
880
+
881
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
882
+ if (!apiKey) {
883
+ console.error(colors.red(' error: missing required argument `apiKey`'));
884
+ process.exit(1);
885
+ return
886
+ }
887
+
888
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
889
+ if (!projectId) {
890
+ console.error(colors.red(' error: missing required argument `projectId`'));
891
+ process.exit(1);
892
+ return
893
+ }
894
+
895
+ const version = options.ver || config.ver || config.version || process.env.LOCIZE_VERSION || process.env.LOCIZE_VER || 'latest';
896
+
897
+ createBranch({
898
+ cdnType: cdnType || defaultCdnType,
899
+ apiKey,
900
+ projectId,
901
+ apiEndpoint,
902
+ version,
903
+ branch
904
+ });
905
+ })
906
+ .on('--help', () => {
907
+ console.log(' Examples:');
908
+ console.log();
909
+ console.log(' $ locize create-branch featureX');
910
+ console.log(' $ locize create-branch featureX --ver production');
911
+ console.log(' $ locize create-branch featureX --api-key <apiKey> --project-id <projectId> --ver <version>');
912
+ console.log();
913
+ });
914
+
915
+ program
916
+ .command('merge-branch <branch>')
917
+ .alias('mb')
918
+ .description('merge branch')
919
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
920
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
921
+ .option('-d, --delete <true|false>', 'This will delete the branch after merging. (default: false)', 'false')
922
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
923
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
924
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
925
+ .action((branch, options) => {
926
+ try {
927
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
928
+ } catch (e) {}
929
+
930
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
931
+
932
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
933
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
934
+
935
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
936
+ if (!apiKey) {
937
+ console.error(colors.red(' error: missing required argument `apiKey`'));
938
+ process.exit(1);
939
+ return
940
+ }
941
+
942
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
943
+ if (!projectId) {
944
+ console.error(colors.red(' error: missing required argument `projectId`'));
945
+ process.exit(1);
946
+ return
947
+ }
948
+
949
+ mergeBranch({
950
+ apiKey,
951
+ projectId,
952
+ apiEndpoint,
953
+ delete: options.delete === 'true',
954
+ branch
955
+ });
956
+ })
957
+ .on('--help', () => {
958
+ console.log(' Examples:');
959
+ console.log();
960
+ console.log(' $ locize merge-branch featureX');
961
+ console.log(' $ locize merge-branch <projectId-of-branch>');
962
+ console.log(' $ locize merge-branch featureX --delete true');
963
+ console.log(' $ locize merge-branch featureX --api-key <apiKey> --project-id <projectId> --delete true');
964
+ console.log();
965
+ });
966
+
967
+ program
968
+ .command('delete-branch <branch>')
969
+ .alias('db')
970
+ .description('delete branch')
971
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
972
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
973
+ .option('-a, --api-endpoint <url>', `Specify the api-endpoint url that should be used (default: ${defaultApiEndpoint})`)
974
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
975
+ .option('--ct, --cdn-type <standard|pro>', `Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) (default: ${defaultCdnType})`)
976
+ .action((branch, options) => {
977
+ try {
978
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
979
+ } catch (e) {}
980
+
981
+ const cdnType = options.cdnType || config.cdnType || process.env.LOCIZE_CDN_TYPE;
982
+
983
+ let apiEndpoint = options.apiEndpoint || config.apiEndpoint || process.env.LOCIZE_API_ENDPOINT || defaultApiEndpoint;
984
+ if (cdnType) apiEndpoint = fixApiPath(apiEndpoint, cdnType);
985
+
986
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
987
+ if (!apiKey) {
988
+ console.error(colors.red(' error: missing required argument `apiKey`'));
989
+ process.exit(1);
990
+ return
991
+ }
992
+
993
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
994
+ if (!projectId) {
995
+ console.error(colors.red(' error: missing required argument `projectId`'));
996
+ process.exit(1);
997
+ return
998
+ }
999
+
1000
+ deleteBranchEntry({
1001
+ cdnType: cdnType || defaultCdnType,
1002
+ apiKey,
1003
+ projectId,
1004
+ apiEndpoint,
1005
+ branch
1006
+ });
1007
+ })
1008
+ .on('--help', () => {
1009
+ console.log(' Examples:');
1010
+ console.log();
1011
+ console.log(' $ locize delete-branch featureX');
1012
+ console.log(' $ locize delete-branch featureX --api-key <apiKey> --project-id <projectId>');
1013
+ console.log();
1014
+ });
1015
+
1016
+ program.parse(process.argv);
1017
+
1018
+ if (!process.argv.slice(2).length) {
1019
+ program.outputHelp(colors.red);
1020
+ }