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