@melfore/clibelt 3.0.2 → 5.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/README.md +4 -2
- package/dist/cli/i18n-copy/index.d.ts +1 -0
- package/dist/cli/i18n-copy/index.js +144 -0
- package/dist/cli/i18n-msg/index.js +18 -7
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Add required CLIs to your `package.json`, for example:
|
|
|
17
17
|
```json
|
|
18
18
|
"scripts": {
|
|
19
19
|
"i18n": "i18n-msg",
|
|
20
|
+
"i18n:copy": "i18n-copy",
|
|
20
21
|
"pwd2hash": "pwd2hash"
|
|
21
22
|
}
|
|
22
23
|
```
|
|
@@ -34,7 +35,7 @@ Configuration example:
|
|
|
34
35
|
```json
|
|
35
36
|
{
|
|
36
37
|
"i18nMsg": {
|
|
37
|
-
"input": "./resources/messages-all-langs",
|
|
38
|
+
"input": "./resources/messages-all-langs.js",
|
|
38
39
|
"outMsg": "./src/messages",
|
|
39
40
|
"outTs": "./src/messages/i18nMessages.ts"
|
|
40
41
|
}
|
|
@@ -48,6 +49,7 @@ Add arguments to script in `package.json`, for example:
|
|
|
48
49
|
```json
|
|
49
50
|
"scripts": {
|
|
50
51
|
"i18n": "i18n-msg --input new/path --outTs new/constants.ts",
|
|
52
|
+
"i18n:copy": "i18n-copy --from=it --to=fr",
|
|
51
53
|
}
|
|
52
54
|
```
|
|
53
55
|
|
|
@@ -81,7 +83,7 @@ Example:
|
|
|
81
83
|
```json
|
|
82
84
|
{
|
|
83
85
|
"i18nMsg": {
|
|
84
|
-
"input": "./resources/messages-all-langs",
|
|
86
|
+
"input": "./resources/messages-all-langs.js",
|
|
85
87
|
"outMsg": "./src/messages",
|
|
86
88
|
"outTs": "./src/messages/i18nMessages.ts"
|
|
87
89
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
var fs = require("fs");
|
|
66
|
+
var config_1 = __importDefault(require("../../config"));
|
|
67
|
+
var path_1 = __importDefault(require("path"));
|
|
68
|
+
var prettier = __importStar(require("prettier"));
|
|
69
|
+
var checkFile = function (inputPath, from, to) { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
var fileContent, addValue, existLang, newContent, writeContent, prettierContent;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
fileContent = require(inputPath);
|
|
75
|
+
addValue = "";
|
|
76
|
+
existLang = false;
|
|
77
|
+
newContent = fileContent.messages.map(function (messages) {
|
|
78
|
+
messages.tr.forEach(function (value) {
|
|
79
|
+
if (value.l === from) {
|
|
80
|
+
addValue = value.v;
|
|
81
|
+
}
|
|
82
|
+
if (value.l === to) {
|
|
83
|
+
existLang = true;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (!existLang) {
|
|
87
|
+
messages.tr.push({ l: to, v: addValue });
|
|
88
|
+
}
|
|
89
|
+
if (messages.overrides) {
|
|
90
|
+
messages.overrides.forEach(function (i, index) {
|
|
91
|
+
var addOverrideValue = "";
|
|
92
|
+
var existOverridesLang = false;
|
|
93
|
+
i.tr.forEach(function (value) {
|
|
94
|
+
if (value.l === from) {
|
|
95
|
+
addOverrideValue = value.v;
|
|
96
|
+
}
|
|
97
|
+
if (value.l === to) {
|
|
98
|
+
existOverridesLang = true;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (!existOverridesLang) {
|
|
102
|
+
messages.overrides[index].tr.push({ l: to, v: addOverrideValue });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return messages;
|
|
107
|
+
});
|
|
108
|
+
writeContent = "exports.messages = " + JSON.stringify(newContent);
|
|
109
|
+
return [4, prettier.format(writeContent, { parser: "babel" })];
|
|
110
|
+
case 1:
|
|
111
|
+
prettierContent = _a.sent();
|
|
112
|
+
fs.writeFileSync(inputPath, prettierContent, "utf-8");
|
|
113
|
+
return [2];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}); };
|
|
117
|
+
var langCopy = function () {
|
|
118
|
+
var from = process.env.npm_config_from;
|
|
119
|
+
var to = process.env.npm_config_to;
|
|
120
|
+
var inputPath = path_1.default.join(process.cwd(), config_1.default.get("i18nMsg").input);
|
|
121
|
+
var isDir = fs.lstatSync(inputPath).isDirectory();
|
|
122
|
+
if (!from || !to) {
|
|
123
|
+
console.error("Missing params from and to");
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
if (isDir) {
|
|
127
|
+
fs.readdirSync(inputPath).map(function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
+
var filePath;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
filePath = path_1.default.join(inputPath, fileName);
|
|
131
|
+
checkFile(filePath, from, to);
|
|
132
|
+
return [2];
|
|
133
|
+
});
|
|
134
|
+
}); });
|
|
135
|
+
console.log("Successfully copied");
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
checkFile(inputPath, from, to);
|
|
139
|
+
console.log("Successfully copied");
|
|
140
|
+
}
|
|
141
|
+
return 0;
|
|
142
|
+
};
|
|
143
|
+
var res = langCopy();
|
|
144
|
+
process.exit(res);
|
|
@@ -130,6 +130,7 @@ var allLanguagesReport = function (data, languages) {
|
|
|
130
130
|
});
|
|
131
131
|
};
|
|
132
132
|
var report = function (data, languages) {
|
|
133
|
+
var e = 0;
|
|
133
134
|
data.forEach(function (value) {
|
|
134
135
|
var _a;
|
|
135
136
|
var valueLanguages = [];
|
|
@@ -143,15 +144,18 @@ var report = function (data, languages) {
|
|
|
143
144
|
});
|
|
144
145
|
var differentArrOverrides = languages.filter(function (x) { return !valueLanguagesOverrites.includes(x); });
|
|
145
146
|
if (differentArrOverrides[0]) {
|
|
146
|
-
console.
|
|
147
|
+
console.error(" Code: ", "\x1b[31m" + value.code + "\x1b[0m", " Customer: ", "\x1b[31m" + i.customer + "\x1b[0m", " is missing the following languages: ", differentArrOverrides);
|
|
148
|
+
e = 1;
|
|
147
149
|
}
|
|
148
150
|
valueLanguagesOverrites = [];
|
|
149
151
|
});
|
|
150
152
|
var differentArr = languages.filter(function (x) { return !valueLanguages.includes(x); });
|
|
151
153
|
if (differentArr[0]) {
|
|
152
|
-
console.
|
|
154
|
+
console.error(" Code: ", "\x1b[31m" + value.code + "\x1b[0m", " is missing the following languages: ", differentArr);
|
|
155
|
+
e = 1;
|
|
153
156
|
}
|
|
154
157
|
});
|
|
158
|
+
return e;
|
|
155
159
|
};
|
|
156
160
|
var getAllLanguagesUnique = function (languages) {
|
|
157
161
|
return languages.filter(function (value, index) { return languages.indexOf(value) === index; });
|
|
@@ -160,18 +164,22 @@ var multiFileReport = function (languages, namespaces) {
|
|
|
160
164
|
console.log();
|
|
161
165
|
console.log("-------REPORT-------");
|
|
162
166
|
var uniqueLang = getAllLanguagesUnique(languages);
|
|
167
|
+
var numeError = 0;
|
|
163
168
|
for (var _i = 0, namespaces_1 = namespaces; _i < namespaces_1.length; _i++) {
|
|
164
169
|
var _a = namespaces_1[_i], messages = _a[1];
|
|
165
|
-
report(messages, uniqueLang);
|
|
170
|
+
var e = report(messages, uniqueLang);
|
|
171
|
+
numeError = numeError + e;
|
|
166
172
|
}
|
|
167
173
|
console.log("All languages: ", uniqueLang);
|
|
174
|
+
return numeError !== 0 ? 1 : 0;
|
|
168
175
|
};
|
|
169
176
|
var singleFileReport = function (message, languages) {
|
|
170
177
|
console.log();
|
|
171
178
|
console.log("-----REPORT-------");
|
|
172
179
|
var uniqueLang = getAllLanguagesUnique(languages);
|
|
173
|
-
report(message, uniqueLang);
|
|
180
|
+
var e = report(message, uniqueLang);
|
|
174
181
|
console.log("All languages: ", uniqueLang);
|
|
182
|
+
return e !== 0 ? 1 : 0;
|
|
175
183
|
};
|
|
176
184
|
var checkNamespaces = function () {
|
|
177
185
|
fs_1.default.mkdirSync(outTempDir, { recursive: true });
|
|
@@ -185,13 +193,16 @@ var checkNamespaces = function () {
|
|
|
185
193
|
allLanguagesReport(messages, languages);
|
|
186
194
|
splitMessages(messages, ns);
|
|
187
195
|
}
|
|
188
|
-
multiFileReport(languages, namespaces);
|
|
196
|
+
var e = multiFileReport(languages, namespaces);
|
|
189
197
|
writeNamespacesFile(namespaces);
|
|
198
|
+
return e;
|
|
190
199
|
}
|
|
191
200
|
else {
|
|
192
201
|
allLanguagesReport(mal.messages, languages);
|
|
193
202
|
splitMessages(mal.messages);
|
|
194
|
-
singleFileReport(mal.messages, languages);
|
|
203
|
+
var e = singleFileReport(mal.messages, languages);
|
|
204
|
+
return e;
|
|
195
205
|
}
|
|
196
206
|
};
|
|
197
|
-
checkNamespaces();
|
|
207
|
+
var res = checkNamespaces();
|
|
208
|
+
process.exit(res);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melfore/clibelt",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"homepage": "https://github.com/melfore/clibelt#readme",
|
|
5
5
|
"description": "CLI belt: the Melfore tool belt",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"bin": {
|
|
15
15
|
"pwd2hash": "dist/cli/pwd2hash/index.js",
|
|
16
|
-
"i18n-msg": "dist/cli/i18n-msg/index.js"
|
|
16
|
+
"i18n-msg": "dist/cli/i18n-msg/index.js",
|
|
17
|
+
"i18n-copy": "dist/cli/i18n-copy/index.js"
|
|
17
18
|
},
|
|
18
19
|
"engines": {
|
|
19
20
|
"node": ">=18 <19",
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
"prettify": "prettier --write .",
|
|
34
35
|
"preversion": "npm run lintify",
|
|
35
36
|
"version": "npm run prettify",
|
|
36
|
-
"upload": "npm run build && npm publish --access public"
|
|
37
|
+
"upload": "npm run build && npm publish --access public",
|
|
38
|
+
"i18n:copy": "ts-node src/cli/i18n-copy/index.ts"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
41
|
"convict": "^6.2.4",
|