@transifex/cli
Advanced tools
Comparing version 0.8.3 to 0.9.2
@@ -1,1 +0,1 @@ | ||
{"version":"0.8.3","commands":{"push":{"id":"push","description":"Detect translatable strings and push content to Transifex\nParse .js, .ts, .jsx and .tsx 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 --tags=\"master,release:2.5\"\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},"token":{"name":"token","type":"option","description":"Native project public token","default":""},"secret":{"name":"secret","type":"option","description":"Native project secret","default":""},"tags":{"name":"tags","type":"option","description":"Globally tag strings","default":""},"cds-host":{"name":"cds-host","type":"option","description":"CDS host URL","default":""}},"args":[{"name":"pattern","description":"file pattern to scan for strings","required":false,"default":"**/*.{js,jsx,ts,tsx}"}]}}} | ||
{"version":"0.9.2","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 and .tsx 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 --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},"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":""}},"args":[{"name":"pattern","description":"file pattern to scan for strings","required":false,"default":"**/*.{js,jsx,ts,tsx}"}]}}} |
{ | ||
"name": "@transifex/cli", | ||
"description": "Transifex Native CLI", | ||
"version": "0.8.3", | ||
"version": "0.9.2", | ||
"author": "Transifex", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"@oclif/plugin-help": "^3.2.1", | ||
"@transifex/native": "^0.8.3", | ||
"@transifex/native": "^0.9.2", | ||
"axios": "^0.21.1", | ||
@@ -33,0 +33,0 @@ "cli-ux": "^5.5.1", |
@@ -55,2 +55,3 @@ # Transifex Native CLI | ||
* [`txjs-cli push [PATTERN]`](#txjs-cli-push-pattern) | ||
* [`txjs-cli invalidate`](#txjs-cli-invalidate) | ||
@@ -74,3 +75,3 @@ ## `txjs-cli help [COMMAND]` | ||
Detect translatable strings and push content to Transifex | ||
detect and push source content to Transifex | ||
@@ -85,9 +86,11 @@ ``` | ||
OPTIONS | ||
-v, --verbose Verbose output | ||
--cds-host=cds-host CDS host URL | ||
--dry-run Dry run, do not push to Transifex | ||
--purge Purge content on Transifex | ||
--secret=secret Native project secret | ||
--token=token Native project public token | ||
--tags=tags Globally add tags to strings | ||
-v, --verbose verbose output | ||
--append-tags=append-tags append tags to strings | ||
--cds-host=cds-host CDS host URL | ||
--dry-run dry run, do not push to Transifex | ||
--purge purge content on Transifex | ||
--secret=secret native project secret | ||
--token=token native project public token | ||
--with-tags-only=with-tags-only push strings with specific tags | ||
--without-tags-only=without-tags-only push strings without specific tags | ||
@@ -114,3 +117,5 @@ DESCRIPTION | ||
txjs-cli push --dry-run | ||
txjs-cli push --tags="master,release:2.5" | ||
txjs-cli push --append-tags="master,release:2.5" | ||
txjs-cli push --with-tags-only="home,error" | ||
txjs-cli push --without-tags-only="custom" | ||
txjs-cli push --token=mytoken --secret=mysecret | ||
@@ -120,4 +125,45 @@ TRANSIFEX_TOKEN=mytoken TRANSIFEX_SECRET=mysecret txjs-cli push | ||
## `txjs-cli invalidate` | ||
invalidate and refresh CDS cache | ||
``` | ||
USAGE | ||
$ txjs-cli invalidate | ||
OPTIONS | ||
--cds-host=cds-host CDS host URL | ||
--purge force delete CDS cached content | ||
--secret=secret native project secret | ||
--token=token native project public token | ||
DESCRIPTION | ||
Content for delivery is cached in CDS and refreshed automatically every hour. | ||
This command triggers a refresh of cached content on the fly. | ||
By default, invalidation does not remove existing cached content, but | ||
starts the process of updating with latest translations from Transifex. | ||
Passing the --purge option, cached content will be forced to be deleted, | ||
however use that with caution, as it may introduce downtime of | ||
translation delivery to the apps until fresh content is cached in the CDS. | ||
To invalidate translations some environment variables must be set: | ||
TRANSIFEX_TOKEN=<Transifex Native Project Token> | ||
TRANSIFEX_SECRET=<Transifex Native Project Secret> | ||
(optional) TRANSIFEX_CDS_HOST=<CDS HOST> | ||
or passed as --token=<TOKEN> --secret=<SECRET> parameters | ||
Default CDS Host is https://cds.svc.transifex.net | ||
Examples: | ||
txjs-cli invalidate | ||
txjs-cli invalidate --purge | ||
txjs-cli invalidate --token=mytoken --secret=mysecret | ||
TRANSIFEX_TOKEN=mytoken TRANSIFEX_SECRET=mysecret txjs-cli invalidate | ||
``` | ||
# License | ||
Licensed under Apache License 2.0, see [LICENSE](https://github.com/transifex/transifex-javascript/blob/HEAD/LICENSE) file. |
@@ -22,3 +22,3 @@ /* eslint no-underscore-dangle: 0 */ | ||
* @param {String} occurence | ||
* @param {String[]} globalTags | ||
* @param {String[]} appendTags | ||
* @returns {Object} Payload | ||
@@ -33,3 +33,3 @@ * @returns {String} Payload.string | ||
*/ | ||
function createPayload(string, params, occurence, globalTags) { | ||
function createPayload(string, params, occurence, appendTags) { | ||
return { | ||
@@ -42,3 +42,3 @@ string, | ||
character_limit: params._charlimit ? parseInt(params._charlimit, 10) : undefined, | ||
tags: mergeArrays(stringToArray(params._tags), globalTags), | ||
tags: mergeArrays(stringToArray(params._tags), appendTags), | ||
occurrences: [occurence], | ||
@@ -50,2 +50,26 @@ }, _.isNil), | ||
/** | ||
* Check if payload coming from createPayload is valid based on tag filters | ||
* | ||
* @param {Object} payload | ||
* @param {String[]} options.filterWithTags | ||
* @param {String[]} options.filterWithoutTags | ||
* @returns {Boolean} | ||
*/ | ||
function isPayloadValid(payload, options = {}) { | ||
const { filterWithTags, filterWithoutTags } = options; | ||
let isValid = true; | ||
_.each(filterWithTags, (tag) => { | ||
if (!_.includes(payload.meta.tags, tag)) { | ||
isValid = false; | ||
} | ||
}); | ||
_.each(filterWithoutTags, (tag) => { | ||
if (_.includes(payload.meta.tags, tag)) { | ||
isValid = false; | ||
} | ||
}); | ||
return isValid; | ||
} | ||
/** | ||
* Check if callee is a valid Transifex Native function | ||
@@ -99,6 +123,10 @@ * | ||
* @param {String} relativeFile occurence | ||
* @param {String[]} globalTags | ||
* @param {Object} options | ||
* @param {String[]} options.appendTags | ||
* @param {String[]} options.filterWithTags | ||
* @param {String[]} options.filterWithoutTags | ||
* @returns {Object} | ||
*/ | ||
function extractPhrases(file, relativeFile, globalTags) { | ||
function extractPhrases(file, relativeFile, options = {}) { | ||
const { appendTags } = options; | ||
const HASHES = {}; | ||
@@ -132,3 +160,5 @@ const source = fs.readFileSync(file, 'utf8'); | ||
const partial = createPayload(string, params, relativeFile, globalTags); | ||
const partial = createPayload(string, params, relativeFile, appendTags); | ||
if (!isPayloadValid(partial, options)) return; | ||
mergePayload(HASHES, { | ||
@@ -165,3 +195,6 @@ [partial.key]: { | ||
if (!string) return; | ||
const partial = createPayload(string, params, relativeFile, globalTags); | ||
const partial = createPayload(string, params, relativeFile, appendTags); | ||
if (!isPayloadValid(partial, options)) return; | ||
mergePayload(HASHES, { | ||
@@ -168,0 +201,0 @@ [partial.key]: { |
@@ -43,3 +43,5 @@ /* eslint no-shadow: 0 */ | ||
const globalTags = stringToArray(flags.tags); | ||
const appendTags = stringToArray(flags['append-tags']); | ||
const filterWithTags = stringToArray(flags['with-tags-only']); | ||
const filterWithoutTags = stringToArray(flags['without-tags-only']); | ||
@@ -68,2 +70,8 @@ this.log('Parsing all files to detect translatable content...'); | ||
const extractOptions = { | ||
appendTags, | ||
filterWithTags, | ||
filterWithoutTags, | ||
}; | ||
_.each(allFiles, (file) => { | ||
@@ -73,3 +81,3 @@ const relativeFile = file.replace(pwd, ''); | ||
try { | ||
const data = extractPhrases(file, relativeFile, globalTags); | ||
const data = extractPhrases(file, relativeFile, extractOptions); | ||
tree[relativeFile] = data; | ||
@@ -176,3 +184,3 @@ if (_.isEmpty(data)) { | ||
PushCommand.description = `Detect translatable strings and push content to Transifex | ||
PushCommand.description = `detect and push source content to Transifex | ||
Parse .js, .ts, .jsx and .tsx files and detect phrases marked for | ||
@@ -197,3 +205,5 @@ translation by Transifex Native toolkit for Javascript and | ||
txjs-cli push --dry-run | ||
txjs-cli push --tags="master,release:2.5" | ||
txjs-cli push --append-tags="master,release:2.5" | ||
txjs-cli push --with-tags-only="home,error" | ||
txjs-cli push --without-tags-only="custom" | ||
txjs-cli push --token=mytoken --secret=mysecret | ||
@@ -212,3 +222,3 @@ TRANSIFEX_TOKEN=mytoken TRANSIFEX_SECRET=mysecret txjs-cli push | ||
'dry-run': flags.boolean({ | ||
description: 'Dry run, do not push to Transifex', | ||
description: 'dry run, do not push to Transifex', | ||
default: false, | ||
@@ -218,21 +228,29 @@ }), | ||
char: 'v', | ||
description: 'Verbose output', | ||
description: 'verbose output', | ||
default: false, | ||
}), | ||
purge: flags.boolean({ | ||
description: 'Purge content on Transifex', | ||
description: 'purge content on Transifex', | ||
default: false, | ||
}), | ||
token: flags.string({ | ||
description: 'Native project public token', | ||
description: 'native project public token', | ||
default: '', | ||
}), | ||
secret: flags.string({ | ||
description: 'Native project secret', | ||
description: 'native project secret', | ||
default: '', | ||
}), | ||
tags: flags.string({ | ||
description: 'Globally tag strings', | ||
'append-tags': flags.string({ | ||
description: 'append tags to strings', | ||
default: '', | ||
}), | ||
'with-tags-only': flags.string({ | ||
description: 'push strings with specific tags', | ||
default: '', | ||
}), | ||
'without-tags-only': flags.string({ | ||
description: 'push strings without specific tags', | ||
default: '', | ||
}), | ||
'cds-host': flags.string({ | ||
@@ -239,0 +257,0 @@ description: 'CDS host URL', |
31055
13
670
165
9
+ Added@transifex/native@0.9.2(transitive)
- Removed@transifex/native@0.8.3(transitive)
Updated@transifex/native@^0.9.2