Compare commits
2 Commits
e1d4785240
...
62856686f2
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 62856686f2 | |
Derrick Hammer | e1c57ea40b |
|
@ -11,7 +11,8 @@ import arg from "arg";
|
|||
export default class Config {
|
||||
private module;
|
||||
private data;
|
||||
constructor(module: string);
|
||||
private configProperty;
|
||||
constructor(module: string, configProperty: string);
|
||||
inject(options: object): void;
|
||||
load(): void;
|
||||
openDir(dir: string): void;
|
||||
|
|
|
@ -20,10 +20,12 @@ const deep_to_flat_object_1 = __importDefault(require("deep-to-flat-object"));
|
|||
class Config {
|
||||
module;
|
||||
data = {};
|
||||
constructor(module) {
|
||||
configProperty;
|
||||
constructor(module, configProperty) {
|
||||
(0, bsert_1.default)(typeof module === "string");
|
||||
(0, bsert_1.default)(module.length > 0);
|
||||
this.module = module;
|
||||
this.configProperty = configProperty;
|
||||
}
|
||||
inject(options) {
|
||||
for (const key of Object.keys(options)) {
|
||||
|
@ -70,7 +72,7 @@ class Config {
|
|||
save(file, data) {
|
||||
(0, bsert_1.default)(typeof data === "object");
|
||||
(0, bsert_1.default)(!Array.isArray(data));
|
||||
const configDir = this.str("configdir");
|
||||
const configDir = this.str(this.configProperty);
|
||||
const fullPath = path_1.default.join(configDir, `${file}.json`);
|
||||
if (!fs_1.default.existsSync(configDir)) {
|
||||
fs_1.default.mkdirSync(configDir, { recursive: true });
|
||||
|
|
|
@ -20,12 +20,14 @@ import deepToFlatObject from "deep-to-flat-object";
|
|||
export default class Config {
|
||||
private module: string;
|
||||
private data = {};
|
||||
private configProperty;
|
||||
|
||||
constructor(module: string) {
|
||||
constructor(module: string, configProperty: string) {
|
||||
assert(typeof module === "string");
|
||||
assert(module.length > 0);
|
||||
|
||||
this.module = module;
|
||||
this.configProperty = configProperty;
|
||||
}
|
||||
|
||||
public inject(options: object) {
|
||||
|
@ -83,7 +85,7 @@ export default class Config {
|
|||
assert(typeof data === "object");
|
||||
assert(!Array.isArray(data));
|
||||
|
||||
const configDir = this.str("configdir");
|
||||
const configDir = this.str(this.configProperty);
|
||||
const fullPath = Path.join(configDir, `${file}.json`);
|
||||
|
||||
if (!fs.existsSync(configDir)) {
|
||||
|
|
Loading…
Reference in New Issue