node-confmanager 1.4.1 → 1.4.4
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/lib/index.d.ts +19 -2
- package/lib/main.js +21 -28
- package/package.json +10 -10
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
1
|
declare module "node-confmanager" {
|
|
4
2
|
|
|
3
|
+
type tType = "array" | "boolean" | "color" | "email" | "float" | "ipv4" | "ipv6" | "integer" | "object" | "string" | "url";
|
|
4
|
+
|
|
5
5
|
import Container = require("node-containerpattern");
|
|
6
6
|
|
|
7
7
|
class ConfManager extends Container {
|
|
@@ -23,6 +23,23 @@ declare module "node-confmanager" {
|
|
|
23
23
|
public load(): Promise<void>;
|
|
24
24
|
public save(): Promise<void>;
|
|
25
25
|
|
|
26
|
+
// rewrite to force proper return
|
|
27
|
+
public clear(): ConfManager;
|
|
28
|
+
public clearData(): ConfManager;
|
|
29
|
+
public clearDocumentations(): ConfManager;
|
|
30
|
+
public clearLimits(): ConfManager;
|
|
31
|
+
public clearMinsMaxs(): ConfManager;
|
|
32
|
+
public clearRegexs(): ConfManager;
|
|
33
|
+
public clearSkeletons(): ConfManager;
|
|
34
|
+
public delete(key: string): ConfManager;
|
|
35
|
+
public document(key: string, value: string): ConfManager;
|
|
36
|
+
public limit(key: string, limit: Array<any>): ConfManager;
|
|
37
|
+
public min(key: string, min: number): ConfManager;
|
|
38
|
+
public max(key: string, max: number): ConfManager;
|
|
39
|
+
public regex(key: string, regex: RegExp): ConfManager;
|
|
40
|
+
public set(key: string, value: any): ConfManager;
|
|
41
|
+
public skeleton(key: string, value: tType): ConfManager;
|
|
42
|
+
|
|
26
43
|
}
|
|
27
44
|
|
|
28
45
|
export = ConfManager;
|
package/lib/main.js
CHANGED
|
@@ -55,45 +55,33 @@ module.exports = class ConfManager extends Container {
|
|
|
55
55
|
|
|
56
56
|
return Promise.resolve().then(() => {
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
(0, process).argv.slice(2, (0, process).argv.length).forEach((arg, i, args) => {
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
if (arg.startsWith("-")) {
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
const isShortcut = !arg.startsWith("--");
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const argument = arg.slice(isShortcut ? 1 : 2, arg.length);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
if (!isShortcut || this.shortcuts[argument]) {
|
|
67
67
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
if (!isShortcut || this.shortcuts[argument]) {
|
|
71
|
-
|
|
72
|
-
const key = isShortcut ? this.shortcuts[argument] : argument;
|
|
73
|
-
|
|
74
|
-
if (i + 1 < args.length && -1 >= args[i + 1].indexOf("--")) {
|
|
75
|
-
|
|
76
|
-
this.set(key, args[i + 1]);
|
|
77
|
-
++i;
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
else if (this.skeletons[key] && "boolean" === this.skeletons[key]) {
|
|
81
|
-
|
|
82
|
-
this.set(key, true);
|
|
83
|
-
++i;
|
|
84
|
-
|
|
85
|
-
}
|
|
68
|
+
const key = isShortcut ? this.shortcuts[argument] : argument;
|
|
86
69
|
|
|
70
|
+
if (i + 1 < args.length && -1 >= args[i + 1].indexOf("--")) {
|
|
71
|
+
this.set(key, args[i + 1]);
|
|
72
|
+
}
|
|
73
|
+
else if (this.skeletons[key] && "boolean" === this.skeletons[key]) {
|
|
74
|
+
this.set(key, true);
|
|
87
75
|
}
|
|
88
76
|
|
|
89
77
|
}
|
|
90
78
|
|
|
91
79
|
}
|
|
92
80
|
|
|
93
|
-
resolve();
|
|
94
|
-
|
|
95
81
|
});
|
|
96
82
|
|
|
83
|
+
return Promise.resolve();
|
|
84
|
+
|
|
97
85
|
});
|
|
98
86
|
|
|
99
87
|
}
|
|
@@ -132,7 +120,7 @@ module.exports = class ConfManager extends Container {
|
|
|
132
120
|
|
|
133
121
|
return this.fileExists().then((exists) => {
|
|
134
122
|
|
|
135
|
-
return !exists ? this._loadFromConsole() : readJSONFileProm(this.filePath).then((data) => {
|
|
123
|
+
return !exists ? this._loadFromConsole() : readJSONFileProm(this.filePath, "utf8").then((data) => {
|
|
136
124
|
|
|
137
125
|
for (const key in data) {
|
|
138
126
|
this.set(key, data[key]);
|
|
@@ -156,8 +144,13 @@ module.exports = class ConfManager extends Container {
|
|
|
156
144
|
});
|
|
157
145
|
|
|
158
146
|
return this.spaces ?
|
|
159
|
-
writeJSONFileProm(this.filePath, objects,
|
|
160
|
-
|
|
147
|
+
writeJSONFileProm(this.filePath, objects, {
|
|
148
|
+
"encoding": "utf8",
|
|
149
|
+
"space": 2
|
|
150
|
+
}) :
|
|
151
|
+
writeJSONFileProm(this.filePath, objects, {
|
|
152
|
+
"encoding": "utf8"
|
|
153
|
+
});
|
|
161
154
|
|
|
162
155
|
});
|
|
163
156
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-confmanager",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A configuration manager",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -46,17 +46,17 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"node-containerpattern": "1.4.2",
|
|
49
|
-
"node-promfs": "3.
|
|
49
|
+
"node-promfs": "3.7.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
52
|
+
"@types/node": "17.0.34",
|
|
53
|
+
"check-version-modules": "1.3.5",
|
|
54
|
+
"coveralls": "3.1.1",
|
|
55
|
+
"eslint": "8.15.0",
|
|
56
|
+
"husky": "8.0.1",
|
|
57
|
+
"mocha": "10.0.0",
|
|
58
|
+
"nyc": "15.1.0",
|
|
59
|
+
"typescript": "4.6.4"
|
|
60
60
|
},
|
|
61
61
|
"homepage": "https://github.com/Psychopoulet/node-confmanager#readme",
|
|
62
62
|
"engines": {
|