@melfore/clibelt 6.0.1 → 6.0.3

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 CHANGED
@@ -17,7 +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
+ "i18n:copy": "i18n-copy --from it --to fr",
21
21
  "pwd2hash": "pwd2hash"
22
22
  }
23
23
  ```
@@ -48,8 +48,7 @@ Add arguments to script in `package.json`, for example:
48
48
 
49
49
  ```json
50
50
  "scripts": {
51
- "i18n": "i18n-msg --input new/path --outTs new/constants.ts",
52
- "i18n:copy": "i18n-copy --from=it --to=fr",
51
+ "i18n": "i18n-msg --input new/path --outTs new/constants.ts"
53
52
  }
54
53
  ```
55
54
 
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var utils_1 = require("../utils");
43
+ var testFileResult_js_1 = __importDefault(require("./testFileResult.js"));
44
+ 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 () {
48
+ var res;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0: return [4, (0, utils_1.checkSingleFile)(file, "it", "pl")];
52
+ case 1:
53
+ res = _a.sent();
54
+ expect(res).toEqual(testFileResult_js_1.default.messages);
55
+ return [2];
56
+ }
57
+ });
58
+ }); });
59
+ it("Wrong --from param", function () { return __awaiter(void 0, void 0, void 0, function () {
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0: return [4, expect(function () { return (0, utils_1.checkSingleFile)(file, "FR", "pl"); }).rejects.toThrow("--from FR not exist")];
63
+ case 1:
64
+ _a.sent();
65
+ return [2];
66
+ }
67
+ });
68
+ }); });
69
+ });
@@ -0,0 +1,21 @@
1
+ export const messages: ({
2
+ code: string;
3
+ tr: {
4
+ l: string;
5
+ v: string;
6
+ }[];
7
+ overrides?: undefined;
8
+ } | {
9
+ code: string;
10
+ tr: {
11
+ l: string;
12
+ v: string;
13
+ }[];
14
+ overrides: {
15
+ customer: string;
16
+ tr: {
17
+ l: string;
18
+ v: string;
19
+ }[];
20
+ }[];
21
+ })[];
@@ -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: "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
+ { l: "pl", v: "Siamo spiacenti, la richiesta è errata (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: "Accesso negato 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: "Accesso negato 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: "Accesso negato 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: "Errore di comunicazione generica" },
51
+ ],
52
+ },
53
+ ];
@@ -0,0 +1,21 @@
1
+ export const messages: ({
2
+ code: string;
3
+ tr: {
4
+ l: string;
5
+ v: string;
6
+ }[];
7
+ overrides?: undefined;
8
+ } | {
9
+ code: string;
10
+ tr: {
11
+ l: string;
12
+ v: string;
13
+ }[];
14
+ overrides: {
15
+ customer: string;
16
+ tr: {
17
+ l: string;
18
+ v: string;
19
+ }[];
20
+ }[];
21
+ })[];
@@ -0,0 +1,89 @@
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
+ ];
@@ -1,27 +1,4 @@
1
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
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -65,80 +42,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
65
42
  var fs = require("fs");
66
43
  var config_1 = __importDefault(require("../../config"));
67
44
  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;
45
+ var utils_1 = require("./utils");
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;
71
48
  return __generator(this, function (_a) {
72
49
  switch (_a.label) {
73
50
  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" })];
51
+ _a.trys.push([0, 8, , 9]);
52
+ from = config_1.default.get("i18nMsg").from;
53
+ to = config_1.default.get("i18nMsg").to;
54
+ inputPath = path_1.default.join(process.cwd(), config_1.default.get("i18nMsg").input);
55
+ isDir = fs.lstatSync(inputPath).isDirectory();
56
+ if (!from || !to) {
57
+ console.error("Missing from/to Param");
58
+ return [2, 1];
59
+ }
60
+ if (!isDir) return [3, 5];
61
+ filesCheck = fs.readdirSync(inputPath);
62
+ _i = 0, filesCheck_1 = filesCheck;
63
+ _a.label = 1;
110
64
  case 1:
111
- prettierContent = _a.sent();
112
- fs.writeFileSync(inputPath, prettierContent, "utf-8");
113
- return [2];
65
+ if (!(_i < filesCheck_1.length)) return [3, 4];
66
+ fileName = filesCheck_1[_i];
67
+ if (!(fileName !== "index.js")) return [3, 3];
68
+ filePath = path_1.default.join(inputPath, fileName);
69
+ return [4, (0, utils_1.checkMultipleFile)(filePath, from, to)];
70
+ case 2:
71
+ _a.sent();
72
+ _a.label = 3;
73
+ case 3:
74
+ _i++;
75
+ return [3, 1];
76
+ case 4: return [3, 7];
77
+ case 5: return [4, (0, utils_1.checkSingleFile)(inputPath, from, to)];
78
+ case 6:
79
+ _a.sent();
80
+ _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];
114
89
  }
115
90
  });
116
91
  }); };
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);
92
+ langCopy().then(function (res) {
93
+ process.exit(res);
94
+ });
@@ -0,0 +1,2 @@
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>;
@@ -0,0 +1,177 @@
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
+ exports.checkMultipleFile = exports.checkSingleFile = void 0;
66
+ var fs_1 = __importDefault(require("fs"));
67
+ 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;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ 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" })];
115
+ case 1:
116
+ prettierContent = _a.sent();
117
+ fs_1.default.writeFileSync(inputPath, prettierContent, "utf-8");
118
+ return [2, newContent];
119
+ }
120
+ });
121
+ }); };
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;
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ 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" })];
170
+ case 1:
171
+ prettierContent = _a.sent();
172
+ fs_1.default.writeFileSync(inputPath, prettierContent, "utf-8");
173
+ return [2];
174
+ }
175
+ });
176
+ }); };
177
+ exports.checkMultipleFile = checkMultipleFile;
@@ -109,11 +109,12 @@ var writeNamespacesFile = function (namespaces) {
109
109
  var ns = _a[0];
110
110
  return result + "export * from './".concat(ns, "';").concat(os_1.EOL);
111
111
  }, AUTOGENERATED_HEADER);
112
- fs_1.default.writeFile(outTsFile, content, function (err) {
113
- if (err) {
114
- console.log("Error writing to", outTsFile);
115
- }
116
- });
112
+ try {
113
+ fs_1.default.writeFileSync(outTsFile, content);
114
+ }
115
+ catch (e) {
116
+ console.log("Error writing to", outTsFile);
117
+ }
117
118
  };
118
119
  var allLanguagesReport = function (data, languages) {
119
120
  data.forEach(function (value) {
@@ -129,18 +130,48 @@ var allLanguagesReport = function (data, languages) {
129
130
  }
130
131
  });
131
132
  };
132
- var report = function (data, languages) {
133
+ var report = function (data, languages, uniqueCode, uniqueOverrides) {
133
134
  var e = 0;
134
135
  data.forEach(function (value) {
135
136
  var _a;
136
137
  var valueLanguages = [];
137
138
  var valueLanguagesOverrites = [];
139
+ var isUniqueCode = uniqueCode.includes(value.code);
140
+ if (!isUniqueCode) {
141
+ uniqueCode.push(value.code);
142
+ }
143
+ else {
144
+ console.log("\x1b[31m Duplicate Code: \x1b[0m", value.code);
145
+ e = 1;
146
+ }
138
147
  value.tr.forEach(function (i) {
139
- valueLanguages.push(i.l);
148
+ var isUniqueLang = valueLanguages.includes(i.l);
149
+ if (!isUniqueLang) {
150
+ valueLanguages.push(i.l);
151
+ }
152
+ else {
153
+ console.log("\x1b[31m Duplicate language: \x1b[0m", i.l, "\x1b[31m in Code: \x1b[0m", value.code);
154
+ e = 1;
155
+ }
140
156
  });
141
157
  (_a = value.overrides) === null || _a === void 0 ? void 0 : _a.forEach(function (i) {
158
+ var isUniqueOverrides = uniqueOverrides.includes(i.customer);
159
+ if (!isUniqueOverrides) {
160
+ uniqueOverrides.push(i.customer);
161
+ }
162
+ else {
163
+ console.log("\x1b[31m Duplicate Customer: \x1b[0m", i.customer);
164
+ e = 1;
165
+ }
142
166
  i.tr.forEach(function (value) {
143
- valueLanguagesOverrites.push(value.l);
167
+ var isUniqueOverridesLang = valueLanguagesOverrites.includes(value.l);
168
+ if (!isUniqueOverridesLang) {
169
+ valueLanguagesOverrites.push(value.l);
170
+ }
171
+ else {
172
+ console.log("\x1b[31m Duplicate language: \x1b[0m", value.l, "\x1b[31m in Customer: \x1b[0m", i.customer);
173
+ e = 1;
174
+ }
144
175
  });
145
176
  var differentArrOverrides = languages.filter(function (x) { return !valueLanguagesOverrites.includes(x); });
146
177
  if (differentArrOverrides[0]) {
@@ -165,19 +196,23 @@ var multiFileReport = function (languages, namespaces) {
165
196
  console.log("-------REPORT-------");
166
197
  var uniqueLang = getAllLanguagesUnique(languages);
167
198
  var numeError = 0;
199
+ var uniqueCode = [];
200
+ var uniqueOverrides = [];
168
201
  for (var _i = 0, namespaces_1 = namespaces; _i < namespaces_1.length; _i++) {
169
202
  var _a = namespaces_1[_i], messages = _a[1];
170
- var e = report(messages, uniqueLang);
203
+ var e = report(messages, uniqueLang, uniqueCode, uniqueOverrides);
171
204
  numeError = numeError + e;
172
205
  }
173
206
  console.log("All languages: ", uniqueLang);
174
207
  return numeError !== 0 ? 1 : 0;
175
208
  };
176
209
  var singleFileReport = function (message, languages) {
210
+ var uniqueCode = [];
211
+ var uniqueOverrides = [];
177
212
  console.log();
178
213
  console.log("-----REPORT-------");
179
214
  var uniqueLang = getAllLanguagesUnique(languages);
180
- var e = report(message, uniqueLang);
215
+ var e = report(message, uniqueLang, uniqueCode, uniqueOverrides);
181
216
  console.log("All languages: ", uniqueLang);
182
217
  return e !== 0 ? 1 : 0;
183
218
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var pwd2hash_1 = require("./pwd2hash");
3
+ var pwd2hash_1 = require("../pwd2hash");
4
4
  describe("verify password hash", function () {
5
5
  it("returns md5 hex value of password in case of password hash is running well", function () {
6
6
  var password = "NonDireGatto";
@@ -28,6 +28,16 @@ declare const _default: {
28
28
  arg: string;
29
29
  env: string;
30
30
  };
31
+ from: {
32
+ format: string;
33
+ default: undefined;
34
+ arg: string;
35
+ };
36
+ to: {
37
+ format: string;
38
+ default: undefined;
39
+ arg: string;
40
+ };
31
41
  };
32
42
  };
33
43
  export default _default;
@@ -30,5 +30,15 @@ exports.default = {
30
30
  arg: "i18n-out-ts",
31
31
  env: "I18N_OUT_TS",
32
32
  },
33
+ from: {
34
+ format: "countryCode",
35
+ default: undefined,
36
+ arg: "from",
37
+ },
38
+ to: {
39
+ format: "countryCode",
40
+ default: undefined,
41
+ arg: "to",
42
+ },
33
43
  },
34
44
  };
@@ -28,6 +28,11 @@ export declare const int: {
28
28
  coerce: (v: any) => any;
29
29
  validate: (x: any) => void;
30
30
  };
31
+ export declare const countryCode: {
32
+ name: string;
33
+ coerce: (v: any) => any;
34
+ validate: (x: any) => void;
35
+ };
31
36
  declare const _default: {
32
37
  email: {
33
38
  name: string;
@@ -54,5 +59,10 @@ declare const _default: {
54
59
  coerce: (v: any) => any;
55
60
  validate: (x: any) => void;
56
61
  };
62
+ countryCode: {
63
+ name: string;
64
+ coerce: (v: any) => any;
65
+ validate: (x: any) => void;
66
+ };
57
67
  };
58
68
  export default _default;
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.int = exports.serverPort = exports.strictBoolean = exports.url = exports.ipaddress = exports.email = void 0;
6
+ exports.countryCode = exports.int = exports.serverPort = exports.strictBoolean = exports.url = exports.ipaddress = exports.email = void 0;
7
7
  var isEmail_1 = __importDefault(require("validator/lib/isEmail"));
8
8
  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
13
  var assert = function (assertion, err_msg) {
13
14
  if (!assertion) {
14
15
  throw new Error(err_msg);
@@ -56,10 +57,18 @@ exports.int = {
56
57
  assert((0, isInt_1.default)(x === null || x === void 0 ? void 0 : x.toString()), "must be a valid integer number");
57
58
  },
58
59
  };
60
+ exports.countryCode = {
61
+ name: "countryCode",
62
+ coerce: function (v) { return v.toString(); },
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");
65
+ },
66
+ };
59
67
  exports.default = {
60
68
  email: exports.email,
61
69
  ipaddress: exports.ipaddress,
62
70
  url: exports.url,
63
71
  strictBoolean: exports.strictBoolean,
64
72
  serverPort: exports.serverPort,
73
+ countryCode: exports.countryCode,
65
74
  };
@@ -5,6 +5,8 @@ declare const config: convict.Config<{
5
5
  outMsg: string;
6
6
  outTemp: string;
7
7
  outTs: string;
8
+ from: undefined;
9
+ to: undefined;
8
10
  };
9
11
  }>;
10
12
  export { config };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melfore/clibelt",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "homepage": "https://github.com/melfore/clibelt#readme",
5
5
  "description": "CLI belt: the Melfore tool belt",
6
6
  "repository": {
@@ -28,14 +28,14 @@
28
28
  "copy:assets": "copyfiles --verbose ./src/**/*.{json,png,jpg,svg,xls,xlsx} ./dist/",
29
29
  "republish": "npm run build:clean && yalc push",
30
30
  "test:i18n": "rm -f test/out/*.json test/out/*.ts && nodemon --exec 'ts-node' src/cli/i18n-msg/index.ts",
31
- "test": "jest --config jest.config.js --runInBand",
31
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js --runInBand",
32
32
  "test:watch": "jest --config jest.config.js --watch --detectOpenHandles",
33
33
  "lintify": "eslint .",
34
34
  "prettify": "prettier --write .",
35
35
  "preversion": "npm run lintify",
36
36
  "version": "npm run prettify",
37
37
  "upload": "npm run build && npm publish --access public",
38
- "i18n:copy": "ts-node src/cli/i18n-copy/index.ts"
38
+ "i18n:copy": "ts-node src/cli/i18n-copy/index.ts --from it --to fr"
39
39
  },
40
40
  "dependencies": {
41
41
  "convict": "^6.2.4",