yata-fetch 1.3.2 → 2.0.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.json +16 -0
- package/.github/workflows/publish.yaml +23 -0
- package/.github/workflows/test.yaml +143 -0
- package/.prettierignore +15 -0
- package/.prettierrc +9 -0
- package/.tool-versions +1 -1
- package/README.md +35 -33
- package/bin/yata-fetch.js +2 -2
- package/dist/cli.cjs +2 -0
- package/package.json +22 -20
- package/src/cli.ts +48 -0
- package/src/log.ts +22 -0
- package/src/vite-env.d.ts +1 -0
- package/src/yata.ts +153 -0
- package/test/fixtures/yata.json +2 -4
- package/test/unit/yata.spec.js +111 -0
- package/tsconfig.json +20 -0
- package/vite.config.js +15 -0
- package/.circleci/config.yml +0 -17
- package/.eslintrc.js +0 -141
- package/dist/cli.js +0 -112
- package/dist/cli.js.map +0 -1
- package/dist/log.js +0 -26
- package/dist/log.js.map +0 -1
- package/dist/yata.js +0 -133
- package/dist/yata.js.map +0 -1
- package/gulpfile.js +0 -66
- package/src/cli.js +0 -42
- package/src/log.js +0 -20
- package/src/yata.js +0 -144
- package/test/unit/.eslintrc.js +0 -20
- package/test/unit/yata-spec.js +0 -103
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { expect, it, describe } from 'vitest'
|
|
2
|
+
import yata from '../../src/yata'
|
|
3
|
+
|
|
4
|
+
describe('yata library', function () {
|
|
5
|
+
describe('getConfigPath function', function () {
|
|
6
|
+
it('return default config path', function () {
|
|
7
|
+
expect(yata.getConfigPath()).to.equal('./yata.json')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('return custom config path', function () {
|
|
11
|
+
expect(yata.getConfigPath('./custom-yata.json')).to.equal(
|
|
12
|
+
'./custom-yata.json'
|
|
13
|
+
)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('validateConfig function', function () {
|
|
18
|
+
it('return exception if no token in ENV', function () {
|
|
19
|
+
expect(() => {
|
|
20
|
+
yata.validateConfig()
|
|
21
|
+
}).to.throw('token')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('return exception if no project', function () {
|
|
25
|
+
expect(() => {
|
|
26
|
+
yata.validateConfig('token')
|
|
27
|
+
}).to.throw('project')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('return exception if empty locales', function () {
|
|
31
|
+
expect(() => {
|
|
32
|
+
yata.validateConfig('token', 'project', [])
|
|
33
|
+
}).to.throw('locales')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('return exception if no locales', function () {
|
|
37
|
+
expect(() => {
|
|
38
|
+
yata.validateConfig('token', 'project')
|
|
39
|
+
}).to.throw('locales')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('return exception if locales as string', function () {
|
|
43
|
+
expect(() => {
|
|
44
|
+
yata.validateConfig('token', 'project', 'pl_PL')
|
|
45
|
+
}).to.throw('locales')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('passes validaiton when using only required params', function () {
|
|
49
|
+
const validation = yata.validateConfig('token', 'project', ['pl_PL'])
|
|
50
|
+
|
|
51
|
+
expect(validation).to.be.true
|
|
52
|
+
expect(yata.format).to.equal('yml')
|
|
53
|
+
expect(yata.root).to.be.false
|
|
54
|
+
expect(yata.stripEmpty).to.be.false
|
|
55
|
+
expect(yata.outputPath).to.be.equal('translations')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('passes validaiton when passing all params', function () {
|
|
59
|
+
const validation = yata.validateConfig(
|
|
60
|
+
'token',
|
|
61
|
+
'project',
|
|
62
|
+
['pl_PL'],
|
|
63
|
+
'json',
|
|
64
|
+
true,
|
|
65
|
+
'locales',
|
|
66
|
+
true
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
expect(validation).to.be.true
|
|
70
|
+
expect(yata.token).to.equal('token')
|
|
71
|
+
expect(yata.project).to.equal('project')
|
|
72
|
+
expect(yata.locales).to.deep.equal(['pl_PL'])
|
|
73
|
+
expect(yata.format).to.equal('json')
|
|
74
|
+
expect(yata.root).to.be.true
|
|
75
|
+
expect(yata.stripEmpty).to.be.true
|
|
76
|
+
expect(yata.outputPath).to.be.equal('locales')
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe('downloadTranslation function', function () {
|
|
81
|
+
it('throw exception if no locale', function () {
|
|
82
|
+
expect(() => yata.downloadTranslation()).to.throw('locale')
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('normalizeLocale function', function () {
|
|
87
|
+
it('work with undefined value', function () {
|
|
88
|
+
expect(() => yata.normalizeLocale()).to.not.throw()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('work with null value', function () {
|
|
92
|
+
expect(() => yata.normalizeLocale(null)).to.not.throw()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('work with empty string value', function () {
|
|
96
|
+
expect(yata.normalizeLocale('')).to.equal()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('work ISO notation', function () {
|
|
100
|
+
expect(yata.normalizeLocale('en-us')).to.equal('en_US')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('work with simple notation', function () {
|
|
104
|
+
expect(yata.normalizeLocale('EN')).to.equal('en')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('work with already correct version', function () {
|
|
108
|
+
expect(yata.normalizeLocale('en_US')).to.equal('en_US')
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ESNext", "DOM"],
|
|
7
|
+
"moduleResolution": "Node",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true,
|
|
16
|
+
"noImplicitReturns": true,
|
|
17
|
+
"skipLibCheck": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src"]
|
|
20
|
+
}
|
package/vite.config.js
ADDED
package/.circleci/config.yml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
version: 2.1
|
|
2
|
-
jobs:
|
|
3
|
-
build:
|
|
4
|
-
docker:
|
|
5
|
-
- image: circleci/node:12.16.1
|
|
6
|
-
working_directory: ~/repo
|
|
7
|
-
steps:
|
|
8
|
-
- checkout
|
|
9
|
-
- restore_cache:
|
|
10
|
-
keys:
|
|
11
|
-
- v1-dependencies-{{ checksum "package.json" }}
|
|
12
|
-
- run: yarn install
|
|
13
|
-
- save_cache:
|
|
14
|
-
paths:
|
|
15
|
-
- node_modules
|
|
16
|
-
key: v1-dependencies-{{ checksum "package.json" }}
|
|
17
|
-
- run: yarn test
|
package/.eslintrc.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
parser: "babel-eslint",
|
|
4
|
-
parserOptions: {
|
|
5
|
-
ecmaVersion: 2017,
|
|
6
|
-
sourceType: "module",
|
|
7
|
-
},
|
|
8
|
-
extends: "eslint:recommended",
|
|
9
|
-
env: {
|
|
10
|
-
browser: true,
|
|
11
|
-
},
|
|
12
|
-
rules: {
|
|
13
|
-
/*** Possible Errors ***/
|
|
14
|
-
|
|
15
|
-
"no-console": 0,
|
|
16
|
-
"no-template-curly-in-string": 2,
|
|
17
|
-
"no-unsafe-negation": 2,
|
|
18
|
-
|
|
19
|
-
/*** Best Practices ***/
|
|
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": [
|
|
28
|
-
2,
|
|
29
|
-
{
|
|
30
|
-
exceptions: {
|
|
31
|
-
ObjectExpression: true,
|
|
32
|
-
Property: true,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
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,
|
|
46
|
-
|
|
47
|
-
/*** Strict Mode ***/
|
|
48
|
-
|
|
49
|
-
strict: [2, "global"],
|
|
50
|
-
|
|
51
|
-
/*** Variables ***/
|
|
52
|
-
|
|
53
|
-
"no-undef": 2,
|
|
54
|
-
"no-unused-vars": 2,
|
|
55
|
-
"no-use-before-define": [2, "nofunc"],
|
|
56
|
-
|
|
57
|
-
/*** Stylistic Issues ***/
|
|
58
|
-
|
|
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,
|
|
108
|
-
|
|
109
|
-
/*** ECMAScript 6 ***/
|
|
110
|
-
|
|
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,
|
|
134
|
-
},
|
|
135
|
-
globals: {
|
|
136
|
-
module: true,
|
|
137
|
-
require: true,
|
|
138
|
-
process: true,
|
|
139
|
-
Promise: true,
|
|
140
|
-
},
|
|
141
|
-
};
|
package/dist/cli.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
-
|
|
7
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
-
|
|
9
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
10
|
-
|
|
11
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
var yata = require("./yata");
|
|
16
|
-
|
|
17
|
-
var nconf = require("nconf");
|
|
18
|
-
|
|
19
|
-
var log = require("./log");
|
|
20
|
-
|
|
21
|
-
require("dotenv").config();
|
|
22
|
-
|
|
23
|
-
module.exports = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
24
|
-
var _iterator, _step, locale;
|
|
25
|
-
|
|
26
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
27
|
-
while (1) {
|
|
28
|
-
switch (_context.prev = _context.next) {
|
|
29
|
-
case 0:
|
|
30
|
-
// read argv for potential custom config path
|
|
31
|
-
nconf.argv(); // read ENV for token
|
|
32
|
-
|
|
33
|
-
nconf.env(); // load config path
|
|
34
|
-
|
|
35
|
-
nconf.file({
|
|
36
|
-
file: yata.getConfigPath(nconf.get("config"))
|
|
37
|
-
}); // setup API host
|
|
38
|
-
|
|
39
|
-
yata.apiHost = nconf.get("YATA_API_HOST") || "https://api.yatapp.net";
|
|
40
|
-
_context.prev = 4;
|
|
41
|
-
|
|
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"))) {
|
|
43
|
-
_context.next = 28;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!nconf.get("locale")) {
|
|
48
|
-
_context.next = 11;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_context.next = 9;
|
|
53
|
-
return yata.downloadTranslation(nconf.get("locale"));
|
|
54
|
-
|
|
55
|
-
case 9:
|
|
56
|
-
_context.next = 28;
|
|
57
|
-
break;
|
|
58
|
-
|
|
59
|
-
case 11:
|
|
60
|
-
_iterator = _createForOfIteratorHelper(yata.locales);
|
|
61
|
-
_context.prev = 12;
|
|
62
|
-
|
|
63
|
-
_iterator.s();
|
|
64
|
-
|
|
65
|
-
case 14:
|
|
66
|
-
if ((_step = _iterator.n()).done) {
|
|
67
|
-
_context.next = 20;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
locale = _step.value;
|
|
72
|
-
_context.next = 18;
|
|
73
|
-
return yata.downloadTranslation(locale);
|
|
74
|
-
|
|
75
|
-
case 18:
|
|
76
|
-
_context.next = 14;
|
|
77
|
-
break;
|
|
78
|
-
|
|
79
|
-
case 20:
|
|
80
|
-
_context.next = 25;
|
|
81
|
-
break;
|
|
82
|
-
|
|
83
|
-
case 22:
|
|
84
|
-
_context.prev = 22;
|
|
85
|
-
_context.t0 = _context["catch"](12);
|
|
86
|
-
|
|
87
|
-
_iterator.e(_context.t0);
|
|
88
|
-
|
|
89
|
-
case 25:
|
|
90
|
-
_context.prev = 25;
|
|
91
|
-
|
|
92
|
-
_iterator.f();
|
|
93
|
-
|
|
94
|
-
return _context.finish(25);
|
|
95
|
-
|
|
96
|
-
case 28:
|
|
97
|
-
_context.next = 33;
|
|
98
|
-
break;
|
|
99
|
-
|
|
100
|
-
case 30:
|
|
101
|
-
_context.prev = 30;
|
|
102
|
-
_context.t1 = _context["catch"](4);
|
|
103
|
-
log("red", _context.t1);
|
|
104
|
-
|
|
105
|
-
case 33:
|
|
106
|
-
case "end":
|
|
107
|
-
return _context.stop();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}, _callee, null, [[4, 30], [12, 22, 25, 28]]);
|
|
111
|
-
}));
|
|
112
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["cli.js"],"names":["yata","require","nconf","log","config","module","exports","argv","env","file","getConfigPath","get","apiHost","validateConfig","downloadTranslation","locales","locale"],"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AAA;;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
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = function (color, message) {
|
|
4
|
-
var code;
|
|
5
|
-
|
|
6
|
-
switch (color) {
|
|
7
|
-
case "red":
|
|
8
|
-
code = "\x1b[31m";
|
|
9
|
-
break;
|
|
10
|
-
|
|
11
|
-
case "green":
|
|
12
|
-
code = "\x1b[32m";
|
|
13
|
-
break;
|
|
14
|
-
|
|
15
|
-
case "yellow":
|
|
16
|
-
code = "\x1b[33m";
|
|
17
|
-
break;
|
|
18
|
-
|
|
19
|
-
default:
|
|
20
|
-
code = "\x1b[37m";
|
|
21
|
-
// white
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return console.log("".concat(code, "%s\x1B[0m"), message);
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=log.js.map
|
package/dist/log.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var https = require("https");
|
|
4
|
-
|
|
5
|
-
var fs = require("fs");
|
|
6
|
-
|
|
7
|
-
var path = require("path");
|
|
8
|
-
|
|
9
|
-
var log = require("./log");
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
config: null,
|
|
13
|
-
defaultConfigPath: "./yata.json",
|
|
14
|
-
configPath: null,
|
|
15
|
-
token: null,
|
|
16
|
-
project: null,
|
|
17
|
-
locales: [],
|
|
18
|
-
format: "yml",
|
|
19
|
-
root: false,
|
|
20
|
-
outputPath: "translations",
|
|
21
|
-
stripEmpty: false,
|
|
22
|
-
apiHost: null,
|
|
23
|
-
getConfigPath: function getConfigPath(configPath) {
|
|
24
|
-
if (configPath) {
|
|
25
|
-
this.configPath = configPath;
|
|
26
|
-
} else {
|
|
27
|
-
this.configPath = this.defaultConfigPath;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return this.configPath;
|
|
31
|
-
},
|
|
32
|
-
validateConfig: function validateConfig(token, project, locales, format, root, outputPath, stripEmpty) {
|
|
33
|
-
if (!token) {
|
|
34
|
-
throw new Error("No `token` in ENV");
|
|
35
|
-
} else {
|
|
36
|
-
this.token = token;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!project) {
|
|
40
|
-
throw new Error("No `project` in config file");
|
|
41
|
-
} else {
|
|
42
|
-
this.project = project;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!Array.isArray(locales) || locales.length === 0) {
|
|
46
|
-
throw new Error("No `locales` in config file");
|
|
47
|
-
} else {
|
|
48
|
-
this.locales = locales;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (format && typeof format === "string") {
|
|
52
|
-
this.format = format;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (root && typeof root === "boolean") {
|
|
56
|
-
this.root = root;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (outputPath && typeof outputPath === "string") {
|
|
60
|
-
this.outputPath = outputPath;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (stripEmpty && typeof stripEmpty === "boolean") {
|
|
64
|
-
this.stripEmpty = stripEmpty;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return true;
|
|
68
|
-
},
|
|
69
|
-
normalizeLocale: function normalizeLocale(locale) {
|
|
70
|
-
if (!locale) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
var localeSegments = locale.replace("-", "_").split("_");
|
|
75
|
-
var newLocale = [];
|
|
76
|
-
newLocale.push(localeSegments[0].toLowerCase()); // two segment locale
|
|
77
|
-
|
|
78
|
-
if (localeSegments[1]) {
|
|
79
|
-
newLocale.push(localeSegments[1].toUpperCase());
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return newLocale.join("_");
|
|
83
|
-
},
|
|
84
|
-
downloadTranslation: function downloadTranslation(locale) {
|
|
85
|
-
var normalizedLocale = this.normalizeLocale(locale);
|
|
86
|
-
|
|
87
|
-
if (!normalizedLocale) {
|
|
88
|
-
throw new Error("No locale passed to download function");
|
|
89
|
-
} // if output folder doesn't exist we create it
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!fs.existsSync(this.outputPath)) {
|
|
93
|
-
fs.mkdirSync(this.outputPath);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var fileName = "".concat(normalizedLocale, ".").concat(this.format);
|
|
97
|
-
var filePath = path.join(process.cwd(), "".concat(this.outputPath, "/").concat(fileName));
|
|
98
|
-
var url = "".concat(this.apiHost, "/api/v1/project/").concat(this.project, "/").concat(locale, "/").concat(this.format, "?apiToken=").concat(this.token, "&root=").concat(this.root, "&strip_empty=").concat(this.stripEmpty);
|
|
99
|
-
var bufferFile; // if file exist we grab it's size
|
|
100
|
-
|
|
101
|
-
if (fs.existsSync(filePath)) {
|
|
102
|
-
bufferFile = fs.readFileSync(filePath);
|
|
103
|
-
} // we start stream
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var file = fs.createWriteStream(filePath);
|
|
107
|
-
return new Promise(function (resolve, reject) {
|
|
108
|
-
https.get(url, function (response) {
|
|
109
|
-
var statusCode = response.statusCode;
|
|
110
|
-
|
|
111
|
-
if (statusCode !== 200) {
|
|
112
|
-
return reject("Request Failed.\nStatus Code: ".concat(statusCode));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
response.pipe(file);
|
|
116
|
-
file.on("finish", function () {
|
|
117
|
-
var newBufferFile = fs.readFileSync(filePath);
|
|
118
|
-
|
|
119
|
-
if (bufferFile && bufferFile.equals(newBufferFile)) {
|
|
120
|
-
log("yellow", "Generating \"".concat(locale, "\" translation. Skipped."));
|
|
121
|
-
} else {
|
|
122
|
-
log("green", "Generating \"".concat(locale, "\" translation. Done."));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
resolve();
|
|
126
|
-
});
|
|
127
|
-
}).on("error", function (e) {
|
|
128
|
-
log("red", e);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
//# sourceMappingURL=yata.js.map
|
package/dist/yata.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,UAA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BH,CAoBM,OApBN,EAoBe,UAACG,CAAD,EAAO;AAClBrD,QAAAA,GAAG,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/gulpfile.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const gulp = require('gulp');
|
|
2
|
-
const mocha = require('gulp-mocha');
|
|
3
|
-
const eslint = require('gulp-eslint');
|
|
4
|
-
const sourcemaps = require('gulp-sourcemaps');
|
|
5
|
-
const babel = require('gulp-babel');
|
|
6
|
-
|
|
7
|
-
// Lint
|
|
8
|
-
|
|
9
|
-
gulp.task('lint:src', function() {
|
|
10
|
-
return gulp.src('./src/**/*.js')
|
|
11
|
-
.pipe(eslint())
|
|
12
|
-
.pipe(eslint.format())
|
|
13
|
-
.pipe(eslint.failAfterError());
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
gulp.task('lint:bin', function() {
|
|
17
|
-
return gulp.src('./bin/**/*.js')
|
|
18
|
-
.pipe(eslint())
|
|
19
|
-
.pipe(eslint.format())
|
|
20
|
-
.pipe(eslint.failAfterError());
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
gulp.task('lint:test', function() {
|
|
24
|
-
return gulp.src('./test/**/*.js')
|
|
25
|
-
.pipe(eslint())
|
|
26
|
-
.pipe(eslint.format())
|
|
27
|
-
.pipe(eslint.failAfterError());
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Build task
|
|
31
|
-
|
|
32
|
-
gulp.task('babel:src', function() {
|
|
33
|
-
return gulp.src('./src/**/*.js')
|
|
34
|
-
.pipe(sourcemaps.init())
|
|
35
|
-
.pipe(babel({
|
|
36
|
-
presets: ['@babel/preset-env'],
|
|
37
|
-
"plugins": [
|
|
38
|
-
["@babel/plugin-transform-runtime",
|
|
39
|
-
{
|
|
40
|
-
"regenerator": true
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
]
|
|
44
|
-
}))
|
|
45
|
-
.pipe(sourcemaps.write('.'))
|
|
46
|
-
.pipe(gulp.dest('dist'));
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
gulp.task('build', gulp.series('lint:src', 'babel:src'));
|
|
50
|
-
|
|
51
|
-
// Tests tasks
|
|
52
|
-
|
|
53
|
-
gulp.task('test', gulp.series('lint:test', 'lint:src', 'lint:bin', 'babel:src', () =>
|
|
54
|
-
gulp.src('./test/**/*.js', { read: false })
|
|
55
|
-
.pipe(mocha())
|
|
56
|
-
));
|
|
57
|
-
|
|
58
|
-
// Watch tasks
|
|
59
|
-
|
|
60
|
-
gulp.task('watch', function() {
|
|
61
|
-
gulp.watch('test/**/*.js', gulp.series('test'));
|
|
62
|
-
gulp.watch('src/**/*.js', gulp.series('test'));
|
|
63
|
-
gulp.watch('bin/**/*.js', gulp.series('test'));
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
gulp.task('default', gulp.series('test', 'watch'));
|