node-confmanager 1.9.0 → 1.10.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/LICENSE +1 -1
- package/README.md +69 -64
- package/lib/cjs/NodeConfManager.d.ts +2 -2
- package/lib/cjs/NodeConfManager.js +24 -22
- package/lib/cjs/utils/checkShortcut.js +1 -1
- package/lib/cjs/utils/clone.d.ts +1 -1
- package/lib/cjs/utils/clone.js +6 -7
- package/lib/cjs/utils/isFile.js +1 -1
- package/package.json +28 -24
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,64 +1,69 @@
|
|
|
1
|
-
# node-confmanager
|
|
2
|
-
A configuration manager
|
|
3
|
-
|
|
4
|
-
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
|
|
5
|
+
[](https://github.com/Psychopoulet/node-confmanager/issues)
|
|
6
|
+
[](https://github.com/Psychopoulet/node-confmanager/pulls)
|
|
7
|
+
|
|
8
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
|
|
10
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
|
|
11
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
|
|
12
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
|
|
13
|
+
|
|
14
|
+
[](https://snyk.io/test/github/Psychopoulet/node-confmanager)
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
$ npm install node-confmanager
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
* All the features of the [node-containerpattern](https://www.npmjs.com/package/node-containerpattern) package
|
|
25
|
+
* clone data in "get" action to avoid unwanted changes
|
|
26
|
+
* Saving the data in a JSON file
|
|
27
|
+
* Load the data from this JSON file and/or commandline
|
|
28
|
+
* access to the data with shortcuts in commandline
|
|
29
|
+
|
|
30
|
+
## Doc
|
|
31
|
+
|
|
32
|
+
### Inheritance
|
|
33
|
+
|
|
34
|
+
[check the official 'node-containerpattern' object documentation](https://github.com/Psychopoulet/node-containerpattern)
|
|
35
|
+
|
|
36
|
+
### Content
|
|
37
|
+
|
|
38
|
+
[check the TypeScript definition file](https://github.com/Psychopoulet/node-confmanager/blob/master/lib/index.d.ts)
|
|
39
|
+
|
|
40
|
+
## Examples
|
|
41
|
+
|
|
42
|
+
[check the TypeScript compilation tests](https://github.com/Psychopoulet/node-confmanager/blob/master/test/typescript/compilation.ts)
|
|
43
|
+
|
|
44
|
+
### Run
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# if "debug" skeleton is setted & defined as a boolean
|
|
48
|
+
node mysoft.js -d # if "debug" shortcut is setted
|
|
49
|
+
node mysoft.js --debug
|
|
50
|
+
node mysoft.js --debug "true"
|
|
51
|
+
node mysoft.js --debug "yes"
|
|
52
|
+
node mysoft.js --debug "y"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# if "arr" skeleton is defined as a array
|
|
57
|
+
node mysoft.js --arr test1 test2
|
|
58
|
+
node mysoft.js --arr "[ \"test1\", \"test2\" ]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Tests
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
$ npm run-script tests
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
[ISC](LICENSE)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import NodeContainerPattern
|
|
1
|
+
import NodeContainerPattern from "node-containerpattern";
|
|
2
2
|
export default class ConfManager extends NodeContainerPattern {
|
|
3
3
|
filePath: string;
|
|
4
4
|
spaces: boolean;
|
|
@@ -9,7 +9,7 @@ export default class ConfManager extends NodeContainerPattern {
|
|
|
9
9
|
clearShortcuts(): this;
|
|
10
10
|
deleteFile(): Promise<void>;
|
|
11
11
|
fileExists(): Promise<boolean>;
|
|
12
|
-
get(key: string):
|
|
12
|
+
get(key: string): unknown;
|
|
13
13
|
load(loadConsole?: boolean): Promise<void>;
|
|
14
14
|
save(): Promise<void>;
|
|
15
15
|
shortcut(_key: string, _shortkey: string): this;
|
|
@@ -8,20 +8,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
9
|
const promises_1 = require("node:fs/promises");
|
|
10
10
|
// externals
|
|
11
|
-
const
|
|
11
|
+
const node_containerpattern_1 = __importDefault(require("node-containerpattern"));
|
|
12
12
|
// locals
|
|
13
13
|
const checkShortcut_1 = __importDefault(require("./utils/checkShortcut"));
|
|
14
14
|
const clone_1 = __importDefault(require("./utils/clone"));
|
|
15
15
|
const isFile_1 = __importDefault(require("./utils/isFile"));
|
|
16
16
|
// module
|
|
17
|
-
class ConfManager extends
|
|
17
|
+
class ConfManager extends node_containerpattern_1.default {
|
|
18
|
+
// attributes
|
|
19
|
+
// public
|
|
20
|
+
filePath;
|
|
21
|
+
spaces;
|
|
22
|
+
shortcuts;
|
|
18
23
|
// constructor
|
|
19
24
|
constructor(filePath, spaces = false, recursionSeparator = ".") {
|
|
20
25
|
if ("undefined" !== typeof filePath && "string" !== typeof filePath) {
|
|
21
26
|
throw new TypeError("\"filePath\" parameter is not a string");
|
|
22
27
|
}
|
|
23
|
-
else if ("
|
|
24
|
-
throw new
|
|
28
|
+
else if ("string" === typeof filePath && "" === filePath.trim()) {
|
|
29
|
+
throw new RangeError("\"filePath\" parameter is empty");
|
|
25
30
|
}
|
|
26
31
|
else if ("undefined" !== typeof spaces && "boolean" !== typeof spaces) {
|
|
27
32
|
throw new TypeError("The \"spaces\" parameter is not a boolean");
|
|
@@ -29,8 +34,8 @@ class ConfManager extends NodeContainerPattern {
|
|
|
29
34
|
else if ("undefined" !== typeof recursionSeparator && "string" !== typeof recursionSeparator) {
|
|
30
35
|
throw new TypeError("The \"recursionSeparator\" parameter is not a string");
|
|
31
36
|
}
|
|
32
|
-
else if ("
|
|
33
|
-
throw new
|
|
37
|
+
else if ("string" === typeof recursionSeparator && "" === recursionSeparator.trim()) {
|
|
38
|
+
throw new RangeError("\"recursionSeparator\" parameter is empty");
|
|
34
39
|
}
|
|
35
40
|
else {
|
|
36
41
|
super(recursionSeparator);
|
|
@@ -51,7 +56,7 @@ class ConfManager extends NodeContainerPattern {
|
|
|
51
56
|
if (argument && (!isShortcut || this.shortcuts[argument])) {
|
|
52
57
|
const key = isShortcut ? this.shortcuts[argument] : argument;
|
|
53
58
|
// boolean
|
|
54
|
-
if (this.skeletons[key] && "boolean" === this.skeletons[key]) {
|
|
59
|
+
if ("string" === typeof this.skeletons[key] && "boolean" === this.skeletons[key]) {
|
|
55
60
|
this.set(key, true);
|
|
56
61
|
}
|
|
57
62
|
// check args
|
|
@@ -70,7 +75,7 @@ class ConfManager extends NodeContainerPattern {
|
|
|
70
75
|
if (nextArgs.length) {
|
|
71
76
|
const endArrayArgs = nextArgs.findIndex((a) => {
|
|
72
77
|
return a.startsWith("--")
|
|
73
|
-
|| (a.startsWith("-") &&
|
|
78
|
+
|| (a.startsWith("-") && Boolean(this.shortcuts[a.slice(1)]));
|
|
74
79
|
});
|
|
75
80
|
const values = 0 < endArrayArgs ? nextArgs.slice(0, endArrayArgs) : nextArgs;
|
|
76
81
|
if (1 === values.length && values[0].startsWith("[") && values[0].endsWith("]")) {
|
|
@@ -118,21 +123,18 @@ class ConfManager extends NodeContainerPattern {
|
|
|
118
123
|
this.clearData();
|
|
119
124
|
return this.fileExists().then((exists) => {
|
|
120
125
|
if (!exists) {
|
|
121
|
-
|
|
122
|
-
this._loadFromConsole();
|
|
123
|
-
}
|
|
126
|
+
return Promise.resolve();
|
|
124
127
|
}
|
|
125
|
-
|
|
126
|
-
return
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
128
|
+
return (0, promises_1.readFile)(this.filePath, "utf-8").then((content) => {
|
|
129
|
+
return JSON.parse(content);
|
|
130
|
+
}).then((data) => {
|
|
131
|
+
for (const key in data) {
|
|
132
|
+
this.set(key, data[key]);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}).then(() => {
|
|
136
|
+
if (loadConsole) {
|
|
137
|
+
this._loadFromConsole();
|
|
136
138
|
}
|
|
137
139
|
});
|
|
138
140
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// module
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = checkShortcut;
|
|
4
5
|
function checkShortcut(key, shortkey) {
|
|
5
6
|
if ("undefined" === typeof key) {
|
|
6
7
|
throw new ReferenceError("Missing \"key\" parameter");
|
|
@@ -27,4 +28,3 @@ function checkShortcut(key, shortkey) {
|
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
exports.default = checkShortcut;
|
package/lib/cjs/utils/clone.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function clone(from:
|
|
1
|
+
export default function clone(from: unknown): unknown;
|
package/lib/cjs/utils/clone.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// module
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = clone;
|
|
4
5
|
function clone(from) {
|
|
5
|
-
if (
|
|
6
|
+
if ("object" === typeof from && null !== from) {
|
|
6
7
|
if (Object === from.constructor) {
|
|
7
|
-
return
|
|
8
|
+
return { ...from };
|
|
8
9
|
}
|
|
9
10
|
else if (Array.isArray(from)) {
|
|
10
11
|
return [...from];
|
|
11
12
|
}
|
|
12
13
|
else {
|
|
13
|
-
|
|
14
|
+
const FromConstructor = from.constructor;
|
|
15
|
+
return new FromConstructor(from);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
return from;
|
|
18
|
-
}
|
|
18
|
+
return from;
|
|
19
19
|
}
|
|
20
|
-
exports.default = clone;
|
package/lib/cjs/utils/isFile.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// deps
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = isFile;
|
|
4
5
|
// natives
|
|
5
6
|
const node_fs_1 = require("node:fs");
|
|
6
7
|
// module
|
|
@@ -22,4 +23,3 @@ function isFile(file) {
|
|
|
22
23
|
}
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
exports.default = isFile;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "node-confmanager",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"description": "A configuration manager",
|
|
4
|
+
"version": "1.10.0",
|
|
5
|
+
"description": "A configuration manager.",
|
|
6
6
|
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"typings": "./lib/cjs/main.d.cts",
|
|
@@ -19,49 +19,53 @@
|
|
|
19
19
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
|
|
22
|
-
"prepare": "npx husky
|
|
22
|
+
"prepare": "npx husky || true",
|
|
23
23
|
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
|
|
25
|
+
"lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*",
|
|
26
|
+
"lint": "npm run lint-back && npm run lint-tests",
|
|
26
27
|
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
28
|
+
"clean-back": "npx rimraf ./lib/cjs",
|
|
29
|
+
"clean": "npm run clean-back",
|
|
30
|
+
|
|
31
|
+
"build-back": "npm run clean-back && npx tsc --project ./tsconfig.json",
|
|
32
|
+
"build": "npm run build-back",
|
|
33
|
+
|
|
34
|
+
"check-requires": "npx used-deps-analyzer ./package.json ./lib/src --no-dev",
|
|
35
|
+
"check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
|
|
30
36
|
"unit-tests": "npm run build && npx nyc --reporter=html --reporter=text mocha",
|
|
31
37
|
|
|
32
|
-
"tests": "npm run
|
|
38
|
+
"tests": "npm run lint && npm run check-requires && npm run check-updates && npm run unit-tests"
|
|
33
39
|
|
|
34
40
|
},
|
|
35
41
|
|
|
36
42
|
"files": [
|
|
37
|
-
"/
|
|
38
|
-
"/lib",
|
|
39
|
-
"/public"
|
|
43
|
+
"lib/cjs"
|
|
40
44
|
],
|
|
41
45
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
46
|
+
"node": ">=22.22.0"
|
|
43
47
|
},
|
|
44
48
|
|
|
45
49
|
"dependencies": {
|
|
46
|
-
"node-containerpattern": "1.
|
|
50
|
+
"node-containerpattern": "1.9.0"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
|
-
"@types/node": "
|
|
50
|
-
"check-version-modules": "2.
|
|
53
|
+
"@types/node": "25.5.0",
|
|
54
|
+
"check-version-modules": "2.2.2",
|
|
51
55
|
"colors": "1.4.0",
|
|
52
56
|
"eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
|
|
53
|
-
"husky": "
|
|
54
|
-
"mocha": "
|
|
55
|
-
"nyc": "
|
|
56
|
-
"rimraf": "
|
|
57
|
-
"typescript": "5.
|
|
58
|
-
"used-deps-analyzer": "0.
|
|
57
|
+
"husky": "9.1.7",
|
|
58
|
+
"mocha": "11.7.5",
|
|
59
|
+
"nyc": "18.0.0",
|
|
60
|
+
"rimraf": "6.1.3",
|
|
61
|
+
"typescript": "5.9.3",
|
|
62
|
+
"used-deps-analyzer": "0.2.0"
|
|
59
63
|
},
|
|
60
|
-
"optionalDependencies": {},
|
|
61
64
|
|
|
62
65
|
"husky": {
|
|
63
66
|
"hooks": {
|
|
64
|
-
"pre-
|
|
67
|
+
"pre-commit": "npm run lint",
|
|
68
|
+
"pre-push": "npm run unit-tests"
|
|
65
69
|
}
|
|
66
70
|
},
|
|
67
71
|
"keywords": [
|