@transifex/cli 1.0.5 → 2.0.0-rc1
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/README.md +8 -1
- package/oclif.manifest.json +1 -1
- package/package.json +5 -5
- package/src/api/extract.js +15 -22
- package/src/commands/push.js +8 -0
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@ Related packages:
|
|
|
6
6
|
* [@transifex/native](https://www.npmjs.com/package/@transifex/native)
|
|
7
7
|
* [@transifex/react](https://www.npmjs.com/package/@transifex/react)
|
|
8
8
|
|
|
9
|
+
# Upgrade to v2
|
|
10
|
+
|
|
11
|
+
If you are upgrading from the `1.x.x` version, please read this [migration guide](https://github.com/transifex/transifex-javascript/blob/HEAD/UPGRADE_TO_V2.md), as there are breaking changes in place.
|
|
12
|
+
|
|
9
13
|
# Usage
|
|
10
14
|
|
|
11
15
|
## Global installation
|
|
@@ -85,6 +89,8 @@ OPTIONS
|
|
|
85
89
|
--append-tags=append-tags append tags to strings
|
|
86
90
|
--cds-host=cds-host CDS host URL
|
|
87
91
|
--dry-run dry run, do not push to Transifex
|
|
92
|
+
--key-generator=source|hash [default: source] use hashed or source based keys
|
|
93
|
+
--no-wait disable polling for upload results
|
|
88
94
|
--purge purge content on Transifex
|
|
89
95
|
--secret=secret native project secret
|
|
90
96
|
--token=token native project public token
|
|
@@ -92,7 +98,7 @@ OPTIONS
|
|
|
92
98
|
--without-tags-only=without-tags-only push strings without specific tags
|
|
93
99
|
|
|
94
100
|
DESCRIPTION
|
|
95
|
-
Parse .js, .ts, .jsx and .
|
|
101
|
+
Parse .js, .ts, .jsx, .tsx and .html files and detect phrases marked for
|
|
96
102
|
translation by Transifex Native toolkit for Javascript and
|
|
97
103
|
upload them to Transifex for translation.
|
|
98
104
|
|
|
@@ -112,6 +118,7 @@ DESCRIPTION
|
|
|
112
118
|
txjs-cli push "*.js"
|
|
113
119
|
txjs-cli push --dry-run
|
|
114
120
|
txjs-cli push --no-wait
|
|
121
|
+
txjs-cli push --key-generator=hash
|
|
115
122
|
txjs-cli push --append-tags="master,release:2.5"
|
|
116
123
|
txjs-cli push --with-tags-only="home,error"
|
|
117
124
|
txjs-cli push --without-tags-only="custom"
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"
|
|
1
|
+
{"version":"2.0.0-rc1","commands":{"invalidate":{"id":"invalidate","description":"invalidate and refresh CDS cache\nContent for delivery is cached in CDS and refreshed automatically every hour.\nThis command triggers a refresh of cached content on the fly.\n\nBy default, invalidation does not remove existing cached content, but\nstarts the process of updating with latest translations from Transifex.\n\nPassing the --purge option, cached content will be forced to be deleted,\nhowever use that with caution, as it may introduce downtime of\ntranslation delivery to the apps until fresh content is cached in the CDS.\n\nTo invalidate translations some environment variables must be set:\nTRANSIFEX_TOKEN=<Transifex Native Project Token>\nTRANSIFEX_SECRET=<Transifex Native Project Secret>\n(optional) TRANSIFEX_CDS_HOST=<CDS HOST>\n\nor passed as --token=<TOKEN> --secret=<SECRET> parameters\n\nDefault CDS Host is https://cds.svc.transifex.net\n\nExamples:\ntxjs-cli invalidate\ntxjs-cli invalidate --purge\ntxjs-cli invalidate --token=mytoken --secret=mysecret\nTRANSIFEX_TOKEN=mytoken TRANSIFEX_SECRET=mysecret txjs-cli invalidate\n","pluginName":"@transifex/cli","pluginType":"core","aliases":[],"flags":{"purge":{"name":"purge","type":"boolean","description":"force delete CDS cached content","allowNo":false},"token":{"name":"token","type":"option","description":"native project public token","default":""},"secret":{"name":"secret","type":"option","description":"native project secret","default":""},"cds-host":{"name":"cds-host","type":"option","description":"CDS host URL","default":""}},"args":[]},"push":{"id":"push","description":"detect and push source content to Transifex\nParse .js, .ts, .jsx, .tsx and .html files and detect phrases marked for\ntranslation by Transifex Native toolkit for Javascript and\nupload them to Transifex for translation.\n\nTo push content some environment variables must be set:\nTRANSIFEX_TOKEN=<Transifex Native Project Token>\nTRANSIFEX_SECRET=<Transifex Native Project Secret>\n(optional) TRANSIFEX_CDS_HOST=<CDS HOST>\n\nor passed as --token=<TOKEN> --secret=<SECRET> parameters\n\nDefault CDS Host is https://cds.svc.transifex.net\n\nExamples:\ntxjs-cli push -v\ntxjs-cli push src/\ntxjs-cli push /home/repo/src\ntxjs-cli push \"*.js\"\ntxjs-cli push --dry-run\ntxjs-cli push --no-wait\ntxjs-cli push --key-generator=hash\ntxjs-cli push --append-tags=\"master,release:2.5\"\ntxjs-cli push --with-tags-only=\"home,error\"\ntxjs-cli push --without-tags-only=\"custom\"\ntxjs-cli push --token=mytoken --secret=mysecret\nTRANSIFEX_TOKEN=mytoken TRANSIFEX_SECRET=mysecret txjs-cli push\n","pluginName":"@transifex/cli","pluginType":"core","aliases":[],"flags":{"dry-run":{"name":"dry-run","type":"boolean","description":"dry run, do not push to Transifex","allowNo":false},"verbose":{"name":"verbose","type":"boolean","char":"v","description":"verbose output","allowNo":false},"purge":{"name":"purge","type":"boolean","description":"purge content on Transifex","allowNo":false},"no-wait":{"name":"no-wait","type":"boolean","description":"disable polling for upload results","allowNo":false},"token":{"name":"token","type":"option","description":"native project public token","default":""},"secret":{"name":"secret","type":"option","description":"native project secret","default":""},"append-tags":{"name":"append-tags","type":"option","description":"append tags to strings","default":""},"with-tags-only":{"name":"with-tags-only","type":"option","description":"push strings with specific tags","default":""},"without-tags-only":{"name":"without-tags-only","type":"option","description":"push strings without specific tags","default":""},"cds-host":{"name":"cds-host","type":"option","description":"CDS host URL","default":""},"key-generator":{"name":"key-generator","type":"option","description":"use hashed or source based keys","options":["source","hash"],"default":"source"}},"args":[{"name":"pattern","description":"file pattern to scan for strings","required":false,"default":"**/*.{js,jsx,ts,tsx}"}]}}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transifex/cli",
|
|
3
3
|
"description": "Transifex Native CLI",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-rc1",
|
|
5
5
|
"author": "Transifex",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"transifex",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@oclif/config": "^1.17.0",
|
|
28
28
|
"@oclif/errors": "^1.3.4",
|
|
29
29
|
"@oclif/plugin-help": "^3.2.1",
|
|
30
|
-
"@transifex/native": "^
|
|
30
|
+
"@transifex/native": "^2.0.0-rc1",
|
|
31
31
|
"angular-html-parser": "^1.7.1",
|
|
32
|
-
"axios": "^0.
|
|
32
|
+
"axios": "^0.24.0",
|
|
33
33
|
"cli-ux": "^5.5.1",
|
|
34
34
|
"colors": "^1.4.0",
|
|
35
35
|
"glob": "^7.1.6",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
45
45
|
"eslint-plugin-import": "^2.22.1",
|
|
46
46
|
"globby": "^11.0.1",
|
|
47
|
-
"mocha": "^
|
|
47
|
+
"mocha": "^9.1.3",
|
|
48
48
|
"nock": "^13.0.11",
|
|
49
49
|
"nyc": "^15.1.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
52
|
+
"node": ">=12.0.0"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"/bin",
|
package/src/api/extract.js
CHANGED
|
@@ -6,7 +6,7 @@ const babelParser = require('@babel/parser');
|
|
|
6
6
|
const babelTraverse = require('@babel/traverse').default;
|
|
7
7
|
const _ = require('lodash');
|
|
8
8
|
const path = require('path');
|
|
9
|
-
const { generateKey } = require('@transifex/native');
|
|
9
|
+
const { generateKey, generateHashedKey } = require('@transifex/native');
|
|
10
10
|
|
|
11
11
|
const { mergePayload } = require('./merge');
|
|
12
12
|
const { stringToArray, mergeArrays } = require('./utils');
|
|
@@ -21,27 +21,21 @@ const { stringToArray, mergeArrays } = require('./utils');
|
|
|
21
21
|
* @param {Number} params._charlimit
|
|
22
22
|
* @param {Number} params._tags
|
|
23
23
|
* @param {String} occurence
|
|
24
|
-
* @param {
|
|
25
|
-
* @returns {Object} Payload
|
|
26
|
-
* @returns {String} Payload.string
|
|
27
|
-
* @returns {String} Payload.key
|
|
28
|
-
* @returns {String} Payload.meta.context
|
|
29
|
-
* @returns {String} Payload.meta.developer_comment
|
|
30
|
-
* @returns {Number} Payload.meta.character_limit
|
|
31
|
-
* @returns {String[]} Payload.meta.tags
|
|
32
|
-
* @returns {String[]} Payload.meta.occurrences
|
|
24
|
+
* @param {Object} options
|
|
33
25
|
*/
|
|
34
|
-
function createPayload(string, params, occurence,
|
|
26
|
+
function createPayload(string, params, occurence, options = {}) {
|
|
35
27
|
return {
|
|
36
28
|
string,
|
|
37
|
-
key:
|
|
29
|
+
key: options.useHashedKeys
|
|
30
|
+
? generateHashedKey(string, params)
|
|
31
|
+
: generateKey(string, params),
|
|
38
32
|
meta: _.omitBy({
|
|
39
33
|
context: stringToArray(params._context || params.context),
|
|
40
34
|
developer_comment: params._comment || params.comment,
|
|
41
35
|
character_limit: params._charlimit || params.charlimit
|
|
42
36
|
? parseInt(params._charlimit || params.charlimit, 10)
|
|
43
37
|
: undefined,
|
|
44
|
-
tags: mergeArrays(stringToArray(params._tags || params.tags), appendTags),
|
|
38
|
+
tags: mergeArrays(stringToArray(params._tags || params.tags), options.appendTags),
|
|
45
39
|
occurrences: [occurence],
|
|
46
40
|
}, _.isNil),
|
|
47
41
|
};
|
|
@@ -132,8 +126,7 @@ function looseJsonParse(obj) {
|
|
|
132
126
|
* @param {Object} options
|
|
133
127
|
* @returns void
|
|
134
128
|
*/
|
|
135
|
-
function parseHTMLTemplateFile(HASHES, filename, relativeFile,
|
|
136
|
-
appendTags, options) {
|
|
129
|
+
function parseHTMLTemplateFile(HASHES, filename, relativeFile, options) {
|
|
137
130
|
const TXComponents = [];
|
|
138
131
|
const TXTemplateStrings = [];
|
|
139
132
|
|
|
@@ -228,7 +221,7 @@ function parseHTMLTemplateFile(HASHES, filename, relativeFile,
|
|
|
228
221
|
});
|
|
229
222
|
}
|
|
230
223
|
if (string) {
|
|
231
|
-
const partial = createPayload(string, params, relativeFile,
|
|
224
|
+
const partial = createPayload(string, params, relativeFile, options);
|
|
232
225
|
if (!isPayloadValid(partial, options)) return;
|
|
233
226
|
|
|
234
227
|
mergePayload(HASHES, {
|
|
@@ -247,7 +240,7 @@ function parseHTMLTemplateFile(HASHES, filename, relativeFile,
|
|
|
247
240
|
key = txStr.params.key;
|
|
248
241
|
}
|
|
249
242
|
|
|
250
|
-
const partial = createPayload(txStr.string, txStr.params, relativeFile,
|
|
243
|
+
const partial = createPayload(txStr.string, txStr.params, relativeFile, options);
|
|
251
244
|
if (!isPayloadValid(partial, options)) return;
|
|
252
245
|
|
|
253
246
|
mergePayload(HASHES, {
|
|
@@ -374,10 +367,10 @@ function findDeclaredValue(scope, init) {
|
|
|
374
367
|
* @param {String[]} options.appendTags
|
|
375
368
|
* @param {String[]} options.filterWithTags
|
|
376
369
|
* @param {String[]} options.filterWithoutTags
|
|
370
|
+
* @param {Boolean} options.useHashedKeys
|
|
377
371
|
* @returns {Object}
|
|
378
372
|
*/
|
|
379
373
|
function extractPhrases(file, relativeFile, options = {}) {
|
|
380
|
-
const { appendTags } = options;
|
|
381
374
|
const HASHES = {};
|
|
382
375
|
const source = fs.readFileSync(file, 'utf8');
|
|
383
376
|
if (path.extname(file) !== '.html') {
|
|
@@ -410,7 +403,7 @@ function extractPhrases(file, relativeFile, options = {}) {
|
|
|
410
403
|
});
|
|
411
404
|
}
|
|
412
405
|
|
|
413
|
-
const partial = createPayload(string, params, relativeFile,
|
|
406
|
+
const partial = createPayload(string, params, relativeFile, options);
|
|
414
407
|
if (!isPayloadValid(partial, options)) return;
|
|
415
408
|
|
|
416
409
|
mergePayload(HASHES, {
|
|
@@ -446,7 +439,7 @@ function extractPhrases(file, relativeFile, options = {}) {
|
|
|
446
439
|
});
|
|
447
440
|
|
|
448
441
|
if (string) {
|
|
449
|
-
const partial = createPayload(string, params, relativeFile,
|
|
442
|
+
const partial = createPayload(string, params, relativeFile, options);
|
|
450
443
|
if (!isPayloadValid(partial, options)) return;
|
|
451
444
|
|
|
452
445
|
mergePayload(HASHES, {
|
|
@@ -483,7 +476,7 @@ function extractPhrases(file, relativeFile, options = {}) {
|
|
|
483
476
|
|
|
484
477
|
if (!string) return;
|
|
485
478
|
|
|
486
|
-
const partial = createPayload(string, params, relativeFile,
|
|
479
|
+
const partial = createPayload(string, params, relativeFile, options);
|
|
487
480
|
if (!isPayloadValid(partial, options)) return;
|
|
488
481
|
|
|
489
482
|
mergePayload(HASHES, {
|
|
@@ -495,7 +488,7 @@ function extractPhrases(file, relativeFile, options = {}) {
|
|
|
495
488
|
},
|
|
496
489
|
});
|
|
497
490
|
} else if (path.extname(file) === '.html') {
|
|
498
|
-
parseHTMLTemplateFile(HASHES, file, relativeFile,
|
|
491
|
+
parseHTMLTemplateFile(HASHES, file, relativeFile, options);
|
|
499
492
|
}
|
|
500
493
|
|
|
501
494
|
return HASHES;
|
package/src/commands/push.js
CHANGED
|
@@ -44,6 +44,7 @@ class PushCommand extends Command {
|
|
|
44
44
|
const appendTags = stringToArray(flags['append-tags']);
|
|
45
45
|
const filterWithTags = stringToArray(flags['with-tags-only']);
|
|
46
46
|
const filterWithoutTags = stringToArray(flags['without-tags-only']);
|
|
47
|
+
const useHashedKeys = flags['key-generator'] === 'hash';
|
|
47
48
|
|
|
48
49
|
this.log('Parsing all files to detect translatable content...');
|
|
49
50
|
|
|
@@ -71,6 +72,7 @@ class PushCommand extends Command {
|
|
|
71
72
|
appendTags,
|
|
72
73
|
filterWithTags,
|
|
73
74
|
filterWithoutTags,
|
|
75
|
+
useHashedKeys,
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
_.each(allFiles, (file) => {
|
|
@@ -244,6 +246,7 @@ txjs-cli push /home/repo/src
|
|
|
244
246
|
txjs-cli push "*.js"
|
|
245
247
|
txjs-cli push --dry-run
|
|
246
248
|
txjs-cli push --no-wait
|
|
249
|
+
txjs-cli push --key-generator=hash
|
|
247
250
|
txjs-cli push --append-tags="master,release:2.5"
|
|
248
251
|
txjs-cli push --with-tags-only="home,error"
|
|
249
252
|
txjs-cli push --without-tags-only="custom"
|
|
@@ -300,6 +303,11 @@ PushCommand.flags = {
|
|
|
300
303
|
description: 'CDS host URL',
|
|
301
304
|
default: '',
|
|
302
305
|
}),
|
|
306
|
+
'key-generator': flags.string({
|
|
307
|
+
description: 'use hashed or source based keys',
|
|
308
|
+
default: 'source',
|
|
309
|
+
options: ['source', 'hash'],
|
|
310
|
+
}),
|
|
303
311
|
};
|
|
304
312
|
|
|
305
313
|
module.exports = PushCommand;
|