@wocker/core
Advanced tools
Comparing version 1.0.19-dev.0 to 1.0.19-dev.1
@@ -1,9 +0,8 @@ | ||
import { AppConfig, AppConfigProperties } from "./AppConfig"; | ||
export type ConfigProperties = AppConfigProperties; | ||
/** | ||
* @deprecated | ||
* @see AppConfig | ||
*/ | ||
export declare abstract class Config extends AppConfig { | ||
protected constructor(data: ConfigProperties); | ||
export type ConfigProperties = { | ||
name: string; | ||
}; | ||
export declare class Config<T extends ConfigProperties> { | ||
name: string; | ||
constructor(data: T); | ||
toObject(): T; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Config = void 0; | ||
const AppConfig_1 = require("./AppConfig"); | ||
/* istanbul ignore next */ | ||
/** | ||
* @deprecated | ||
* @see AppConfig | ||
*/ | ||
class Config extends AppConfig_1.AppConfig { | ||
class Config { | ||
constructor(data) { | ||
super(data); | ||
this.name = data.name; | ||
} | ||
toObject() { | ||
return Object.keys(this) | ||
.reduce((res, key) => { | ||
res[key] = this[key]; | ||
return res; | ||
}, {}); | ||
} | ||
} | ||
exports.Config = Config; |
@@ -1,3 +0,3 @@ | ||
import FS, { RmOptions, Stats, WriteFileOptions } from "fs"; | ||
type ReaddirOptions = FS.ObjectEncodingOptions & { | ||
import fs, { RmOptions, Stats, WriteFileOptions } from "fs"; | ||
type ReaddirOptions = fs.ObjectEncodingOptions & { | ||
recursive?: boolean | undefined; | ||
@@ -12,10 +12,12 @@ }; | ||
stat(...parts: string[]): Stats; | ||
mkdir(path: string, options?: FS.MakeDirectoryOptions): void; | ||
readdir(...parts: string[]): Promise<unknown>; | ||
mkdir(path?: string, options?: fs.MakeDirectoryOptions): void; | ||
readdir(...parts: string[]): Promise<string[]>; | ||
readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>; | ||
readJSON(...paths: string[]): any; | ||
writeFile(path: string, data: string | Buffer): Promise<void>; | ||
writeJSON(path: string, data: any, options?: WriteFileOptions): Promise<void>; | ||
writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): Promise<void>; | ||
writeJSON(path: string, data: any, options?: WriteFileOptions): void; | ||
rm(path: string, options?: RmOptions): Promise<void>; | ||
createWriteStream(path: string): fs.WriteStream; | ||
createReadStream(path: string): fs.ReadStream; | ||
} | ||
export {}; |
@@ -40,3 +40,2 @@ "use strict"; | ||
const fs_1 = __importDefault(require("fs")); | ||
const fs_2 = __importDefault(require("fs")); | ||
const Path = __importStar(require("path")); | ||
@@ -55,11 +54,11 @@ class FileSystem { | ||
const fullPath = this.path(...parts); | ||
return fs_2.default.existsSync(fullPath); | ||
return fs_1.default.existsSync(fullPath); | ||
} | ||
stat(...parts) { | ||
const fullPath = this.path(...parts); | ||
return fs_2.default.statSync(fullPath); | ||
return fs_1.default.statSync(fullPath); | ||
} | ||
mkdir(path, options) { | ||
mkdir(path = "", options) { | ||
const fullPath = this.path(path); | ||
fs_2.default.mkdirSync(fullPath, options); | ||
fs_1.default.mkdirSync(fullPath, options); | ||
} | ||
@@ -70,3 +69,3 @@ readdir(...parts) { | ||
return new Promise((resolve, reject) => { | ||
fs_2.default.readdir(fullPath, (err, files) => { | ||
fs_1.default.readdir(fullPath, (err, files) => { | ||
if (err) { | ||
@@ -85,3 +84,3 @@ reject(err); | ||
return new Promise((resolve, reject) => { | ||
fs_2.default.readdir(fullPath, options, (err, files) => { | ||
fs_1.default.readdir(fullPath, options, (err, files) => { | ||
if (err) { | ||
@@ -102,9 +101,9 @@ reject(err); | ||
const filePath = this.path(...paths); | ||
const res = fs_2.default.readFileSync(filePath); | ||
const res = fs_1.default.readFileSync(filePath); | ||
return JSON.parse(res.toString()); | ||
} | ||
writeFile(path, data) { | ||
writeFile(path, data, options) { | ||
const fullPath = this.path(path); | ||
return new Promise((resolve, reject) => { | ||
fs_2.default.writeFile(fullPath, data, (err) => { | ||
const callback = (err) => { | ||
if (err) { | ||
@@ -115,25 +114,15 @@ reject(err); | ||
resolve(undefined); | ||
}); | ||
}; | ||
if (options) { | ||
fs_1.default.writeFile(fullPath, data, options, callback); | ||
} | ||
else { | ||
fs_1.default.writeFile(fullPath, data, callback); | ||
} | ||
}); | ||
} | ||
writeJSON(path, data, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fullPath = this.path(path); | ||
const json = JSON.stringify(data, null, 4); | ||
return new Promise((resolve, reject) => { | ||
const callback = (err) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(undefined); | ||
}; | ||
if (options) { | ||
fs_2.default.writeFile(fullPath, json, options, callback); | ||
} | ||
else { | ||
fs_2.default.writeFile(fullPath, json, callback); | ||
} | ||
}); | ||
}); | ||
const fullPath = this.path(path); | ||
const json = JSON.stringify(data, null, 4); | ||
fs_1.default.writeFileSync(fullPath, json, options); | ||
} | ||
@@ -160,3 +149,9 @@ rm(path, options) { | ||
} | ||
createWriteStream(path) { | ||
return fs_1.default.createWriteStream(this.path(path)); | ||
} | ||
createReadStream(path) { | ||
return fs_1.default.createReadStream(this.path(path)); | ||
} | ||
} | ||
exports.FileSystem = FileSystem; |
export * from "./AppConfig"; | ||
export * from "./Config"; | ||
export * from "./ConfigCollection"; | ||
export * from "./Container"; | ||
@@ -4,0 +5,0 @@ export * from "./FileSystem"; |
@@ -19,2 +19,3 @@ "use strict"; | ||
__exportStar(require("./Config"), exports); | ||
__exportStar(require("./ConfigCollection"), exports); | ||
__exportStar(require("./Container"), exports); | ||
@@ -21,0 +22,0 @@ __exportStar(require("./FileSystem"), exports); |
@@ -1,15 +0,27 @@ | ||
import { WriteFileOptions, MakeDirectoryOptions, RmOptions } from "fs"; | ||
import { WriteFileOptions, MakeDirectoryOptions, RmOptions, WriteStream, ReadStream } from "fs"; | ||
import { FileSystem } from "../makes"; | ||
export declare class PluginConfigService { | ||
protected readonly pluginDir: string; | ||
constructor(pluginDir: string); | ||
get fs(): FileSystem; | ||
/** @deprecated */ | ||
dataPath(...parts: string[]): string; | ||
mkdir(path: string, options?: MakeDirectoryOptions): Promise<void>; | ||
/** @deprecated */ | ||
mkdir(path: string, options?: MakeDirectoryOptions): void; | ||
/** @deprecated */ | ||
writeFile(path: string, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>; | ||
writeJSON(path: string, data: any, options?: WriteFileOptions): Promise<void>; | ||
readJSON(path: string): Promise<any>; | ||
/** @deprecated */ | ||
writeJSON(path: string, data: any, options?: WriteFileOptions): void; | ||
/** @deprecated */ | ||
readJSON(path: string): any; | ||
/** @deprecated */ | ||
exists(path: string): boolean; | ||
rm(path: string, options?: RmOptions): Promise<unknown>; | ||
/** @deprecated */ | ||
rm(path: string, options?: RmOptions): Promise<void>; | ||
/** @deprecated */ | ||
readdir(path: string): Promise<string[]>; | ||
createWriteSteam(path: string): import("fs").WriteStream; | ||
createReadStream(path: string): import("fs").ReadStream; | ||
/** @deprecated */ | ||
createWriteSteam(path: string): WriteStream; | ||
/** @deprecated */ | ||
createReadStream(path: string): ReadStream; | ||
} |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -24,9 +8,2 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
@@ -49,4 +26,2 @@ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
exports.PluginConfigService = void 0; | ||
const Path = __importStar(require("path")); | ||
const fs_1 = require("fs"); | ||
const makes_1 = require("../makes"); | ||
@@ -59,69 +34,57 @@ const decorators_1 = require("../decorators"); | ||
} | ||
dataPath(...parts) { | ||
get fs() { | ||
if (!this.pluginDir) { | ||
throw new Error("Plugin dir missed"); | ||
} | ||
if (!(0, fs_1.existsSync)(this.pluginDir)) { | ||
(0, fs_1.mkdirSync)(this.pluginDir, { | ||
recursive: true | ||
}); | ||
const fs = new makes_1.FileSystem(this.pluginDir); | ||
if (!fs.exists()) { | ||
fs.mkdir(); | ||
} | ||
return Path.join(this.pluginDir, ...parts); | ||
return fs; | ||
} | ||
/** @deprecated */ | ||
dataPath(...parts) { | ||
return this.fs.path(...parts); | ||
} | ||
/** @deprecated */ | ||
mkdir(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield makes_1.FS.mkdir(this.dataPath(path), options); | ||
}); | ||
this.fs.mkdir(path, options); | ||
} | ||
/** @deprecated */ | ||
writeFile(path, data, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield makes_1.FS.writeFile(this.dataPath(path), data, options); | ||
yield this.fs.writeFile(path, data, options); | ||
}); | ||
} | ||
/** @deprecated */ | ||
writeJSON(path, data, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield makes_1.FS.writeJSON(this.dataPath(path), data, options); | ||
}); | ||
this.fs.writeJSON(path, data, options); | ||
} | ||
/** @deprecated */ | ||
readJSON(path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return makes_1.FS.readJSON(this.dataPath(path)); | ||
}); | ||
return this.fs.readJSON(path); | ||
} | ||
/** @deprecated */ | ||
exists(path) { | ||
return (0, fs_1.existsSync)(this.dataPath(path)); | ||
return this.fs.exists(path); | ||
} | ||
rm(path_1) { | ||
return __awaiter(this, arguments, void 0, function* (path, options = {}) { | ||
const fullPath = this.dataPath(path); | ||
return new Promise((resolve, reject) => { | ||
(0, fs_1.rm)(fullPath, options, (err) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(undefined); | ||
}); | ||
}); | ||
/** @deprecated */ | ||
rm(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.fs.rm(path, options); | ||
}); | ||
} | ||
/** @deprecated */ | ||
readdir(path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fullPath = this.dataPath(path); | ||
return new Promise((resolve, reject) => { | ||
(0, fs_1.readdir)(fullPath, (err, files) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(files); | ||
}); | ||
}); | ||
return this.fs.readdir(path); | ||
}); | ||
} | ||
/** @deprecated */ | ||
createWriteSteam(path) { | ||
return (0, fs_1.createWriteStream)(this.dataPath(path)); | ||
return this.fs.createWriteStream(path); | ||
} | ||
/** @deprecated */ | ||
createReadStream(path) { | ||
return (0, fs_1.createReadStream)(this.dataPath(path)); | ||
return this.fs.createReadStream(path); | ||
} | ||
@@ -128,0 +91,0 @@ }; |
{ | ||
"name": "@wocker/core", | ||
"version": "1.0.19-dev.0", | ||
"version": "1.0.19-dev.1", | ||
"author": "Kris Papercut <krispcut@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Core of the Wocker", |
100976
103
2563
3