@transifex/cli 2.4.0 → 3.1.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.
@@ -1 +1 @@
1
- {"version":"2.4.0","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}"}]}}}
1
+ {"version":"3.1.0","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,html,vue,pug,ejs}"}]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@transifex/cli",
3
3
  "description": "Transifex Native CLI",
4
- "version": "2.4.0",
4
+ "version": "3.1.0",
5
5
  "author": "Transifex",
6
6
  "keywords": [
7
7
  "transifex",
@@ -21,25 +21,27 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@babel/parser": "^7.13.10",
24
+ "@babel/parser": "^7.17.8",
25
25
  "@babel/traverse": "^7.13.0",
26
+ "@colors/colors": "^1.5.0",
26
27
  "@oclif/command": "^1.8.0",
27
28
  "@oclif/config": "^1.17.0",
28
29
  "@oclif/errors": "^1.3.4",
29
- "@oclif/plugin-help": "^3.2.1",
30
- "@transifex/native": "^2.4.0",
30
+ "@oclif/plugin-help": "^5.1.12",
31
+ "@transifex/native": "^3.1.0",
31
32
  "angular-html-parser": "^1.7.1",
32
- "axios": "^0.24.0",
33
- "cli-ux": "^5.5.1",
34
- "colors": "1.4.0",
33
+ "axios": "^0.26.1",
34
+ "cli-ux": "^6.0.9",
35
+ "ejs": "^3.1.6",
35
36
  "glob": "^7.1.6",
36
37
  "lodash": "^4.17.21",
38
+ "pug": "^3.0.2",
37
39
  "shelljs": "^0.8.4",
38
40
  "vue-template-compiler": "^2.6.14"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@oclif/dev-cli": "^1.26.0",
42
- "@oclif/test": "^1.2.8",
44
+ "@oclif/test": "^2.1.0",
43
45
  "chai": "^4.3.3",
44
46
  "eslint": "^7.21.0",
45
47
  "eslint-config-airbnb-base": "^14.2.1",
@@ -69,7 +71,7 @@
69
71
  "scripts": {
70
72
  "postpack": "rm -f oclif.manifest.json",
71
73
  "prepack": "oclif-dev manifest",
72
- "lint": "eslint src/",
74
+ "lint": "eslint src/ test/",
73
75
  "test": "nyc mocha \"test/**/*.test.js\"",
74
76
  "publish-npm": "npm publish"
75
77
  }
@@ -3,6 +3,9 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
 
6
+ const ejs = require('ejs');
7
+ const pug = require('pug');
8
+
6
9
  const { parseHTMLTemplateFile } = require('./parsers/angularHTML');
7
10
  const { babelExtractPhrases } = require('./parsers/babel');
8
11
  const { extractVuePhrases } = require('./parsers/vue');
@@ -21,7 +24,17 @@ const { extractVuePhrases } = require('./parsers/vue');
21
24
  */
22
25
  function extractPhrases(file, relativeFile, options = {}) {
23
26
  const HASHES = {};
24
- const source = fs.readFileSync(file, 'utf8');
27
+ let source = fs.readFileSync(file, 'utf8');
28
+
29
+ // Handle simple templates that compile to javascript
30
+ if (path.extname(file) === '.pug') {
31
+ source = pug.compileClient(source);
32
+ } else if (path.extname(file) === '.ejs') {
33
+ const template = new ejs.Template(source);
34
+ template.generateSource();
35
+ source = template.source;
36
+ }
37
+
25
38
  if (path.extname(file) === '.html') {
26
39
  parseHTMLTemplateFile(HASHES, file, relativeFile, options);
27
40
  } else if (path.extname(file) === '.vue') {
@@ -55,7 +55,7 @@ function babelExtractPhrases(HASHES, source, relativeFile, options) {
55
55
  const params = {};
56
56
  if (
57
57
  node.arguments[1]
58
- && node.arguments[1].type === 'ObjectExpression'
58
+ && node.arguments[1].type === 'ObjectExpression'
59
59
  ) {
60
60
  _.each(node.arguments[1].properties, (prop) => {
61
61
  // get only string on number params
@@ -112,7 +112,18 @@ function isPayloadValid(payload, options = {}) {
112
112
  function isTransifexCall(node) {
113
113
  const { callee } = node;
114
114
  if (!callee) return false;
115
- if (_.includes(['t', 'useT', '$t'], callee.name)) { return true; }
115
+
116
+ let fnName;
117
+ if (callee.type === 'MemberExpression'
118
+ && callee.property.type === 'Identifier') {
119
+ fnName = callee.property.name;
120
+ } else if (callee.type === 'Identifier') {
121
+ fnName = callee.name;
122
+ } else {
123
+ return false;
124
+ }
125
+
126
+ if (_.includes(['t', 'ut', '$t'], fnName)) { return true; }
116
127
  if (!callee.object || !callee.property) return false;
117
128
  if (callee.property.name === 'translate') return true;
118
129
  return false;
@@ -1,6 +1,6 @@
1
1
  /* eslint no-shadow: 0 */
2
2
 
3
- require('colors');
3
+ require('@colors/colors');
4
4
  const { Command, flags } = require('@oclif/command');
5
5
  const { cli } = require('cli-ux');
6
6
  const { invalidateCDS } = require('../api/invalidate');
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-await-in-loop */
2
2
  /* eslint no-shadow: 0 */
3
3
 
4
- require('colors');
4
+ require('@colors/colors');
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
7
  const _ = require('lodash');
@@ -38,7 +38,7 @@ class PushCommand extends Command {
38
38
  : path.join(pwd, args.pattern);
39
39
 
40
40
  if (isFolder(filePattern)) {
41
- filePattern = path.join(filePattern, '**/*.{js,jsx,ts,tsx,html,vue}');
41
+ filePattern = path.join(filePattern, PushCommand.args[0].default);
42
42
  }
43
43
 
44
44
  const appendTags = stringToArray(flags['append-tags']);
@@ -261,7 +261,7 @@ TRANSIFEX_TOKEN=mytoken TRANSIFEX_SECRET=mysecret txjs-cli push
261
261
  PushCommand.args = [{
262
262
  name: 'pattern',
263
263
  description: 'file pattern to scan for strings',
264
- default: '**/*.{js,jsx,ts,tsx}',
264
+ default: '**/*.{js,jsx,ts,tsx,html,vue,pug,ejs}',
265
265
  required: false,
266
266
  }];
267
267