yata-fetch 1.2.8 → 1.3.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/.eslintrc.js CHANGED
@@ -1,124 +1,141 @@
1
1
  module.exports = {
2
2
  root: true,
3
- parser: 'babel-eslint',
3
+ parser: "babel-eslint",
4
4
  parserOptions: {
5
5
  ecmaVersion: 2017,
6
- sourceType: 'module'
6
+ sourceType: "module",
7
7
  },
8
- extends: 'eslint:recommended',
8
+ extends: "eslint:recommended",
9
9
  env: {
10
- browser: true
10
+ browser: true,
11
11
  },
12
12
  rules: {
13
13
  /*** Possible Errors ***/
14
14
 
15
- 'no-console': 0,
16
- 'no-template-curly-in-string': 2,
17
- 'no-unsafe-negation': 2,
15
+ "no-console": 0,
16
+ "no-template-curly-in-string": 2,
17
+ "no-unsafe-negation": 2,
18
18
 
19
19
  /*** Best Practices ***/
20
20
 
21
- 'curly': 2,
22
- 'eqeqeq': 2,
23
- 'guard-for-in': 0,
24
- 'no-caller': 2,
25
- 'no-eq-null': 2,
26
- 'no-eval': 2,
27
- 'no-multi-spaces': [2, {
28
- 'exceptions': {
29
- 'ObjectExpression': true,
30
- 'Property': true,
21
+ curly: 2,
22
+ eqeqeq: 2,
23
+ "guard-for-in": 0,
24
+ "no-caller": 2,
25
+ "no-eq-null": 2,
26
+ "no-eval": 2,
27
+ "no-multi-spaces": [
28
+ 2,
29
+ {
30
+ exceptions: {
31
+ ObjectExpression: true,
32
+ Property: true,
33
+ },
31
34
  },
32
- }],
33
- 'no-new': 0,
34
- 'no-unused-expressions': [2, {
35
- allowShortCircuit: true,
36
- allowTernary: true,
37
- }],
38
- 'wrap-iife': 0,
39
- 'yoda': 2,
35
+ ],
36
+ "no-new": 0,
37
+ "no-unused-expressions": [
38
+ 2,
39
+ {
40
+ allowShortCircuit: true,
41
+ allowTernary: true,
42
+ },
43
+ ],
44
+ "wrap-iife": 0,
45
+ yoda: 2,
40
46
 
41
47
  /*** Strict Mode ***/
42
48
 
43
- 'strict': [2, 'global'],
49
+ strict: [2, "global"],
44
50
 
45
51
  /*** Variables ***/
46
52
 
47
- 'no-undef': 2,
48
- 'no-unused-vars': 2,
49
- 'no-use-before-define': [2, 'nofunc'],
53
+ "no-undef": 2,
54
+ "no-unused-vars": 2,
55
+ "no-use-before-define": [2, "nofunc"],
50
56
 
51
57
  /*** Stylistic Issues ***/
52
58
 
53
- 'array-bracket-spacing': 2,
54
- 'block-spacing': 2,
55
- 'brace-style': [2, '1tbs', {
56
- 'allowSingleLine': true,
57
- }],
58
- 'camelcase': 0,
59
- 'comma-dangle': [2, 'never'],
60
- 'comma-spacing': 2,
61
- 'comma-style': 2,
62
- 'eol-last': 2,
63
- 'func-call-spacing': 2,
64
- 'indent': [2, 2, {
65
- 'SwitchCase': 1,
66
- 'VariableDeclarator': { 'var': 2, 'let': 2, 'const': 3 }
67
- }],
68
- 'key-spacing': [2, { 'mode': 'minimum' }],
69
- 'keyword-spacing': 2,
70
- 'linebreak-style': [2, 'unix'],
71
- 'new-cap': [2, {
72
- properties: false,
73
- }],
74
- 'new-parens': 2,
75
- 'no-array-constructor': 2,
76
- 'no-bitwise': 2,
77
- 'no-lonely-if': 2,
78
- 'no-mixed-operators': 2,
79
- 'no-plusplus': 0,
80
- 'no-trailing-spaces': 2,
81
- 'no-unneeded-ternary': 2,
82
- 'no-whitespace-before-property': 2,
83
- 'object-curly-spacing': [2, 'always'],
84
- 'semi-spacing': 2,
85
- 'semi': 2,
86
- 'space-before-blocks': 2,
87
- 'space-before-function-paren': [2, 'never'],
88
- 'space-in-parens': 2,
89
- 'space-infix-ops': 2,
90
- 'space-unary-ops': 2,
91
- 'quotes': [2, 'single', {
92
- 'allowTemplateLiterals': true,
93
- }],
94
- 'semi': [2, 'always'],
95
- 'wrap-regex': 2,
59
+ "array-bracket-spacing": 2,
60
+ "block-spacing": 2,
61
+ "brace-style": [
62
+ 2,
63
+ "1tbs",
64
+ {
65
+ allowSingleLine: true,
66
+ },
67
+ ],
68
+ camelcase: 0,
69
+ "comma-spacing": 2,
70
+ "comma-style": 2,
71
+ "eol-last": 2,
72
+ "func-call-spacing": 2,
73
+ indent: [
74
+ 2,
75
+ 2,
76
+ {
77
+ SwitchCase: 1,
78
+ VariableDeclarator: { var: 2, let: 2, const: 3 },
79
+ },
80
+ ],
81
+ "key-spacing": [2, { mode: "minimum" }],
82
+ "keyword-spacing": 2,
83
+ "linebreak-style": [2, "unix"],
84
+ "new-cap": [
85
+ 2,
86
+ {
87
+ properties: false,
88
+ },
89
+ ],
90
+ "new-parens": 2,
91
+ "no-array-constructor": 2,
92
+ "no-bitwise": 2,
93
+ "no-lonely-if": 2,
94
+ "no-mixed-operators": 2,
95
+ "no-plusplus": 0,
96
+ "no-trailing-spaces": 2,
97
+ "no-unneeded-ternary": 2,
98
+ "no-whitespace-before-property": 2,
99
+ "object-curly-spacing": [2, "always"],
100
+ "semi-spacing": 2,
101
+ semi: 2,
102
+ "space-before-blocks": 2,
103
+ "space-in-parens": 2,
104
+ "space-infix-ops": 2,
105
+ "space-unary-ops": 2,
106
+ semi: [2, "always"],
107
+ "wrap-regex": 2,
96
108
 
97
109
  /*** ECMAScript 6 ***/
98
110
 
99
- 'arrow-body-style': 2,
100
- 'arrow-parens': [2, 'as-needed'],
101
- 'arrow-spacing': 2,
102
- 'generator-star-spacing': 2,
103
- 'no-confusing-arrow': [2, {
104
- 'allowParens': true,
105
- }],
106
- 'no-useless-computed-key': 2,
107
- 'no-var': 2,
108
- 'object-shorthand': 2,
109
- 'prefer-arrow-callback': [2, {
110
- 'allowNamedFunctions': true,
111
- }],
112
- 'prefer-template': 2,
113
- 'rest-spread-spacing': 2,
114
- 'symbol-description': 2,
115
- 'template-curly-spacing': 2,
116
- 'yield-star-spacing': 2
111
+ "arrow-body-style": 2,
112
+ "arrow-spacing": 2,
113
+ "generator-star-spacing": 2,
114
+ "no-confusing-arrow": [
115
+ 2,
116
+ {
117
+ allowParens: true,
118
+ },
119
+ ],
120
+ "no-useless-computed-key": 2,
121
+ "no-var": 2,
122
+ "object-shorthand": 2,
123
+ "prefer-arrow-callback": [
124
+ 2,
125
+ {
126
+ allowNamedFunctions: true,
127
+ },
128
+ ],
129
+ "prefer-template": 2,
130
+ "rest-spread-spacing": 2,
131
+ "symbol-description": 2,
132
+ "template-curly-spacing": 2,
133
+ "yield-star-spacing": 2,
117
134
  },
118
135
  globals: {
119
136
  module: true,
120
137
  require: true,
121
138
  process: true,
122
- Promise: true
123
- }
139
+ Promise: true,
140
+ },
124
141
  };
package/dist/cli.js CHANGED
@@ -12,11 +12,13 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
12
12
 
13
13
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
14
 
15
- var yata = require('./yata');
15
+ var yata = require("./yata");
16
16
 
17
- var nconf = require('nconf');
17
+ var nconf = require("nconf");
18
18
 
19
- var log = require('./log');
19
+ var log = require("./log");
20
+
21
+ require("dotenv").config();
20
22
 
21
23
  module.exports = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
22
24
  var _iterator, _step, locale;
@@ -31,24 +33,24 @@ module.exports = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_
31
33
  nconf.env(); // load config path
32
34
 
33
35
  nconf.file({
34
- file: yata.getConfigPath(nconf.get('config'))
36
+ file: yata.getConfigPath(nconf.get("config"))
35
37
  }); // setup API host
36
38
 
37
- yata.apiHost = nconf.get('YATA_API_HOST') || 'https://api.yatapp.net';
39
+ yata.apiHost = nconf.get("YATA_API_HOST") || "https://api.yatapp.net";
38
40
  _context.prev = 4;
39
41
 
40
- if (!yata.validateConfig(nconf.get(nconf.get('token')), nconf.get('project'), nconf.get('locales'), nconf.get('format'), nconf.get('root'), nconf.get('outputPath'), nconf.get('strip_empty'))) {
42
+ if (!yata.validateConfig(nconf.get(nconf.get("token")), nconf.get("project"), nconf.get("locales"), nconf.get("format"), nconf.get("root"), nconf.get("outputPath"), nconf.get("strip_empty"))) {
41
43
  _context.next = 28;
42
44
  break;
43
45
  }
44
46
 
45
- if (!nconf.get('locale')) {
47
+ if (!nconf.get("locale")) {
46
48
  _context.next = 11;
47
49
  break;
48
50
  }
49
51
 
50
52
  _context.next = 9;
51
- return yata.downloadTranslation(nconf.get('locale'));
53
+ return yata.downloadTranslation(nconf.get("locale"));
52
54
 
53
55
  case 9:
54
56
  _context.next = 28;
@@ -98,7 +100,7 @@ module.exports = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_
98
100
  case 30:
99
101
  _context.prev = 30;
100
102
  _context.t1 = _context["catch"](4);
101
- log('red', _context.t1);
103
+ log("red", _context.t1);
102
104
 
103
105
  case 33:
104
106
  case "end":
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["cli.js"],"names":["yata","require","nconf","log","module","exports","argv","env","file","getConfigPath","get","apiHost","validateConfig","downloadTranslation","locales","locale"],"mappings":";;;;;;;;;;;;;;AAAA,IAAMA,IAAI,GAAGC,OAAO,CAAC,QAAD,CAApB;;AACA,IAAMC,KAAK,GAAGD,OAAO,CAAC,OAAD,CAArB;;AACA,IAAME,GAAG,GAAGF,OAAO,CAAC,OAAD,CAAnB;;AAEAG,MAAM,CAACC,OAAP,8FAAiB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACf;AACAH,UAAAA,KAAK,CAACI,IAAN,GAFe,CAIf;;AACAJ,UAAAA,KAAK,CAACK,GAAN,GALe,CAOf;;AACAL,UAAAA,KAAK,CAACM,IAAN,CAAW;AAAEA,YAAAA,IAAI,EAAER,IAAI,CAACS,aAAL,CAAmBP,KAAK,CAACQ,GAAN,CAAU,QAAV,CAAnB;AAAR,WAAX,EARe,CAUf;;AACAV,UAAAA,IAAI,CAACW,OAAL,GAAeT,KAAK,CAACQ,GAAN,CAAU,eAAV,KAA8B,wBAA7C;AAXe;;AAAA,eAcTV,IAAI,CAACY,cAAL,CACFV,KAAK,CAACQ,GAAN,CAAUR,KAAK,CAACQ,GAAN,CAAU,OAAV,CAAV,CADE,EAEFR,KAAK,CAACQ,GAAN,CAAU,SAAV,CAFE,EAGFR,KAAK,CAACQ,GAAN,CAAU,SAAV,CAHE,EAIFR,KAAK,CAACQ,GAAN,CAAU,QAAV,CAJE,EAKFR,KAAK,CAACQ,GAAN,CAAU,MAAV,CALE,EAMFR,KAAK,CAACQ,GAAN,CAAU,YAAV,CANE,EAOFR,KAAK,CAACQ,GAAN,CAAU,aAAV,CAPE,CAdS;AAAA;AAAA;AAAA;;AAAA,eAwBPR,KAAK,CAACQ,GAAN,CAAU,QAAV,CAxBO;AAAA;AAAA;AAAA;;AAAA;AAAA,iBAyBHV,IAAI,CAACa,mBAAL,CAAyBX,KAAK,CAACQ,GAAN,CAAU,QAAV,CAAzB,CAzBG;;AAAA;AAAA;AAAA;;AAAA;AAAA,iDA2BUV,IAAI,CAACc,OA3Bf;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AA2BAC,UAAAA,MA3BA;AAAA;AAAA,iBA4BDf,IAAI,CAACa,mBAAL,CAAyBE,MAAzB,CA5BC;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAiCbZ,UAAAA,GAAG,CAAC,KAAD,cAAH;;AAjCa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAjB","sourcesContent":["const yata = require('./yata');\nconst nconf = require('nconf');\nconst log = require('./log');\n\nmodule.exports = async function() {\n // read argv for potential custom config path\n nconf.argv();\n\n // read ENV for token\n nconf.env();\n\n // load config path\n nconf.file({ file: yata.getConfigPath(nconf.get('config')) });\n\n // setup API host\n yata.apiHost = nconf.get('YATA_API_HOST') || 'https://api.yatapp.net';\n\n try {\n if (yata.validateConfig(\n nconf.get(nconf.get('token')),\n nconf.get('project'),\n nconf.get('locales'),\n nconf.get('format'),\n nconf.get('root'),\n nconf.get('outputPath'),\n nconf.get('strip_empty'))) {\n\n // if passed locale explicit download just one\n if (nconf.get('locale')) {\n await yata.downloadTranslation(nconf.get('locale'));\n } else {\n for (let locale of yata.locales) {\n await yata.downloadTranslation(locale);\n }\n }\n }\n } catch (e) {\n log('red', e);\n }\n};\n"],"file":"cli.js"}
1
+ {"version":3,"sources":["cli.js"],"names":["yata","require","nconf","log","config","module","exports","argv","env","file","getConfigPath","get","apiHost","validateConfig","downloadTranslation","locales","locale"],"mappings":";;;;;;;;;;;;;;AAAA,IAAMA,IAAI,GAAGC,OAAO,CAAC,QAAD,CAApB;;AACA,IAAMC,KAAK,GAAGD,OAAO,CAAC,OAAD,CAArB;;AACA,IAAME,GAAG,GAAGF,OAAO,CAAC,OAAD,CAAnB;;AACAA,OAAO,CAAC,QAAD,CAAP,CAAkBG,MAAlB;;AAEAC,MAAM,CAACC,OAAP,8FAAiB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACf;AACAJ,UAAAA,KAAK,CAACK,IAAN,GAFe,CAIf;;AACAL,UAAAA,KAAK,CAACM,GAAN,GALe,CAOf;;AACAN,UAAAA,KAAK,CAACO,IAAN,CAAW;AAAEA,YAAAA,IAAI,EAAET,IAAI,CAACU,aAAL,CAAmBR,KAAK,CAACS,GAAN,CAAU,QAAV,CAAnB;AAAR,WAAX,EARe,CAUf;;AACAX,UAAAA,IAAI,CAACY,OAAL,GAAeV,KAAK,CAACS,GAAN,CAAU,eAAV,KAA8B,wBAA7C;AAXe;;AAAA,eAeXX,IAAI,CAACa,cAAL,CACEX,KAAK,CAACS,GAAN,CAAUT,KAAK,CAACS,GAAN,CAAU,OAAV,CAAV,CADF,EAEET,KAAK,CAACS,GAAN,CAAU,SAAV,CAFF,EAGET,KAAK,CAACS,GAAN,CAAU,SAAV,CAHF,EAIET,KAAK,CAACS,GAAN,CAAU,QAAV,CAJF,EAKET,KAAK,CAACS,GAAN,CAAU,MAAV,CALF,EAMET,KAAK,CAACS,GAAN,CAAU,YAAV,CANF,EAOET,KAAK,CAACS,GAAN,CAAU,aAAV,CAPF,CAfW;AAAA;AAAA;AAAA;;AAAA,eA0BPT,KAAK,CAACS,GAAN,CAAU,QAAV,CA1BO;AAAA;AAAA;AAAA;;AAAA;AAAA,iBA2BHX,IAAI,CAACc,mBAAL,CAAyBZ,KAAK,CAACS,GAAN,CAAU,QAAV,CAAzB,CA3BG;;AAAA;AAAA;AAAA;;AAAA;AAAA,iDA6BUX,IAAI,CAACe,OA7Bf;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AA6BAC,UAAAA,MA7BA;AAAA;AAAA,iBA8BDhB,IAAI,CAACc,mBAAL,CAAyBE,MAAzB,CA9BC;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAmCbb,UAAAA,GAAG,CAAC,KAAD,cAAH;;AAnCa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAjB","sourcesContent":["const yata = require(\"./yata\");\nconst nconf = require(\"nconf\");\nconst log = require(\"./log\");\nrequire(\"dotenv\").config();\n\nmodule.exports = async function () {\n // read argv for potential custom config path\n nconf.argv();\n\n // read ENV for token\n nconf.env();\n\n // load config path\n nconf.file({ file: yata.getConfigPath(nconf.get(\"config\")) });\n\n // setup API host\n yata.apiHost = nconf.get(\"YATA_API_HOST\") || \"https://api.yatapp.net\";\n\n try {\n if (\n yata.validateConfig(\n nconf.get(nconf.get(\"token\")),\n nconf.get(\"project\"),\n nconf.get(\"locales\"),\n nconf.get(\"format\"),\n nconf.get(\"root\"),\n nconf.get(\"outputPath\"),\n nconf.get(\"strip_empty\")\n )\n ) {\n // if passed locale explicit download just one\n if (nconf.get(\"locale\")) {\n await yata.downloadTranslation(nconf.get(\"locale\"));\n } else {\n for (let locale of yata.locales) {\n await yata.downloadTranslation(locale);\n }\n }\n }\n } catch (e) {\n log(\"red\", e);\n }\n};\n"],"file":"cli.js"}
package/dist/log.js CHANGED
@@ -4,20 +4,20 @@ module.exports = function (color, message) {
4
4
  var code;
5
5
 
6
6
  switch (color) {
7
- case 'red':
8
- code = '\x1b[31m';
7
+ case "red":
8
+ code = "\x1b[31m";
9
9
  break;
10
10
 
11
- case 'green':
12
- code = '\x1b[32m';
11
+ case "green":
12
+ code = "\x1b[32m";
13
13
  break;
14
14
 
15
- case 'yellow':
16
- code = '\x1b[33m';
15
+ case "yellow":
16
+ code = "\x1b[33m";
17
17
  break;
18
18
 
19
19
  default:
20
- code = '\x1b[37m';
20
+ code = "\x1b[37m";
21
21
  // white
22
22
  }
23
23
 
package/dist/log.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["log.js"],"names":["module","exports","color","message","code","console","log"],"mappings":";;AACAA,MAAM,CAACC,OAAP,GAAiB,UAASC,KAAT,EAAgBC,OAAhB,EAAyB;AACxC,MAAIC,IAAJ;;AAEA,UAAQF,KAAR;AACE,SAAK,KAAL;AACEE,MAAAA,IAAI,GAAG,UAAP;AACA;;AACF,SAAK,OAAL;AACEA,MAAAA,IAAI,GAAG,UAAP;AACA;;AACF,SAAK,QAAL;AACEA,MAAAA,IAAI,GAAG,UAAP;AACA;;AAEF;AACEA,MAAAA,IAAI,GAAG,UAAP;AAAmB;AAZvB;;AAeA,SAAOC,OAAO,CAACC,GAAR,WAAeF,IAAf,gBAAgCD,OAAhC,CAAP;AACD,CAnBD","sourcesContent":["\nmodule.exports = function(color, message) {\n let code;\n\n switch (color) {\n case 'red':\n code = '\\x1b[31m';\n break;\n case 'green':\n code = '\\x1b[32m';\n break;\n case 'yellow':\n code = '\\x1b[33m';\n break;\n\n default:\n code = '\\x1b[37m'; // white\n }\n\n return console.log(`${code}%s\\x1b[0m`, message);\n};\n"],"file":"log.js"}
1
+ {"version":3,"sources":["log.js"],"names":["module","exports","color","message","code","console","log"],"mappings":";;AAAAA,MAAM,CAACC,OAAP,GAAiB,UAAUC,KAAV,EAAiBC,OAAjB,EAA0B;AACzC,MAAIC,IAAJ;;AAEA,UAAQF,KAAR;AACE,SAAK,KAAL;AACEE,MAAAA,IAAI,GAAG,UAAP;AACA;;AACF,SAAK,OAAL;AACEA,MAAAA,IAAI,GAAG,UAAP;AACA;;AACF,SAAK,QAAL;AACEA,MAAAA,IAAI,GAAG,UAAP;AACA;;AAEF;AACEA,MAAAA,IAAI,GAAG,UAAP;AAAmB;AAZvB;;AAeA,SAAOC,OAAO,CAACC,GAAR,WAAeF,IAAf,gBAAgCD,OAAhC,CAAP;AACD,CAnBD","sourcesContent":["module.exports = function (color, message) {\n let code;\n\n switch (color) {\n case \"red\":\n code = \"\\x1b[31m\";\n break;\n case \"green\":\n code = \"\\x1b[32m\";\n break;\n case \"yellow\":\n code = \"\\x1b[33m\";\n break;\n\n default:\n code = \"\\x1b[37m\"; // white\n }\n\n return console.log(`${code}%s\\x1b[0m`, message);\n};\n"],"file":"log.js"}
package/dist/yata.js CHANGED
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
 
3
- var https = require('https');
3
+ var https = require("https");
4
4
 
5
- var fs = require('fs');
5
+ var fs = require("fs");
6
6
 
7
- var path = require('path');
7
+ var path = require("path");
8
8
 
9
- var log = require('./log');
9
+ var log = require("./log");
10
10
 
11
11
  module.exports = {
12
12
  config: null,
13
- defaultConfigPath: './yata.json',
13
+ defaultConfigPath: "./yata.json",
14
14
  configPath: null,
15
15
  token: null,
16
16
  project: null,
17
17
  locales: [],
18
- format: 'yml',
18
+ format: "yml",
19
19
  root: false,
20
- outputPath: 'translations',
20
+ outputPath: "translations",
21
21
  stripEmpty: false,
22
22
  apiHost: null,
23
23
  getConfigPath: function getConfigPath(configPath) {
@@ -31,36 +31,36 @@ module.exports = {
31
31
  },
32
32
  validateConfig: function validateConfig(token, project, locales, format, root, outputPath, stripEmpty) {
33
33
  if (!token) {
34
- throw new Error('No `token` in ENV');
34
+ throw new Error("No `token` in ENV");
35
35
  } else {
36
36
  this.token = token;
37
37
  }
38
38
 
39
39
  if (!project) {
40
- throw new Error('No `project` in config file');
40
+ throw new Error("No `project` in config file");
41
41
  } else {
42
42
  this.project = project;
43
43
  }
44
44
 
45
45
  if (!Array.isArray(locales) || locales.length === 0) {
46
- throw new Error('No `locales` in config file');
46
+ throw new Error("No `locales` in config file");
47
47
  } else {
48
48
  this.locales = locales;
49
49
  }
50
50
 
51
- if (format && typeof format === 'string') {
51
+ if (format && typeof format === "string") {
52
52
  this.format = format;
53
53
  }
54
54
 
55
- if (root && typeof root === 'boolean') {
55
+ if (root && typeof root === "boolean") {
56
56
  this.root = root;
57
57
  }
58
58
 
59
- if (outputPath && typeof outputPath === 'string') {
59
+ if (outputPath && typeof outputPath === "string") {
60
60
  this.outputPath = outputPath;
61
61
  }
62
62
 
63
- if (stripEmpty && typeof stripEmpty === 'boolean') {
63
+ if (stripEmpty && typeof stripEmpty === "boolean") {
64
64
  this.stripEmpty = stripEmpty;
65
65
  }
66
66
 
@@ -71,7 +71,7 @@ module.exports = {
71
71
  return;
72
72
  }
73
73
 
74
- var localeSegments = locale.replace('-', '_').split('_');
74
+ var localeSegments = locale.replace("-", "_").split("_");
75
75
  var newLocale = [];
76
76
  newLocale.push(localeSegments[0].toLowerCase()); // two segment locale
77
77
 
@@ -79,13 +79,13 @@ module.exports = {
79
79
  newLocale.push(localeSegments[1].toUpperCase());
80
80
  }
81
81
 
82
- return newLocale.join('_');
82
+ return newLocale.join("_");
83
83
  },
84
84
  downloadTranslation: function downloadTranslation(locale) {
85
85
  var normalizedLocale = this.normalizeLocale(locale);
86
86
 
87
87
  if (!normalizedLocale) {
88
- throw new Error('No locale passed to download function');
88
+ throw new Error("No locale passed to download function");
89
89
  } // if output folder doesn't exist we create it
90
90
 
91
91
 
@@ -113,19 +113,19 @@ module.exports = {
113
113
  }
114
114
 
115
115
  response.pipe(file);
116
- file.on('finish', function () {
116
+ file.on("finish", function () {
117
117
  var newBufferFile = fs.readFileSync(filePath);
118
118
 
119
119
  if (bufferFile && bufferFile.equals(newBufferFile)) {
120
- log('yellow', "Generating \"".concat(locale, "\" translation. Skipped."));
120
+ log("yellow", "Generating \"".concat(locale, "\" translation. Skipped."));
121
121
  } else {
122
- log('green', "Generating \"".concat(locale, "\" translation. Done."));
122
+ log("green", "Generating \"".concat(locale, "\" translation. Done."));
123
123
  }
124
124
 
125
125
  resolve();
126
126
  });
127
- }).on('error', function (e) {
128
- log('red', e);
127
+ }).on("error", function (e) {
128
+ log("red", e);
129
129
  });
130
130
  });
131
131
  }
package/dist/yata.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["yata.js"],"names":["https","require","fs","path","log","module","exports","config","defaultConfigPath","configPath","token","project","locales","format","root","outputPath","stripEmpty","apiHost","getConfigPath","validateConfig","Error","Array","isArray","length","normalizeLocale","locale","localeSegments","replace","split","newLocale","push","toLowerCase","toUpperCase","join","downloadTranslation","normalizedLocale","existsSync","mkdirSync","fileName","filePath","process","cwd","url","bufferFile","readFileSync","file","createWriteStream","Promise","resolve","reject","get","response","statusCode","pipe","on","newBufferFile","equals","e"],"mappings":";;AAAA,IAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAArB;;AACA,IAAMC,EAAE,GAAGD,OAAO,CAAC,IAAD,CAAlB;;AACA,IAAME,IAAI,GAAGF,OAAO,CAAC,MAAD,CAApB;;AACA,IAAMG,GAAG,GAAGH,OAAO,CAAC,OAAD,CAAnB;;AAEAI,MAAM,CAACC,OAAP,GAAiB;AACfC,EAAAA,MAAM,EAAa,IADJ;AAEfC,EAAAA,iBAAiB,EAAE,aAFJ;AAGfC,EAAAA,UAAU,EAAS,IAHJ;AAIfC,EAAAA,KAAK,EAAc,IAJJ;AAKfC,EAAAA,OAAO,EAAY,IALJ;AAMfC,EAAAA,OAAO,EAAY,EANJ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G,CAAC,KAAD,EAAQqD,CAAR,CAAH;AACD,OApBD;AAqBD,KAtBM,CAAP;AAuBD;AA3Hc,CAAjB","sourcesContent":["const https = require('https');\nconst fs = require('fs');\nconst path = require('path');\nconst log = require('./log');\n\nmodule.exports = {\n config: null,\n defaultConfigPath: './yata.json',\n configPath: null,\n token: null,\n project: null,\n locales: [],\n format: 'yml',\n root: false,\n outputPath: 'translations',\n stripEmpty: false,\n apiHost: null,\n\n getConfigPath(configPath) {\n if (configPath) {\n this.configPath = configPath;\n } else {\n this.configPath = this.defaultConfigPath;\n }\n\n return this.configPath;\n },\n\n validateConfig(token, project, locales, format, root, outputPath, stripEmpty) {\n if (!token) {\n throw new Error('No `token` in ENV');\n } else {\n this.token = token;\n }\n\n if (!project) {\n throw new Error('No `project` in config file');\n } else {\n this.project = project;\n }\n\n if (!Array.isArray(locales) || locales.length === 0) {\n throw new Error('No `locales` in config file');\n } else {\n this.locales = locales;\n }\n\n if (format && typeof format === 'string') {\n this.format = format;\n }\n\n if (root && typeof root === 'boolean') {\n this.root = root;\n }\n\n if (outputPath && typeof outputPath === 'string') {\n this.outputPath = outputPath;\n }\n\n if (stripEmpty && typeof stripEmpty === 'boolean') {\n this.stripEmpty = stripEmpty;\n }\n\n return true;\n },\n\n normalizeLocale(locale) {\n if (!locale) { return; }\n\n const localeSegments = locale.replace('-', '_').split('_');\n let newLocale = [];\n newLocale.push(localeSegments[0].toLowerCase());\n\n // two segment locale\n if (localeSegments[1]) {\n newLocale.push(localeSegments[1].toUpperCase());\n }\n\n return newLocale.join('_');\n },\n\n downloadTranslation(locale) {\n const normalizedLocale = this.normalizeLocale(locale);\n\n if (!normalizedLocale) { throw new Error('No locale passed to download function'); }\n\n // if output folder doesn't exist we create it\n if (!fs.existsSync(this.outputPath)) {\n fs.mkdirSync(this.outputPath);\n }\n\n const fileName = `${normalizedLocale}.${this.format}`;\n const filePath = path.join(process.cwd(), `${this.outputPath}/${fileName}`);\n const url = `${this.apiHost}/api/v1/project/${this.project}/${locale}/${this.format}?apiToken=${this.token}&root=${this.root}&strip_empty=${this.stripEmpty}`;\n\n let bufferFile;\n\n // if file exist we grab it's size\n if (fs.existsSync(filePath)) {\n bufferFile = fs.readFileSync(filePath);\n }\n\n // we start stream\n const file = fs.createWriteStream(filePath);\n\n return new Promise((resolve, reject) => {\n https.get(url, response => {\n const { statusCode } = response;\n\n if (statusCode !== 200) {\n return reject(`Request Failed.\\nStatus Code: ${statusCode}`);\n }\n\n response.pipe(file);\n file.on('finish', () => {\n const newBufferFile = fs.readFileSync(filePath);\n\n if (bufferFile && bufferFile.equals(newBufferFile)) {\n log('yellow', `Generating \"${locale}\" translation. Skipped.`);\n } else {\n log('green', `Generating \"${locale}\" translation. Done.`);\n }\n resolve();\n });\n }).on('error', e => {\n log('red', e);\n });\n });\n }\n};\n"],"file":"yata.js"}
1
+ {"version":3,"sources":["yata.js"],"names":["https","require","fs","path","log","module","exports","config","defaultConfigPath","configPath","token","project","locales","format","root","outputPath","stripEmpty","apiHost","getConfigPath","validateConfig","Error","Array","isArray","length","normalizeLocale","locale","localeSegments","replace","split","newLocale","push","toLowerCase","toUpperCase","join","downloadTranslation","normalizedLocale","existsSync","mkdirSync","fileName","filePath","process","cwd","url","bufferFile","readFileSync","file","createWriteStream","Promise","resolve","reject","get","response","statusCode","pipe","on","newBufferFile","equals","e"],"mappings":";;AAAA,IAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAArB;;AACA,IAAMC,EAAE,GAAGD,OAAO,CAAC,IAAD,CAAlB;;AACA,IAAME,IAAI,GAAGF,OAAO,CAAC,MAAD,CAApB;;AACA,IAAMG,GAAG,GAAGH,OAAO,CAAC,OAAD,CAAnB;;AAEAI,MAAM,CAACC,OAAP,GAAiB;AACfC,EAAAA,MAAM,EAAE,IADO;AAEfC,EAAAA,iBAAiB,EAAE,aAFJ;AAGfC,EAAAA,UAAU,EAAE,IAHG;AAIfC,EAAAA,KAAK,EAAE,IAJQ;AAKfC,EAAAA,O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CAAC,KAAD,EAAQqD,CAAR,CAAH;AACD,OAtBH;AAuBD,KAxBM,CAAP;AAyBD;AAzIc,CAAjB","sourcesContent":["const https = require(\"https\");\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst log = require(\"./log\");\n\nmodule.exports = {\n config: null,\n defaultConfigPath: \"./yata.json\",\n configPath: null,\n token: null,\n project: null,\n locales: [],\n format: \"yml\",\n root: false,\n outputPath: \"translations\",\n stripEmpty: false,\n apiHost: null,\n\n getConfigPath(configPath) {\n if (configPath) {\n this.configPath = configPath;\n } else {\n this.configPath = this.defaultConfigPath;\n }\n\n return this.configPath;\n },\n\n validateConfig(\n token,\n project,\n locales,\n format,\n root,\n outputPath,\n stripEmpty\n ) {\n if (!token) {\n throw new Error(\"No `token` in ENV\");\n } else {\n this.token = token;\n }\n\n if (!project) {\n throw new Error(\"No `project` in config file\");\n } else {\n this.project = project;\n }\n\n if (!Array.isArray(locales) || locales.length === 0) {\n throw new Error(\"No `locales` in config file\");\n } else {\n this.locales = locales;\n }\n\n if (format && typeof format === \"string\") {\n this.format = format;\n }\n\n if (root && typeof root === \"boolean\") {\n this.root = root;\n }\n\n if (outputPath && typeof outputPath === \"string\") {\n this.outputPath = outputPath;\n }\n\n if (stripEmpty && typeof stripEmpty === \"boolean\") {\n this.stripEmpty = stripEmpty;\n }\n\n return true;\n },\n\n normalizeLocale(locale) {\n if (!locale) {\n return;\n }\n\n const localeSegments = locale.replace(\"-\", \"_\").split(\"_\");\n let newLocale = [];\n newLocale.push(localeSegments[0].toLowerCase());\n\n // two segment locale\n if (localeSegments[1]) {\n newLocale.push(localeSegments[1].toUpperCase());\n }\n\n return newLocale.join(\"_\");\n },\n\n downloadTranslation(locale) {\n const normalizedLocale = this.normalizeLocale(locale);\n\n if (!normalizedLocale) {\n throw new Error(\"No locale passed to download function\");\n }\n\n // if output folder doesn't exist we create it\n if (!fs.existsSync(this.outputPath)) {\n fs.mkdirSync(this.outputPath);\n }\n\n const fileName = `${normalizedLocale}.${this.format}`;\n const filePath = path.join(process.cwd(), `${this.outputPath}/${fileName}`);\n const url = `${this.apiHost}/api/v1/project/${this.project}/${locale}/${this.format}?apiToken=${this.token}&root=${this.root}&strip_empty=${this.stripEmpty}`;\n\n let bufferFile;\n\n // if file exist we grab it's size\n if (fs.existsSync(filePath)) {\n bufferFile = fs.readFileSync(filePath);\n }\n\n // we start stream\n const file = fs.createWriteStream(filePath);\n\n return new Promise((resolve, reject) => {\n https\n .get(url, (response) => {\n const { statusCode } = response;\n\n if (statusCode !== 200) {\n return reject(`Request Failed.\\nStatus Code: ${statusCode}`);\n }\n\n response.pipe(file);\n file.on(\"finish\", () => {\n const newBufferFile = fs.readFileSync(filePath);\n\n if (bufferFile && bufferFile.equals(newBufferFile)) {\n log(\"yellow\", `Generating \"${locale}\" translation. Skipped.`);\n } else {\n log(\"green\", `Generating \"${locale}\" translation. Done.`);\n }\n resolve();\n });\n })\n .on(\"error\", (e) => {\n log(\"red\", e);\n });\n });\n },\n};\n"],"file":"yata.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yata-fetch",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "description": "Adds CLI interface for importing translation files from Yata",
5
5
  "license": "MIT",
6
6
  "main": "./dist/yata",
@@ -27,6 +27,7 @@
27
27
  "generate": "node bin/yata-fetch.js --config test/fixtures/yata.json"
28
28
  },
29
29
  "dependencies": {
30
+ "dotenv": "10.0.0",
30
31
  "nconf": "^0.11.2"
31
32
  },
32
33
  "devDependencies": {
package/src/cli.js CHANGED
@@ -1,8 +1,8 @@
1
- const yata = require('./yata');
2
- const nconf = require('nconf');
3
- const log = require('./log');
1
+ const yata = require("./yata");
2
+ const nconf = require("nconf");
3
+ const log = require("./log");
4
4
 
5
- module.exports = async function() {
5
+ module.exports = async function () {
6
6
  // read argv for potential custom config path
7
7
  nconf.argv();
8
8
 
@@ -10,24 +10,26 @@ module.exports = async function() {
10
10
  nconf.env();
11
11
 
12
12
  // load config path
13
- nconf.file({ file: yata.getConfigPath(nconf.get('config')) });
13
+ nconf.file({ file: yata.getConfigPath(nconf.get("config")) });
14
14
 
15
15
  // setup API host
16
- yata.apiHost = nconf.get('YATA_API_HOST') || 'https://api.yatapp.net';
16
+ yata.apiHost = nconf.get("YATA_API_HOST") || "https://api.yatapp.net";
17
17
 
18
18
  try {
19
- if (yata.validateConfig(
20
- nconf.get(nconf.get('token')),
21
- nconf.get('project'),
22
- nconf.get('locales'),
23
- nconf.get('format'),
24
- nconf.get('root'),
25
- nconf.get('outputPath'),
26
- nconf.get('strip_empty'))) {
27
-
19
+ if (
20
+ yata.validateConfig(
21
+ nconf.get(nconf.get("token")),
22
+ nconf.get("project"),
23
+ nconf.get("locales"),
24
+ nconf.get("format"),
25
+ nconf.get("root"),
26
+ nconf.get("outputPath"),
27
+ nconf.get("strip_empty")
28
+ )
29
+ ) {
28
30
  // if passed locale explicit download just one
29
- if (nconf.get('locale')) {
30
- await yata.downloadTranslation(nconf.get('locale'));
31
+ if (nconf.get("locale")) {
32
+ await yata.downloadTranslation(nconf.get("locale"));
31
33
  } else {
32
34
  for (let locale of yata.locales) {
33
35
  await yata.downloadTranslation(locale);
@@ -35,6 +37,6 @@ module.exports = async function() {
35
37
  }
36
38
  }
37
39
  } catch (e) {
38
- log('red', e);
40
+ log("red", e);
39
41
  }
40
42
  };
package/src/log.js CHANGED
@@ -1,20 +1,19 @@
1
-
2
- module.exports = function(color, message) {
1
+ module.exports = function (color, message) {
3
2
  let code;
4
3
 
5
4
  switch (color) {
6
- case 'red':
7
- code = '\x1b[31m';
5
+ case "red":
6
+ code = "\x1b[31m";
8
7
  break;
9
- case 'green':
10
- code = '\x1b[32m';
8
+ case "green":
9
+ code = "\x1b[32m";
11
10
  break;
12
- case 'yellow':
13
- code = '\x1b[33m';
11
+ case "yellow":
12
+ code = "\x1b[33m";
14
13
  break;
15
14
 
16
15
  default:
17
- code = '\x1b[37m'; // white
16
+ code = "\x1b[37m"; // white
18
17
  }
19
18
 
20
19
  return console.log(`${code}%s\x1b[0m`, message);
package/src/yata.js CHANGED
@@ -1,20 +1,20 @@
1
- const https = require('https');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const log = require('./log');
1
+ const https = require("https");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const log = require("./log");
5
5
 
6
6
  module.exports = {
7
- config: null,
8
- defaultConfigPath: './yata.json',
9
- configPath: null,
10
- token: null,
11
- project: null,
12
- locales: [],
13
- format: 'yml',
14
- root: false,
15
- outputPath: 'translations',
16
- stripEmpty: false,
17
- apiHost: null,
7
+ config: null,
8
+ defaultConfigPath: "./yata.json",
9
+ configPath: null,
10
+ token: null,
11
+ project: null,
12
+ locales: [],
13
+ format: "yml",
14
+ root: false,
15
+ outputPath: "translations",
16
+ stripEmpty: false,
17
+ apiHost: null,
18
18
 
19
19
  getConfigPath(configPath) {
20
20
  if (configPath) {
@@ -26,38 +26,46 @@ module.exports = {
26
26
  return this.configPath;
27
27
  },
28
28
 
29
- validateConfig(token, project, locales, format, root, outputPath, stripEmpty) {
29
+ validateConfig(
30
+ token,
31
+ project,
32
+ locales,
33
+ format,
34
+ root,
35
+ outputPath,
36
+ stripEmpty
37
+ ) {
30
38
  if (!token) {
31
- throw new Error('No `token` in ENV');
39
+ throw new Error("No `token` in ENV");
32
40
  } else {
33
41
  this.token = token;
34
42
  }
35
43
 
36
44
  if (!project) {
37
- throw new Error('No `project` in config file');
45
+ throw new Error("No `project` in config file");
38
46
  } else {
39
47
  this.project = project;
40
48
  }
41
49
 
42
50
  if (!Array.isArray(locales) || locales.length === 0) {
43
- throw new Error('No `locales` in config file');
51
+ throw new Error("No `locales` in config file");
44
52
  } else {
45
53
  this.locales = locales;
46
54
  }
47
55
 
48
- if (format && typeof format === 'string') {
56
+ if (format && typeof format === "string") {
49
57
  this.format = format;
50
58
  }
51
59
 
52
- if (root && typeof root === 'boolean') {
60
+ if (root && typeof root === "boolean") {
53
61
  this.root = root;
54
62
  }
55
63
 
56
- if (outputPath && typeof outputPath === 'string') {
64
+ if (outputPath && typeof outputPath === "string") {
57
65
  this.outputPath = outputPath;
58
66
  }
59
67
 
60
- if (stripEmpty && typeof stripEmpty === 'boolean') {
68
+ if (stripEmpty && typeof stripEmpty === "boolean") {
61
69
  this.stripEmpty = stripEmpty;
62
70
  }
63
71
 
@@ -65,9 +73,11 @@ module.exports = {
65
73
  },
66
74
 
67
75
  normalizeLocale(locale) {
68
- if (!locale) { return; }
76
+ if (!locale) {
77
+ return;
78
+ }
69
79
 
70
- const localeSegments = locale.replace('-', '_').split('_');
80
+ const localeSegments = locale.replace("-", "_").split("_");
71
81
  let newLocale = [];
72
82
  newLocale.push(localeSegments[0].toLowerCase());
73
83
 
@@ -76,13 +86,15 @@ module.exports = {
76
86
  newLocale.push(localeSegments[1].toUpperCase());
77
87
  }
78
88
 
79
- return newLocale.join('_');
89
+ return newLocale.join("_");
80
90
  },
81
91
 
82
92
  downloadTranslation(locale) {
83
93
  const normalizedLocale = this.normalizeLocale(locale);
84
94
 
85
- if (!normalizedLocale) { throw new Error('No locale passed to download function'); }
95
+ if (!normalizedLocale) {
96
+ throw new Error("No locale passed to download function");
97
+ }
86
98
 
87
99
  // if output folder doesn't exist we create it
88
100
  if (!fs.existsSync(this.outputPath)) {
@@ -104,27 +116,29 @@ module.exports = {
104
116
  const file = fs.createWriteStream(filePath);
105
117
 
106
118
  return new Promise((resolve, reject) => {
107
- https.get(url, response => {
108
- const { statusCode } = response;
109
-
110
- if (statusCode !== 200) {
111
- return reject(`Request Failed.\nStatus Code: ${statusCode}`);
112
- }
119
+ https
120
+ .get(url, (response) => {
121
+ const { statusCode } = response;
113
122
 
114
- response.pipe(file);
115
- file.on('finish', () => {
116
- const newBufferFile = fs.readFileSync(filePath);
117
-
118
- if (bufferFile && bufferFile.equals(newBufferFile)) {
119
- log('yellow', `Generating "${locale}" translation. Skipped.`);
120
- } else {
121
- log('green', `Generating "${locale}" translation. Done.`);
123
+ if (statusCode !== 200) {
124
+ return reject(`Request Failed.\nStatus Code: ${statusCode}`);
122
125
  }
123
- resolve();
126
+
127
+ response.pipe(file);
128
+ file.on("finish", () => {
129
+ const newBufferFile = fs.readFileSync(filePath);
130
+
131
+ if (bufferFile && bufferFile.equals(newBufferFile)) {
132
+ log("yellow", `Generating "${locale}" translation. Skipped.`);
133
+ } else {
134
+ log("green", `Generating "${locale}" translation. Done.`);
135
+ }
136
+ resolve();
137
+ });
138
+ })
139
+ .on("error", (e) => {
140
+ log("red", e);
124
141
  });
125
- }).on('error', e => {
126
- log('red', e);
127
- });
128
142
  });
129
- }
143
+ },
130
144
  };