@wocker/core 1.0.32 → 1.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/env.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const WOCKER_VERSION = "1.0.32";
1
+ export declare const WOCKER_VERSION = "1.1.0";
2
2
  export declare const WOCKER_VERSION_KEY = "__WOCKER_VERSION__";
3
3
  export declare const WOCKER_DATA_DIR: string;
4
4
  export declare const WOCKER_DATA_DIR_KEY = "__WOCKER_DATA_DIR__";
package/lib/env.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.ALIAS_METADATA = exports.ARGS_OLD_METADATA = exports.ARGS_METADATA = exports.LISTENER_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = exports.IS_CONTROLLER_METADATA = exports.PLUGIN_DIR_KEY = exports.FILE_SYSTEM_DRIVER_KEY = exports.WOCKER_DATA_DIR_KEY = exports.WOCKER_DATA_DIR = exports.WOCKER_VERSION_KEY = exports.WOCKER_VERSION = void 0;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  const path_1 = __importDefault(require("path"));
9
- exports.WOCKER_VERSION = "1.0.32";
9
+ exports.WOCKER_VERSION = "1.1.0";
10
10
  exports.WOCKER_VERSION_KEY = "__WOCKER_VERSION__";
11
11
  exports.WOCKER_DATA_DIR = process.env.WS_DIR || path_1.default.join(os_1.default.homedir(), ".workspace");
12
12
  exports.WOCKER_DATA_DIR_KEY = "__WOCKER_DATA_DIR__";
@@ -1,4 +1,5 @@
1
1
  import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef, PresetSource } from "../types";
2
+ import { FileSystem } from "./FileSystem";
2
3
  export type AppConfigProperties = {
3
4
  debug?: boolean;
4
5
  pm?: PackageManagerType;
@@ -10,7 +11,7 @@ export type AppConfigProperties = {
10
11
  meta?: EnvConfig;
11
12
  env?: EnvConfig;
12
13
  };
13
- export declare class AppConfig {
14
+ export declare abstract class AppConfig {
14
15
  debug?: boolean;
15
16
  pm?: PackageManagerType;
16
17
  keystore?: string;
@@ -33,10 +34,41 @@ export declare class AppConfig {
33
34
  getMeta(name: string, defaultValue: string): string;
34
35
  setMeta(name: string, value: string): void;
35
36
  unsetMeta(name: string): void;
36
- getEnv(name: string): string | undefined;
37
- getEnv(name: string, defaultValue: string): string;
37
+ getEnv(key: string, byDefault?: string): string | undefined;
38
+ getEnv(key: string, byDefault: string): string;
38
39
  setEnv(name: string, value: string): void;
39
40
  unsetEnv(name: string): void;
41
+ abstract save(): void;
40
42
  toObject(): AppConfigProperties;
41
43
  toJsString(): string;
44
+ static make(fs: FileSystem): {
45
+ save(): void;
46
+ debug?: boolean;
47
+ pm?: PackageManagerType;
48
+ keystore?: string;
49
+ logLevel: "off" | "info" | "warn" | "error";
50
+ plugins: PluginRef[];
51
+ presets: PresetRef[];
52
+ projects: ProjectRef[];
53
+ meta?: EnvConfig;
54
+ env?: EnvConfig;
55
+ addPlugin(name: string, env?: PluginRef["env"]): void;
56
+ removePlugin(name: string): void;
57
+ getProject(name: string): ProjectRef | undefined;
58
+ addProject(name: string, path: string): void;
59
+ removeProject(name: string): void;
60
+ registerPreset(name: string, source: PresetSource, path?: string): void;
61
+ unregisterPreset(name: string): void;
62
+ hasMeta(name: string): boolean;
63
+ getMeta(name: string, defaultValue?: string): string | undefined;
64
+ getMeta(name: string, defaultValue: string): string;
65
+ setMeta(name: string, value: string): void;
66
+ unsetMeta(name: string): void;
67
+ getEnv(key: string, byDefault?: string): string | undefined;
68
+ getEnv(key: string, byDefault: string): string;
69
+ setEnv(name: string, value: string): void;
70
+ unsetEnv(name: string): void;
71
+ toObject(): AppConfigProperties;
72
+ toJsString(): string;
73
+ };
42
74
  }
@@ -142,11 +142,11 @@ class AppConfig {
142
142
  delete this.meta;
143
143
  }
144
144
  }
145
- getEnv(name, defaultValue) {
146
- if (!this.env || !(name in this.env)) {
147
- return defaultValue;
145
+ getEnv(key, byDefault) {
146
+ if (!this.env || !(key in this.env)) {
147
+ return byDefault;
148
148
  }
149
- return this.env[name];
149
+ return this.env[key];
150
150
  }
151
151
  setEnv(name, value) {
152
152
  if (!this.env) {
@@ -180,5 +180,52 @@ class AppConfig {
180
180
  const json = JSON.stringify(this.toObject(), null, 4);
181
181
  return `// Wocker config\nexports.config = ${json};`;
182
182
  }
183
+ static make(fs) {
184
+ let data = {};
185
+ if (fs.exists("wocker.config.js")) {
186
+ try {
187
+ const { config } = require(fs.path("wocker.config.js"));
188
+ data = config;
189
+ }
190
+ catch (err) {
191
+ // TODO: Log somehow
192
+ let json = fs.readJSON("wocker.config.json");
193
+ if (typeof json === "string") {
194
+ json = JSON.parse(json);
195
+ }
196
+ data = json;
197
+ }
198
+ }
199
+ else if (fs.exists("wocker.config.json")) {
200
+ data = fs.readJSON("wocker.config.json");
201
+ }
202
+ else if (fs.exists("wocker.json")) {
203
+ let json = fs.readJSON("wocker.json");
204
+ if (typeof json === "string") {
205
+ json = JSON.parse(json);
206
+ }
207
+ data = json;
208
+ }
209
+ else if (fs.exists("data.json")) {
210
+ data = fs.readJSON("data.json");
211
+ }
212
+ return new class extends AppConfig {
213
+ save() {
214
+ if (!fs.exists()) {
215
+ fs.mkdir("", {
216
+ recursive: true
217
+ });
218
+ }
219
+ fs.writeFile("wocker.config.js", this.toJsString());
220
+ fs.writeJSON("wocker.config.json", this.toObject()); // Backup file
221
+ if (fs.exists("data.json")) {
222
+ fs.rm("data.json");
223
+ }
224
+ if (fs.exists("wocker.json")) {
225
+ fs.rm("wocker.json");
226
+ }
227
+ }
228
+ }(data);
229
+ }
183
230
  }
184
231
  exports.AppConfig = AppConfig;
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = void 0;
4
4
  const core_1 = require("../core");
5
- const services_1 = require("../services");
5
+ // noinspection ES6PreferShortImport
6
+ const LogService_1 = require("../services/LogService");
6
7
  class Logger {
7
8
  static getLogService() {
8
9
  var _a;
@@ -10,7 +11,7 @@ class Logger {
10
11
  if (!container) {
11
12
  return;
12
13
  }
13
- return (_a = container.getProvider(services_1.LogService)) === null || _a === void 0 ? void 0 : _a.instance;
14
+ return (_a = container.getProvider(LogService_1.LogService)) === null || _a === void 0 ? void 0 : _a.instance;
14
15
  }
15
16
  static log(...data) {
16
17
  var _a;
@@ -0,0 +1,22 @@
1
+ type VersionData = {
2
+ major: number;
3
+ minor: number;
4
+ patch: number;
5
+ tag?: string;
6
+ build?: number;
7
+ };
8
+ export declare class Version {
9
+ static readonly REGEXP: RegExp;
10
+ protected static cache: Map<string, Version>;
11
+ readonly major: number;
12
+ readonly minor: number;
13
+ readonly patch: number;
14
+ readonly tag?: string;
15
+ readonly build?: number;
16
+ constructor(data: VersionData);
17
+ parts(): number[];
18
+ compare(version: string | Version): number;
19
+ static valid(version: string): boolean;
20
+ static parse(version: string): Version;
21
+ }
22
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Version = void 0;
4
+ class Version {
5
+ constructor(data) {
6
+ Object.assign(this, data);
7
+ }
8
+ parts() {
9
+ var _a;
10
+ return [
11
+ this.major,
12
+ this.minor,
13
+ this.patch,
14
+ (_a = this.build) !== null && _a !== void 0 ? _a : 0
15
+ ];
16
+ }
17
+ compare(version) {
18
+ var _a, _b;
19
+ if (typeof version === "string") {
20
+ version = Version.parse(version);
21
+ }
22
+ const a = this.parts(), b = version.parts();
23
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24
+ if (i === 3) {
25
+ if (this.tag && !version.tag)
26
+ return -1;
27
+ else if (!this.tag && version.tag)
28
+ return 1;
29
+ else if (this.tag !== version.tag)
30
+ return this.tag < version.tag ? -1 : 1;
31
+ }
32
+ const diff = ((_a = a[i]) !== null && _a !== void 0 ? _a : 0) - ((_b = b[i]) !== null && _b !== void 0 ? _b : 0);
33
+ if (diff !== 0) {
34
+ return diff > 0 ? 1 : -1;
35
+ }
36
+ }
37
+ return 0;
38
+ }
39
+ static valid(version) {
40
+ return Version.REGEXP.test(version);
41
+ }
42
+ static parse(version) {
43
+ if (!Version.cache.has(version)) {
44
+ if (!Version.REGEXP.test(version)) {
45
+ throw new RangeError("Invalid version format");
46
+ }
47
+ const [, major, minor, patch, tag, build] = Version.REGEXP.exec(version) || [];
48
+ Version.cache.set(version, new Version({
49
+ major: parseInt(major),
50
+ minor: parseInt(minor),
51
+ patch: parseInt(patch),
52
+ tag,
53
+ build: build ? parseInt(build) : undefined
54
+ }));
55
+ }
56
+ return Version.cache.get(version);
57
+ }
58
+ }
59
+ exports.Version = Version;
60
+ Version.REGEXP = /^v?(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)(?:\.(\d+))?)?/;
61
+ Version.cache = new Map();
@@ -0,0 +1,6 @@
1
+ import { VersionRule } from "./VersionRule";
2
+ export declare class VersionRange {
3
+ protected rules: VersionRule[][];
4
+ constructor(rules: VersionRule[][]);
5
+ static parse(range: string): VersionRange;
6
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VersionRange = void 0;
4
+ const VersionRule_1 = require("./VersionRule");
5
+ class VersionRange {
6
+ constructor(rules) {
7
+ this.rules = rules;
8
+ }
9
+ static parse(range) {
10
+ const rules = range.split("||").map((range) => {
11
+ return range.split(" ").map((rule) => {
12
+ return VersionRule_1.VersionRule.parse(rule);
13
+ });
14
+ });
15
+ return new VersionRange(rules);
16
+ }
17
+ }
18
+ exports.VersionRange = VersionRange;
@@ -0,0 +1,24 @@
1
+ import { Version } from "./Version";
2
+ type VersionRuleData = {
3
+ prefix?: string;
4
+ major?: number;
5
+ minor?: number;
6
+ patch?: number;
7
+ tag?: string;
8
+ build?: number;
9
+ };
10
+ export declare class VersionRule {
11
+ static readonly REGEXP: RegExp;
12
+ protected static map: Map<string, VersionRule>;
13
+ readonly prefix?: string;
14
+ readonly major?: number;
15
+ readonly minor?: number;
16
+ readonly patch?: number;
17
+ readonly tag?: string;
18
+ readonly build?: number;
19
+ constructor(data: VersionRuleData);
20
+ get version(): Version;
21
+ match(version: string | Version, withTag?: boolean): boolean;
22
+ static parse(rule: string): VersionRule;
23
+ }
24
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VersionRule = void 0;
4
+ const Version_1 = require("./Version");
5
+ class VersionRule {
6
+ constructor(data) {
7
+ Object.assign(this, data);
8
+ }
9
+ get version() {
10
+ var _a, _b, _c;
11
+ return new Version_1.Version({
12
+ major: (_a = this.major) !== null && _a !== void 0 ? _a : 0,
13
+ minor: (_b = this.minor) !== null && _b !== void 0 ? _b : 0,
14
+ patch: (_c = this.patch) !== null && _c !== void 0 ? _c : 0,
15
+ tag: this.tag,
16
+ build: this.build
17
+ });
18
+ }
19
+ match(version, withTag) {
20
+ if (typeof version === "string") {
21
+ version = Version_1.Version.parse(version);
22
+ }
23
+ if ((!withTag || this.tag) && this.tag !== version.tag) {
24
+ return false;
25
+ }
26
+ const cmp = version.compare(this.version);
27
+ switch (this.prefix) {
28
+ case ">":
29
+ return cmp > 0;
30
+ case ">=":
31
+ return cmp >= 0;
32
+ case "<":
33
+ return cmp < 0;
34
+ case "<=":
35
+ return cmp <= 0;
36
+ case "^":
37
+ return (this.major === version.major &&
38
+ cmp >= 0);
39
+ case "~":
40
+ return (this.major === version.major &&
41
+ this.minor === version.minor &&
42
+ cmp >= 0);
43
+ default:
44
+ return ((this.major === undefined || this.major === version.major) &&
45
+ (this.minor === undefined || this.minor === version.minor) &&
46
+ (this.patch === undefined || this.patch === version.patch));
47
+ }
48
+ }
49
+ static parse(rule) {
50
+ if (!VersionRule.map.has(rule)) {
51
+ if (!VersionRule.REGEXP.test(rule)) {
52
+ throw new Error("Invalid version rule");
53
+ }
54
+ const [, prefix, major, minor, patch, tag, build, onlyTag] = VersionRule.REGEXP.exec(rule) || [];
55
+ VersionRule.map.set(rule, new VersionRule({
56
+ prefix,
57
+ major: major && major !== "x" && major !== "*" ? parseInt(major) : undefined,
58
+ minor: minor && minor !== "x" ? parseInt(minor) : undefined,
59
+ patch: patch && patch !== "x" ? parseInt(patch) : undefined,
60
+ tag: tag || onlyTag,
61
+ build: build && build !== "x" ? parseInt(build) : undefined
62
+ }));
63
+ }
64
+ return VersionRule.map.get(rule);
65
+ }
66
+ }
67
+ exports.VersionRule = VersionRule;
68
+ VersionRule.REGEXP = /^(?:(\^|~|<=|>=|<|>)?(x|\d+)(?:\.(\*|x|\d+))?(?:\.(x|\d+))?(?:-([a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*)(?:\.(\d+))?)?|([a-zA-Z0-9]+(?:-[a-zAZ0-9]+)*))$/;
69
+ VersionRule.map = new Map();
@@ -4,3 +4,6 @@ export * from "./ConfigCollection";
4
4
  export * from "./FileSystem";
5
5
  export * from "./FileSystemManager";
6
6
  export * from "./Logger";
7
+ export * from "./Version";
8
+ export * from "./VersionRange";
9
+ export * from "./VersionRule";
@@ -20,3 +20,6 @@ __exportStar(require("./ConfigCollection"), exports);
20
20
  __exportStar(require("./FileSystem"), exports);
21
21
  __exportStar(require("./FileSystemManager"), exports);
22
22
  __exportStar(require("./Logger"), exports);
23
+ __exportStar(require("./Version"), exports);
24
+ __exportStar(require("./VersionRange"), exports);
25
+ __exportStar(require("./VersionRule"), exports);
@@ -1,4 +1,4 @@
1
1
  export * from "./makes/Project";
2
2
  export * from "./repositories/ProjectRepository";
3
3
  export * from "./services/ProjectService";
4
- export { PROJECT_TYPE_IMAGE, PROJECT_TYPE_DOCKERFILE, PROJECT_TYPE_COMPOSE, PROJECT_TYPE_PRESET, ProjectType, ServiceProperties } from "./types";
4
+ export { ServiceProperties } from "./types";
@@ -14,12 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.PROJECT_TYPE_PRESET = exports.PROJECT_TYPE_COMPOSE = exports.PROJECT_TYPE_DOCKERFILE = exports.PROJECT_TYPE_IMAGE = void 0;
18
17
  __exportStar(require("./makes/Project"), exports);
19
18
  __exportStar(require("./repositories/ProjectRepository"), exports);
20
19
  __exportStar(require("./services/ProjectService"), exports);
21
- var types_1 = require("./types");
22
- Object.defineProperty(exports, "PROJECT_TYPE_IMAGE", { enumerable: true, get: function () { return types_1.PROJECT_TYPE_IMAGE; } });
23
- Object.defineProperty(exports, "PROJECT_TYPE_DOCKERFILE", { enumerable: true, get: function () { return types_1.PROJECT_TYPE_DOCKERFILE; } });
24
- Object.defineProperty(exports, "PROJECT_TYPE_COMPOSE", { enumerable: true, get: function () { return types_1.PROJECT_TYPE_COMPOSE; } });
25
- Object.defineProperty(exports, "PROJECT_TYPE_PRESET", { enumerable: true, get: function () { return types_1.PROJECT_TYPE_PRESET; } });
@@ -1,5 +1,5 @@
1
- import { EnvConfig } from "../../../types";
2
- import { ServiceProperties, ProjectType, ProjectV1 } from "../types";
1
+ import { EnvConfig, ProjectType } from "../../../types";
2
+ import { ServiceProperties, ProjectV1 } from "../types";
3
3
  export declare class Project {
4
4
  /** @deprecated */
5
5
  id?: string;
@@ -1,5 +1,4 @@
1
- import { EnvConfig } from "../../../types";
2
- import { ProjectType } from "./ProjectType";
1
+ import { EnvConfig, ProjectType } from "../../../types";
3
2
  import { ServiceProperties } from "./ServiceProperties";
4
3
  export type ProjectV1 = {
5
4
  name: string;
@@ -1,3 +1,2 @@
1
- export * from "./ProjectType";
2
1
  export * from "./ProjectV1";
3
2
  export * from "./ServiceProperties";
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./ProjectType"), exports);
18
17
  __exportStar(require("./ProjectV1"), exports);
19
18
  __exportStar(require("./ServiceProperties"), exports);
@@ -1,29 +1,43 @@
1
1
  import { AppConfig } from "../makes/AppConfig";
2
- import { PresetSource, PresetRef, ProjectRef, PluginRef } from "../types";
2
+ import { ProjectRef, PluginRef, PresetRef, PresetSource } from "../types";
3
+ import { AppService } from "./AppService";
3
4
  import { AppFileSystemService } from "./AppFileSystemService";
4
5
  import { ProcessService } from "./ProcessService";
5
- type TypeMap = {
6
- [type: string]: string;
7
- };
6
+ /**
7
+ * @deprecated
8
+ */
8
9
  export declare class AppConfigService {
9
- readonly version: string;
10
- protected readonly processService: ProcessService;
10
+ protected readonly appService: AppService;
11
11
  readonly fs: AppFileSystemService;
12
- protected _pwd: string;
13
- protected _config?: AppConfig;
14
- protected readonly mapTypes: TypeMap;
15
- constructor(version: string, processService: ProcessService, fs: AppFileSystemService);
16
- get experimentalFeatures(): string[];
12
+ protected readonly processService: ProcessService;
13
+ constructor(appService: AppService, fs: AppFileSystemService, processService: ProcessService);
14
+ get config(): AppConfig;
17
15
  get debug(): boolean;
18
16
  set debug(debug: boolean);
19
- get config(): AppConfig;
20
- get presets(): PresetRef[];
17
+ get experimentalFeatures(): string[];
21
18
  get projects(): ProjectRef[];
22
19
  get plugins(): PluginRef[];
23
- /**
24
- * @deprecated
25
- */
20
+ get presets(): PresetRef[];
21
+ getConfig(): AppConfig;
22
+ getProjectTypes(): {
23
+ [type: string]: string;
24
+ };
25
+ addProject(name: string, path: string): void;
26
+ removeProject(name: string): void;
27
+ addPlugin(name: string, env?: PluginRef["env"]): void;
28
+ removePlugin(name: string): void;
29
+ registerPreset(name: string, source: PresetSource, path?: string): void;
30
+ unregisterPreset(name: string): void;
31
+ getEnv(key: string, byDefault?: string): string | undefined;
32
+ getEnv(key: string, byDefault: string): string;
33
+ setEnv(key: string, value: string): void;
34
+ unsetEnv(key: string): void;
35
+ getMeta(key: string, byDefault?: string): string | undefined;
36
+ getMeta(key: string, byDefault: string): string;
37
+ setMeta(key: string, value: string): void;
38
+ unsetMeta(key: string): void;
26
39
  isVersionGTE(version: string): boolean;
40
+ isExperimentalEnabled(key: string): boolean;
27
41
  /**
28
42
  * @deprecated
29
43
  */
@@ -32,28 +46,6 @@ export declare class AppConfigService {
32
46
  * @deprecated
33
47
  */
34
48
  setPWD(pwd: string): void;
35
- /**
36
- * @deprecated
37
- */
38
49
  dataPath(...args: string[]): string;
39
- /**
40
- * @deprecated
41
- */
42
- getConfig(): AppConfig;
43
- addProject(name: string, path: string): void;
44
- removeProject(name: string): void;
45
- registerPreset(name: string, source: PresetSource, path?: string): void;
46
- unregisterPreset(name: string): void;
47
- addPlugin(name: string, env?: PluginRef["env"]): void;
48
- removePlugin(name: string): void;
49
- setEnv(name: string, value: string): void;
50
- unsetEnv(name: string): void;
51
- getMeta(name: string, byDefault?: string): string | undefined;
52
- getMeta(name: string, byDefault: string): string;
53
- setMeta(name: string, value: string): void;
54
- unsetMeta(name: string): void;
55
- isExperimentalEnabled(key: string): boolean;
56
- getProjectTypes(): TypeMap;
57
50
  save(): void;
58
51
  }
59
- export {};
@@ -8,9 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
15
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
16
13
  };
@@ -18,193 +15,110 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
15
  exports.AppConfigService = void 0;
19
16
  const path_1 = __importDefault(require("path"));
20
17
  const decorators_1 = require("../decorators");
21
- const project_1 = require("../modules/project");
22
- const AppConfig_1 = require("../makes/AppConfig");
18
+ const AppService_1 = require("./AppService");
23
19
  const AppFileSystemService_1 = require("./AppFileSystemService");
24
20
  const ProcessService_1 = require("./ProcessService");
25
- const env_1 = require("../env");
21
+ /**
22
+ * @deprecated
23
+ */
26
24
  let AppConfigService = class AppConfigService {
27
- constructor(version, processService, fs) {
28
- this.version = version;
29
- this.processService = processService;
25
+ constructor(appService, fs, processService) {
26
+ this.appService = appService;
30
27
  this.fs = fs;
31
- this.mapTypes = {
32
- [project_1.PROJECT_TYPE_IMAGE]: "Image",
33
- [project_1.PROJECT_TYPE_PRESET]: "Preset",
34
- [project_1.PROJECT_TYPE_DOCKERFILE]: "Dockerfile"
35
- };
36
- this._pwd = (process.cwd() || process.env.PWD);
28
+ this.processService = processService;
37
29
  }
38
- get experimentalFeatures() {
39
- return [
40
- "projectComposeType",
41
- "buildKit",
42
- "dns"
43
- ];
30
+ get config() {
31
+ return this.appService.config;
44
32
  }
45
33
  get debug() {
46
- return this.config.debug || false;
34
+ return this.appService.debug;
47
35
  }
48
36
  set debug(debug) {
49
- this.config.debug = debug;
50
- }
51
- get config() {
52
- if (!this._config) {
53
- let data = {};
54
- if (this.fs.exists("wocker.config.js")) {
55
- try {
56
- const { config } = require(this.fs.path("wocker.config.js"));
57
- data = config;
58
- }
59
- catch (err) {
60
- // TODO: Log somehow
61
- // this.logService.error(err);
62
- if (this.fs.exists("wocker.config.json")) {
63
- let json = this.fs.readJSON("wocker.config.json");
64
- if (typeof json === "string") {
65
- json = JSON.parse(json);
66
- }
67
- data = json;
68
- }
69
- }
70
- }
71
- else if (this.fs.exists("wocker.config.json")) {
72
- data = this.fs.readJSON("wocker.config.json");
73
- }
74
- else if (this.fs.exists("wocker.json")) {
75
- let json = this.fs.readJSON("wocker.json");
76
- if (typeof json === "string") {
77
- json = JSON.parse(json);
78
- }
79
- data = json;
80
- }
81
- else if (this.fs.exists("data.json")) {
82
- data = this.fs.readJSON("data.json");
83
- }
84
- else if (!this.fs.exists()) {
85
- this.fs.mkdir("", {
86
- recursive: true
87
- });
88
- }
89
- this._config = new AppConfig_1.AppConfig(data);
90
- }
91
- return this._config;
37
+ this.appService.debug = debug;
92
38
  }
93
- get presets() {
94
- return this.config.presets;
39
+ get experimentalFeatures() {
40
+ return this.appService.experimentalFeatures;
95
41
  }
96
42
  get projects() {
97
- return this.config.projects;
43
+ return this.appService.projects;
98
44
  }
99
45
  get plugins() {
100
- return this.config.plugins;
46
+ return this.appService.plugins;
101
47
  }
102
- /**
103
- * @deprecated
104
- */
105
- isVersionGTE(version) {
106
- const current = this.version.split(".").map(Number);
107
- const compare = version.split(".").map(Number);
108
- for (let i = 0; i < 3; i++) {
109
- if (current[i] > compare[i]) {
110
- return true;
111
- }
112
- else if (current[i] < compare[i]) {
113
- return false;
114
- }
115
- }
116
- return true;
117
- }
118
- /**
119
- * @deprecated
120
- */
121
- pwd(...parts) {
122
- return this.processService.pwd(path_1.default.join(...parts));
123
- }
124
- /**
125
- * @deprecated
126
- */
127
- setPWD(pwd) {
128
- this.processService.chdir(pwd);
129
- }
130
- /**
131
- * @deprecated
132
- */
133
- dataPath(...args) {
134
- return this.fs.path(...args);
48
+ get presets() {
49
+ return this.appService.presets;
135
50
  }
136
- /**
137
- * @deprecated
138
- */
139
51
  getConfig() {
140
52
  return this.config;
141
53
  }
54
+ getProjectTypes() {
55
+ return this.appService.getProjectTypes();
56
+ }
142
57
  addProject(name, path) {
143
- this.config.addProject(name, path);
58
+ this.appService.addProject(name, path);
144
59
  }
145
60
  removeProject(name) {
146
- this.config.removeProject(name);
147
- this.save();
61
+ this.appService.removeProject(name);
62
+ }
63
+ addPlugin(name, env) {
64
+ this.appService.addPlugin(name, env);
65
+ }
66
+ removePlugin(name) {
67
+ this.appService.removePlugin(name);
148
68
  }
149
69
  registerPreset(name, source, path) {
150
- this.config.registerPreset(name, source, path);
151
- this.save();
70
+ this.appService.registerPreset(name, source, path);
152
71
  }
153
72
  unregisterPreset(name) {
154
- this.config.unregisterPreset(name);
155
- this.save();
73
+ this.appService.unregisterPreset(name);
156
74
  }
157
- addPlugin(name, env) {
158
- this.config.addPlugin(name, env);
75
+ getEnv(key, byDefault) {
76
+ return this.appService.getEnv(key, byDefault);
159
77
  }
160
- removePlugin(name) {
161
- this.config.removePlugin(name);
78
+ setEnv(key, value) {
79
+ this.appService.setEnv(key, value);
162
80
  }
163
- setEnv(name, value) {
164
- this.config.setEnv(name, value);
81
+ unsetEnv(key) {
82
+ this.appService.unsetEnv(key);
165
83
  }
166
- unsetEnv(name) {
167
- this.config.unsetEnv(name);
84
+ getMeta(key, byDefault) {
85
+ return this.appService.getMeta(key, byDefault);
168
86
  }
169
- getMeta(name, byDefault) {
170
- return this.config.getMeta(name, byDefault);
87
+ setMeta(key, value) {
88
+ this.appService.setMeta(key, value);
171
89
  }
172
- setMeta(name, value) {
173
- this.config.setMeta(name, value);
90
+ unsetMeta(key) {
91
+ this.appService.unsetMeta(key);
174
92
  }
175
- unsetMeta(name) {
176
- this.config.unsetMeta(name);
93
+ isVersionGTE(version) {
94
+ return this.appService.isVersionGTE(version);
177
95
  }
178
96
  isExperimentalEnabled(key) {
179
- return this.config.getMeta(`experimental.${key}`) === "enabled";
97
+ return this.appService.isExperimentalEnabled(key);
180
98
  }
181
- getProjectTypes() {
182
- if (this.isExperimentalEnabled("projectComposeType")) {
183
- return Object.assign(Object.assign({}, this.mapTypes), { [project_1.PROJECT_TYPE_COMPOSE]: "Docker compose" });
184
- }
185
- return this.mapTypes;
99
+ /**
100
+ * @deprecated
101
+ */
102
+ pwd(...parts) {
103
+ return this.processService.pwd(path_1.default.join(...parts));
104
+ }
105
+ /**
106
+ * @deprecated
107
+ */
108
+ setPWD(pwd) {
109
+ this.processService.chdir(pwd);
110
+ }
111
+ dataPath(...args) {
112
+ return this.appService.fs.path(path_1.default.join(...args));
186
113
  }
187
114
  save() {
188
- const fs = this.fs;
189
- if (!fs.exists()) {
190
- fs.mkdir("", {
191
- recursive: true
192
- });
193
- }
194
- fs.writeFile("wocker.config.js", this.config.toJsString());
195
- fs.writeJSON("wocker.config.json", this.config.toObject()); // Backup file
196
- if (fs.exists("data.json")) {
197
- fs.rm("data.json");
198
- }
199
- if (fs.exists("wocker.json")) {
200
- fs.rm("wocker.json");
201
- }
115
+ this.config.save();
202
116
  }
203
117
  };
204
118
  exports.AppConfigService = AppConfigService;
205
119
  exports.AppConfigService = AppConfigService = __decorate([
206
120
  (0, decorators_1.Injectable)("APP_CONFIG"),
207
- __param(0, (0, decorators_1.Inject)(env_1.WOCKER_VERSION_KEY)),
208
- __metadata("design:paramtypes", [String, ProcessService_1.ProcessService,
209
- AppFileSystemService_1.AppFileSystemService])
121
+ __metadata("design:paramtypes", [AppService_1.AppService,
122
+ AppFileSystemService_1.AppFileSystemService,
123
+ ProcessService_1.ProcessService])
210
124
  ], AppConfigService);
@@ -1,4 +1,4 @@
1
- import { FileSystemDriver } from "../types/FileSystemDriver";
1
+ import { FileSystemDriver } from "../types";
2
2
  import { FileSystem } from "../makes/FileSystem";
3
3
  export declare class AppFileSystemService extends FileSystem {
4
4
  constructor(dataDir: string, fsDriver: FileSystemDriver);
@@ -1,20 +1,42 @@
1
- import { AppConfigService } from "./AppConfigService";
1
+ import { AppConfig } from "../makes/AppConfig";
2
2
  import { AppFileSystemService } from "./AppFileSystemService";
3
- import { ProjectRef } from "../types";
3
+ import { ProcessService } from "./ProcessService";
4
+ import { ProjectRef, PluginRef, PresetRef, PresetSource } from "../types";
4
5
  type TypeMap = {
5
6
  [type: string]: string;
6
7
  };
7
8
  export declare class AppService {
8
9
  readonly version: string;
9
- protected readonly appConfigService: AppConfigService;
10
- protected readonly fs: AppFileSystemService;
11
- constructor(version: string, appConfigService: AppConfigService, fs: AppFileSystemService);
10
+ protected readonly processService: ProcessService;
11
+ readonly fs: AppFileSystemService;
12
+ protected _config?: AppConfig;
13
+ protected readonly mapTypes: TypeMap;
14
+ constructor(version: string, processService: ProcessService, fs: AppFileSystemService);
15
+ get config(): AppConfig;
16
+ get debug(): boolean;
17
+ set debug(debug: boolean);
12
18
  get projects(): ProjectRef[];
19
+ get plugins(): PluginRef[];
20
+ get presets(): PresetRef[];
21
+ isVersionGT(version: string): boolean;
13
22
  isVersionGTE(version: string): boolean;
14
- get experimentalFeatures(): string[];
15
23
  getProjectTypes(): TypeMap;
16
24
  addProject(name: string, path: string): void;
17
- getMeta(name: string, byDefault?: string): string | undefined;
18
- getMeta(name: string, byDefault: string): string;
25
+ removeProject(name: string): void;
26
+ addPlugin(name: string, env?: PluginRef["env"]): void;
27
+ removePlugin(name: string): void;
28
+ registerPreset(name: string, source: PresetSource, path?: string): void;
29
+ unregisterPreset(name: string): void;
30
+ getEnv(key: string, byDefault?: string): string | undefined;
31
+ getEnv(key: string, byDefault: string): string;
32
+ setEnv(key: string, value: string): void;
33
+ unsetEnv(key: string): void;
34
+ getMeta(key: string, byDefault?: string): string | undefined;
35
+ getMeta(key: string, byDefault: string): string;
36
+ setMeta(key: string, value: string): void;
37
+ unsetMeta(key: string): void;
38
+ get experimentalFeatures(): string[];
39
+ isExperimentalEnabled(key: string): boolean;
40
+ save(): void;
19
41
  }
20
42
  export {};
@@ -14,49 +14,120 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AppService = void 0;
16
16
  const decorators_1 = require("../decorators");
17
- const AppConfigService_1 = require("./AppConfigService");
17
+ const Version_1 = require("../makes/Version");
18
+ const AppConfig_1 = require("../makes/AppConfig");
18
19
  const AppFileSystemService_1 = require("./AppFileSystemService");
20
+ const ProcessService_1 = require("./ProcessService");
21
+ const types_1 = require("../types");
19
22
  const env_1 = require("../env");
20
23
  let AppService = class AppService {
21
- constructor(version, appConfigService, fs) {
24
+ constructor(version, processService, fs) {
22
25
  this.version = version;
23
- this.appConfigService = appConfigService;
26
+ this.processService = processService;
24
27
  this.fs = fs;
28
+ this.mapTypes = {
29
+ [types_1.ProjectType.IMAGE]: "Image",
30
+ [types_1.ProjectType.PRESET]: "Preset",
31
+ [types_1.ProjectType.DOCKERFILE]: "Dockerfile"
32
+ };
33
+ }
34
+ get config() {
35
+ if (!this._config) {
36
+ this._config = AppConfig_1.AppConfig.make(this.fs);
37
+ }
38
+ return this._config;
39
+ }
40
+ get debug() {
41
+ return this.config.debug || false;
42
+ }
43
+ set debug(debug) {
44
+ this.config.debug = debug;
25
45
  }
26
46
  get projects() {
27
- return this.appConfigService.projects;
47
+ return this.config.projects;
28
48
  }
29
- isVersionGTE(version) {
30
- const current = this.version.split(".").map(Number);
31
- const compare = version.split(".").map(Number);
32
- for (let i = 0; i < 3; i++) {
33
- if (current[i] > compare[i]) {
34
- return true;
35
- }
36
- else if (current[i] < compare[i]) {
37
- return false;
38
- }
39
- }
40
- return true;
49
+ get plugins() {
50
+ return this.config.plugins;
41
51
  }
42
- get experimentalFeatures() {
43
- return this.appConfigService.experimentalFeatures;
52
+ get presets() {
53
+ return this.config.presets;
54
+ }
55
+ isVersionGT(version) {
56
+ return Version_1.Version.parse(this.version).compare(version) > 0;
57
+ }
58
+ isVersionGTE(version) {
59
+ return Version_1.Version.parse(this.version).compare(version) >= 0;
44
60
  }
45
61
  getProjectTypes() {
46
- return this.appConfigService.getProjectTypes();
62
+ if (this.isExperimentalEnabled("projectComposeType")) {
63
+ return Object.assign(Object.assign({}, this.mapTypes), { [types_1.ProjectType.COMPOSE]: "Docker compose" });
64
+ }
65
+ return this.mapTypes;
47
66
  }
48
67
  addProject(name, path) {
49
- this.appConfigService.addProject(name, path);
50
- this.appConfigService.save();
68
+ this.config.addProject(name, path);
69
+ this.config.save();
70
+ }
71
+ removeProject(name) {
72
+ this.config.removeProject(name);
73
+ this.config.save();
74
+ }
75
+ addPlugin(name, env) {
76
+ this.config.addPlugin(name, env);
77
+ this.config.save();
78
+ }
79
+ removePlugin(name) {
80
+ this.config.removePlugin(name);
81
+ this.config.save();
82
+ }
83
+ registerPreset(name, source, path) {
84
+ this.config.registerPreset(name, source, path);
85
+ this.config.save();
86
+ }
87
+ unregisterPreset(name) {
88
+ this.config.unregisterPreset(name);
89
+ this.config.save();
90
+ }
91
+ getEnv(key, byDefault) {
92
+ return this.config.getEnv(key, byDefault);
93
+ }
94
+ setEnv(key, value) {
95
+ this.config.setEnv(key, value);
96
+ this.config.save();
97
+ }
98
+ unsetEnv(key) {
99
+ this.config.unsetEnv(key);
100
+ this.config.save();
101
+ }
102
+ getMeta(key, byDefault) {
103
+ return this.config.getMeta(key, byDefault);
104
+ }
105
+ setMeta(key, value) {
106
+ this.config.setMeta(key, value);
107
+ this.config.save();
108
+ }
109
+ unsetMeta(key) {
110
+ this.config.unsetMeta(key);
111
+ this.config.save();
112
+ }
113
+ get experimentalFeatures() {
114
+ return [
115
+ "projectComposeType",
116
+ "buildKit",
117
+ "dns"
118
+ ];
119
+ }
120
+ isExperimentalEnabled(key) {
121
+ return this.config.getMeta(`experimental.${key}`) === "enabled";
51
122
  }
52
- getMeta(name, byDefault) {
53
- return this.appConfigService.getMeta(name, byDefault);
123
+ save() {
124
+ this.config.save();
54
125
  }
55
126
  };
56
127
  exports.AppService = AppService;
57
128
  exports.AppService = AppService = __decorate([
58
129
  (0, decorators_1.Injectable)("APP_SERVICE"),
59
130
  __param(0, (0, decorators_1.Inject)(env_1.WOCKER_VERSION_KEY)),
60
- __metadata("design:paramtypes", [String, AppConfigService_1.AppConfigService,
131
+ __metadata("design:paramtypes", [String, ProcessService_1.ProcessService,
61
132
  AppFileSystemService_1.AppFileSystemService])
62
133
  ], AppService);
@@ -1,9 +1,9 @@
1
- import { AppConfigService } from "./AppConfigService";
1
+ import { AppService } from "./AppService";
2
2
  import { AppFileSystemService } from "./AppFileSystemService";
3
3
  export declare class LogService {
4
- protected readonly appConfigService: AppConfigService;
4
+ protected readonly appService: AppService;
5
5
  protected readonly fs: AppFileSystemService;
6
- constructor(appConfigService: AppConfigService, fs: AppFileSystemService);
6
+ constructor(appService: AppService, fs: AppFileSystemService);
7
7
  protected get logName(): string;
8
8
  protected _log(type: string, ...data: any[]): void;
9
9
  debug(...data: any[]): void;
@@ -12,18 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.LogService = void 0;
13
13
  const format_1 = require("date-fns/format");
14
14
  const decorators_1 = require("../decorators");
15
- const AppConfigService_1 = require("./AppConfigService");
15
+ const AppService_1 = require("./AppService");
16
16
  const AppFileSystemService_1 = require("./AppFileSystemService");
17
17
  let LogService = class LogService {
18
- constructor(appConfigService, fs) {
19
- this.appConfigService = appConfigService;
18
+ constructor(appService, fs) {
19
+ this.appService = appService;
20
20
  this.fs = fs;
21
21
  }
22
22
  get logName() {
23
23
  return "ws.log";
24
24
  }
25
25
  _log(type, ...data) {
26
- if (type === "debug" && !this.appConfigService.config.debug) {
26
+ if (type === "debug" && !this.appService.debug) {
27
27
  return;
28
28
  }
29
29
  const time = (0, format_1.format)(new Date(), "yyyy-MM-dd HH:mm:ss");
@@ -57,6 +57,6 @@ let LogService = class LogService {
57
57
  exports.LogService = LogService;
58
58
  exports.LogService = LogService = __decorate([
59
59
  (0, decorators_1.Injectable)("LOG_SERVICE"),
60
- __metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
60
+ __metadata("design:paramtypes", [AppService_1.AppService,
61
61
  AppFileSystemService_1.AppFileSystemService])
62
62
  ], LogService);
@@ -0,0 +1,19 @@
1
+ declare enum ProjectTypeEnum {
2
+ DOCKERFILE = "dockerfile",
3
+ IMAGE = "image",
4
+ COMPOSE = "compose",
5
+ PRESET = "preset"
6
+ }
7
+ /** @deprecated */
8
+ export declare const PROJECT_TYPE_DOCKERFILE = ProjectTypeEnum.DOCKERFILE;
9
+ /** @deprecated */
10
+ export declare const PROJECT_TYPE_IMAGE = ProjectTypeEnum.IMAGE;
11
+ /** @deprecated */
12
+ export declare const PROJECT_TYPE_PRESET = ProjectTypeEnum.PRESET;
13
+ /** @deprecated */
14
+ export declare const PROJECT_TYPE_COMPOSE = ProjectTypeEnum.COMPOSE;
15
+ export type ProjectType = ProjectTypeEnum;
16
+ export declare const ProjectType: typeof ProjectTypeEnum & {
17
+ values(): ProjectTypeEnum[];
18
+ };
19
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectType = exports.PROJECT_TYPE_COMPOSE = exports.PROJECT_TYPE_PRESET = exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = void 0;
4
+ var ProjectTypeEnum;
5
+ (function (ProjectTypeEnum) {
6
+ ProjectTypeEnum["DOCKERFILE"] = "dockerfile";
7
+ ProjectTypeEnum["IMAGE"] = "image";
8
+ ProjectTypeEnum["COMPOSE"] = "compose";
9
+ ProjectTypeEnum["PRESET"] = "preset";
10
+ })(ProjectTypeEnum || (ProjectTypeEnum = {}));
11
+ /** @deprecated */
12
+ exports.PROJECT_TYPE_DOCKERFILE = ProjectTypeEnum.DOCKERFILE;
13
+ /** @deprecated */
14
+ exports.PROJECT_TYPE_IMAGE = ProjectTypeEnum.IMAGE;
15
+ /** @deprecated */
16
+ exports.PROJECT_TYPE_PRESET = ProjectTypeEnum.PRESET;
17
+ /** @deprecated */
18
+ exports.PROJECT_TYPE_COMPOSE = ProjectTypeEnum.COMPOSE;
19
+ exports.ProjectType = Object.assign({}, ProjectTypeEnum, {
20
+ values() {
21
+ return Object.values(ProjectTypeEnum);
22
+ }
23
+ });
@@ -11,6 +11,7 @@ export * from "./PresetRef";
11
11
  export * from "./PresetSource";
12
12
  export * from "./ProviderType";
13
13
  export * from "./ProjectRef";
14
+ export * from "./ProjectType";
14
15
  export * from "./Type";
15
16
  export * from "./Volume";
16
17
  export type {
@@ -27,5 +27,6 @@ __exportStar(require("./PresetRef"), exports);
27
27
  __exportStar(require("./PresetSource"), exports);
28
28
  __exportStar(require("./ProviderType"), exports);
29
29
  __exportStar(require("./ProjectRef"), exports);
30
+ __exportStar(require("./ProjectType"), exports);
30
31
  __exportStar(require("./Type"), exports);
31
32
  __exportStar(require("./Volume"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
3
  "type": "commonjs",
4
- "version": "1.0.32",
4
+ "version": "1.1.0-beta.0",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Core of the Wocker",
7
7
  "license": "MIT",
@@ -39,6 +39,7 @@
39
39
  "@types/dockerode": "^3.3.23",
40
40
  "@types/jest": "^30.0.0",
41
41
  "@types/node": "^24.5.2",
42
+ "@wocker/testing": "^1.0.7",
42
43
  "jest": "^30.1.3",
43
44
  "make-coverage-badge": "^1.2.0",
44
45
  "memfs": "^4.17.1",
@@ -1,5 +0,0 @@
1
- export declare const PROJECT_TYPE_DOCKERFILE = "dockerfile";
2
- export declare const PROJECT_TYPE_IMAGE = "image";
3
- export declare const PROJECT_TYPE_PRESET = "preset";
4
- export declare const PROJECT_TYPE_COMPOSE = "compose";
5
- export type ProjectType = typeof PROJECT_TYPE_DOCKERFILE | typeof PROJECT_TYPE_IMAGE | typeof PROJECT_TYPE_PRESET | typeof PROJECT_TYPE_COMPOSE;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROJECT_TYPE_COMPOSE = exports.PROJECT_TYPE_PRESET = exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = void 0;
4
- exports.PROJECT_TYPE_DOCKERFILE = "dockerfile";
5
- exports.PROJECT_TYPE_IMAGE = "image";
6
- exports.PROJECT_TYPE_PRESET = "preset";
7
- exports.PROJECT_TYPE_COMPOSE = "compose";