@wocker/core 1.1.0-beta.0 → 1.1.0-beta.2

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.
Files changed (35) hide show
  1. package/lib/core/ApplicationContext.d.ts +4 -2
  2. package/lib/core/ApplicationContext.js +2 -1
  3. package/lib/core/Factory.d.ts +2 -1
  4. package/lib/core/Factory.js +3 -3
  5. package/lib/core/Scanner.js +1 -1
  6. package/lib/makes/AppConfig.d.ts +10 -39
  7. package/lib/makes/AppConfig.js +0 -2
  8. package/lib/modules/project/index.d.ts +1 -0
  9. package/lib/modules/project/index.js +1 -0
  10. package/lib/modules/project/makes/Project.d.ts +37 -28
  11. package/lib/modules/project/makes/Project.js +127 -163
  12. package/lib/modules/project/makes/ProjectConfig.d.ts +61 -0
  13. package/lib/modules/project/makes/ProjectConfig.js +164 -0
  14. package/lib/modules/project/makes/ServiceConfig.d.ts +2 -0
  15. package/lib/modules/project/makes/ServiceConfig.js +6 -0
  16. package/lib/modules/project/repositories/ProjectRepository.d.ts +14 -5
  17. package/lib/modules/project/repositories/ProjectRepository.js +61 -1
  18. package/lib/modules/project/types/ProjectConfigScope.d.ts +9 -0
  19. package/lib/modules/project/types/ProjectConfigScope.js +20 -0
  20. package/lib/modules/project/types/index.d.ts +1 -0
  21. package/lib/modules/project/types/index.js +1 -0
  22. package/lib/services/AppFileSystemService.js +1 -1
  23. package/lib/services/AppService.d.ts +5 -2
  24. package/lib/services/AppService.js +10 -4
  25. package/lib/services/LogService.d.ts +6 -4
  26. package/lib/services/LogService.js +18 -10
  27. package/lib/services/ProcessService.d.ts +3 -0
  28. package/lib/services/ProcessService.js +15 -6
  29. package/lib/types/ApplicationOptions.d.ts +1 -0
  30. package/lib/types/ApplicationOptions.js +2 -0
  31. package/lib/types/LogLevel.d.ts +13 -0
  32. package/lib/types/LogLevel.js +20 -0
  33. package/lib/types/index.d.ts +1 -0
  34. package/lib/types/index.js +1 -0
  35. package/package.json +1 -2
@@ -1,9 +1,11 @@
1
- import { Type, InjectionToken } from "../types";
2
1
  import { Container } from "./Container";
2
+ import { Type, InjectionToken } from "../types";
3
+ import { ApplicationOptions } from "../types/ApplicationOptions";
3
4
  export declare class ApplicationContext {
4
5
  protected readonly module: Type;
5
6
  protected readonly container: Container;
6
- constructor(module: Type, container: Container);
7
+ protected readonly options: ApplicationOptions;
8
+ constructor(module: Type, container: Container, options?: ApplicationOptions);
7
9
  get<TInput = any, TResult = TInput>(typeOrToken: InjectionToken<TInput>): TResult;
8
10
  run(args: string[]): Promise<string>;
9
11
  }
@@ -14,9 +14,10 @@ const cli_1 = require("@kearisp/cli");
14
14
  const AsyncStorage_1 = require("./AsyncStorage");
15
15
  const env_1 = require("../env");
16
16
  class ApplicationContext {
17
- constructor(module, container) {
17
+ constructor(module, container, options = {}) {
18
18
  this.module = module;
19
19
  this.container = container;
20
+ this.options = options;
20
21
  }
21
22
  get(typeOrToken) {
22
23
  const module = this.container.getModule(this.module);
@@ -1,5 +1,6 @@
1
1
  import { ApplicationContext } from "./ApplicationContext";
2
2
  import { Type } from "../types";
3
+ import { ApplicationOptions } from "../types/ApplicationOptions";
3
4
  export declare class Factory {
4
- static create(module: Type): Promise<ApplicationContext>;
5
+ static create(module: Type, options?: ApplicationOptions): Promise<ApplicationContext>;
5
6
  }
@@ -14,11 +14,11 @@ const ApplicationContext_1 = require("./ApplicationContext");
14
14
  const Container_1 = require("./Container");
15
15
  const Scanner_1 = require("./Scanner");
16
16
  class Factory {
17
- static create(module) {
18
- return __awaiter(this, void 0, void 0, function* () {
17
+ static create(module_1) {
18
+ return __awaiter(this, arguments, void 0, function* (module, options = {}) {
19
19
  const container = new Container_1.Container(), scanner = new Scanner_1.Scanner(container);
20
20
  yield scanner.scan(module);
21
- return new ApplicationContext_1.ApplicationContext(module, container);
21
+ return new ApplicationContext_1.ApplicationContext(module, container, options);
22
22
  });
23
23
  }
24
24
  }
@@ -14,8 +14,8 @@ const cli_1 = require("@kearisp/cli");
14
14
  const Container_1 = require("./Container");
15
15
  const ModuleWrapper_1 = require("./ModuleWrapper");
16
16
  const CoreModule_1 = require("./CoreModule");
17
- const env_1 = require("../env");
18
17
  const InstanceWrapper_1 = require("./InstanceWrapper");
18
+ const env_1 = require("../env");
19
19
  class Scanner {
20
20
  constructor(container) {
21
21
  this.container = container || new Container_1.Container();
@@ -1,27 +1,15 @@
1
- import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef, PresetSource } from "../types";
2
1
  import { FileSystem } from "./FileSystem";
3
- export type AppConfigProperties = {
4
- debug?: boolean;
5
- pm?: PackageManagerType;
6
- keystore?: string;
7
- logLevel?: "off" | "info" | "warn" | "error";
8
- plugins?: PluginRef[];
9
- presets?: PresetRef[];
10
- projects?: ProjectOldRef[];
11
- meta?: EnvConfig;
12
- env?: EnvConfig;
13
- };
2
+ import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef, PresetSource } from "../types";
14
3
  export declare abstract class AppConfig {
15
4
  debug?: boolean;
16
5
  pm?: PackageManagerType;
17
6
  keystore?: string;
18
- logLevel: "off" | "info" | "warn" | "error";
19
7
  plugins: PluginRef[];
20
8
  presets: PresetRef[];
21
9
  projects: ProjectRef[];
22
10
  meta?: EnvConfig;
23
11
  env?: EnvConfig;
24
- constructor(data: AppConfigProperties);
12
+ constructor(data: AppConfig.Data);
25
13
  addPlugin(name: string, env?: PluginRef["env"]): void;
26
14
  removePlugin(name: string): void;
27
15
  getProject(name: string): ProjectRef | undefined;
@@ -39,36 +27,19 @@ export declare abstract class AppConfig {
39
27
  setEnv(name: string, value: string): void;
40
28
  unsetEnv(name: string): void;
41
29
  abstract save(): void;
42
- toObject(): AppConfigProperties;
30
+ toObject(): AppConfig.Data;
43
31
  toJsString(): string;
44
- static make(fs: FileSystem): {
45
- save(): void;
32
+ static make(fs: FileSystem): AppConfig;
33
+ }
34
+ export declare namespace AppConfig {
35
+ type Data = {
46
36
  debug?: boolean;
47
37
  pm?: PackageManagerType;
48
38
  keystore?: string;
49
- logLevel: "off" | "info" | "warn" | "error";
50
- plugins: PluginRef[];
51
- presets: PresetRef[];
52
- projects: ProjectRef[];
39
+ plugins?: PluginRef[];
40
+ presets?: PresetRef[];
41
+ projects?: ProjectOldRef[];
53
42
  meta?: EnvConfig;
54
43
  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
44
  };
74
45
  }
@@ -15,7 +15,6 @@ exports.AppConfig = void 0;
15
15
  const types_1 = require("../types");
16
16
  class AppConfig {
17
17
  constructor(data) {
18
- this.logLevel = "off";
19
18
  const { plugins = [], presets = [], projects = [] } = data, rest = __rest(data, ["plugins", "presets", "projects"]);
20
19
  Object.assign(this, rest);
21
20
  this.plugins = plugins.map((plugin) => {
@@ -167,7 +166,6 @@ class AppConfig {
167
166
  return {
168
167
  debug: this.debug,
169
168
  pm: this.pm,
170
- logLevel: this.logLevel,
171
169
  keystore: this.keystore,
172
170
  plugins: this.plugins.length > 0 ? this.plugins : undefined,
173
171
  presets: this.presets.length > 0 ? this.presets : undefined,
@@ -1,4 +1,5 @@
1
1
  export * from "./makes/Project";
2
+ export * from "./makes/ProjectConfig";
2
3
  export * from "./repositories/ProjectRepository";
3
4
  export * from "./services/ProjectService";
4
5
  export { ServiceProperties } from "./types";
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./makes/Project"), exports);
18
+ __exportStar(require("./makes/ProjectConfig"), exports);
18
19
  __exportStar(require("./repositories/ProjectRepository"), exports);
19
20
  __exportStar(require("./services/ProjectService"), exports);
@@ -1,59 +1,68 @@
1
1
  import { EnvConfig, ProjectType } from "../../../types";
2
- import { ServiceProperties, ProjectV1 } from "../types";
2
+ import { ProjectConfigScope } from "../types";
3
+ import { ProjectConfig } from "./ProjectConfig";
3
4
  export declare class Project {
4
- /** @deprecated */
5
- id?: string;
6
5
  name: string;
7
- type: ProjectType;
8
6
  path: string;
9
- cmd?: string[];
10
- imageName?: string;
11
- dockerfile?: string;
12
- composefile?: string;
13
- preset?: string;
14
- presetMode?: "global" | "project";
15
- scripts?: {
16
- [script: string]: string;
17
- };
18
- services: {
19
- [name: string]: ServiceProperties;
20
- };
21
- buildArgs: EnvConfig;
22
- env: EnvConfig;
23
- metadata: EnvConfig;
24
- ports: string[];
25
- extraHosts: EnvConfig;
26
- volumes: string[];
27
- constructor(data: ProjectV1);
7
+ protected configs: Record<ProjectConfigScope, ProjectConfig>;
8
+ constructor(name: string, path: string);
9
+ protected getConfig(scope: ProjectConfigScope): ProjectConfig;
10
+ get type(): ProjectType;
11
+ set type(type: ProjectType);
28
12
  get containerName(): string;
13
+ get scripts(): {
14
+ [x: string]: string;
15
+ };
16
+ get preset(): string | undefined;
17
+ set preset(preset: string | undefined);
18
+ get presetMode(): "project" | "global";
19
+ set presetMode(mode: "project" | "global");
20
+ get imageName(): string | undefined;
21
+ set imageName(image: string | undefined);
22
+ get dockerfile(): string | undefined;
23
+ set dockerfile(dockerfile: string | undefined);
24
+ get composefile(): string | undefined;
25
+ set composefile(composefile: string | undefined);
26
+ get cmd(): string[] | undefined;
29
27
  get domains(): string[];
30
28
  hasDomain(domain: string): boolean;
31
29
  addDomain(addDomain: string): void;
32
30
  removeDomain(removeDomain: string): void;
33
31
  clearDomains(): void;
32
+ get volumes(): string[];
33
+ get ports(): string[];
34
+ set ports(ports: string[]);
34
35
  linkPort(hostPort: number, containerPort: number): void;
35
36
  unlinkPort(hostPort: number, containerPort: number): void;
37
+ get buildArgs(): EnvConfig;
38
+ set buildArgs(buildArgs: EnvConfig);
36
39
  setBuildArg(name: string, value: string, service?: string): void;
37
40
  unsetBuildArg(name: string, service?: string): void;
41
+ get env(): EnvConfig;
42
+ set env(env: EnvConfig);
38
43
  hasEnv(name: string): boolean;
39
44
  getEnv(key: string): string | undefined;
40
45
  getEnv(key: string, byDefault: string): string;
41
- setEnv(name: string, value: string | boolean, service?: string): void;
42
- unsetEnv(name: string, service?: string): void;
43
- hasMeta(name: string): boolean;
44
- getMeta<D = string | undefined>(name: string, defaultValue?: D): D;
46
+ setEnv(key: string, value: string | boolean, service?: string): void;
47
+ unsetEnv(key: string, service?: string): void;
48
+ hasMeta(key: string): boolean;
49
+ getMeta(key: string): string | undefined;
50
+ getMeta(key: string, byDefault: string): string;
45
51
  setMeta(name: string, value: string | boolean): void;
46
52
  unsetMeta(name: string): void;
47
53
  getVolumeBySource(source: string): string | undefined;
48
54
  getVolumeByDestination(destination: string): string | undefined;
49
55
  volumeMount(...volumes: string[]): void;
50
56
  volumeUnmount(...volumes: string[]): void;
57
+ get extraHosts(): {
58
+ [x: string]: string;
59
+ };
51
60
  addExtraHost(host: string, domain: string): void;
52
61
  removeExtraHost(host: string): void;
62
+ get services(): Record<string, import("../types").ServiceProperties>;
53
63
  getSecret(key: string): Promise<string | undefined>;
54
64
  getSecret(key: string, byDefault: string): Promise<string>;
55
65
  setSecret(key: string, value: string): Promise<void>;
56
66
  unsetSecret(key: string): Promise<void>;
57
67
  save(): void;
58
- toObject(): ProjectV1;
59
68
  }
@@ -8,38 +8,71 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
11
  Object.defineProperty(exports, "__esModule", { value: true });
23
12
  exports.Project = void 0;
24
13
  const AsyncStorage_1 = require("../../../core/AsyncStorage");
14
+ const AppService_1 = require("../../../services/AppService");
25
15
  const volumeParse_1 = require("../../../utils/volumeParse");
26
16
  const ProjectRepository_1 = require("../repositories/ProjectRepository");
17
+ const types_1 = require("../types");
27
18
  class Project {
28
- constructor(data) {
29
- const { name, services = {}, buildArgs = {}, env = {}, metadata = {}, ports = [], extraHosts = {}, volumes = [] } = data, rest = __rest(data, ["name", "services", "buildArgs", "env", "metadata", "ports", "extraHosts", "volumes"]);
30
- this.id = this.name = name;
31
- this.services = services;
32
- this.buildArgs = buildArgs;
33
- this.env = env;
34
- this.metadata = metadata;
35
- this.ports = ports;
36
- this.extraHosts = extraHosts;
37
- this.volumes = volumes;
38
- Object.assign(this, rest);
19
+ constructor(name, path) {
20
+ this.name = name;
21
+ this.path = path;
22
+ this.configs = {
23
+ [types_1.ProjectConfigScope.APP]: this.getConfig(types_1.ProjectConfigScope.APP),
24
+ [types_1.ProjectConfigScope.LOCAL]: this.getConfig(types_1.ProjectConfigScope.LOCAL)
25
+ };
26
+ }
27
+ getConfig(scope) {
28
+ const container = AsyncStorage_1.AsyncStorage.getContainer(), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
29
+ return projectRepository.getConfig(this.name, scope);
30
+ }
31
+ get type() {
32
+ return this.configs.app.type || this.configs.project.type;
33
+ }
34
+ set type(type) {
35
+ this.configs.app.type = type;
39
36
  }
40
37
  get containerName() {
41
38
  return `${this.name}.workspace`;
42
39
  }
40
+ get scripts() {
41
+ return Object.assign(Object.assign({}, this.configs.project.scripts), this.configs.app.scripts);
42
+ }
43
+ get preset() {
44
+ return this.configs.app.preset;
45
+ }
46
+ set preset(preset) {
47
+ this.configs.app.preset = preset;
48
+ }
49
+ get presetMode() {
50
+ return this.configs.app.presetMode;
51
+ }
52
+ set presetMode(mode) {
53
+ this.configs.app.presetMode = mode;
54
+ }
55
+ get imageName() {
56
+ return this.configs.app.image;
57
+ }
58
+ set imageName(image) {
59
+ this.configs.app.image = image;
60
+ }
61
+ get dockerfile() {
62
+ return this.configs.project.dockerfile || this.configs.app.dockerfile;
63
+ }
64
+ set dockerfile(dockerfile) {
65
+ this.configs.app.dockerfile = dockerfile;
66
+ }
67
+ get composefile() {
68
+ return this.configs.project.composefile || this.configs.app.composefile;
69
+ }
70
+ set composefile(composefile) {
71
+ this.configs.app.composefile = composefile;
72
+ }
73
+ get cmd() {
74
+ return this.configs.app.cmd;
75
+ }
43
76
  get domains() {
44
77
  const host = this.getEnv("VIRTUAL_HOST");
45
78
  if (!host) {
@@ -71,169 +104,116 @@ class Project {
71
104
  clearDomains() {
72
105
  this.unsetEnv("VIRTUAL_HOST");
73
106
  }
107
+ get volumes() {
108
+ return [
109
+ ...this.configs.project.volumes.filter((volume) => {
110
+ return !this.configs.app.getVolumeByDestination((0, volumeParse_1.volumeParse)(volume).destination);
111
+ }),
112
+ ...this.configs.app.volumes
113
+ ];
114
+ }
115
+ get ports() {
116
+ return [
117
+ ...this.configs.project.ports,
118
+ ...this.configs.app.ports
119
+ ];
120
+ }
121
+ set ports(ports) {
122
+ this.configs.app.ports = ports;
123
+ }
74
124
  linkPort(hostPort, containerPort) {
75
- this.ports = [
76
- ...this.ports.filter((link) => {
125
+ this.configs.app.ports = [
126
+ ...this.configs.app.ports.filter((link) => {
77
127
  return link !== `${hostPort}:${containerPort}`;
78
128
  }),
79
129
  `${hostPort}:${containerPort}`
80
130
  ];
81
131
  }
82
132
  unlinkPort(hostPort, containerPort) {
83
- if (!this.ports) {
84
- return;
85
- }
86
- this.ports = this.ports.filter((link) => {
133
+ this.configs.app.ports = this.configs.app.ports.filter((link) => {
87
134
  return link !== `${hostPort}:${containerPort}`;
88
135
  });
89
136
  }
137
+ get buildArgs() {
138
+ return Object.assign(Object.assign({}, this.configs.project.buildArgs), this.configs.app.buildArgs);
139
+ }
140
+ set buildArgs(buildArgs) {
141
+ this.configs.app.buildArgs = buildArgs;
142
+ }
90
143
  setBuildArg(name, value, service) {
91
144
  if (service) {
92
- if (!this.services[service]) {
145
+ if (!this.configs.app.services[service]) {
93
146
  throw new Error(`Service "${service}" not found`);
94
147
  }
95
- if (!this.services[service].buildArgs) {
96
- this.services[service].buildArgs = {};
148
+ if (!this.configs.app.services[service].buildArgs) {
149
+ this.configs.app.services[service].buildArgs = {};
97
150
  }
98
- this.services[service].buildArgs[name] = value;
151
+ this.configs.app.services[service].buildArgs[name] = value;
99
152
  return;
100
153
  }
101
- this.buildArgs[name] = value;
154
+ this.configs.app.buildArgs[name] = value;
102
155
  }
103
156
  unsetBuildArg(name, service) {
104
- if (service) {
105
- if (!this.services[service]) {
106
- throw new Error(`Service "${service}" not found`);
107
- }
108
- if (this.services[service].buildArgs && name in this.services[service].buildArgs) {
109
- delete this.services[service].buildArgs[name];
110
- if (Object.keys(this.services[service].buildArgs).length === 0) {
111
- delete this.services[service].buildArgs;
112
- }
113
- }
114
- return;
115
- }
116
- if (name in this.buildArgs) {
117
- delete this.buildArgs[name];
118
- }
157
+ this.configs.app.unsetBuildArg(name, service);
158
+ }
159
+ get env() {
160
+ return Object.assign(Object.assign({}, this.configs.project.env), this.configs.app.env);
161
+ }
162
+ set env(env) {
163
+ this.configs.app.env = env;
119
164
  }
120
165
  hasEnv(name) {
121
- if (!this.env) {
122
- return false;
123
- }
124
- return this.env.hasOwnProperty(name);
166
+ return this.configs.app.hasEnv(name) || this.configs.project.hasEnv(name);
125
167
  }
126
- getEnv(name, defaultValue) {
127
- const { [name]: value = defaultValue } = this.env || {};
128
- return value;
168
+ getEnv(key, byDefault) {
169
+ return this.configs.app.env[key] || this.configs.project.env[key] || byDefault;
129
170
  }
130
- setEnv(name, value, service) {
131
- if (!this.env) {
132
- this.env = {};
133
- }
134
- if (service) {
135
- if (!this.services[service]) {
136
- throw new Error(`Service "${service}" not found`);
137
- }
138
- if (!this.services[service].env) {
139
- this.services[service].env = {};
140
- }
141
- this.services[service].env[name] = typeof value === "boolean"
142
- ? (value ? "true" : "false")
143
- : value;
144
- return;
145
- }
146
- this.env[name] = typeof value === "boolean"
147
- ? (value ? "true" : "false")
148
- : value;
171
+ setEnv(key, value, service) {
172
+ this.configs.app.setEnv(key, value, service);
149
173
  }
150
- unsetEnv(name, service) {
151
- if (service) {
152
- if (!this.services[service]) {
153
- throw new Error(`Service "${service}" not found`);
154
- }
155
- if (this.services[service].env && name in this.services[service].env) {
156
- delete this.services[service].env[name];
157
- if (Object.keys(this.services[service].env).length === 0) {
158
- delete this.services[service].env;
159
- }
160
- }
161
- return;
162
- }
163
- if (name in this.env) {
164
- delete this.env[name];
165
- }
174
+ unsetEnv(key, service) {
175
+ this.configs.app.unsetEnv(key, service);
166
176
  }
167
- hasMeta(name) {
168
- return !!this.metadata && this.metadata.hasOwnProperty(name);
177
+ hasMeta(key) {
178
+ return this.configs.app.metadata.hasOwnProperty(key) || this.configs.project.metadata.hasOwnProperty(key);
169
179
  }
170
- getMeta(name, defaultValue) {
171
- const { [name]: value = defaultValue } = this.metadata || {};
172
- return value;
180
+ getMeta(key, byDefault) {
181
+ return this.configs.app.metadata[key] || this.configs.project.metadata[key] || byDefault;
173
182
  }
174
183
  setMeta(name, value) {
175
- if (!this.metadata) {
176
- this.metadata = {};
177
- }
178
- this.metadata[name] = typeof value === "boolean"
184
+ this.configs.app.metadata[name] = typeof value === "boolean"
179
185
  ? (value ? "true" : "false")
180
186
  : value;
181
187
  }
182
188
  unsetMeta(name) {
183
- if (name in this.metadata) {
184
- delete this.metadata[name];
189
+ if (name in this.configs.app.metadata) {
190
+ delete this.configs.app.metadata[name];
185
191
  }
186
192
  }
187
193
  getVolumeBySource(source) {
188
- return (this.volumes || []).find((volume) => {
189
- return (0, volumeParse_1.volumeParse)(volume).source === source;
190
- });
194
+ return this.configs.project.getVolumeBySource(source) || this.configs.app.getVolumeBySource(source);
191
195
  }
192
196
  getVolumeByDestination(destination) {
193
- return (this.volumes || []).find((volume) => {
194
- return (0, volumeParse_1.volumeParse)(volume).destination === destination;
195
- });
197
+ return this.configs.project.getVolumeByDestination(destination) || this.configs.app.getVolumeByDestination(destination);
196
198
  }
197
199
  volumeMount(...volumes) {
198
- if (volumes.length === 0) {
199
- return;
200
- }
201
- const [volume, ...restVolumes] = volumes;
202
- const { destination } = (0, volumeParse_1.volumeParse)(volume);
203
- this.volumes = [
204
- ...(this.volumes || []).filter((v) => {
205
- return v !== this.getVolumeByDestination(destination);
206
- }),
207
- volume
208
- ];
209
- this.volumeMount(...restVolumes);
200
+ this.configs.app.volumeMount(...volumes);
210
201
  }
211
202
  volumeUnmount(...volumes) {
212
- if (!this.volumes || volumes.length === 0) {
213
- return;
214
- }
215
- const [volume, ...restVolumes] = volumes;
216
- const v = (0, volumeParse_1.volumeParse)(volume);
217
- this.volumes = this.volumes.filter((mounted) => {
218
- const m = (0, volumeParse_1.volumeParse)(mounted);
219
- return v.source !== m.source && v.destination !== m.destination;
220
- });
221
- if (this.volumes.length === 0) {
222
- return;
223
- }
224
- this.volumeUnmount(...restVolumes);
203
+ this.configs.app.volumeUnmount(...volumes);
204
+ }
205
+ get extraHosts() {
206
+ return Object.assign(Object.assign({}, this.configs.project.extraHosts), this.configs.app.extraHosts);
225
207
  }
208
+ ;
226
209
  addExtraHost(host, domain) {
227
- if (!this.extraHosts) {
228
- this.extraHosts = {};
229
- }
230
- this.extraHosts[host] = domain;
210
+ this.configs.app.addExtraHost(host, domain);
231
211
  }
232
212
  removeExtraHost(host) {
233
- if (!this.extraHosts || !this.extraHosts[host]) {
234
- return;
235
- }
236
- delete this.extraHosts[host];
213
+ this.configs.app.removeExtraHost(host);
214
+ }
215
+ get services() {
216
+ return this.configs.app.services;
237
217
  }
238
218
  getSecret(key, byDefault) {
239
219
  return __awaiter(this, void 0, void 0, function* () {
@@ -254,29 +234,13 @@ class Project {
254
234
  });
255
235
  }
256
236
  save() {
257
- const container = AsyncStorage_1.AsyncStorage.getContainer(), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
258
- projectRepository.save(this);
259
- }
260
- toObject() {
261
- return {
262
- name: this.name,
263
- type: this.type,
264
- path: this.path,
265
- imageName: this.imageName,
266
- dockerfile: this.dockerfile,
267
- composefile: this.composefile,
268
- preset: this.preset,
269
- presetMode: this.presetMode,
270
- cmd: this.cmd,
271
- scripts: this.scripts,
272
- services: Object.keys(this.services).length > 0 ? this.services : undefined,
273
- buildArgs: Object.keys(this.buildArgs).length > 0 ? this.buildArgs : undefined,
274
- env: Object.keys(this.env).length > 0 ? this.env : undefined,
275
- metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
276
- ports: this.ports.length > 0 ? this.ports : undefined,
277
- extraHosts: Object.keys(this.extraHosts).length ? this.extraHosts : undefined,
278
- volumes: this.volumes.length > 0 ? this.volumes : undefined,
279
- };
237
+ const container = AsyncStorage_1.AsyncStorage.getContainer(), appService = container.get(AppService_1.AppService), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
238
+ appService.addProject(this.name, this.path);
239
+ this.configs.app.save();
240
+ // const container = AsyncStorage.getContainer(),
241
+ // projectRepository = container.get(ProjectRepository);
242
+ //
243
+ // projectRepository.save(this);
280
244
  }
281
245
  }
282
246
  exports.Project = Project;