node-confmanager 1.4.7 → 1.5.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 +5 -88
- package/lib/index.d.ts +11 -11
- package/lib/main.js +24 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,100 +24,17 @@ $ npm install node-confmanager
|
|
|
24
24
|
|
|
25
25
|
## Doc
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
### Inheritance
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
[check the official 'node-containerpattern' object documentation](https://github.com/Psychopoulet/node-containerpattern)
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
### Content
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
* ``` spaces: string ``` formate file
|
|
35
|
-
* ``` shortcuts: string ``` for container
|
|
36
|
-
|
|
37
|
-
-- Constructor --
|
|
38
|
-
|
|
39
|
-
* ``` constructor(confPath?: string, spaces?: boolean, recursionSeparator?: string) ```
|
|
40
|
-
|
|
41
|
-
-- Methods --
|
|
42
|
-
|
|
43
|
-
* ``` deleteFile() : return Promise instance ``` delete the conf file
|
|
44
|
-
* ``` fileExists() : return Promise instance => then((exists) => {}) ``` check if the conf file exists
|
|
45
|
-
* ``` clearShortcuts() : return this ``` forget all the shortcuts
|
|
46
|
-
* ``` clear() : return this ``` node-containerpattern.clear & clearShortcuts
|
|
47
|
-
* ``` load() : return Promise instance ``` load data from conf file then commandline (commandline takeover)
|
|
48
|
-
* ``` save() : return Promise instance ``` save data into conf file
|
|
49
|
-
* ``` shortcut(string key, string shortkey) : return this ``` bind a shortcut for commandline
|
|
33
|
+
[check the TypeScript definition file](https://github.com/Psychopoulet/node-confmanager/blob/master/lib/index.d.ts)
|
|
50
34
|
|
|
51
35
|
## Examples
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
```javascript
|
|
56
|
-
const ConfManager = require("node-confmanager");
|
|
57
|
-
|
|
58
|
-
const conf = new ConfManager(require("path").join(__dirname, "conf.json"));
|
|
59
|
-
|
|
60
|
-
conf
|
|
61
|
-
.skeleton("debug", "boolean") // add skeleton (based on [node-containerpattern](https://www.npmjs.com/package/node-containerpattern)) to check datatype
|
|
62
|
-
.shortcut("debug", "d") // add shortcut to simply use comandline params, can add "-d true" to commandline to activate debug
|
|
63
|
-
.shortcut("usr.login", "ul")
|
|
64
|
-
.shortcut("usr.password", "up");
|
|
65
|
-
|
|
66
|
-
conf.fileExists().then((exists) => {
|
|
67
|
-
|
|
68
|
-
return exists ? Promise.resolve() : Conf.set("usr", { login : "login", pwd : "pwd" })
|
|
69
|
-
.set("debug", false)
|
|
70
|
-
.set("prod", "n") // = false
|
|
71
|
-
.save();
|
|
72
|
-
|
|
73
|
-
}).then(() => {
|
|
74
|
-
|
|
75
|
-
// can add "--usr.login login2" or "-ul login2" to commandline to force login change
|
|
76
|
-
return conf.load();
|
|
77
|
-
|
|
78
|
-
}).then(() => {
|
|
79
|
-
|
|
80
|
-
console.log(conf.get("debug"));
|
|
81
|
-
console.log(conf.get("usr.login"));
|
|
82
|
-
|
|
83
|
-
}).catch((err) => {
|
|
84
|
-
console.log(err);
|
|
85
|
-
});
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Typescript
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
import ConfManager = require("node-confmanager");
|
|
92
|
-
import { join } from "path";
|
|
93
|
-
|
|
94
|
-
const Conf = new ConfManager(join(__dirname, "conf.json"));
|
|
95
|
-
|
|
96
|
-
Conf
|
|
97
|
-
.skeleton("debug", "boolean").shortcut("debug", "d")
|
|
98
|
-
.shortcut("usr.login", "ul")
|
|
99
|
-
.shortcut("usr.password", "up");
|
|
100
|
-
|
|
101
|
-
Conf.fileExists().then((exists: boolean) => {
|
|
102
|
-
|
|
103
|
-
return exists ? Promise.resolve() : Conf.set("usr", { login : "login", pwd : "pwd" })
|
|
104
|
-
.set("debug", false)
|
|
105
|
-
.set("prod", "n") // = false
|
|
106
|
-
.save();
|
|
107
|
-
|
|
108
|
-
}).then(() => {
|
|
109
|
-
|
|
110
|
-
return Conf.load();
|
|
111
|
-
|
|
112
|
-
}).then(() => {
|
|
113
|
-
|
|
114
|
-
console.log(Conf.get("debug"));
|
|
115
|
-
console.log(Conf.get("usr.login"));
|
|
116
|
-
|
|
117
|
-
}).catch((err: Error) => {
|
|
118
|
-
console.log(err);
|
|
119
|
-
});
|
|
120
|
-
```
|
|
37
|
+
[check the TypeScript compilation tests](https://github.com/Psychopoulet/node-confmanager/blob/master/test/typescript/compilation.ts)
|
|
121
38
|
|
|
122
39
|
### Run
|
|
123
40
|
|
package/lib/index.d.ts
CHANGED
|
@@ -6,22 +6,22 @@ declare module "node-confmanager" {
|
|
|
6
6
|
|
|
7
7
|
class ConfManager extends Container {
|
|
8
8
|
|
|
9
|
-
public filePath: string;
|
|
10
|
-
public spaces: boolean;
|
|
11
|
-
public shortcuts: Array<string>;
|
|
9
|
+
public filePath: string; // conf file
|
|
10
|
+
public spaces: boolean; // formate file
|
|
11
|
+
public shortcuts: Array<string>; // for container
|
|
12
12
|
|
|
13
13
|
constructor(filePath?: string, spaces?: boolean, recursionSeparator?: string);
|
|
14
14
|
|
|
15
15
|
protected _loadFromConsole(): Promise<void>;
|
|
16
16
|
|
|
17
|
-
public
|
|
18
|
-
public clearShortcuts(): this;
|
|
19
|
-
public
|
|
20
|
-
public
|
|
21
|
-
public get(key: string): any;
|
|
22
|
-
public
|
|
23
|
-
public
|
|
24
|
-
public
|
|
17
|
+
// public clear(): void; // Container.clear & clearShortcuts
|
|
18
|
+
public clearShortcuts(): this; // forget all the shortcuts
|
|
19
|
+
public deleteFile(): Promise<void>; // delete the conf file
|
|
20
|
+
public fileExists(): Promise<boolean>; // check if the conf file exists
|
|
21
|
+
// public get(key: string): any; // Container.get with cloned data
|
|
22
|
+
public load(): Promise<void>; // load data from conf file then commandline (commandline takeover)
|
|
23
|
+
public save(): Promise<void>; // save data into conf file
|
|
24
|
+
public shortcut(key: string, shortkey: string): this; // bind a shortcut for commandline
|
|
25
25
|
|
|
26
26
|
}
|
|
27
27
|
|
package/lib/main.js
CHANGED
|
@@ -86,26 +86,21 @@ module.exports = class ConfManager extends Container {
|
|
|
86
86
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const { key, shortkey } = checkShortcut(_key, _shortkey);
|
|
92
|
-
|
|
93
|
-
this.shortcuts[shortkey] = key;
|
|
94
|
-
|
|
95
|
-
return this;
|
|
89
|
+
// public
|
|
96
90
|
|
|
91
|
+
// Container.clear & clearShortcuts
|
|
92
|
+
clear () {
|
|
93
|
+
super.clear();
|
|
94
|
+
this.clearShortcuts();
|
|
97
95
|
}
|
|
98
96
|
|
|
97
|
+
// forget all the shortcuts
|
|
99
98
|
clearShortcuts () {
|
|
100
99
|
this.shortcuts = [];
|
|
101
100
|
return this;
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
super.clear();
|
|
106
|
-
return this.clearShortcuts();
|
|
107
|
-
}
|
|
108
|
-
|
|
103
|
+
// delete the conf file
|
|
109
104
|
deleteFile () {
|
|
110
105
|
|
|
111
106
|
return !this.filePath ? Promise.resolve() : pathExists(this.filePath).then((exists) => {
|
|
@@ -114,10 +109,17 @@ module.exports = class ConfManager extends Container {
|
|
|
114
109
|
|
|
115
110
|
}
|
|
116
111
|
|
|
112
|
+
// check if the conf file exists
|
|
117
113
|
fileExists () {
|
|
118
114
|
return !this.filePath ? Promise.resolve(false) : pathExists(this.filePath);
|
|
119
115
|
}
|
|
120
116
|
|
|
117
|
+
// Container.get with cloned data
|
|
118
|
+
get (key) {
|
|
119
|
+
return clone(super.get(key));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// load data from conf file then commandline (commandline takeover)
|
|
121
123
|
load () {
|
|
122
124
|
|
|
123
125
|
this.clearData();
|
|
@@ -138,6 +140,7 @@ module.exports = class ConfManager extends Container {
|
|
|
138
140
|
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
// save data into conf file
|
|
141
144
|
save () {
|
|
142
145
|
|
|
143
146
|
return !this.filePath ? Promise.resolve() : mkdirp(dirname(this.filePath)).then(() => {
|
|
@@ -158,8 +161,15 @@ module.exports = class ConfManager extends Container {
|
|
|
158
161
|
|
|
159
162
|
}
|
|
160
163
|
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
// bind a shortcut for commandline
|
|
165
|
+
shortcut (_key, _shortkey) {
|
|
166
|
+
|
|
167
|
+
const { key, shortkey } = checkShortcut(_key, _shortkey);
|
|
168
|
+
|
|
169
|
+
this.shortcuts[shortkey] = key;
|
|
170
|
+
|
|
171
|
+
return this;
|
|
172
|
+
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-confmanager",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A configuration manager",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"url": "https://github.com/Psychopoulet/node-confmanager/issues"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"node-containerpattern": "1.
|
|
48
|
+
"node-containerpattern": "1.5.1",
|
|
49
49
|
"fs-extra": "10.1.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|