@melfore/clibelt 0.1.2 → 1.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 CHANGED
@@ -1,3 +1,101 @@
1
1
  # clibelt
2
2
 
3
3
  CLI belt: the Melfore tool belt
4
+
5
+ ## Usage
6
+
7
+ ### Install
8
+
9
+ ```shell
10
+ npm install @melfore/clibelt
11
+ ```
12
+
13
+ ### Add scripts to `package.json`
14
+
15
+ Add required CLIs to your `package.json`, for example:
16
+
17
+ ```json
18
+ "scripts": {
19
+ "i18n": "i18n-msg",
20
+ "pwd2hash": "pwd2hash"
21
+ }
22
+ ```
23
+
24
+ ### Configure
25
+
26
+ There are three ways to configure a CLI.
27
+
28
+ #### Clibelt configuration
29
+
30
+ Create a file `.clibelt.json` in project root.
31
+
32
+ Configuration example:
33
+
34
+ ```json
35
+ {
36
+ "i18nMsg": {
37
+ "input": "./resources/messages-all-langs",
38
+ "outMsg": "./src/messages",
39
+ "outTs": "./src/messages/i18nMessages.ts"
40
+ }
41
+ }
42
+ ```
43
+
44
+ #### Command line arguments
45
+
46
+ Add arguments to script in `package.json`, for example:
47
+
48
+ ```json
49
+ "scripts": {
50
+ "i18n": "i18n-msg --input new/path --outTs new/constants.ts",
51
+ }
52
+ ```
53
+
54
+ #### Environment variables
55
+
56
+ Run script with CLI's specific env variables set.
57
+
58
+ ## CLIs
59
+
60
+ ### i18n-msg
61
+
62
+ `i18n-msg`:
63
+
64
+ - splits an input file containing all the translations into one file for each language
65
+ - creates a TypeScript source containing a constant for each message.
66
+
67
+ #### Configuration
68
+
69
+ Add `i18nMsg` to `.clibelt.json`.
70
+
71
+ ##### Options
72
+
73
+ | .clibelt param | command line arg | env variable | Description | Example |
74
+ | -------------- | ---------------- | ------------ | ------------------------------------------ | ------------------------------ |
75
+ | input | i18n-input | I18N_INPUT | the input file containing all translations | ./resources/messages-all-langs |
76
+ | outMsg | i18n-out-msg | I18N_OUT_MSG | splitted messages output directory | ./src/messages |
77
+ | outTs | i18n-out-ts | I18N_OUT_TS | TypeScript constants output file | ./src/messages/i18nMessages.ts |
78
+
79
+ Example:
80
+
81
+ ```json
82
+ {
83
+ "i18nMsg": {
84
+ "input": "./resources/messages-all-langs",
85
+ "outMsg": "./src/messages",
86
+ "outTs": "./src/messages/i18nMessages.ts"
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### pwd2hash
92
+
93
+ `pwd2hash` generates an hash for input string
94
+
95
+ #### Configuration
96
+
97
+ No configuration is required, just add to `package.json` script and run:
98
+
99
+ ```shell
100
+ npm run pwd2hash string_to_hash
101
+ ```
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.CLI_NAME = void 0;
8
8
  var fs_1 = __importDefault(require("fs"));
9
9
  var path_1 = __importDefault(require("path"));
10
- var os_1 = __importDefault(require("os"));
10
+ var os_1 = require("os");
11
11
  var config_1 = __importDefault(require("../../config"));
12
12
  exports.CLI_NAME = "i18nMsg";
13
13
  var inputFile = path_1.default.join(process.cwd(), config_1.default.get(exports.CLI_NAME).input);
@@ -15,26 +15,26 @@ var mal = require(inputFile);
15
15
  var outMsgDir = path_1.default.join(process.cwd(), config_1.default.get(exports.CLI_NAME).outMsg);
16
16
  var outTsFile = path_1.default.join(process.cwd(), config_1.default.get(exports.CLI_NAME).outTs);
17
17
  var EXT = "json";
18
- var info = "Splitting \"" + config_1.default.get(exports.CLI_NAME).input + "\" into lang messages in folder \"" + config_1.default.get(exports.CLI_NAME).outMsg + "\" and TS constants \"" + config_1.default.get(exports.CLI_NAME).outTs + "\"...";
18
+ var info = "Splitting \"".concat(config_1.default.get(exports.CLI_NAME).input, "\" into lang messages in folder \"").concat(config_1.default.get(exports.CLI_NAME).outMsg, "\" and TS constants \"").concat(config_1.default.get(exports.CLI_NAME).outTs, "\"...");
19
19
  console.log(info);
20
20
  var writeObjJson = function (filename, obj) {
21
21
  var data = "";
22
22
  switch (EXT) {
23
23
  case "js":
24
- data = "exports.messages = " + JSON.stringify(obj, null, 2) + ";";
24
+ data = "exports.messages = ".concat(JSON.stringify(obj, null, 2), ";");
25
25
  break;
26
26
  case "json":
27
27
  data = JSON.stringify(obj, null, 2);
28
28
  break;
29
29
  default:
30
- console.log("Invalid output file extension \"" + filename + "\"");
30
+ console.log("Invalid output file extension \"".concat(filename, "\""));
31
31
  break;
32
32
  }
33
33
  if (data) {
34
34
  fs_1.default.writeFile(filename, data, function (err) {
35
35
  if (err)
36
36
  console.log(err);
37
- console.log("Successfully written to file \"" + filename + "\"");
37
+ console.log("Successfully written to file \"".concat(filename, "\""));
38
38
  });
39
39
  }
40
40
  };
@@ -44,25 +44,24 @@ var tsName = function (code) {
44
44
  });
45
45
  };
46
46
  var writeTs = function (filename, messages) {
47
- var EOL = os_1.default.EOL;
48
- var output = "";
49
- messages.map(function (msg) {
50
- output += "export const " + tsName(msg.code) + " = \"" + msg.code + "\";" + EOL;
51
- });
47
+ var output = messages.reduce(function (result, msg) {
48
+ return result + "export const ".concat(tsName(msg.code), " = \"").concat(msg.code, "\";").concat(os_1.EOL);
49
+ }, "");
52
50
  fs_1.default.writeFile(filename, output, function (err) {
53
51
  if (err)
54
52
  console.log(err);
55
- console.log("Successfully written to file \"" + filename + "\"");
53
+ console.log("Successfully written to file \"".concat(filename, "\""));
56
54
  });
57
55
  };
58
- var splitMessages = function () {
59
- var messages = mal.messages;
56
+ var splitMessages = function (messages, namespace) {
60
57
  var sortedMessages = messages.sort(function (a, b) { return a.code.localeCompare(b.code); });
61
- writeObjJson(outMsgDir + "/messages-sort-temp." + EXT, sortedMessages);
62
- writeTs(outTsFile, sortedMessages);
58
+ var sortedName = namespace ? "".concat(namespace, "-sort-temp") : "messages-sort-temp";
59
+ var tsFile = namespace ? "".concat(outMsgDir, "/").concat(namespace, ".ts") : outTsFile;
60
+ writeObjJson("".concat(outMsgDir, "/").concat(sortedName, ".").concat(EXT), sortedMessages);
61
+ writeTs(tsFile, sortedMessages);
63
62
  var res = {};
64
- sortedMessages.map(function (k) {
65
- k.tr.map(function (t) {
63
+ sortedMessages.forEach(function (k) {
64
+ k.tr.forEach(function (t) {
66
65
  if (!res[t.l]) {
67
66
  res[t.l] = {};
68
67
  }
@@ -70,7 +69,35 @@ var splitMessages = function () {
70
69
  });
71
70
  });
72
71
  Object.keys(res).map(function (n) {
73
- writeObjJson(outMsgDir + "/" + n + "." + EXT, res[n]);
72
+ var dest = namespace ? "".concat(outMsgDir, "/").concat(n, "/").concat(namespace, ".").concat(EXT) : "".concat(outMsgDir, "/").concat(n, ".").concat(EXT);
73
+ var langDir = path_1.default.dirname(dest);
74
+ fs_1.default.mkdirSync(langDir, { recursive: true });
75
+ writeObjJson(dest, res[n]);
76
+ });
77
+ };
78
+ var writeNamespacesFile = function (namespaces) {
79
+ var content = namespaces.reduce(function (result, _a) {
80
+ var ns = _a[0];
81
+ return result + "export * from './".concat(ns, "';").concat(os_1.EOL);
82
+ }, "");
83
+ fs_1.default.writeFile(outTsFile, content, function (err) {
84
+ if (err) {
85
+ console.log("Error writing to", outTsFile);
86
+ }
74
87
  });
75
88
  };
76
- splitMessages();
89
+ var checkNamespaces = function () {
90
+ fs_1.default.mkdirSync(outMsgDir, { recursive: true });
91
+ var namespaces = mal.namespaces ? Object.entries(mal.namespaces) : [];
92
+ if (namespaces.length > 0) {
93
+ namespaces.forEach(function (_a) {
94
+ var ns = _a[0], messages = _a[1];
95
+ splitMessages(messages, ns);
96
+ });
97
+ writeNamespacesFile(namespaces);
98
+ }
99
+ else {
100
+ splitMessages(mal.messages);
101
+ }
102
+ };
103
+ checkNamespaces();
@@ -5,8 +5,8 @@ var pwd2hash_1 = require("./pwd2hash");
5
5
  var pwd2hash = function () {
6
6
  var password = process.argv[2];
7
7
  console.log();
8
- var pwdHash = pwd2hash_1.passwordHash(password);
9
- console.log("\t[" + password + "] -> [" + pwdHash + "]");
8
+ var pwdHash = (0, pwd2hash_1.passwordHash)(password);
9
+ console.log("\t[".concat(password, "] -> [").concat(pwdHash, "]"));
10
10
  console.log();
11
11
  console.log();
12
12
  };
@@ -1,19 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.passwordHash = exports.genMD5Enc = void 0;
7
- var crypto_js_1 = __importDefault(require("crypto-js"));
8
- exports.genMD5Enc = function (str) {
4
+ var crypto_1 = require("crypto");
5
+ var genMD5Enc = function (str) {
9
6
  if (!str) {
10
7
  return "";
11
8
  }
12
- var hash = crypto_js_1.default.MD5(str);
13
- var hashEnc = hash.toString(crypto_js_1.default.enc.Hex);
9
+ var hashEnc = (0, crypto_1.createHash)("md5").update(str).digest("hex");
14
10
  return hashEnc;
15
11
  };
16
- exports.passwordHash = function (password) {
17
- var hash = exports.genMD5Enc(password);
12
+ exports.genMD5Enc = genMD5Enc;
13
+ var passwordHash = function (password) {
14
+ var hash = (0, exports.genMD5Enc)(password);
18
15
  return hash;
19
16
  };
17
+ exports.passwordHash = passwordHash;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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 () {
6
+ var password = "NonDireGatto";
7
+ var pwdHash = (0, pwd2hash_1.passwordHash)(password);
8
+ expect(pwdHash).toEqual("07d13c5f2f88ef41e18383e288b9d99a");
9
+ });
10
+ it("returns error in case of password is equal to password hash", function () {
11
+ var password = "NonDireGatto";
12
+ var pwdHash = (0, pwd2hash_1.passwordHash)(password);
13
+ expect(pwdHash).not.toEqual("NonDireGatto");
14
+ });
15
+ });
@@ -18,42 +18,42 @@ exports.email = {
18
18
  name: "email",
19
19
  coerce: function (v) { return v.toString(); },
20
20
  validate: function (x) {
21
- assert(isEmail_1.default(x), "must be an email address");
21
+ assert((0, isEmail_1.default)(x), "must be an email address");
22
22
  },
23
23
  };
24
24
  exports.ipaddress = {
25
25
  name: "ipaddress",
26
26
  coerce: function (v) { return v.toString(); },
27
27
  validate: function (x) {
28
- assert(isIP_1.default(x), "must be an IP address");
28
+ assert((0, isIP_1.default)(x), "must be an IP address");
29
29
  },
30
30
  };
31
31
  exports.url = {
32
32
  name: "url",
33
33
  coerce: function (v) { return v.toString(); },
34
34
  validate: function (x) {
35
- assert(isURL_1.default(x, { require_tld: false }), "must be a URL");
35
+ assert((0, isURL_1.default)(x, { require_tld: false }), "must be a URL");
36
36
  },
37
37
  };
38
38
  exports.strictBoolean = {
39
39
  name: "strictBoolean",
40
40
  coerce: function (v) { return v.toString(); },
41
41
  validate: function (x) {
42
- assert(isBoolean_1.default(x), "must be a boolean");
42
+ assert((0, isBoolean_1.default)(x), "must be a boolean");
43
43
  },
44
44
  };
45
45
  exports.serverPort = {
46
46
  name: "serverPort",
47
47
  coerce: function (v) { return v.toString(); },
48
48
  validate: function (x) {
49
- assert(isInt_1.default(x === null || x === void 0 ? void 0 : x.toString(), { min: 1024, max: 65535 }), "must be a valid port number");
49
+ assert((0, isInt_1.default)(x === null || x === void 0 ? void 0 : x.toString(), { min: 1024, max: 65535 }), "must be a valid port number");
50
50
  },
51
51
  };
52
52
  exports.int = {
53
53
  name: "int",
54
54
  coerce: function (v) { return v.toString(); },
55
55
  validate: function (x) {
56
- assert(isInt_1.default(x === null || x === void 0 ? void 0 : x.toString()), "must be a valid integer number");
56
+ assert((0, isInt_1.default)(x === null || x === void 0 ? void 0 : x.toString()), "must be a valid integer number");
57
57
  },
58
58
  };
59
59
  exports.default = {
@@ -1,336 +1,10 @@
1
1
  import convict from "convict";
2
- export declare const getProp: (cliName: string) => (param: string) => any;
3
- declare const _default: {
4
- getProp: (cliName: string) => (param: string) => any;
5
- get<K extends string | null | undefined = undefined>(name?: K | undefined): K extends null | undefined ? {
6
- i18nMsg: {
7
- input: any;
8
- outMsg: any;
9
- outTs: any;
10
- };
11
- } : K extends "i18nMsg" ? {
12
- i18nMsg: {
13
- input: any;
14
- outMsg: any;
15
- outTs: any;
16
- };
17
- }[K] : any;
18
- get<K_1 extends "i18nMsg", K2 extends keyof {
19
- i18nMsg: {
20
- input: any;
21
- outMsg: any;
22
- outTs: any;
23
- };
24
- }[K_1]>(name: string): {
25
- i18nMsg: {
26
- input: any;
27
- outMsg: any;
28
- outTs: any;
29
- };
30
- }[K_1][K2];
31
- get<K_2 extends "i18nMsg", K2_1 extends keyof {
32
- i18nMsg: {
33
- input: any;
34
- outMsg: any;
35
- outTs: any;
36
- };
37
- }[K_2], K3 extends keyof {
38
- i18nMsg: {
39
- input: any;
40
- outMsg: any;
41
- outTs: any;
42
- };
43
- }[K_2][K2_1]>(name: K_2): {
44
- i18nMsg: {
45
- input: any;
46
- outMsg: any;
47
- outTs: any;
48
- };
49
- }[K_2][K2_1][K3];
50
- get<K_3 extends "i18nMsg", K2_2 extends keyof {
51
- i18nMsg: {
52
- input: any;
53
- outMsg: any;
54
- outTs: any;
55
- };
56
- }[K_3], K3_1 extends keyof {
57
- i18nMsg: {
58
- input: any;
59
- outMsg: any;
60
- outTs: any;
61
- };
62
- }[K_3][K2_2], K4 extends keyof {
63
- i18nMsg: {
64
- input: any;
65
- outMsg: any;
66
- outTs: any;
67
- };
68
- }[K_3][K2_2][K3_1]>(name: string): {
69
- i18nMsg: {
70
- input: any;
71
- outMsg: any;
72
- outTs: any;
73
- };
74
- }[K_3][K2_2][K3_1][K4];
75
- default<K_4 extends string | null | undefined = undefined>(name?: K_4 | undefined): K_4 extends "i18nMsg" ? {
76
- i18nMsg: {
77
- input: any;
78
- outMsg: any;
79
- outTs: any;
80
- };
81
- }[K_4] : K_4 extends null | undefined ? {
82
- i18nMsg: {
83
- input: any;
84
- outMsg: any;
85
- outTs: any;
86
- };
87
- } : any;
88
- default<K_5 extends "i18nMsg">(name?: K_5 | undefined): {
89
- i18nMsg: {
90
- input: any;
91
- outMsg: any;
92
- outTs: any;
93
- };
94
- }[K_5];
95
- default<K_6 extends "i18nMsg", K2_3 extends keyof {
96
- i18nMsg: {
97
- input: any;
98
- outMsg: any;
99
- outTs: any;
100
- };
101
- }[K_6]>(name: string): {
102
- i18nMsg: {
103
- input: any;
104
- outMsg: any;
105
- outTs: any;
106
- };
107
- }[K_6][K2_3];
108
- default<K_7 extends "i18nMsg", K2_4 extends keyof {
109
- i18nMsg: {
110
- input: any;
111
- outMsg: any;
112
- outTs: any;
113
- };
114
- }[K_7], K3_2 extends keyof {
115
- i18nMsg: {
116
- input: any;
117
- outMsg: any;
118
- outTs: any;
119
- };
120
- }[K_7][K2_4]>(name: K_7): {
121
- i18nMsg: {
122
- input: any;
123
- outMsg: any;
124
- outTs: any;
125
- };
126
- }[K_7][K2_4][K3_2];
127
- default<K_8 extends "i18nMsg", K2_5 extends keyof {
128
- i18nMsg: {
129
- input: any;
130
- outMsg: any;
131
- outTs: any;
132
- };
133
- }[K_8], K3_3 extends keyof {
134
- i18nMsg: {
135
- input: any;
136
- outMsg: any;
137
- outTs: any;
138
- };
139
- }[K_8][K2_5], K4_1 extends keyof {
140
- i18nMsg: {
141
- input: any;
142
- outMsg: any;
143
- outTs: any;
144
- };
145
- }[K_8][K2_5][K3_3]>(name: string): {
146
- i18nMsg: {
147
- input: any;
148
- outMsg: any;
149
- outTs: any;
150
- };
151
- }[K_8][K2_5][K3_3][K4_1];
152
- has<K_9 extends string = string>(name: K_9): boolean;
153
- has<K_10 extends "i18nMsg", K2_6 extends keyof {
154
- i18nMsg: {
155
- input: any;
156
- outMsg: any;
157
- outTs: any;
158
- };
159
- }[K_10]>(name: string): boolean;
160
- has<K_11 extends "i18nMsg", K2_7 extends keyof {
161
- i18nMsg: {
162
- input: any;
163
- outMsg: any;
164
- outTs: any;
165
- };
166
- }[K_11], K3_4 extends keyof {
167
- i18nMsg: {
168
- input: any;
169
- outMsg: any;
170
- outTs: any;
171
- };
172
- }[K_11][K2_7]>(name: K_11): boolean;
173
- has<K_12 extends "i18nMsg", K2_8 extends keyof {
174
- i18nMsg: {
175
- input: any;
176
- outMsg: any;
177
- outTs: any;
178
- };
179
- }[K_12], K3_5 extends keyof {
180
- i18nMsg: {
181
- input: any;
182
- outMsg: any;
183
- outTs: any;
184
- };
185
- }[K_12][K2_8], K4_2 extends keyof {
186
- i18nMsg: {
187
- input: any;
188
- outMsg: any;
189
- outTs: any;
190
- };
191
- }[K_12][K2_8][K3_5]>(name: string): boolean;
192
- set<K_13 extends string>(name: K_13, value: K_13 extends "i18nMsg" ? {
193
- i18nMsg: {
194
- input: any;
195
- outMsg: any;
196
- outTs: any;
197
- };
198
- }[K_13] : any): convict.Config<{
199
- i18nMsg: {
200
- input: any;
201
- outMsg: any;
202
- outTs: any;
203
- };
204
- }>;
205
- set<K_14 extends "i18nMsg", K2_9 extends string | keyof {
206
- i18nMsg: {
207
- input: any;
208
- outMsg: any;
209
- outTs: any;
210
- };
211
- }[K_14]>(name: K_14, value: K2_9 extends keyof {
212
- i18nMsg: {
213
- input: any;
214
- outMsg: any;
215
- outTs: any;
216
- };
217
- }[K_14] ? {
218
- i18nMsg: {
219
- input: any;
220
- outMsg: any;
221
- outTs: any;
222
- };
223
- }[K_14][K2_9] : any): convict.Config<{
224
- i18nMsg: {
225
- input: any;
226
- outMsg: any;
227
- outTs: any;
228
- };
229
- }>;
230
- set<K_15 extends "i18nMsg", K2_10 extends keyof {
231
- i18nMsg: {
232
- input: any;
233
- outMsg: any;
234
- outTs: any;
235
- };
236
- }[K_15], K3_6 extends string | keyof {
237
- i18nMsg: {
238
- input: any;
239
- outMsg: any;
240
- outTs: any;
241
- };
242
- }[K_15][K2_10]>(name: K_15, value: K3_6 extends keyof {
243
- i18nMsg: {
244
- input: any;
245
- outMsg: any;
246
- outTs: any;
247
- };
248
- }[K_15][K2_10] ? {
249
- i18nMsg: {
250
- input: any;
251
- outMsg: any;
252
- outTs: any;
253
- };
254
- }[K_15][K2_10][K3_6] : any): convict.Config<{
255
- i18nMsg: {
256
- input: any;
257
- outMsg: any;
258
- outTs: any;
259
- };
260
- }>;
261
- set<K_16 extends "i18nMsg", K2_11 extends keyof {
262
- i18nMsg: {
263
- input: any;
264
- outMsg: any;
265
- outTs: any;
266
- };
267
- }[K_16], K3_7 extends keyof {
268
- i18nMsg: {
269
- input: any;
270
- outMsg: any;
271
- outTs: any;
272
- };
273
- }[K_16][K2_11], K4_3 extends string | keyof {
274
- i18nMsg: {
275
- input: any;
276
- outMsg: any;
277
- outTs: any;
278
- };
279
- }[K_16][K2_11][K3_7]>(name: K_16, value: K4_3 extends keyof {
280
- i18nMsg: {
281
- input: any;
282
- outMsg: any;
283
- outTs: any;
284
- };
285
- }[K_16][K2_11][K3_7] ? {
286
- i18nMsg: {
287
- input: any;
288
- outMsg: any;
289
- outTs: any;
290
- };
291
- }[K_16][K2_11][K3_7][K4_3] : any): convict.Config<{
292
- i18nMsg: {
293
- input: any;
294
- outMsg: any;
295
- outTs: any;
296
- };
297
- }>;
298
- load<U>(conf: U): convict.Config<convict.Overwrite<{
299
- i18nMsg: {
300
- input: any;
301
- outMsg: any;
302
- outTs: any;
303
- };
304
- }, U>>;
305
- loadFile<U_1>(files: string | string[]): convict.Config<convict.Overwrite<{
306
- i18nMsg: {
307
- input: any;
308
- outMsg: any;
309
- outTs: any;
310
- };
311
- }, U_1>>;
312
- validate(options?: convict.ValidateOptions | undefined): convict.Config<{
313
- i18nMsg: {
314
- input: any;
315
- outMsg: any;
316
- outTs: any;
317
- };
318
- }>;
319
- getProperties(): {
320
- i18nMsg: {
321
- input: any;
322
- outMsg: any;
323
- outTs: any;
324
- };
2
+ declare const config: convict.Config<{
3
+ i18nMsg: {
4
+ input: string;
5
+ outMsg: string;
6
+ outTs: string;
325
7
  };
326
- getSchema(): convict.InternalSchema<{
327
- i18nMsg: {
328
- input: any;
329
- outMsg: any;
330
- outTs: any;
331
- };
332
- }>;
333
- toString(): string;
334
- getSchemaString(): string;
335
- };
336
- export default _default;
8
+ }>;
9
+ export { config };
10
+ export default config;
@@ -1,32 +1,21 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getProp = void 0;
18
- var convict_1 = __importDefault(require("convict"));
19
- var convict_format_with_moment = require("convict-format-with-moment");
6
+ exports.config = void 0;
20
7
  var path_1 = __importDefault(require("path"));
21
- var config_validators_1 = __importDefault(require("./config-validators"));
8
+ var convict_1 = __importDefault(require("convict"));
22
9
  var config_schema_1 = __importDefault(require("./config-schema"));
10
+ var config_validators_1 = __importDefault(require("./config-validators"));
11
+ var convict_format_with_moment = require("convict-format-with-moment");
23
12
  var VALIDATE_WARN = { allowed: "warn" };
24
13
  var VALIDATE_ERROR = { allowed: "strict" };
25
14
  convict_1.default.addFormats(config_validators_1.default);
26
15
  convict_1.default.addFormats(convict_format_with_moment);
27
- var config = convict_1.default(config_schema_1.default);
16
+ var config = (0, convict_1.default)(config_schema_1.default);
17
+ exports.config = config;
28
18
  var pathName = path_1.default.join(process.cwd(), ".clibelt.json");
29
19
  config.loadFile(pathName);
30
20
  config.validate(VALIDATE_WARN);
31
- exports.getProp = function (cliName) { return function (param) { return config.get(cliName + "." + param); }; };
32
- exports.default = __assign(__assign({}, config), { getProp: exports.getProp });
21
+ exports.default = config;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadConfigFromFile = void 0;
4
4
  var path = require("path");
5
5
  var fs = require("fs");
6
- exports.loadConfigFromFile = function (_a) {
6
+ var loadConfigFromFile = function (_a) {
7
7
  var cliName = _a.cliName, _b = _a.dir, dir = _b === void 0 ? "." : _b;
8
8
  var pathName = path.join(process.cwd(), dir, ".clibelt.json");
9
9
  console.log("pathName", pathName);
10
- console.log("loadConfig - read configuration for cli:" + cliName + " from file:" + pathName);
10
+ console.log("loadConfig - read configuration for cli:".concat(cliName, " from file:").concat(pathName));
11
11
  var content = fs.readFileSync(pathName);
12
12
  var config = JSON.parse(content);
13
13
  return config[cliName];
14
14
  };
15
+ exports.loadConfigFromFile = loadConfigFromFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melfore/clibelt",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "homepage": "https://github.com/melfore/clibelt#readme",
5
5
  "description": "CLI belt: the Melfore tool belt",
6
6
  "repository": {
@@ -15,6 +15,10 @@
15
15
  "pwd2hash": "dist/cli/pwd2hash/index.js",
16
16
  "i18n-msg": "dist/cli/i18n-msg/index.js"
17
17
  },
18
+ "engines": {
19
+ "node": ">=16 <17",
20
+ "npm": ">=8 <9"
21
+ },
18
22
  "scripts": {
19
23
  "build2": "tsc -p .",
20
24
  "build": "npm run prettify && tsc -p . && npm run copy:assets",
@@ -23,9 +27,8 @@
23
27
  "copy:assets": "copyfiles --verbose ./src/**/*.{json,png,jpg,svg,xls,xlsx} ./dist/",
24
28
  "republish": "npm run build:clean && yalc push",
25
29
  "test:i18n": "rm -f test/out/*.json test/out/*.ts && nodemon --watch 'src/**/*.ts' --watch '.clibelt.json' --exec 'ts-node' src/cli/i18n-msg/index.ts",
26
- "test": "echo \"Error: no test specified\" && exit 0",
27
- "TODOtest": "jest --config jest.config.js --testTimeout=10000",
28
- "TODOtest:watch": "jest --config jest.config.js --watch --detectOpenHandles",
30
+ "test": "jest --config jest.config.js --runInBand",
31
+ "test:watch": "jest --config jest.config.js --watch --detectOpenHandles",
29
32
  "lintify": "eslint .",
30
33
  "prettify": "prettier --write .",
31
34
  "preversion": "npm run lintify",
@@ -33,29 +36,27 @@
33
36
  "upload": "npm run build && npm publish --access public"
34
37
  },
35
38
  "dependencies": {
36
- "convict": "^6.0.0",
37
- "convict-format-with-moment": "^6.0.0",
38
- "crypto-js": "^4.0.0",
39
- "validator": "^13.0.0",
40
- "prettier": "^2.0.5"
39
+ "convict": "^6.2.3",
40
+ "convict-format-with-moment": "^6.2.0",
41
+ "validator": "^13.7.0",
42
+ "prettier": "^2.7.1"
41
43
  },
42
44
  "devDependencies": {
43
- "@types/convict": "^5.2.1",
44
- "@types/crypto-js": "^3.1.47",
45
- "@types/jest": "^25.2.2",
46
- "@types/node": "^14.0.5",
47
- "@types/validator": "^13.0.0",
48
- "copyfiles": "^2.2.0",
49
- "eslint": "^7.0.0",
50
- "eslint-config-prettier": "^6.10.1",
51
- "eslint-plugin-import": "^2.20.2",
52
- "eslint-plugin-jest": "^23.13.0",
53
- "eslint-plugin-prettier": "^3.1.3",
54
- "jest": "^26.0.1",
55
- "nodemon": "^2.0.4",
56
- "ts-jest": "^26.0.0",
57
- "ts-node": "^8.10.1",
58
- "typescript": "^3.9.3"
45
+ "@types/convict": "^6.1.1",
46
+ "@types/jest": "^29.0.2",
47
+ "@types/node": "^18.7.18",
48
+ "@types/validator": "^13.7.6",
49
+ "copyfiles": "^2.4.1",
50
+ "eslint": "^8.23.1",
51
+ "eslint-config-prettier": "^8.5.0",
52
+ "eslint-plugin-import": "^2.26.0",
53
+ "eslint-plugin-jest": "^27.0.4",
54
+ "eslint-plugin-prettier": "^4.2.1",
55
+ "jest": "^29.0.3",
56
+ "nodemon": "^2.0.19",
57
+ "ts-jest": "^29.0.1",
58
+ "ts-node": "^10.9.1",
59
+ "typescript": "^4.8.3"
59
60
  },
60
61
  "license": "MIT"
61
62
  }