Update Settings class to export properly. Replace use of any in Device.

This commit is contained in:
Matt McWilliams 2024-05-22 23:36:40 -04:00
parent 7e24c70454
commit 8e8fac92d1
5 changed files with 66 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1,39 @@
export {};
export declare class Settings {
private file;
private defaultState;
state: any;
/**
*
**/
constructor();
private exists;
private freshState;
/**
*
**/
private checkDir;
/**
*
**/
save(): Promise<void>;
/**
*
**/
update(key: string, val: any): void;
/**
*
**/
get(key: string): any;
/**
*
**/
all(): any;
/**
*
**/
restore(): Promise<void>;
/**
*
**/
reset(): Promise<void>;
}

View File

@ -1,14 +1,15 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const os = require("os");
const path = require("path");
const fs = require("fs-extra");
exports.Settings = void 0;
const os_1 = require("os");
const path_1 = require("path");
const promises_1 = require("fs/promises");
class Settings {
/**
*
**/
constructor() {
this.file = path.join(os.homedir(), `/.mcopy/settings.json`);
this.file = (0, path_1.join)((0, os_1.homedir)(), `/.mcopy/settings.json`);
this.defaultState = {
server: {
port: 1111,
@ -24,6 +25,15 @@ class Settings {
};
this.state = this.freshState();
}
async exists(path) {
try {
await (0, promises_1.access)(path);
return true;
}
catch (_a) {
return false;
}
}
freshState() {
return JSON.parse(JSON.stringify(this.defaultState));
}
@ -31,11 +41,11 @@ class Settings {
*
**/
async checkDir() {
const dir = path.join(os.homedir(), '.mcopy/');
const exists = await fs.exists(dir);
const dir = (0, path_1.join)((0, os_1.homedir)(), '.mcopy/');
const exists = await this.exists(dir);
if (!exists) {
try {
await fs.mkdir(dir);
await (0, promises_1.mkdir)(dir);
}
catch (err) {
if (err.code === 'EEXIST')
@ -52,7 +62,7 @@ class Settings {
const str = JSON.stringify(this.state, null, '\t');
this.checkDir();
try {
await fs.writeFile(this.file, str, 'utf8');
await (0, promises_1.writeFile)(this.file, str, 'utf8');
}
catch (err) {
console.error(err);
@ -80,12 +90,12 @@ class Settings {
*
**/
async restore() {
let exists;
let exists = false;
let str;
this.checkDir();
exists = await fs.exists(this.file);
exists = await this.exists(this.file);
if (exists) {
str = await fs.readFile(this.file, 'utf8');
str = await (0, promises_1.readFile)(this.file, 'utf8');
this.state = JSON.parse(str);
//console.dir(this.state)
}
@ -97,10 +107,10 @@ class Settings {
*
**/
async reset() {
const exists = await fs.exists(this.file);
const exists = await this.exists(this.file);
if (exists) {
try {
await fs.unlink(this.file);
await (0, promises_1.unlink)(this.file);
}
catch (err) {
console.error(err);
@ -111,5 +121,6 @@ class Settings {
}
;
}
exports.Settings = Settings;
module.exports = new Settings();
//# sourceMappingURL=index.js.map

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,yBAA0B;AAC1B,6BAA8B;AAC9B,+BAAgC;AAEhC,MAAM,QAAQ;IAgBb;;QAEI;IACJ;QAlBQ,SAAI,GAAW,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,uBAAuB,CAAC,CAAC;QAChE,iBAAY,GAAS;YAC5B,MAAM,EAAG;gBACR,IAAI,EAAG,IAAI;gBACX,OAAO,EAAG,IAAI;aACd;YACD,OAAO,EAAG,EAAE;YACZ,OAAO,EAAG,OAAO;YACjB,MAAM,EAAG,EAAE;YACX,SAAS,EAAG,EAAE;YACd,KAAK,EAAG,EAAE;YACV,MAAM,EAAG,EAAE;YACX,MAAM,EAAG,EAAE;SACX,CAAA;QAMA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IAEO,UAAU;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,CAAC;IACD;;QAEI;IACI,KAAK,CAAC,QAAQ;QACrB,MAAM,GAAG,GAAY,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC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HC;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,QAAQ,EAAE,CAAC"}

2
app/package-lock.json generated
View File

@ -6,7 +6,7 @@
"packages": {
"": {
"name": "mcopy-app",
"version": "1.8.103",
"version": "1.8.109",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {