@wocker/core 1.0.19-dev.0 → 1.0.19-dev.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/lib/makes/Config.d.ts +7 -8
- package/lib/makes/Config.js +9 -8
- package/lib/makes/ConfigCollection.d.ts +14 -0
- package/lib/makes/ConfigCollection.js +46 -0
- package/lib/makes/FileSystem.d.ts +8 -6
- package/lib/makes/FileSystem.js +25 -30
- package/lib/makes/index.d.ts +1 -0
- package/lib/makes/index.js +1 -0
- package/lib/services/PluginConfigService.d.ts +20 -7
- package/lib/services/PluginConfigService.js +34 -69
- package/package.json +1 -1
package/lib/makes/Config.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
protected constructor(data: ConfigProperties);
|
|
1
|
+
export type ConfigProperties = {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
export declare class Config<T extends ConfigProperties> {
|
|
5
|
+
name: string;
|
|
6
|
+
constructor(data: T);
|
|
7
|
+
toObject(): T;
|
|
9
8
|
}
|
package/lib/makes/Config.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Config = void 0;
|
|
4
|
-
|
|
5
|
-
/* istanbul ignore next */
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated
|
|
8
|
-
* @see AppConfig
|
|
9
|
-
*/
|
|
10
|
-
class Config extends AppConfig_1.AppConfig {
|
|
4
|
+
class Config {
|
|
11
5
|
constructor(data) {
|
|
12
|
-
|
|
6
|
+
this.name = data.name;
|
|
7
|
+
}
|
|
8
|
+
toObject() {
|
|
9
|
+
return Object.keys(this)
|
|
10
|
+
.reduce((res, key) => {
|
|
11
|
+
res[key] = this[key];
|
|
12
|
+
return res;
|
|
13
|
+
}, {});
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
exports.Config = Config;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Config, ConfigProperties } from "./Config";
|
|
2
|
+
interface Constructible<P extends ConfigProperties, C extends Config<P>> {
|
|
3
|
+
new (props: P): C;
|
|
4
|
+
}
|
|
5
|
+
export declare class ConfigCollection<C extends Config<P>, P extends ConfigProperties> {
|
|
6
|
+
protected ConfigClass: Constructible<P, C>;
|
|
7
|
+
items: C[];
|
|
8
|
+
constructor(ConfigClass: Constructible<P, C>, items: P[]);
|
|
9
|
+
setConfig(config: C): void;
|
|
10
|
+
getConfig(name: string): C | undefined;
|
|
11
|
+
removeConfig(name: string): void;
|
|
12
|
+
toArray(): P[];
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigCollection = void 0;
|
|
4
|
+
class ConfigCollection {
|
|
5
|
+
constructor(ConfigClass, items) {
|
|
6
|
+
this.ConfigClass = ConfigClass;
|
|
7
|
+
this.items = items.map((props) => {
|
|
8
|
+
return new this.ConfigClass(props);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
setConfig(config) {
|
|
12
|
+
let exists = false;
|
|
13
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
14
|
+
if (this.items[i].name === config.name) {
|
|
15
|
+
exists = true;
|
|
16
|
+
this.items[i] = config;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!exists) {
|
|
20
|
+
this.items.push(config);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getConfig(name) {
|
|
24
|
+
return this.items.find((config) => {
|
|
25
|
+
return config.name === name;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
removeConfig(name) {
|
|
29
|
+
const index = this.items.findIndex((storage) => {
|
|
30
|
+
return storage.name === name;
|
|
31
|
+
});
|
|
32
|
+
if (index === -1) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.items = [
|
|
36
|
+
...this.items.slice(0, index),
|
|
37
|
+
...this.items.slice(index + 1)
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
toArray() {
|
|
41
|
+
return this.items.map((item) => {
|
|
42
|
+
return item.toObject();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ConfigCollection = ConfigCollection;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
type ReaddirOptions =
|
|
1
|
+
import fs, { RmOptions, Stats, WriteFileOptions } from "fs";
|
|
2
|
+
type ReaddirOptions = fs.ObjectEncodingOptions & {
|
|
3
3
|
recursive?: boolean | undefined;
|
|
4
4
|
};
|
|
5
5
|
export declare class FileSystem {
|
|
@@ -9,12 +9,14 @@ export declare class FileSystem {
|
|
|
9
9
|
basename(...parts: string[]): string;
|
|
10
10
|
exists(...parts: string[]): boolean;
|
|
11
11
|
stat(...parts: string[]): Stats;
|
|
12
|
-
mkdir(path
|
|
13
|
-
readdir(...parts: string[]): Promise<
|
|
12
|
+
mkdir(path?: string, options?: fs.MakeDirectoryOptions): void;
|
|
13
|
+
readdir(...parts: string[]): Promise<string[]>;
|
|
14
14
|
readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
|
|
15
15
|
readJSON(...paths: string[]): any;
|
|
16
|
-
writeFile(path: string, data: string | Buffer): Promise<void>;
|
|
17
|
-
writeJSON(path: string, data: any, options?: WriteFileOptions):
|
|
16
|
+
writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): Promise<void>;
|
|
17
|
+
writeJSON(path: string, data: any, options?: WriteFileOptions): void;
|
|
18
18
|
rm(path: string, options?: RmOptions): Promise<void>;
|
|
19
|
+
createWriteStream(path: string): fs.WriteStream;
|
|
20
|
+
createReadStream(path: string): fs.ReadStream;
|
|
19
21
|
}
|
|
20
22
|
export {};
|
package/lib/makes/FileSystem.js
CHANGED
|
@@ -37,7 +37,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.FileSystem = void 0;
|
|
39
39
|
const fs_1 = __importDefault(require("fs"));
|
|
40
|
-
const fs_2 = __importDefault(require("fs"));
|
|
41
40
|
const Path = __importStar(require("path"));
|
|
42
41
|
class FileSystem {
|
|
43
42
|
constructor(source) {
|
|
@@ -51,21 +50,21 @@ class FileSystem {
|
|
|
51
50
|
}
|
|
52
51
|
exists(...parts) {
|
|
53
52
|
const fullPath = this.path(...parts);
|
|
54
|
-
return
|
|
53
|
+
return fs_1.default.existsSync(fullPath);
|
|
55
54
|
}
|
|
56
55
|
stat(...parts) {
|
|
57
56
|
const fullPath = this.path(...parts);
|
|
58
|
-
return
|
|
57
|
+
return fs_1.default.statSync(fullPath);
|
|
59
58
|
}
|
|
60
|
-
mkdir(path, options) {
|
|
59
|
+
mkdir(path = "", options) {
|
|
61
60
|
const fullPath = this.path(path);
|
|
62
|
-
|
|
61
|
+
fs_1.default.mkdirSync(fullPath, options);
|
|
63
62
|
}
|
|
64
63
|
readdir(...parts) {
|
|
65
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
65
|
const fullPath = this.path(...parts);
|
|
67
66
|
return new Promise((resolve, reject) => {
|
|
68
|
-
|
|
67
|
+
fs_1.default.readdir(fullPath, (err, files) => {
|
|
69
68
|
if (err) {
|
|
70
69
|
reject(err);
|
|
71
70
|
return;
|
|
@@ -79,7 +78,7 @@ class FileSystem {
|
|
|
79
78
|
return __awaiter(this, arguments, void 0, function* (path = "", options) {
|
|
80
79
|
const fullPath = this.path(path);
|
|
81
80
|
return new Promise((resolve, reject) => {
|
|
82
|
-
|
|
81
|
+
fs_1.default.readdir(fullPath, options, (err, files) => {
|
|
83
82
|
if (err) {
|
|
84
83
|
reject(err);
|
|
85
84
|
return;
|
|
@@ -95,41 +94,31 @@ class FileSystem {
|
|
|
95
94
|
}
|
|
96
95
|
readJSON(...paths) {
|
|
97
96
|
const filePath = this.path(...paths);
|
|
98
|
-
const res =
|
|
97
|
+
const res = fs_1.default.readFileSync(filePath);
|
|
99
98
|
return JSON.parse(res.toString());
|
|
100
99
|
}
|
|
101
|
-
writeFile(path, data) {
|
|
100
|
+
writeFile(path, data, options) {
|
|
102
101
|
const fullPath = this.path(path);
|
|
103
102
|
return new Promise((resolve, reject) => {
|
|
104
|
-
|
|
103
|
+
const callback = (err) => {
|
|
105
104
|
if (err) {
|
|
106
105
|
reject(err);
|
|
107
106
|
return;
|
|
108
107
|
}
|
|
109
108
|
resolve(undefined);
|
|
110
|
-
}
|
|
109
|
+
};
|
|
110
|
+
if (options) {
|
|
111
|
+
fs_1.default.writeFile(fullPath, data, options, callback);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
fs_1.default.writeFile(fullPath, data, callback);
|
|
115
|
+
}
|
|
111
116
|
});
|
|
112
117
|
}
|
|
113
118
|
writeJSON(path, data, options) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return new Promise((resolve, reject) => {
|
|
118
|
-
const callback = (err) => {
|
|
119
|
-
if (err) {
|
|
120
|
-
reject(err);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
resolve(undefined);
|
|
124
|
-
};
|
|
125
|
-
if (options) {
|
|
126
|
-
fs_2.default.writeFile(fullPath, json, options, callback);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
fs_2.default.writeFile(fullPath, json, callback);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
119
|
+
const fullPath = this.path(path);
|
|
120
|
+
const json = JSON.stringify(data, null, 4);
|
|
121
|
+
fs_1.default.writeFileSync(fullPath, json, options);
|
|
133
122
|
}
|
|
134
123
|
rm(path, options) {
|
|
135
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -151,5 +140,11 @@ class FileSystem {
|
|
|
151
140
|
});
|
|
152
141
|
});
|
|
153
142
|
}
|
|
143
|
+
createWriteStream(path) {
|
|
144
|
+
return fs_1.default.createWriteStream(this.path(path));
|
|
145
|
+
}
|
|
146
|
+
createReadStream(path) {
|
|
147
|
+
return fs_1.default.createReadStream(this.path(path));
|
|
148
|
+
}
|
|
154
149
|
}
|
|
155
150
|
exports.FileSystem = FileSystem;
|
package/lib/makes/index.d.ts
CHANGED
package/lib/makes/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./AppConfig"), exports);
|
|
18
18
|
__exportStar(require("./Config"), exports);
|
|
19
|
+
__exportStar(require("./ConfigCollection"), exports);
|
|
19
20
|
__exportStar(require("./Container"), exports);
|
|
20
21
|
__exportStar(require("./FileSystem"), exports);
|
|
21
22
|
__exportStar(require("./FS"), exports);
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import { WriteFileOptions, MakeDirectoryOptions, RmOptions } from "fs";
|
|
1
|
+
import { WriteFileOptions, MakeDirectoryOptions, RmOptions, WriteStream, ReadStream } from "fs";
|
|
2
|
+
import { FileSystem } from "../makes";
|
|
2
3
|
export declare class PluginConfigService {
|
|
3
4
|
protected readonly pluginDir: string;
|
|
5
|
+
protected _fs?: FileSystem;
|
|
4
6
|
constructor(pluginDir: string);
|
|
7
|
+
get fs(): FileSystem;
|
|
8
|
+
/** @deprecated */
|
|
5
9
|
dataPath(...parts: string[]): string;
|
|
6
|
-
|
|
10
|
+
/** @deprecated */
|
|
11
|
+
mkdir(path: string, options?: MakeDirectoryOptions): void;
|
|
12
|
+
/** @deprecated */
|
|
7
13
|
writeFile(path: string, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
writeJSON(path: string, data: any, options?: WriteFileOptions): void;
|
|
16
|
+
/** @deprecated */
|
|
17
|
+
readJSON(path: string): any;
|
|
18
|
+
/** @deprecated */
|
|
10
19
|
exists(path: string): boolean;
|
|
11
|
-
|
|
20
|
+
/** @deprecated */
|
|
21
|
+
rm(path: string, options?: RmOptions): Promise<void>;
|
|
22
|
+
/** @deprecated */
|
|
12
23
|
readdir(path: string): Promise<string[]>;
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
/** @deprecated */
|
|
25
|
+
createWriteSteam(path: string): WriteStream;
|
|
26
|
+
/** @deprecated */
|
|
27
|
+
createReadStream(path: string): ReadStream;
|
|
15
28
|
}
|
|
@@ -1,33 +1,10 @@
|
|
|
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
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
10
|
};
|
|
@@ -45,8 +22,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
45
22
|
};
|
|
46
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
24
|
exports.PluginConfigService = void 0;
|
|
48
|
-
const Path = __importStar(require("path"));
|
|
49
|
-
const fs_1 = require("fs");
|
|
50
25
|
const makes_1 = require("../makes");
|
|
51
26
|
const decorators_1 = require("../decorators");
|
|
52
27
|
const env_1 = require("../env");
|
|
@@ -54,73 +29,63 @@ let PluginConfigService = class PluginConfigService {
|
|
|
54
29
|
constructor(pluginDir) {
|
|
55
30
|
this.pluginDir = pluginDir;
|
|
56
31
|
}
|
|
57
|
-
|
|
58
|
-
if (!this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
32
|
+
get fs() {
|
|
33
|
+
if (!this._fs) {
|
|
34
|
+
if (!this.pluginDir) {
|
|
35
|
+
throw new Error("Plugin dir missed");
|
|
36
|
+
}
|
|
37
|
+
this._fs = new makes_1.FileSystem(this.pluginDir);
|
|
38
|
+
if (!this._fs.exists()) {
|
|
39
|
+
this._fs.mkdir();
|
|
40
|
+
}
|
|
65
41
|
}
|
|
66
|
-
return
|
|
42
|
+
return this._fs;
|
|
67
43
|
}
|
|
44
|
+
/** @deprecated */
|
|
45
|
+
dataPath(...parts) {
|
|
46
|
+
return this.fs.path(...parts);
|
|
47
|
+
}
|
|
48
|
+
/** @deprecated */
|
|
68
49
|
mkdir(path, options) {
|
|
69
|
-
|
|
70
|
-
yield makes_1.FS.mkdir(this.dataPath(path), options);
|
|
71
|
-
});
|
|
50
|
+
this.fs.mkdir(path, options);
|
|
72
51
|
}
|
|
52
|
+
/** @deprecated */
|
|
73
53
|
writeFile(path, data, options) {
|
|
74
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
yield
|
|
55
|
+
yield this.fs.writeFile(path, data, options);
|
|
76
56
|
});
|
|
77
57
|
}
|
|
58
|
+
/** @deprecated */
|
|
78
59
|
writeJSON(path, data, options) {
|
|
79
|
-
|
|
80
|
-
yield makes_1.FS.writeJSON(this.dataPath(path), data, options);
|
|
81
|
-
});
|
|
60
|
+
this.fs.writeJSON(path, data, options);
|
|
82
61
|
}
|
|
62
|
+
/** @deprecated */
|
|
83
63
|
readJSON(path) {
|
|
84
|
-
return
|
|
85
|
-
return makes_1.FS.readJSON(this.dataPath(path));
|
|
86
|
-
});
|
|
64
|
+
return this.fs.readJSON(path);
|
|
87
65
|
}
|
|
66
|
+
/** @deprecated */
|
|
88
67
|
exists(path) {
|
|
89
|
-
return
|
|
68
|
+
return this.fs.exists(path);
|
|
90
69
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
(0, fs_1.rm)(fullPath, options, (err) => {
|
|
96
|
-
if (err) {
|
|
97
|
-
reject(err);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
resolve(undefined);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
70
|
+
/** @deprecated */
|
|
71
|
+
rm(path, options) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
yield this.fs.rm(path, options);
|
|
103
74
|
});
|
|
104
75
|
}
|
|
76
|
+
/** @deprecated */
|
|
105
77
|
readdir(path) {
|
|
106
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
|
|
108
|
-
return new Promise((resolve, reject) => {
|
|
109
|
-
(0, fs_1.readdir)(fullPath, (err, files) => {
|
|
110
|
-
if (err) {
|
|
111
|
-
reject(err);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
resolve(files);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
79
|
+
return this.fs.readdir(path);
|
|
117
80
|
});
|
|
118
81
|
}
|
|
82
|
+
/** @deprecated */
|
|
119
83
|
createWriteSteam(path) {
|
|
120
|
-
return
|
|
84
|
+
return this.fs.createWriteStream(path);
|
|
121
85
|
}
|
|
86
|
+
/** @deprecated */
|
|
122
87
|
createReadStream(path) {
|
|
123
|
-
return
|
|
88
|
+
return this.fs.createReadStream(path);
|
|
124
89
|
}
|
|
125
90
|
};
|
|
126
91
|
exports.PluginConfigService = PluginConfigService;
|