*Force create of config directory if it does not exist
This commit is contained in:
parent
3e412d5090
commit
7c631f3af5
10
src/index.ts
10
src/index.ts
|
@ -80,6 +80,7 @@ export default class Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public inject(options: object) {
|
public inject(options: object) {
|
||||||
for (const key of Object.keys(options)) {
|
for (const key of Object.keys(options)) {
|
||||||
const value = options[key];
|
const value = options[key];
|
||||||
|
@ -174,6 +175,10 @@ export default class Config {
|
||||||
|
|
||||||
const fullPath = Path.join(this.str("configdir"), file);
|
const fullPath = Path.join(this.str("configdir"), file);
|
||||||
|
|
||||||
|
if (!fs.existsSync(fullPath)) {
|
||||||
|
fs.mkdirSync(fullPath, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
fs.writeFileSync(fullPath, JSON.stringify(data));
|
fs.writeFileSync(fullPath, JSON.stringify(data));
|
||||||
this.openJson(fullPath);
|
this.openJson(fullPath);
|
||||||
}
|
}
|
||||||
|
@ -317,6 +322,7 @@ export default class Config {
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int(key, fallback = null) {
|
int(key, fallback = null) {
|
||||||
const value = this.get(key);
|
const value = this.get(key);
|
||||||
|
|
||||||
|
@ -398,6 +404,7 @@ export default class Config {
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
ufloat(key, fallback = null) {
|
ufloat(key, fallback = null) {
|
||||||
const value = this.float(key);
|
const value = this.float(key);
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
|
@ -424,6 +431,7 @@ export default class Config {
|
||||||
throw new Error(`${fmt(key)} must be a fixed number.`);
|
throw new Error(`${fmt(key)} must be a fixed number.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ufixed(key, exp, fallback = null) {
|
ufixed(key, exp, fallback = null) {
|
||||||
const value = this.fixed(key, exp);
|
const value = this.fixed(key, exp);
|
||||||
|
|
||||||
|
@ -473,6 +481,7 @@ export default class Config {
|
||||||
|
|
||||||
throw new Error(`${fmt(key)} must be a boolean.`);
|
throw new Error(`${fmt(key)} must be a boolean.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf(key: string, fallback = null, enc: BufferEncoding = "hex") {
|
buf(key: string, fallback = null, enc: BufferEncoding = "hex") {
|
||||||
const value = this.get(key);
|
const value = this.get(key);
|
||||||
|
|
||||||
|
@ -875,6 +884,7 @@ export default class Config {
|
||||||
|
|
||||||
return this.parseForm(query, "?", this.query);
|
return this.parseForm(query, "?", this.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseHash(hash: string) {
|
public parseHash(hash: string) {
|
||||||
if (typeof hash !== "string") {
|
if (typeof hash !== "string") {
|
||||||
if (!global.location) {
|
if (!global.location) {
|
||||||
|
|
Loading…
Reference in New Issue