@melfore/clibelt 6.0.6 → 6.0.7

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.
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -39,27 +39,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ var vitest_1 = require("vitest");
42
43
  var utils_1 = require("../utils");
43
- var testFileResult_js_1 = __importDefault(require("./testFileResult.js"));
44
+ var testFileResultENPL_js_1 = __importDefault(require("./testFileResultENPL.js"));
45
+ var testFileResultITPL_js_1 = __importDefault(require("./testFileResultITPL.js"));
44
46
  var node_path_1 = __importDefault(require("node:path"));
45
- describe("Copy-Test", function () {
46
- var file = node_path_1.default.join(process.cwd(), "src/cli/i18n-copy/_test_/testFile.js");
47
- it("CheckSignleFile", function () { return __awaiter(void 0, void 0, void 0, function () {
47
+ (0, vitest_1.describe)("Copy-Test", function () {
48
+ var file = node_path_1.default.join(__dirname, "testFile.js");
49
+ (0, vitest_1.it)("CheckSignleFile EN-PL", function () { return __awaiter(void 0, void 0, void 0, function () {
48
50
  var res;
49
51
  return __generator(this, function (_a) {
50
52
  switch (_a.label) {
51
- case 0: return [4, (0, utils_1.checkSingleFile)(file, "it", "pl")];
53
+ case 0: return [4, (0, utils_1.checkSingleFile)(file, "en", "pl", true)];
52
54
  case 1:
53
55
  res = _a.sent();
54
- expect(res).toEqual(testFileResult_js_1.default.messages);
56
+ (0, vitest_1.expect)(res).toEqual(testFileResultENPL_js_1.default.messages);
55
57
  return [2];
56
58
  }
57
59
  });
58
60
  }); });
59
- it("Wrong --from param", function () { return __awaiter(void 0, void 0, void 0, function () {
61
+ (0, vitest_1.it)("CheckSignleFile IT-PL", function () { return __awaiter(void 0, void 0, void 0, function () {
62
+ var res;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0: return [4, (0, utils_1.checkSingleFile)(file, "it", "pl", true)];
66
+ case 1:
67
+ res = _a.sent();
68
+ (0, vitest_1.expect)(res).toEqual(testFileResultITPL_js_1.default.messages);
69
+ return [2];
70
+ }
71
+ });
72
+ }); });
73
+ (0, vitest_1.it)("Wrong --from param", function () { return __awaiter(void 0, void 0, void 0, function () {
60
74
  return __generator(this, function (_a) {
61
75
  switch (_a.label) {
62
- case 0: return [4, expect(function () { return (0, utils_1.checkSingleFile)(file, "FR", "pl"); }).rejects.toThrow("--from FR not exist")];
76
+ case 0: return [4, (0, vitest_1.expect)(function () { return (0, utils_1.checkSingleFile)(file, "FR", "pl", true); }).rejects.toThrow("--from FR not exist")];
63
77
  case 1:
64
78
  _a.sent();
65
79
  return [2];
File without changes
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ exports = {
3
+ messages: [
4
+ {
5
+ code: "error.code.login.failed",
6
+ tr: [
7
+ { l: "en", v: "Access denied. Please check your credentials and retry" },
8
+ { l: "it", v: "Accesso negato. Controllare le credenziali e riprovare" },
9
+ ],
10
+ },
11
+ {
12
+ code: "http.error.code.400",
13
+ tr: [
14
+ { l: "en", v: "Sorry, the request is wrong (400)" },
15
+ { l: "it", v: "Siamo spiacenti, la richiesta è errata (400)" },
16
+ ],
17
+ overrides: [
18
+ {
19
+ customer: "c1",
20
+ tr: [
21
+ { l: "en", v: "Access denied C1" },
22
+ { l: "it", v: "Accesso negato C1" },
23
+ ],
24
+ },
25
+ {
26
+ customer: "c2",
27
+ tr: [
28
+ { l: "en", v: "Access denied C2" },
29
+ { l: "it", v: "Accesso negato C2" },
30
+ ],
31
+ },
32
+ {
33
+ customer: "c1",
34
+ tr: [
35
+ { l: "en", v: "Access denied C1" },
36
+ { l: "it", v: "Accesso negato C1" },
37
+ ],
38
+ },
39
+ ],
40
+ },
41
+ {
42
+ code: "http.error.code.generic",
43
+ tr: [
44
+ { l: "en", v: "Generic comunication error" },
45
+ { l: "it", v: "Errore di comunicazione generica" },
46
+ ],
47
+ },
48
+ ],
49
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ exports.messages = [
3
+ {
4
+ code: "error.code.login.failed",
5
+ tr: [
6
+ { l: "en", v: "Access denied. Please check your credentials and retry" },
7
+ { l: "it", v: "Accesso negato. Controllare le credenziali e riprovare" },
8
+ { l: "pl", v: "Access denied. Please check your credentials and retry" },
9
+ ],
10
+ },
11
+ {
12
+ code: "http.error.code.400",
13
+ tr: [
14
+ { l: "en", v: "Sorry, the request is wrong (400)" },
15
+ { l: "it", v: "Siamo spiacenti, la richiesta è errata (400)" },
16
+ { l: "pl", v: "Sorry, the request is wrong (400)" },
17
+ ],
18
+ overrides: [
19
+ {
20
+ customer: "c1",
21
+ tr: [
22
+ { l: "en", v: "Access denied C1" },
23
+ { l: "it", v: "Accesso negato C1" },
24
+ { l: "pl", v: "Access denied C1" },
25
+ ],
26
+ },
27
+ {
28
+ customer: "c2",
29
+ tr: [
30
+ { l: "en", v: "Access denied C2" },
31
+ { l: "it", v: "Accesso negato C2" },
32
+ { l: "pl", v: "Access denied C2" },
33
+ ],
34
+ },
35
+ {
36
+ customer: "c1",
37
+ tr: [
38
+ { l: "en", v: "Access denied C1" },
39
+ { l: "it", v: "Accesso negato C1" },
40
+ { l: "pl", v: "Access denied C1" },
41
+ ],
42
+ },
43
+ ],
44
+ },
45
+ {
46
+ code: "http.error.code.generic",
47
+ tr: [
48
+ { l: "en", v: "Generic comunication error" },
49
+ { l: "it", v: "Errore di comunicazione generica" },
50
+ { l: "pl", v: "Generic comunication error" },
51
+ ],
52
+ },
53
+ ];
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -44,18 +44,35 @@ var config_1 = __importDefault(require("../../config"));
44
44
  var path_1 = __importDefault(require("path"));
45
45
  var utils_1 = require("./utils");
46
46
  var langCopy = function () { return __awaiter(void 0, void 0, void 0, function () {
47
- var from, to, inputPath, isDir, filesCheck, _i, filesCheck_1, fileName, filePath, e_1;
47
+ var inputPath, from, to, ret, e_1;
48
48
  return __generator(this, function (_a) {
49
49
  switch (_a.label) {
50
50
  case 0:
51
- _a.trys.push([0, 8, , 9]);
51
+ _a.trys.push([0, 2, , 3]);
52
+ inputPath = path_1.default.join(process.cwd(), config_1.default.get("i18nMsg").input);
52
53
  from = config_1.default.get("i18nMsg").from;
53
54
  to = config_1.default.get("i18nMsg").to;
54
- inputPath = path_1.default.join(process.cwd(), config_1.default.get("i18nMsg").input);
55
+ return [4, langCopyExec(inputPath, from, to)];
56
+ case 1:
57
+ ret = _a.sent();
58
+ console.log("Successfully copied");
59
+ return [2, 0];
60
+ case 2:
61
+ e_1 = _a.sent();
62
+ console.error(e_1);
63
+ return [2, 1];
64
+ case 3: return [2];
65
+ }
66
+ });
67
+ }); };
68
+ var langCopyExec = function (inputPath, from, to) { return __awaiter(void 0, void 0, void 0, function () {
69
+ var isDir, filesCheck, _i, filesCheck_1, fileName, filePath;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
55
73
  isDir = fs.lstatSync(inputPath).isDirectory();
56
74
  if (!from || !to) {
57
- console.error("Missing from/to Param");
58
- return [2, 1];
75
+ throw new Error("Missing from/to Param");
59
76
  }
60
77
  if (!isDir) return [3, 5];
61
78
  filesCheck = fs.readdirSync(inputPath);
@@ -78,14 +95,7 @@ var langCopy = function () { return __awaiter(void 0, void 0, void 0, function (
78
95
  case 6:
79
96
  _a.sent();
80
97
  _a.label = 7;
81
- case 7:
82
- console.log("Successfully copied");
83
- return [2, 0];
84
- case 8:
85
- e_1 = _a.sent();
86
- console.error(e_1);
87
- return [2, 1];
88
- case 9: return [2];
98
+ case 7: return [2];
89
99
  }
90
100
  });
91
101
  }); };
@@ -1,2 +1,16 @@
1
- export declare const checkSingleFile: (inputPath: string, from: string, to: string) => Promise<any>;
2
- export declare const checkMultipleFile: (inputPath: string, from: string, to: string) => Promise<void>;
1
+ interface Translation {
2
+ l: string;
3
+ v: string;
4
+ }
5
+ interface CustomerOverride {
6
+ customer: string;
7
+ tr: Translation[];
8
+ }
9
+ interface Message {
10
+ code: string;
11
+ tr: Translation[];
12
+ overrides?: CustomerOverride[];
13
+ }
14
+ export declare const checkSingleFile: (inputPath: string, from: string, to: string, disableWrite?: boolean) => Promise<Message[]>;
15
+ export declare const checkMultipleFile: (inputPath: string, from: string, to: string, disableWrite?: boolean) => Promise<Message[]>;
16
+ export {};
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -32,8 +42,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
42
  });
33
43
  };
34
44
  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;
45
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
47
  function verb(n) { return function (v) { return step([n, v]); }; }
38
48
  function step(op) {
39
49
  if (f) throw new TypeError("Generator is already executing.");
@@ -58,115 +68,184 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
58
68
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
69
  }
60
70
  };
71
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
73
+ if (ar || !(i in from)) {
74
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
75
+ ar[i] = from[i];
76
+ }
77
+ }
78
+ return to.concat(ar || Array.prototype.slice.call(from));
79
+ };
61
80
  var __importDefault = (this && this.__importDefault) || function (mod) {
62
81
  return (mod && mod.__esModule) ? mod : { "default": mod };
63
82
  };
64
83
  Object.defineProperty(exports, "__esModule", { value: true });
65
84
  exports.checkMultipleFile = exports.checkSingleFile = void 0;
66
85
  var fs_1 = __importDefault(require("fs"));
86
+ var path_1 = __importDefault(require("path"));
67
87
  var prettier = __importStar(require("prettier"));
68
- var checkSingleFile = function (inputPath, from, to) { return __awaiter(void 0, void 0, void 0, function () {
69
- var fileContent, addValue, existLang, newContent, writeContent, prettierContent;
88
+ var checkSingleFile = function (inputPath_1, from_1, to_1) {
89
+ var args_1 = [];
90
+ for (var _i = 3; _i < arguments.length; _i++) {
91
+ args_1[_i - 3] = arguments[_i];
92
+ }
93
+ return __awaiter(void 0, __spreadArray([inputPath_1, from_1, to_1], args_1, true), void 0, function (inputPath, from, to, disableWrite) {
94
+ var fileContent, messages, newContent;
95
+ if (disableWrite === void 0) { disableWrite = false; }
96
+ return __generator(this, function (_a) {
97
+ switch (_a.label) {
98
+ case 0:
99
+ fileContent = readTranslationFile(inputPath);
100
+ messages = manageContent(fileContent, inputPath);
101
+ newContent = processMessages(messages, from, to);
102
+ return [4, saveInputFile(disableWrite, fileContent, inputPath, newContent, "exports")];
103
+ case 1:
104
+ _a.sent();
105
+ return [2, newContent];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ exports.checkSingleFile = checkSingleFile;
111
+ var checkMultipleFile = function (inputPath_1, from_1, to_1) {
112
+ var args_1 = [];
113
+ for (var _i = 3; _i < arguments.length; _i++) {
114
+ args_1[_i - 3] = arguments[_i];
115
+ }
116
+ return __awaiter(void 0, __spreadArray([inputPath_1, from_1, to_1], args_1, true), void 0, function (inputPath, from, to, disableWrite) {
117
+ var fileContent, messages, newContent;
118
+ if (disableWrite === void 0) { disableWrite = false; }
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ fileContent = readTranslationFile(inputPath);
123
+ messages = manageContent(fileContent, inputPath);
124
+ newContent = processMessages(messages, from, to);
125
+ return [4, saveInputFile(disableWrite, fileContent, inputPath, newContent, "module.exports")];
126
+ case 1:
127
+ _a.sent();
128
+ return [2, newContent];
129
+ }
130
+ });
131
+ });
132
+ };
133
+ exports.checkMultipleFile = checkMultipleFile;
134
+ var readTranslationFile = function (inputPath) {
135
+ try {
136
+ var fileContent = fs_1.default.readFileSync(inputPath, "utf-8");
137
+ var result = void 0;
138
+ if (fileContent.includes("exports = ")) {
139
+ var jsonContent = fileContent
140
+ .replace(/^[\s\S]*exports\s*=\s*/, "")
141
+ .replace(/;[\s\S]*$/, "");
142
+ var vm = require("vm");
143
+ var sandbox = { result: null };
144
+ vm.createContext(sandbox);
145
+ vm.runInContext("result = ".concat(jsonContent), sandbox);
146
+ result = sandbox.result;
147
+ }
148
+ else if (fileContent.includes("module.exports = ")) {
149
+ var jsonContent = fileContent.replace(/^[\s\S]*module\.exports\s*=\s*/, "").replace(/;[\s\S]*$/, "");
150
+ var vm = require("vm");
151
+ var sandbox = { result: null };
152
+ vm.createContext(sandbox);
153
+ vm.runInContext("result = ".concat(jsonContent), sandbox);
154
+ result = sandbox.result;
155
+ }
156
+ else {
157
+ var resolvedPath = path_1.default.resolve(inputPath);
158
+ delete require.cache[resolvedPath];
159
+ result = require(resolvedPath);
160
+ }
161
+ return result;
162
+ }
163
+ catch (error) {
164
+ throw new Error("Errore nella lettura del file ".concat(inputPath, ": ").concat(error instanceof Error ? error.message : String(error)));
165
+ }
166
+ };
167
+ var manageContent = function (fileContent, inputPath) {
168
+ var messages;
169
+ if (fileContent && fileContent.messages) {
170
+ messages = fileContent.messages;
171
+ }
172
+ else if (fileContent && Array.isArray(fileContent)) {
173
+ messages = fileContent;
174
+ }
175
+ else if (fileContent && typeof fileContent === "object") {
176
+ messages = [fileContent];
177
+ }
178
+ else {
179
+ throw new Error("Formato del file non valido: impossibile trovare la struttura dei messaggi in ".concat(inputPath));
180
+ }
181
+ if (!Array.isArray(messages)) {
182
+ throw new Error("Formato del file non valido: impossibile interpretare i messaggi come array in ".concat(inputPath));
183
+ }
184
+ return messages;
185
+ };
186
+ var processMessages = function (messages, from, to) {
187
+ if (!Array.isArray(messages)) {
188
+ throw new Error("Formato dei messaggi non valido: atteso un array, ricevuto ".concat(typeof messages));
189
+ }
190
+ return messages.map(function (message) {
191
+ processTranslations(message.tr, from, to);
192
+ if (message.overrides) {
193
+ message.overrides.forEach(function (override, index) {
194
+ processTranslations(override.tr, from, to);
195
+ });
196
+ }
197
+ return message;
198
+ });
199
+ };
200
+ var processTranslations = function (translations, from, to) {
201
+ var sourceValue = "";
202
+ var targetExists = false;
203
+ translations.forEach(function (translation) {
204
+ if (translation.l === from) {
205
+ sourceValue = translation.v;
206
+ }
207
+ if (translation.l === to) {
208
+ targetExists = true;
209
+ }
210
+ });
211
+ if (!sourceValue) {
212
+ throw new Error("--from ".concat(from, " not exist"));
213
+ }
214
+ if (!targetExists) {
215
+ translations.push({ l: to, v: sourceValue });
216
+ }
217
+ return sourceValue;
218
+ };
219
+ var saveInputFile = function (disableWrite, fileContent, inputPath, newContent, moduleType) { return __awaiter(void 0, void 0, void 0, function () {
70
220
  return __generator(this, function (_a) {
71
221
  switch (_a.label) {
72
222
  case 0:
73
- fileContent = require(inputPath);
74
- addValue = "";
75
- existLang = false;
76
- newContent = fileContent.messages.map(function (messages) {
77
- messages.tr.forEach(function (value) {
78
- if (value.l === from) {
79
- addValue = value.v;
80
- }
81
- if (value.l === to) {
82
- existLang = true;
83
- }
84
- });
85
- if (!addValue) {
86
- throw new Error("--from " + from + " not exist");
87
- }
88
- if (!existLang) {
89
- messages.tr.push({ l: to, v: addValue });
90
- }
91
- if (messages.overrides) {
92
- messages.overrides.forEach(function (i, index) {
93
- var addOverrideValue = "";
94
- var existOverridesLang = false;
95
- i.tr.forEach(function (value) {
96
- if (value.l === from) {
97
- addOverrideValue = value.v;
98
- }
99
- if (value.l === to) {
100
- existOverridesLang = true;
101
- }
102
- });
103
- if (!addOverrideValue) {
104
- throw new Error("--from " + from + " not exist");
105
- }
106
- if (!existOverridesLang) {
107
- messages.overrides[index].tr.push({ l: to, v: addOverrideValue });
108
- }
109
- });
110
- }
111
- return messages;
112
- });
113
- writeContent = "exports.messages = " + JSON.stringify(newContent);
114
- return [4, prettier.format(writeContent, { parser: "babel" })];
223
+ if (disableWrite) {
224
+ return [2];
225
+ }
226
+ if (!(fileContent && fileContent.messages)) return [3, 2];
227
+ return [4, writeFormattedContent(inputPath, { messages: newContent }, moduleType)];
115
228
  case 1:
116
- prettierContent = _a.sent();
117
- fs_1.default.writeFileSync(inputPath, prettierContent, "utf-8");
118
- return [2, newContent];
229
+ _a.sent();
230
+ return [3, 4];
231
+ case 2: return [4, writeFormattedContent(inputPath, newContent, moduleType)];
232
+ case 3:
233
+ _a.sent();
234
+ _a.label = 4;
235
+ case 4: return [2];
119
236
  }
120
237
  });
121
238
  }); };
122
- exports.checkSingleFile = checkSingleFile;
123
- var checkMultipleFile = function (inputPath, from, to) { return __awaiter(void 0, void 0, void 0, function () {
124
- var fileContent, addValue, existLang, newContent, writeContent, prettierContent;
239
+ var writeFormattedContent = function (inputPath, content, moduleType) { return __awaiter(void 0, void 0, void 0, function () {
240
+ var writeContent, prettierContent;
125
241
  return __generator(this, function (_a) {
126
242
  switch (_a.label) {
127
243
  case 0:
128
- fileContent = require(inputPath);
129
- addValue = "";
130
- existLang = false;
131
- newContent = fileContent.map(function (messages) {
132
- messages.tr.forEach(function (value) {
133
- if (value.l === from) {
134
- addValue = value.v;
135
- }
136
- if (value.l === to) {
137
- existLang = true;
138
- }
139
- });
140
- if (!addValue) {
141
- throw new Error("--from " + from + " not exist");
142
- }
143
- if (!existLang) {
144
- messages.tr.push({ l: to, v: addValue });
145
- }
146
- if (messages.overrides) {
147
- messages.overrides.forEach(function (i, index) {
148
- var addOverrideValue = "";
149
- var existOverridesLang = false;
150
- i.tr.forEach(function (value) {
151
- if (value.l === from) {
152
- addOverrideValue = value.v;
153
- }
154
- if (value.l === to) {
155
- existOverridesLang = true;
156
- }
157
- });
158
- if (!addOverrideValue) {
159
- throw new Error("--from " + from + " not exist");
160
- }
161
- if (!existOverridesLang) {
162
- messages.overrides[index].tr.push({ l: to, v: addOverrideValue });
163
- }
164
- });
165
- }
166
- return messages;
167
- });
168
- writeContent = "module.exports = " + JSON.stringify(newContent);
169
- return [4, prettier.format(writeContent, { parser: "babel" })];
244
+ writeContent = "".concat(moduleType, " = ").concat(JSON.stringify(content));
245
+ return [4, prettier.format(writeContent, {
246
+ parser: "babel",
247
+ printWidth: 120,
248
+ })];
170
249
  case 1:
171
250
  prettierContent = _a.sent();
172
251
  fs_1.default.writeFileSync(inputPath, prettierContent, "utf-8");
@@ -174,4 +253,3 @@ var checkMultipleFile = function (inputPath, from, to) { return __awaiter(void 0
174
253
  }
175
254
  });
176
255
  }); };
177
- exports.checkMultipleFile = checkMultipleFile;
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var vitest_1 = require("vitest");
3
4
  var pwd2hash_1 = require("../pwd2hash");
4
- describe("verify password hash", function () {
5
- it("returns md5 hex value of password in case of password hash is running well", function () {
5
+ (0, vitest_1.describe)("verify password hash", function () {
6
+ (0, vitest_1.it)("returns md5 hex value of password in case of password hash is running well", function () {
6
7
  var password = "NonDireGatto";
7
8
  var pwdHash = (0, pwd2hash_1.passwordHash)(password);
8
- expect(pwdHash).toEqual("07d13c5f2f88ef41e18383e288b9d99a");
9
+ (0, vitest_1.expect)(pwdHash).toEqual("07d13c5f2f88ef41e18383e288b9d99a");
9
10
  });
10
- it("returns error in case of password is equal to password hash", function () {
11
+ (0, vitest_1.it)("returns error in case of password is equal to password hash", function () {
11
12
  var password = "NonDireGatto";
12
13
  var pwdHash = (0, pwd2hash_1.passwordHash)(password);
13
- expect(pwdHash).not.toEqual("NonDireGatto");
14
+ (0, vitest_1.expect)(pwdHash).not.toEqual("NonDireGatto");
14
15
  });
15
16
  });
@@ -9,7 +9,7 @@ var isIP_1 = __importDefault(require("validator/lib/isIP"));
9
9
  var isURL_1 = __importDefault(require("validator/lib/isURL"));
10
10
  var isBoolean_1 = __importDefault(require("validator/lib/isBoolean"));
11
11
  var isInt_1 = __importDefault(require("validator/lib/isInt"));
12
- var isISO31661Alpha2_1 = __importDefault(require("validator/lib/isISO31661Alpha2"));
12
+ var isISO6391_1 = __importDefault(require("validator/lib/isISO6391"));
13
13
  var assert = function (assertion, err_msg) {
14
14
  if (!assertion) {
15
15
  throw new Error(err_msg);
@@ -61,7 +61,7 @@ exports.countryCode = {
61
61
  name: "countryCode",
62
62
  coerce: function (v) { return v.toString(); },
63
63
  validate: function (x) {
64
- assert((0, isISO31661Alpha2_1.default)(x === null || x === void 0 ? void 0 : x.toString()), "must be a valid country code");
64
+ assert((0, isISO6391_1.default)(x === null || x === void 0 ? void 0 : x.toString()), "must be a valid country code");
65
65
  },
66
66
  };
67
67
  exports.default = {
@@ -1,4 +1,4 @@
1
1
  export declare const loadConfigFromFile: ({ cliName, dir }: {
2
2
  cliName: string;
3
- dir?: string | undefined;
3
+ dir?: string;
4
4
  }) => object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melfore/clibelt",
3
- "version": "6.0.6",
3
+ "version": "6.0.7",
4
4
  "homepage": "https://github.com/melfore/clibelt#readme",
5
5
  "description": "CLI belt: the Melfore tool belt",
6
6
  "repository": {
@@ -17,8 +17,8 @@
17
17
  "i18n-copy": "dist/cli/i18n-copy/index.js"
18
18
  },
19
19
  "engines": {
20
- "node": ">=20 <21",
21
- "npm": ">=8 <11"
20
+ "node": ">=22 <23",
21
+ "npm": ">=10 <12"
22
22
  },
23
23
  "scripts": {
24
24
  "commit": "npx git-cz",
@@ -29,9 +29,10 @@
29
29
  "copy:assets": "copyfiles --verbose ./src/**/*.{json,png,jpg,svg,xls,xlsx} ./dist/",
30
30
  "republish": "npm run build:clean && yalc push",
31
31
  "test:i18n": "rm -f test/out/*.json test/out/*.ts && nodemon --exec 'ts-node' src/cli/i18n-msg/index.ts",
32
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js --runInBand",
33
- "test:watch": "jest --config jest.config.js --watch --detectOpenHandles",
32
+ "test": "vitest run --config vitest.config.mts",
33
+ "test:watch": "vitest watch --config vitest.config.mts",
34
34
  "lintify": "eslint .",
35
+ "lint-fix": "eslint . --fix",
35
36
  "prettify": "prettier --write .",
36
37
  "preversion": "npm run lintify",
37
38
  "version": "npm run prettify",
@@ -42,28 +43,25 @@
42
43
  "dependencies": {
43
44
  "convict": "^6.2.4",
44
45
  "convict-format-with-moment": "^6.2.0",
45
- "prettier": "^3.1.1",
46
- "validator": "^13.11.0"
46
+ "prettier": "^3.5.3",
47
+ "validator": "^13.12.0",
48
+ "vitest": "^3.0.8"
47
49
  },
48
50
  "devDependencies": {
49
- "@commitlint/cli": "^19.7.1",
50
- "@commitlint/config-conventional": "^19.7.1",
51
+ "@commitlint/cli": "^19.8.0",
52
+ "@commitlint/config-conventional": "^19.8.0",
51
53
  "@types/convict": "^6.1.6",
52
- "@types/jest": "^29.5.11",
53
- "@types/node": "^20.10.5",
54
- "@types/validator": "^13.11.7",
54
+ "@types/node": "^22.13.10",
55
+ "@types/validator": "^13.12.2",
55
56
  "copyfiles": "^2.4.1",
56
- "eslint": "^8.56.0",
57
- "eslint-config-prettier": "^9.1.0",
58
- "eslint-plugin-import": "^2.29.1",
59
- "eslint-plugin-jest": "^27.6.0",
60
- "eslint-plugin-prettier": "^5.1.1",
61
- "husky": "^9.0.6",
62
- "jest": "^29.7.0",
63
- "nodemon": "^3.0.2",
64
- "ts-jest": "^29.1.1",
57
+ "eslint": "^9.22.0",
58
+ "eslint-config-prettier": "^10.1.1",
59
+ "eslint-plugin-import": "^2.31.0",
60
+ "eslint-plugin-prettier": "^5.2.3",
61
+ "husky": "^9.1.7",
62
+ "nodemon": "^3.1.9",
65
63
  "ts-node": "^10.9.2",
66
- "typescript": "^5.3.3"
64
+ "typescript": "^5.8.2"
67
65
  },
68
66
  "license": "MIT"
69
67
  }
@@ -1,89 +0,0 @@
1
- "use strict";
2
- exports.messages = [
3
- {
4
- code: "error.code.login.failed",
5
- tr: [
6
- {
7
- l: "en",
8
- v: "Access denied. Please check your credentials and retry",
9
- },
10
- {
11
- l: "it",
12
- v: "Accesso negato. Controllare le credenziali e riprovare",
13
- },
14
- {
15
- l: "pl",
16
- v: "Accesso negato. Controllare le credenziali e riprovare",
17
- },
18
- ],
19
- },
20
- {
21
- code: "http.error.code.400",
22
- tr: [
23
- { l: "en", v: "Sorry, the request is wrong (400)" },
24
- { l: "it", v: "Siamo spiacenti, la richiesta è errata (400)" },
25
- { l: "pl", v: "Siamo spiacenti, la richiesta è errata (400)" },
26
- ],
27
- overrides: [
28
- {
29
- customer: "c1",
30
- tr: [
31
- {
32
- l: "en",
33
- v: "Access denied C1",
34
- },
35
- {
36
- l: "it",
37
- v: "Accesso negato C1",
38
- },
39
- {
40
- l: "pl",
41
- v: "Accesso negato C1",
42
- },
43
- ],
44
- },
45
- {
46
- customer: "c2",
47
- tr: [
48
- {
49
- l: "en",
50
- v: "Access denied C2",
51
- },
52
- {
53
- l: "it",
54
- v: "Accesso negato C2",
55
- },
56
- {
57
- l: "pl",
58
- v: "Accesso negato C2",
59
- },
60
- ],
61
- },
62
- {
63
- customer: "c1",
64
- tr: [
65
- {
66
- l: "en",
67
- v: "Access denied C1",
68
- },
69
- {
70
- l: "it",
71
- v: "Accesso negato C1",
72
- },
73
- {
74
- l: "pl",
75
- v: "Accesso negato C1",
76
- },
77
- ],
78
- },
79
- ],
80
- },
81
- {
82
- code: "http.error.code.generic",
83
- tr: [
84
- { l: "en", v: "Generic comunication error" },
85
- { l: "it", v: "Errore di comunicazione generica" },
86
- { l: "pl", v: "Errore di comunicazione generica" },
87
- ],
88
- },
89
- ];