@wocker/core
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -0,1 +1,4 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { WriteFileOptions, MakeDirectoryOptions, RmOptions } from "fs"; | ||
export declare class PluginConfigService { | ||
@@ -5,2 +8,11 @@ protected readonly pluginDir: string; | ||
dataPath(...parts: string[]): string; | ||
mkdir(path: string, options?: MakeDirectoryOptions): Promise<void>; | ||
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>; | ||
exists(path: string): boolean; | ||
rm(path: string, options?: RmOptions): Promise<unknown>; | ||
readdir(path: string): Promise<string[]>; | ||
createWriteSteam(path: string): import("fs").WriteStream; | ||
createReadStream(path: string): import("fs").ReadStream; | ||
} |
@@ -37,2 +37,11 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -42,2 +51,3 @@ exports.PluginConfigService = void 0; | ||
const fs_1 = require("fs"); | ||
const makes_1 = require("../makes"); | ||
const decorators_1 = require("../decorators"); | ||
@@ -51,3 +61,3 @@ const env_1 = require("../env"); | ||
if (!this.pluginDir) { | ||
throw new Error(""); | ||
throw new Error("Plugin dir missed"); | ||
} | ||
@@ -61,2 +71,59 @@ if (!(0, fs_1.existsSync)(this.pluginDir)) { | ||
} | ||
mkdir(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield makes_1.FS.mkdir(this.dataPath(path), options); | ||
}); | ||
} | ||
writeFile(path, data, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield makes_1.FS.writeFile(this.dataPath(path), data, options); | ||
}); | ||
} | ||
writeJSON(path, data, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield makes_1.FS.writeJSON(this.dataPath(path), data, options); | ||
}); | ||
} | ||
readJSON(path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return makes_1.FS.readJSON(this.dataPath(path)); | ||
}); | ||
} | ||
exists(path) { | ||
return (0, fs_1.existsSync)(this.dataPath(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); | ||
}); | ||
}); | ||
}); | ||
} | ||
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); | ||
}); | ||
}); | ||
}); | ||
} | ||
createWriteSteam(path) { | ||
return (0, fs_1.createWriteStream)(this.dataPath(path)); | ||
} | ||
createReadStream(path) { | ||
return (0, fs_1.createReadStream)(this.dataPath(path)); | ||
} | ||
}; | ||
@@ -63,0 +130,0 @@ exports.PluginConfigService = PluginConfigService; |
{ | ||
"name": "@wocker/core", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"author": "Kris Papercut <krispcut@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Core of wocker", |
76899
1883