@wocker/core
Advanced tools
Comparing version 1.0.14 to 1.0.15
@@ -7,6 +7,6 @@ "use strict"; | ||
const Description = (description) => { | ||
return (target, propertyKey, descriptor) => { | ||
Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, descriptor); | ||
return (_target, _propertyKey, descriptor) => { | ||
Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, descriptor.value); | ||
}; | ||
}; | ||
exports.Description = Description; |
@@ -0,1 +1,2 @@ | ||
import "reflect-metadata"; | ||
import { Option as O } from "@kearisp/cli"; | ||
@@ -2,0 +3,0 @@ type Params = Omit<O, "name">; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Option = void 0; | ||
require("reflect-metadata"); | ||
const env_1 = require("../env"); | ||
@@ -5,0 +6,0 @@ const Option = (name, params) => { |
@@ -1,36 +0,9 @@ | ||
import { EnvConfig, PickProperties } from "../types"; | ||
import { PresetType } from "./Preset"; | ||
export type ConfigProperties = Omit<PickProperties<Config>, "logLevel"> & { | ||
logLevel?: Config["logLevel"]; | ||
}; | ||
export declare abstract class Config { | ||
debug?: boolean; | ||
logLevel: "off" | "info" | "warn" | "error"; | ||
plugins: string[]; | ||
presets?: { | ||
name: string; | ||
source: PresetType; | ||
path?: string; | ||
}[]; | ||
projects: { | ||
id: string; | ||
name?: string; | ||
src: string; | ||
}[]; | ||
meta?: EnvConfig; | ||
env?: EnvConfig; | ||
import { AppConfig, AppConfigProperties } from "./AppConfig"; | ||
export type ConfigProperties = AppConfigProperties; | ||
/** | ||
* @deprecated | ||
* @see AppConfig | ||
*/ | ||
export declare abstract class Config extends AppConfig { | ||
protected constructor(data: ConfigProperties); | ||
addPlugin(plugin: string): void; | ||
removePlugin(removePlugin: string): void; | ||
setProject(id: string, path: string): void; | ||
registerPreset(name: string, source: PresetType, path?: string): void; | ||
unregisterPreset(name: string): void; | ||
getMeta(name: string, defaultValue: string): string; | ||
setMeta(name: string, value: string): void; | ||
unsetMeta(name: string): void; | ||
getEnv(name: string, defaultValue: string): string; | ||
setEnv(name: string, value: string): void; | ||
unsetEnv(name: string): void; | ||
abstract save(): Promise<void>; | ||
toJson(): ConfigProperties; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Config = void 0; | ||
class Config { | ||
const AppConfig_1 = require("./AppConfig"); | ||
/* istanbul ignore next */ | ||
/** | ||
* @deprecated | ||
* @see AppConfig | ||
*/ | ||
class Config extends AppConfig_1.AppConfig { | ||
constructor(data) { | ||
this.logLevel = "off"; | ||
this.plugins = []; | ||
this.presets = []; | ||
this.projects = []; | ||
Object.assign(this, data); | ||
super(data); | ||
} | ||
addPlugin(plugin) { | ||
if (!this.plugins) { | ||
this.plugins = []; | ||
} | ||
if (this.plugins.includes(plugin)) { | ||
return; | ||
} | ||
this.plugins.push(plugin); | ||
} | ||
removePlugin(removePlugin) { | ||
this.plugins = this.plugins.filter((plugin) => plugin !== removePlugin); | ||
} | ||
setProject(id, path) { | ||
this.projects = [ | ||
...this.projects.filter((project) => { | ||
return project.id !== id && project.src !== path; | ||
}), | ||
{ | ||
id, | ||
src: path | ||
} | ||
]; | ||
} | ||
registerPreset(name, source, path) { | ||
if (!this.presets) { | ||
this.presets = []; | ||
} | ||
const preset = this.presets.find((preset) => { | ||
return preset.name === name; | ||
}); | ||
if (!preset) { | ||
this.presets.push({ | ||
name, | ||
source, | ||
path | ||
}); | ||
} | ||
} | ||
unregisterPreset(name) { | ||
if (!this.presets) { | ||
return; | ||
} | ||
this.presets = this.presets.filter((preset) => { | ||
return preset.name !== name; | ||
}); | ||
if (this.presets.length === 0) { | ||
delete this.presets; | ||
} | ||
} | ||
getMeta(name, defaultValue) { | ||
if (!this.meta || !(name in this.meta)) { | ||
return defaultValue; | ||
} | ||
return this.meta[name]; | ||
} | ||
setMeta(name, value) { | ||
if (!this.meta) { | ||
this.meta = {}; | ||
} | ||
this.meta[name] = value; | ||
} | ||
unsetMeta(name) { | ||
if (!this.meta || !(name in this.meta)) { | ||
return; | ||
} | ||
delete this.meta[name]; | ||
if (Object.keys(this.meta).length === 0) { | ||
delete this.meta; | ||
} | ||
} | ||
getEnv(name, defaultValue) { | ||
if (!this.env || !(name in this.env)) { | ||
return defaultValue; | ||
} | ||
return this.env[name]; | ||
} | ||
setEnv(name, value) { | ||
if (!this.env) { | ||
this.env = {}; | ||
} | ||
this.env[name] = value; | ||
} | ||
unsetEnv(name) { | ||
if (!this.env || !(name in this.env)) { | ||
return; | ||
} | ||
delete this.env[name]; | ||
if (Object.keys(this.env).length === 0) { | ||
delete this.env; | ||
} | ||
} | ||
// noinspection JSUnusedGlobalSymbols | ||
toJson() { | ||
return { | ||
debug: this.debug, | ||
logLevel: this.logLevel, | ||
plugins: this.plugins, | ||
projects: this.projects, | ||
presets: (this.presets || []).length > 0 ? this.presets : undefined, | ||
env: this.env, | ||
meta: this.meta | ||
}; | ||
} | ||
} | ||
exports.Config = Config; |
@@ -1,3 +0,3 @@ | ||
import * as fs from "fs"; | ||
type ReaddirOptions = fs.ObjectEncodingOptions & { | ||
import FS, { RmOptions, Stats, WriteFileOptions } from "fs"; | ||
type ReaddirOptions = FS.ObjectEncodingOptions & { | ||
recursive?: boolean | undefined; | ||
@@ -9,8 +9,12 @@ }; | ||
path(...parts: string[]): string; | ||
basename(...parts: string[]): string; | ||
exists(...parts: string[]): boolean; | ||
stat(...parts: string[]): fs.Stats; | ||
mkdir(path: string, options?: fs.MakeDirectoryOptions): void; | ||
stat(...parts: string[]): Stats; | ||
mkdir(path: string, options?: FS.MakeDirectoryOptions): void; | ||
readdir(...parts: string[]): Promise<unknown>; | ||
readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>; | ||
readJSON(...paths: string[]): Promise<any>; | ||
writeJSON(path: string, data: any, options?: WriteFileOptions): Promise<void>; | ||
rm(path: string, options?: RmOptions): Promise<void>; | ||
} | ||
export {}; |
@@ -34,5 +34,9 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FileSystem = void 0; | ||
const fs = __importStar(require("fs")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const fs_2 = __importDefault(require("fs")); | ||
const Path = __importStar(require("path")); | ||
@@ -46,13 +50,16 @@ class FileSystem { | ||
} | ||
basename(...parts) { | ||
return Path.basename(this.path(...parts)); | ||
} | ||
exists(...parts) { | ||
const fullPath = this.path(...parts); | ||
return fs.existsSync(fullPath); | ||
return fs_2.default.existsSync(fullPath); | ||
} | ||
stat(...parts) { | ||
const fullPath = this.path(...parts); | ||
return fs.statSync(fullPath); | ||
return fs_2.default.statSync(fullPath); | ||
} | ||
mkdir(path, options) { | ||
const fullPath = this.path(path); | ||
fs.mkdirSync(fullPath, options); | ||
fs_2.default.mkdirSync(fullPath, options); | ||
} | ||
@@ -63,3 +70,3 @@ readdir(...parts) { | ||
return new Promise((resolve, reject) => { | ||
fs.readdir(fullPath, (err, files) => { | ||
fs_2.default.readdir(fullPath, (err, files) => { | ||
if (err) { | ||
@@ -78,3 +85,3 @@ reject(err); | ||
return new Promise((resolve, reject) => { | ||
fs.readdir(fullPath, options, (err, files) => { | ||
fs_2.default.readdir(fullPath, options, (err, files) => { | ||
if (err) { | ||
@@ -93,3 +100,59 @@ reject(err); | ||
} | ||
readJSON(...paths) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield new Promise((resolve, reject) => { | ||
const filePath = this.path(...paths); | ||
fs_2.default.readFile(filePath, (err, data) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
return JSON.parse(res.toString()); | ||
}); | ||
} | ||
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); | ||
} | ||
}); | ||
}); | ||
} | ||
rm(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fullPath = this.path(path); | ||
return new Promise((resolve, reject) => { | ||
const callback = (err) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(undefined); | ||
}; | ||
if (options) { | ||
fs_1.default.rm(fullPath, options, callback); | ||
} | ||
else { | ||
fs_1.default.rm(fullPath, callback); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
exports.FileSystem = FileSystem; |
@@ -0,1 +1,2 @@ | ||
export * from "./AppConfig"; | ||
export * from "./Config"; | ||
@@ -2,0 +3,0 @@ export * from "./Container"; |
@@ -17,2 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./AppConfig"), exports); | ||
__exportStar(require("./Config"), exports); | ||
@@ -19,0 +20,0 @@ __exportStar(require("./Container"), exports); |
@@ -29,2 +29,4 @@ import { PickProperties } from "../types"; | ||
version: string; | ||
type?: string; | ||
image?: string; | ||
dockerfile?: string; | ||
@@ -31,0 +33,0 @@ buildArgsOptions?: { |
@@ -7,5 +7,7 @@ "use strict"; | ||
this.name = data.name; | ||
this.version = data.version; | ||
this.type = data.type; | ||
this.source = data.source; | ||
this.path = data.path; | ||
this.version = data.version; | ||
this.image = data.image; | ||
this.dockerfile = data.dockerfile; | ||
@@ -21,4 +23,6 @@ this.buildArgsOptions = data.buildArgsOptions; | ||
name: this.name, | ||
version: this.version, | ||
type: this.type, | ||
source: this.source, | ||
version: this.version, | ||
image: this.image, | ||
dockerfile: this.dockerfile, | ||
@@ -25,0 +29,0 @@ buildArgsOptions: this.buildArgsOptions, |
import { PickProperties, EnvConfig } from "../types"; | ||
export type ProjectType = typeof PROJECT_TYPE_DOCKERFILE | typeof PROJECT_TYPE_IMAGE | typeof PROJECT_TYPE_PRESET; | ||
export type ProjectProperties = Omit<PickProperties<Project>, "containerName" | "domains">; | ||
@@ -3,0 +4,0 @@ export declare abstract class Project { |
@@ -158,5 +158,16 @@ "use strict"; | ||
volumeUnmount(...volumes) { | ||
this.volumes = (this.volumes || []).filter((mounted) => { | ||
return !volumes.includes(mounted); | ||
if (!this.volumes || volumes.length === 0) { | ||
return; | ||
} | ||
const [volume, ...restVolumes] = volumes; | ||
const v = (0, volumeParse_1.volumeParse)(volume); | ||
this.volumes = this.volumes.filter((mounted) => { | ||
const m = (0, volumeParse_1.volumeParse)(mounted); | ||
return v.source !== m.source && v.destination !== m.destination; | ||
}); | ||
if (this.volumes.length === 0) { | ||
delete this.volumes; | ||
return; | ||
} | ||
this.volumeUnmount(...restVolumes); | ||
} | ||
@@ -163,0 +174,0 @@ toJSON() { |
import { Config } from "../makes"; | ||
type TypeMap = { | ||
[type: string]: string; | ||
}; | ||
declare abstract class AppConfigService { | ||
protected config?: Config; | ||
abstract getPWD(): string; | ||
abstract setPWD(pwd: string): void; | ||
abstract dataPath(...args: string[]): string; | ||
abstract pluginsPath(...args: string[]): string; | ||
abstract getPWD(): string; | ||
abstract setPWD(pwd: string): void; | ||
abstract getProjectTypes(): TypeMap; | ||
abstract registerProjectType(name: string, title?: string): void; | ||
getConfig(): Promise<Config>; | ||
protected abstract loadConfig(): Promise<Config>; | ||
getConfig(): Promise<Config>; | ||
} | ||
export { AppConfigService }; |
@@ -1,4 +0,3 @@ | ||
export * from "./AppConfig"; | ||
export * from "./EnvConfig"; | ||
export * from "./PickProperties"; | ||
export * from "./Volume"; |
@@ -17,5 +17,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./AppConfig"), exports); | ||
__exportStar(require("./EnvConfig"), exports); | ||
__exportStar(require("./PickProperties"), exports); | ||
__exportStar(require("./Volume"), exports); |
{ | ||
"name": "@wocker/core", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"author": "Kris Papercut <krispcut@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Core of the Wocker", |
97623
2461
5