@melfore/clibelt 6.0.1 → 6.0.2

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
 
@@ -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<void>;
2
+ export declare const checkMultipleFile: (inputPath: string, from: string, to: string) => Promise<void>;
@@ -0,0 +1,174 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.checkMultipleFile = exports.checkSingleFile = void 0;
63
+ var fs = require("fs");
64
+ var prettier = __importStar(require("prettier"));
65
+ var checkSingleFile = function (inputPath, from, to) { return __awaiter(void 0, void 0, void 0, function () {
66
+ var fileContent, addValue, existLang, newContent, writeContent, prettierContent;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ fileContent = require(inputPath);
71
+ addValue = "";
72
+ existLang = false;
73
+ newContent = fileContent.messages.map(function (messages) {
74
+ messages.tr.forEach(function (value) {
75
+ if (value.l === from) {
76
+ addValue = value.v;
77
+ }
78
+ if (value.l === to) {
79
+ existLang = true;
80
+ }
81
+ });
82
+ if (!addValue) {
83
+ throw new Error("--from " + from + " not exist");
84
+ }
85
+ if (!existLang) {
86
+ messages.tr.push({ l: to, v: addValue });
87
+ }
88
+ if (messages.overrides) {
89
+ messages.overrides.forEach(function (i, index) {
90
+ var addOverrideValue = "";
91
+ var existOverridesLang = false;
92
+ i.tr.forEach(function (value) {
93
+ if (value.l === from) {
94
+ addOverrideValue = value.v;
95
+ }
96
+ if (value.l === to) {
97
+ existOverridesLang = true;
98
+ }
99
+ });
100
+ if (!addOverrideValue) {
101
+ throw new Error("--from " + from + " not exist");
102
+ }
103
+ if (!existOverridesLang) {
104
+ messages.overrides[index].tr.push({ l: to, v: addOverrideValue });
105
+ }
106
+ });
107
+ }
108
+ return messages;
109
+ });
110
+ writeContent = "exports.messages = " + JSON.stringify(newContent);
111
+ return [4, prettier.format(writeContent, { parser: "babel" })];
112
+ case 1:
113
+ prettierContent = _a.sent();
114
+ fs.writeFileSync(inputPath, prettierContent, "utf-8");
115
+ return [2];
116
+ }
117
+ });
118
+ }); };
119
+ exports.checkSingleFile = checkSingleFile;
120
+ var checkMultipleFile = function (inputPath, from, to) { return __awaiter(void 0, void 0, void 0, function () {
121
+ var fileContent, addValue, existLang, newContent, writeContent, prettierContent;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0:
125
+ fileContent = require(inputPath);
126
+ addValue = "";
127
+ existLang = false;
128
+ newContent = fileContent.map(function (messages) {
129
+ messages.tr.forEach(function (value) {
130
+ if (value.l === from) {
131
+ addValue = value.v;
132
+ }
133
+ if (value.l === to) {
134
+ existLang = true;
135
+ }
136
+ });
137
+ if (!addValue) {
138
+ throw new Error("--from " + from + " not exist");
139
+ }
140
+ if (!existLang) {
141
+ messages.tr.push({ l: to, v: addValue });
142
+ }
143
+ if (messages.overrides) {
144
+ messages.overrides.forEach(function (i, index) {
145
+ var addOverrideValue = "";
146
+ var existOverridesLang = false;
147
+ i.tr.forEach(function (value) {
148
+ if (value.l === from) {
149
+ addOverrideValue = value.v;
150
+ }
151
+ if (value.l === to) {
152
+ existOverridesLang = true;
153
+ }
154
+ });
155
+ if (!addOverrideValue) {
156
+ throw new Error("--from " + from + " not exist");
157
+ }
158
+ if (!existOverridesLang) {
159
+ messages.overrides[index].tr.push({ l: to, v: addOverrideValue });
160
+ }
161
+ });
162
+ }
163
+ return messages;
164
+ });
165
+ writeContent = "module.exports = " + JSON.stringify(newContent);
166
+ return [4, prettier.format(writeContent, { parser: "babel" })];
167
+ case 1:
168
+ prettierContent = _a.sent();
169
+ fs.writeFileSync(inputPath, prettierContent, "utf-8");
170
+ return [2];
171
+ }
172
+ });
173
+ }); };
174
+ exports.checkMultipleFile = checkMultipleFile;
@@ -129,12 +129,20 @@ var allLanguagesReport = function (data, languages) {
129
129
  }
130
130
  });
131
131
  };
132
- var report = function (data, languages) {
132
+ var report = function (data, languages, uniqueCode) {
133
133
  var e = 0;
134
134
  data.forEach(function (value) {
135
135
  var _a;
136
136
  var valueLanguages = [];
137
137
  var valueLanguagesOverrites = [];
138
+ var isUniqueCode = uniqueCode.includes(value.code);
139
+ if (!isUniqueCode) {
140
+ uniqueCode.push(value.code);
141
+ }
142
+ else {
143
+ console.log("\x1b[31m Duplicate Code: \x1b[0m", value.code);
144
+ e = 1;
145
+ }
138
146
  value.tr.forEach(function (i) {
139
147
  valueLanguages.push(i.l);
140
148
  });
@@ -165,19 +173,21 @@ var multiFileReport = function (languages, namespaces) {
165
173
  console.log("-------REPORT-------");
166
174
  var uniqueLang = getAllLanguagesUnique(languages);
167
175
  var numeError = 0;
176
+ var uniqueCode = [];
168
177
  for (var _i = 0, namespaces_1 = namespaces; _i < namespaces_1.length; _i++) {
169
178
  var _a = namespaces_1[_i], messages = _a[1];
170
- var e = report(messages, uniqueLang);
179
+ var e = report(messages, uniqueLang, uniqueCode);
171
180
  numeError = numeError + e;
172
181
  }
173
182
  console.log("All languages: ", uniqueLang);
174
183
  return numeError !== 0 ? 1 : 0;
175
184
  };
176
185
  var singleFileReport = function (message, languages) {
186
+ var uniqueCode = [];
177
187
  console.log();
178
188
  console.log("-----REPORT-------");
179
189
  var uniqueLang = getAllLanguagesUnique(languages);
180
- var e = report(message, uniqueLang);
190
+ var e = report(message, uniqueLang, uniqueCode);
181
191
  console.log("All languages: ", uniqueLang);
182
192
  return e !== 0 ? 1 : 0;
183
193
  };
@@ -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.2",
4
4
  "homepage": "https://github.com/melfore/clibelt#readme",
5
5
  "description": "CLI belt: the Melfore tool belt",
6
6
  "repository": {
@@ -35,7 +35,7 @@
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",