@wocker/core 1.1.0-beta.3 → 1.1.0-beta.5

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.
@@ -5,21 +5,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.CoreModule = void 0;
13
10
  const cli_1 = require("@kearisp/cli");
14
- const fs_1 = __importDefault(require("fs"));
15
11
  const decorators_1 = require("../decorators");
16
- const AppService_1 = require("../services/AppService");
17
- const AppConfigService_1 = require("../services/AppConfigService");
18
- const AppFileSystemService_1 = require("../services/AppFileSystemService");
19
- const ProcessService_1 = require("../services/ProcessService");
20
- const EventService_1 = require("../services/EventService");
21
- const LogService_1 = require("../services/LogService");
22
- const ProjectRepository_1 = require("../services/ProjectRepository");
12
+ const services_1 = require("../services");
23
13
  const env_1 = require("../env");
24
14
  let CoreModule = class CoreModule {
25
15
  };
@@ -37,30 +27,26 @@ exports.CoreModule = CoreModule = __decorate([
37
27
  provide: env_1.WOCKER_DATA_DIR_KEY,
38
28
  useValue: env_1.WOCKER_DATA_DIR
39
29
  },
40
- {
41
- provide: env_1.FILE_SYSTEM_DRIVER_KEY,
42
- useValue: fs_1.default
43
- },
44
- AppService_1.AppService,
45
- AppConfigService_1.AppConfigService,
46
- AppFileSystemService_1.AppFileSystemService,
47
- ProjectRepository_1.ProjectRepository,
48
- ProcessService_1.ProcessService,
49
- EventService_1.EventService,
50
- LogService_1.LogService
30
+ services_1.AppService,
31
+ services_1.AppConfigService,
32
+ services_1.AppFileSystemService,
33
+ services_1.ProjectRepository,
34
+ services_1.ProcessService,
35
+ services_1.EventService,
36
+ services_1.LogService
51
37
  ],
52
38
  exports: [
53
39
  cli_1.Cli,
54
40
  env_1.WOCKER_VERSION_KEY,
55
41
  env_1.WOCKER_DATA_DIR_KEY,
56
42
  env_1.FILE_SYSTEM_DRIVER_KEY,
57
- AppService_1.AppService,
58
- AppConfigService_1.AppConfigService,
59
- AppFileSystemService_1.AppFileSystemService,
60
- ProjectRepository_1.ProjectRepository,
61
- ProcessService_1.ProcessService,
62
- EventService_1.EventService,
63
- LogService_1.LogService
43
+ services_1.AppService,
44
+ services_1.AppConfigService,
45
+ services_1.AppFileSystemService,
46
+ services_1.ProjectRepository,
47
+ services_1.ProcessService,
48
+ services_1.EventService,
49
+ services_1.LogService
64
50
  ]
65
51
  })
66
52
  ], CoreModule);
@@ -1,6 +1,5 @@
1
1
  import { ApplicationContext } from "./ApplicationContext";
2
- import { Type } from "../types";
3
- import { ApplicationOptions } from "../types/ApplicationOptions";
2
+ import { ApplicationOptions, Type } from "../types";
4
3
  export declare class Factory {
5
4
  static create(module: Type, options?: ApplicationOptions): Promise<ApplicationContext>;
6
5
  }
@@ -16,7 +16,7 @@ const Scanner_1 = require("./Scanner");
16
16
  class Factory {
17
17
  static create(module_1) {
18
18
  return __awaiter(this, arguments, void 0, function* (module, options = {}) {
19
- const container = new Container_1.Container(), scanner = new Scanner_1.Scanner(container);
19
+ const container = new Container_1.Container(), scanner = new Scanner_1.Scanner(container, options);
20
20
  yield scanner.scan(module);
21
21
  return new ApplicationContext_1.ApplicationContext(module, container, options);
22
22
  });
@@ -1,11 +1,11 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Type, DynamicModule, ProviderType } from "../types";
2
+ import { Type, DynamicModule, ProviderType, ApplicationOptions } from "../types";
3
3
  import { Container } from "./Container";
4
4
  import { ControllerWrapper } from "./ControllerWrapper";
5
5
  import { ModuleWrapper } from "./ModuleWrapper";
6
6
  export declare class Scanner {
7
7
  readonly container: Container;
8
- constructor(container?: Container);
8
+ constructor(container?: Container, options?: ApplicationOptions);
9
9
  scan(moduleDefinition: Type | DynamicModule): Promise<void>;
10
10
  protected getMetadata(moduleDefinition: Type | DynamicModule): DynamicModule;
11
11
  protected scanModule(moduleDefinition: Type | DynamicModule): ModuleWrapper;
@@ -8,21 +8,30 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.Scanner = void 0;
13
16
  const cli_1 = require("@kearisp/cli");
17
+ const fs_1 = __importDefault(require("fs"));
14
18
  const Container_1 = require("./Container");
15
19
  const ModuleWrapper_1 = require("./ModuleWrapper");
16
20
  const CoreModule_1 = require("./CoreModule");
17
21
  const InstanceWrapper_1 = require("./InstanceWrapper");
18
22
  const env_1 = require("../env");
19
23
  class Scanner {
20
- constructor(container) {
24
+ constructor(container, options = {}) {
25
+ const { fsDriver = fs_1.default } = options;
21
26
  this.container = container || new Container_1.Container();
22
27
  this.container.globalProviders.set("CORE_CONTAINER", new InstanceWrapper_1.InstanceWrapper(new ModuleWrapper_1.ModuleWrapper(this.container, null), {
23
28
  provide: "CORE_CONTAINER",
24
29
  useValue: this.container
25
30
  }));
31
+ this.container.globalProviders.set(env_1.FILE_SYSTEM_DRIVER_KEY, new InstanceWrapper_1.InstanceWrapper(new ModuleWrapper_1.ModuleWrapper(this.container, null), {
32
+ provide: env_1.FILE_SYSTEM_DRIVER_KEY,
33
+ useValue: fsDriver
34
+ }));
26
35
  }
27
36
  scan(moduleDefinition) {
28
37
  return __awaiter(this, void 0, void 0, function* () {
@@ -13,6 +13,7 @@ export declare abstract class AppConfig {
13
13
  addPlugin(name: string, env?: PluginRef["env"]): void;
14
14
  removePlugin(name: string): void;
15
15
  getProject(name: string): ProjectRef | undefined;
16
+ getProjectByPath(path: string): ProjectRef | undefined;
16
17
  addProject(name: string, path: string): void;
17
18
  removeProject(name: string): void;
18
19
  registerPreset(name: string, source: PresetSource, path?: string): void;
@@ -61,6 +61,11 @@ class AppConfig {
61
61
  return projectData.name === name;
62
62
  });
63
63
  }
64
+ getProjectByPath(path) {
65
+ return this.projects.find((ref) => {
66
+ return ref.path === path;
67
+ });
68
+ }
64
69
  addProject(name, path) {
65
70
  let projectRef = this.getProject(name);
66
71
  if (!projectRef) {
@@ -1,15 +1,22 @@
1
1
  import { JSONPath, Node, ModificationOptions } from "jsonc-parser";
2
+ type OrderMap = {
3
+ [key: string]: string[] | ((key: string, properties: string[]) => number);
4
+ };
2
5
  export declare class JsonEditor<T extends object> {
3
6
  protected readonly original: string;
7
+ protected readonly orderMap: OrderMap;
4
8
  protected content: string;
5
9
  protected root: Node;
6
10
  state: T;
7
- constructor(original: string);
11
+ constructor(original: string, orderMap?: OrderMap);
8
12
  protected createProxy(keys: JSONPath, options?: JsonEditor.CreateProxyOptions): any;
13
+ protected getInsertionIndex(path: JSONPath): ((properties: string[]) => number) | undefined;
9
14
  get(key: string | JSONPath): any;
10
15
  set(key: string | JSONPath, value: any, options?: ModificationOptions): void;
16
+ unset(key: string | JSONPath): void;
11
17
  isDirty(): boolean;
12
18
  toString(): string;
19
+ static getNodeValue(node: Node): any;
13
20
  }
14
21
  export declare namespace JsonEditor {
15
22
  type CreateProxyOptions = {
@@ -17,3 +24,4 @@ export declare namespace JsonEditor {
17
24
  removeOnEmpty?: boolean;
18
25
  };
19
26
  }
27
+ export {};
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonEditor = void 0;
4
4
  const jsonc_parser_1 = require("jsonc-parser");
5
5
  class JsonEditor {
6
- constructor(original) {
6
+ constructor(original, orderMap = {}) {
7
7
  this.original = original;
8
+ this.orderMap = orderMap;
8
9
  this.content = this.original;
9
10
  this.root = (0, jsonc_parser_1.parseTree)(this.content);
10
11
  this.state = this.createProxy([]);
@@ -21,12 +22,7 @@ class JsonEditor {
21
22
  if (typeof target[property] === "function") {
22
23
  return (...args) => {
23
24
  const res = target[property](...args);
24
- this.set(keys, target, {
25
- formattingOptions: {
26
- keepLines: false,
27
- insertSpaces: true
28
- }
29
- });
25
+ this.set(keys, target);
30
26
  return res;
31
27
  };
32
28
  }
@@ -45,16 +41,11 @@ class JsonEditor {
45
41
  if (Array.isArray(_)) {
46
42
  property = parseInt(property);
47
43
  }
48
- this.set([...keys, property], value, {
49
- formattingOptions: {
50
- keepLines: false,
51
- insertSpaces: true
52
- }
53
- });
44
+ this.set([...keys, property], value);
54
45
  if (removeOnEmpty) {
55
46
  const value = this.get(keys);
56
47
  if (typeof value === "object" && Object.keys(value).length === 0) {
57
- this.set(keys, undefined);
48
+ this.unset(keys);
58
49
  }
59
50
  }
60
51
  return true;
@@ -66,36 +57,94 @@ class JsonEditor {
66
57
  if (Array.isArray(_)) {
67
58
  property = parseInt(property);
68
59
  }
69
- this.set([...keys, property], undefined);
60
+ this.unset([...keys, property]);
70
61
  if (removeOnEmpty) {
71
62
  const value = this.get(keys);
72
63
  if (typeof value === "object" && Object.keys(value).length === 0) {
73
- this.set(keys, undefined);
64
+ this.unset(keys);
74
65
  }
75
66
  }
76
67
  return true;
77
68
  }
78
69
  });
79
70
  }
80
- ;
71
+ getInsertionIndex(path) {
72
+ const key = path[path.length - 1], orderKey = path.slice(0, -1).join("."), ordered = this.orderMap[orderKey];
73
+ if (!ordered) {
74
+ return undefined;
75
+ }
76
+ return (properties) => {
77
+ if (typeof ordered === "function") {
78
+ return ordered(key, properties);
79
+ }
80
+ const keyIndex = ordered.indexOf(key);
81
+ if (keyIndex === -1) {
82
+ return properties.length;
83
+ }
84
+ let insertIndex = 0;
85
+ for (const property of properties) {
86
+ const propertyIndex = ordered.indexOf(property);
87
+ if (propertyIndex !== -1 && propertyIndex < keyIndex) {
88
+ insertIndex++;
89
+ }
90
+ }
91
+ return insertIndex;
92
+ };
93
+ }
81
94
  get(key) {
82
95
  const path = typeof key === "string" ? key.split(".") : key;
83
96
  const node = (0, jsonc_parser_1.findNodeAtLocation)(this.root, path);
84
97
  if (!node) {
85
98
  return undefined;
86
99
  }
87
- return (0, jsonc_parser_1.getNodeValue)(node);
100
+ return JsonEditor.getNodeValue(node);
88
101
  }
89
- set(key, value, options = {}) {
102
+ set(key, value, options) {
90
103
  const path = typeof key === "string" ? key.split(".") : key;
91
- this.content = (0, jsonc_parser_1.applyEdits)(this.content, (0, jsonc_parser_1.modify)(this.content, path, value, options));
104
+ this.content = (0, jsonc_parser_1.applyEdits)(this.content, (0, jsonc_parser_1.modify)(this.content, path, value, options || {
105
+ formattingOptions: {
106
+ insertSpaces: true,
107
+ keepLines: false,
108
+ insertFinalNewline: true
109
+ },
110
+ getInsertionIndex: this.getInsertionIndex(path)
111
+ }));
92
112
  this.root = (0, jsonc_parser_1.parseTree)(this.content);
93
113
  }
114
+ unset(key) {
115
+ this.set(key, undefined);
116
+ }
94
117
  isDirty() {
95
118
  return this.content !== this.original;
96
119
  }
97
120
  toString() {
98
121
  return this.content;
99
122
  }
123
+ static getNodeValue(node) {
124
+ var _a;
125
+ switch (node.type) {
126
+ case "array":
127
+ return (_a = node.children) === null || _a === void 0 ? void 0 : _a.map(jsonc_parser_1.getNodeValue);
128
+ case "object": {
129
+ const obj = Object.create({});
130
+ if (node.children) {
131
+ for (let prop of node.children) {
132
+ const [keyNode, valueNode] = prop.children || [];
133
+ if (keyNode && valueNode) {
134
+ obj[keyNode.value] = this.getNodeValue(valueNode);
135
+ }
136
+ }
137
+ }
138
+ return obj;
139
+ }
140
+ case "null":
141
+ case "string":
142
+ case "number":
143
+ case "boolean":
144
+ return node.value;
145
+ default:
146
+ return undefined;
147
+ }
148
+ }
100
149
  }
101
150
  exports.JsonEditor = JsonEditor;
@@ -3,9 +3,10 @@ import { EnvConfig, ProjectConfigScope, ProjectRef, ProjectType } from "../types
3
3
  export declare class Project {
4
4
  name: string;
5
5
  path: string;
6
- readonly ref?: ProjectRef;
6
+ protected _ref?: ProjectRef;
7
7
  readonly configs: Record<ProjectConfigScope, ProjectConfig>;
8
8
  constructor(name: string, path: string);
9
+ get ref(): ProjectRef | undefined;
9
10
  get type(): ProjectType;
10
11
  set type(type: ProjectType);
11
12
  get containerName(): string;
@@ -14,7 +15,10 @@ export declare class Project {
14
15
  set preset(preset: string | undefined);
15
16
  get presetMode(): "project" | "global";
16
17
  set presetMode(mode: "project" | "global");
18
+ get image(): string | undefined;
19
+ /** @deprecated */
17
20
  get imageName(): string | undefined;
21
+ /** @deprecated */
18
22
  set imageName(image: string | undefined);
19
23
  get dockerfile(): string | undefined;
20
24
  set dockerfile(dockerfile: string | undefined);
@@ -54,6 +58,9 @@ export declare class Project {
54
58
  get extraHosts(): any;
55
59
  addExtraHost(host: string, domain: string): void;
56
60
  removeExtraHost(host: string): void;
61
+ get metadata(): {
62
+ [x: string]: string;
63
+ };
57
64
  get services(): any;
58
65
  getSecret(key: string): Promise<string | undefined>;
59
66
  getSecret(key: string, byDefault: string): Promise<string>;
@@ -20,12 +20,15 @@ class Project {
20
20
  this.name = name;
21
21
  this.path = path;
22
22
  const container = AsyncStorage_1.AsyncStorage.getContainer(), appService = container.get(AppService_1.AppService), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
23
- this.ref = appService.getProject(this.name);
23
+ this._ref = appService.getProject(this.name);
24
24
  this.configs = {
25
- [types_1.ProjectConfigScope.APP]: projectRepository.getConfig(this.name, types_1.ProjectConfigScope.APP),
26
- [types_1.ProjectConfigScope.LOCAL]: projectRepository.getConfig(this.name, types_1.ProjectConfigScope.LOCAL)
25
+ [types_1.ProjectConfigScope.APP]: projectRepository.getConfig(types_1.ProjectConfigScope.APP, this.name, this.path),
26
+ [types_1.ProjectConfigScope.LOCAL]: projectRepository.getConfig(types_1.ProjectConfigScope.LOCAL, this.name, this.path)
27
27
  };
28
28
  }
29
+ get ref() {
30
+ return this._ref;
31
+ }
29
32
  get type() {
30
33
  return this.configs.app.type || this.configs.project.type;
31
34
  }
@@ -39,37 +42,42 @@ class Project {
39
42
  return Object.assign(Object.assign({}, this.configs.project.scripts), this.configs.app.scripts);
40
43
  }
41
44
  get preset() {
42
- return this.configs.project.preset || this.configs.app.preset;
45
+ return this.configs.app.preset || this.configs.project.preset;
43
46
  }
44
47
  set preset(preset) {
45
48
  this.configs.app.preset = preset;
46
49
  }
47
50
  get presetMode() {
48
- return this.configs.app.presetMode;
51
+ return this.configs.app.presetMode || this.configs.project.presetMode;
49
52
  }
50
53
  set presetMode(mode) {
51
54
  this.configs.app.presetMode = mode;
52
55
  }
56
+ get image() {
57
+ return this.configs.app.image || this.configs.project.image;
58
+ }
59
+ /** @deprecated */
53
60
  get imageName() {
54
- return this.configs.app.image;
61
+ return this.configs.app.image || this.configs.project.image;
55
62
  }
63
+ /** @deprecated */
56
64
  set imageName(image) {
57
65
  this.configs.app.image = image;
58
66
  }
59
67
  get dockerfile() {
60
- return this.configs.project.dockerfile || this.configs.app.dockerfile;
68
+ return this.configs.app.dockerfile || this.configs.project.dockerfile;
61
69
  }
62
70
  set dockerfile(dockerfile) {
63
71
  this.configs.app.dockerfile = dockerfile;
64
72
  }
65
73
  get composefile() {
66
- return this.configs.project.composefile || this.configs.app.composefile;
74
+ return this.configs.app.composefile || this.configs.project.composefile;
67
75
  }
68
76
  set composefile(composefile) {
69
77
  this.configs.app.composefile = composefile;
70
78
  }
71
79
  get cmd() {
72
- return this.configs.app.cmd;
80
+ return this.configs.app.cmd || this.configs.project.cmd;
73
81
  }
74
82
  get domains() {
75
83
  const host = this.getEnv("VIRTUAL_HOST");
@@ -200,6 +208,9 @@ class Project {
200
208
  removeExtraHost(host) {
201
209
  this.configs.app.removeExtraHost(host);
202
210
  }
211
+ get metadata() {
212
+ return Object.assign(Object.assign({}, this.configs.project.metadata), this.configs.app.metadata);
213
+ }
203
214
  get services() {
204
215
  return this.configs.app.services;
205
216
  }
@@ -1,32 +1,33 @@
1
- import { FileSystem } from "./FileSystem";
2
- import { EnvConfig, ProjectType } from "../types";
1
+ import { EnvConfig, ProjectType, ProjectConfigScope } from "../types";
3
2
  import { JsonEditor } from "./JsonEditor";
4
3
  import { ServiceConfig } from "./ServiceConfig";
5
4
  export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
6
- constructor(content: string);
5
+ readonly _scope: ProjectConfigScope;
6
+ constructor(_scope: ProjectConfigScope, content: string);
7
7
  get type(): ProjectType | undefined;
8
8
  set type(type: ProjectType | undefined);
9
- get buildArgs(): EnvConfig;
10
- set buildArgs(buildArgs: EnvConfig);
11
- get env(): EnvConfig;
12
- set env(env: EnvConfig | undefined);
13
- get metadata(): EnvConfig;
14
- set metadata(metadata: EnvConfig);
15
- get preset(): string | undefined;
16
- set preset(preset: string | undefined);
17
- get presetMode(): "project" | "global" | undefined;
18
- set presetMode(presetMode: "project" | "global" | undefined);
19
9
  get image(): string | undefined;
20
10
  set image(image: string | undefined);
21
11
  get imageName(): string | undefined;
22
12
  set imageName(image: string | undefined);
23
- get composefile(): string | undefined;
24
- set composefile(composefile: string | undefined);
25
13
  get dockerfile(): string | undefined;
26
14
  set dockerfile(dockerfile: string | undefined);
15
+ get composefile(): string | undefined;
16
+ set composefile(composefile: string | undefined);
17
+ get preset(): string | undefined;
18
+ set preset(preset: string | undefined);
19
+ get presetMode(): ProjectConfig.Data["presetMode"];
20
+ set presetMode(presetMode: ProjectConfig.Data["presetMode"]);
21
+ get buildArgs(): EnvConfig;
22
+ set buildArgs(buildArgs: EnvConfig);
23
+ get env(): EnvConfig;
24
+ set env(env: EnvConfig | undefined);
25
+ get metadata(): EnvConfig;
26
+ set metadata(metadata: EnvConfig);
27
27
  get cmd(): string[] | undefined;
28
28
  set cmd(cmd: string[] | undefined);
29
29
  get scripts(): any;
30
+ set scripts(scripts: any);
30
31
  get services(): any;
31
32
  get extraHosts(): any;
32
33
  set extraHosts(extraHosts: any);
@@ -35,7 +36,7 @@ export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
35
36
  get ports(): string[];
36
37
  set ports(ports: string[]);
37
38
  setBuildArg(key: string, value: string, service?: string): void;
38
- unsetBuildArg(name: string, service?: string): void;
39
+ unsetBuildArg(key: string, service?: string): void;
39
40
  getEnv(key: string): string | undefined;
40
41
  getEnv(key: string, byDefault: string): string;
41
42
  hasEnv(key: string): boolean;
@@ -49,8 +50,6 @@ export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
49
50
  removeExtraHost(host: string): void;
50
51
  addService(name: string, data: ServiceConfig.Data): void;
51
52
  service(name: string): any;
52
- toObject(): ProjectConfig.Data;
53
- static make(fs: FileSystem, filename: string): ProjectConfig;
54
53
  }
55
54
  export declare namespace ProjectConfig {
56
55
  type Data = {
@@ -4,55 +4,32 @@ exports.ProjectConfig = void 0;
4
4
  const volumeParse_1 = require("../utils/volumeParse");
5
5
  const JsonEditor_1 = require("./JsonEditor");
6
6
  class ProjectConfig extends JsonEditor_1.JsonEditor {
7
- // public editor: JsonEditor<ProjectConfig.Data>;
8
- // protected state: ProjectConfig.Data;
9
- // public type?: ProjectType;
10
- // public image?: string;
11
- // public dockerfile?: string;
12
- // public composefile?: string;
13
- // public preset?: string;
14
- // public presetMode?: "global" | "project";
15
- // public scripts: {
16
- // [script: string]: string;
17
- // };
18
- // public cmd?: string[];
19
- // public metadata: EnvConfig;
20
- // public ports: string[];
21
- // public volumes: string[];
22
- // public extraHosts: EnvConfig;
23
- // public services: Record<string, ProjectConfig.Service>;
24
- constructor(content) {
25
- super(content);
26
- // this.editor = new JsonEditor<ProjectConfig.Data>(content);
27
- // const {
28
- // type,
29
- // imageName,
30
- // image = imageName,
31
- // dockerfile,
32
- // composefile,
33
- // preset,
34
- // presetMode,
35
- // scripts = {},
36
- // cmd,
37
- // metadata = {},
38
- // volumes = [],
39
- // ports = [],
40
- // extraHosts = {},
41
- // services = {}
42
- // } = data;
43
- // this.type = type;
44
- // this.image = image;
45
- // this.dockerfile = dockerfile;
46
- // this.composefile = composefile;
47
- // this.preset = preset;
48
- // this.presetMode = presetMode;
49
- // this.scripts = scripts;
50
- // this.cmd = cmd;
51
- // this.metadata = metadata;
52
- // this.volumes = volumes;
53
- // this.ports = ports;
54
- // this.extraHosts = extraHosts;
55
- // this.services = services;
7
+ constructor(_scope, content) {
8
+ super(content, {
9
+ "": [
10
+ // "version",
11
+ "type",
12
+ "image",
13
+ "dockerfile",
14
+ "composefile",
15
+ "preset",
16
+ "presetMode",
17
+ "scripts",
18
+ "cmd",
19
+ "buildArgs",
20
+ "env",
21
+ "metadata",
22
+ "volumes",
23
+ "ports",
24
+ "extraHosts",
25
+ "services"
26
+ ],
27
+ "env": [
28
+ "VIRTUAL_HOST",
29
+ "VIRTUAL_PORT"
30
+ ]
31
+ });
32
+ this._scope = _scope;
56
33
  }
57
34
  get type() {
58
35
  return this.state.type;
@@ -60,29 +37,30 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
60
37
  set type(type) {
61
38
  this.state.type = type;
62
39
  }
63
- get buildArgs() {
64
- return this.createProxy(["buildArgs"], {
65
- removeOnEmpty: true
66
- });
40
+ get image() {
41
+ return this.state.image || this.state.imageName;
67
42
  }
68
- set buildArgs(buildArgs) {
69
- this.state.buildArgs = Object.assign({}, buildArgs);
43
+ set image(image) {
44
+ this.state.image = image;
45
+ this.state.imageName = undefined;
70
46
  }
71
- get env() {
72
- return this.createProxy(["env"], {
73
- removeOnEmpty: true
74
- });
47
+ get imageName() {
48
+ return this.image;
75
49
  }
76
- set env(env) {
77
- this.state.env = env ? Object.assign({}, env) : env;
50
+ set imageName(image) {
51
+ this.image = image;
78
52
  }
79
- get metadata() {
80
- return this.createProxy(["metadata"], {
81
- removeOnEmpty: true
82
- });
53
+ get dockerfile() {
54
+ return this.state.dockerfile;
83
55
  }
84
- set metadata(metadata) {
85
- this.state.metadata = Object.assign({}, metadata);
56
+ set dockerfile(dockerfile) {
57
+ this.state.dockerfile = dockerfile;
58
+ }
59
+ get composefile() {
60
+ return this.state.composefile;
61
+ }
62
+ set composefile(composefile) {
63
+ this.state.composefile = composefile;
86
64
  }
87
65
  get preset() {
88
66
  return this.state.preset;
@@ -96,29 +74,29 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
96
74
  set presetMode(presetMode) {
97
75
  this.state.presetMode = presetMode;
98
76
  }
99
- get image() {
100
- return this.state.image;
101
- }
102
- set image(image) {
103
- this.state.image = image;
104
- }
105
- get imageName() {
106
- return this.state.imageName;
77
+ get buildArgs() {
78
+ return this.createProxy(["buildArgs"], {
79
+ removeOnEmpty: true
80
+ });
107
81
  }
108
- set imageName(image) {
109
- this.state.imageName = image;
82
+ set buildArgs(buildArgs) {
83
+ this.state.buildArgs = Object.assign({}, buildArgs);
110
84
  }
111
- get composefile() {
112
- return this.state.composefile;
85
+ get env() {
86
+ return this.createProxy(["env"], {
87
+ removeOnEmpty: true
88
+ });
113
89
  }
114
- set composefile(composefile) {
115
- this.state.composefile = composefile;
90
+ set env(env) {
91
+ this.state.env = env ? Object.assign({}, env) : env;
116
92
  }
117
- get dockerfile() {
118
- return this.state.dockerfile;
93
+ get metadata() {
94
+ return this.createProxy(["metadata"], {
95
+ removeOnEmpty: true
96
+ });
119
97
  }
120
- set dockerfile(dockerfile) {
121
- this.state.dockerfile = dockerfile;
98
+ set metadata(metadata) {
99
+ this.state.metadata = Object.assign({}, metadata);
122
100
  }
123
101
  get cmd() {
124
102
  return this.state.cmd;
@@ -127,13 +105,20 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
127
105
  this.state.cmd = cmd;
128
106
  }
129
107
  get scripts() {
130
- return {};
108
+ return this.createProxy(["scripts"], {
109
+ removeOnEmpty: true
110
+ });
111
+ }
112
+ set scripts(scripts) {
113
+ this.state.scripts = scripts;
131
114
  }
132
115
  get services() {
133
116
  return {};
134
117
  }
135
118
  get extraHosts() {
136
- return this.createProxy(["extraHosts"]);
119
+ return this.createProxy(["extraHosts"], {
120
+ removeOnEmpty: true
121
+ });
137
122
  }
138
123
  set extraHosts(extraHosts) {
139
124
  this.state.extraHosts = Object.assign({}, extraHosts);
@@ -158,33 +143,17 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
158
143
  }
159
144
  setBuildArg(key, value, service) {
160
145
  if (service) {
161
- // if(!this.services[service]) {
162
- // this.services[service] = {};
163
- // }
164
- //
165
- // if(!this.services[service].buildArgs) {
166
- // this.services[service].buildArgs = {};
167
- // }
168
- //
169
- // this.services[service].buildArgs[key] = value;
146
+ this.set(["services", service, "buildArgs", key], value);
170
147
  return;
171
148
  }
172
149
  this.buildArgs[key] = value;
173
150
  }
174
- unsetBuildArg(name, service) {
151
+ unsetBuildArg(key, service) {
175
152
  if (service) {
176
- // if(!this.services[service]) {
177
- // return;
178
- // }
179
- //
180
- // if(this.services[service].buildArgs && name in this.services[service].buildArgs) {
181
- // delete this.services[service].buildArgs[name];
182
- // }
153
+ this.unset(["services", service, "buildArgs", key]);
183
154
  return;
184
155
  }
185
- if (name in this.buildArgs) {
186
- delete this.buildArgs[name];
187
- }
156
+ delete this.buildArgs[key];
188
157
  }
189
158
  getEnv(key, byDefault) {
190
159
  if (key in this.env) {
@@ -201,32 +170,14 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
201
170
  ? (value ? "true" : "false")
202
171
  : value;
203
172
  if (service) {
204
- // if(!this.services[service]) {
205
- // return;
206
- // }
207
- //
208
- // if(!this.services[service].env) {
209
- // this.services[service].env = {};
210
- // }
211
- //
212
- // this.services[service].env[key] = sValue;
173
+ this.set(["services", service, "env", key], sValue);
213
174
  return;
214
175
  }
215
- this.env[key] = sValue;
176
+ this.set(["env", key], sValue);
216
177
  }
217
178
  unsetEnv(key, service) {
218
179
  if (service) {
219
- // if(!this.services[service]) {
220
- // throw new Error(`Service "${service}" not found`);
221
- // }
222
- //
223
- // if(this.services[service].env && key in this.services[service].env) {
224
- // delete this.services[service].env[key];
225
- //
226
- // if(Object.keys(this.services[service].env).length === 0) {
227
- // delete this.services[service].env;
228
- // }
229
- // }
180
+ this.unset(["services", service, "env", key]);
230
181
  return;
231
182
  }
232
183
  if (key in this.env) {
@@ -290,40 +241,5 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
290
241
  removeOnEmpty: true
291
242
  });
292
243
  }
293
- toObject() {
294
- // return {
295
- // type: this.type,
296
- // image: this.image,
297
- // dockerfile: this.dockerfile,
298
- // composefile: this.composefile,
299
- // preset: this.preset,
300
- // presetMode: this.presetMode,
301
- // scripts: Object.keys(this.scripts).length > 0 ? this.scripts : undefined,
302
- // cmd: this.cmd,
303
- // buildArgs: Object.keys(this.buildArgs).length > 0 ? this.buildArgs : undefined,
304
- // env: Object.keys(this.env).length > 0 ? this.env : undefined,
305
- // metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
306
- // volumes: this.volumes.length > 0 ? this.volumes : undefined,
307
- // ports: this.ports.length > 0 ? this.ports : undefined,
308
- // };
309
- return this.state;
310
- }
311
- static make(fs, filename) {
312
- let content = "{}";
313
- if (fs.exists(filename)) {
314
- content = fs.readFile(filename).toString();
315
- }
316
- return new class extends ProjectConfig {
317
- save() {
318
- // if(!fs.exists()) {
319
- // fs.mkdir("", {
320
- // recursive: true
321
- // });
322
- // }
323
- //
324
- // fs.writeJSON(filename, this.toObject());
325
- }
326
- }(content);
327
- }
328
244
  }
329
245
  exports.ProjectConfig = ProjectConfig;
@@ -8,7 +8,7 @@ export declare class ProjectRepository {
8
8
  protected readonly fs: AppFileSystemService;
9
9
  protected readonly driver: FileSystemDriver;
10
10
  constructor(appService: AppService, fs: AppFileSystemService, driver: FileSystemDriver);
11
- getConfig(name: string, scope: ProjectConfigScope): ProjectConfig;
11
+ getConfig(scope: ProjectConfigScope, name: string, path?: string): ProjectConfig;
12
12
  getByName(name: string): Project;
13
13
  save(project: Project): void;
14
14
  search(params: ProjectRepository.SearchParams): Project[];
@@ -14,9 +14,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ProjectRepository = void 0;
16
16
  const decorators_1 = require("../decorators");
17
+ const makes_1 = require("../makes");
18
+ // noinspection ES6PreferShortImport
17
19
  const Project_1 = require("../makes/Project");
18
20
  const ProjectConfig_1 = require("../makes/ProjectConfig");
19
- const makes_1 = require("../makes");
20
21
  const AppService_1 = require("./AppService");
21
22
  const AppFileSystemService_1 = require("./AppFileSystemService");
22
23
  const types_1 = require("../types");
@@ -27,16 +28,29 @@ let ProjectRepository = class ProjectRepository {
27
28
  this.fs = fs;
28
29
  this.driver = driver;
29
30
  }
30
- getConfig(name, scope) {
31
+ getConfig(scope, name, path) {
31
32
  const ref = this.appService.getProject(name);
32
- if (!ref) {
33
- throw new Error("");
34
- }
35
33
  switch (scope) {
36
- case types_1.ProjectConfigScope.APP:
37
- return ProjectConfig_1.ProjectConfig.make(this.fs.cd(`projects/${ref.name}`), "config.json");
38
- case types_1.ProjectConfigScopeEnum.LOCAL:
39
- return ProjectConfig_1.ProjectConfig.make(new makes_1.FileSystem(ref.path, this.driver), "wocker.config.json");
34
+ case types_1.ProjectConfigScope.APP: {
35
+ if (!ref) {
36
+ return new ProjectConfig_1.ProjectConfig(scope, "{}");
37
+ }
38
+ const fs = this.fs.cd(`projects/${ref.name}`);
39
+ if (!fs.exists("config.json")) {
40
+ return new ProjectConfig_1.ProjectConfig(scope, "{}");
41
+ }
42
+ return new ProjectConfig_1.ProjectConfig(scope, fs.readFile("config.json").toString());
43
+ }
44
+ case types_1.ProjectConfigScope.LOCAL:
45
+ path = path || (ref === null || ref === void 0 ? void 0 : ref.path);
46
+ if (!path) {
47
+ return new ProjectConfig_1.ProjectConfig(scope, "{}");
48
+ }
49
+ const fs = new makes_1.FileSystem(path);
50
+ if (!fs.exists("wocker.config.json")) {
51
+ return new ProjectConfig_1.ProjectConfig(scope, "{}");
52
+ }
53
+ return new ProjectConfig_1.ProjectConfig(scope, fs.readFile("wocker.config.json").toString());
40
54
  }
41
55
  }
42
56
  getByName(name) {
@@ -1 +1,4 @@
1
- export type ApplicationOptions = {};
1
+ import { FileSystemDriver } from "./FileSystemDriver";
2
+ export type ApplicationOptions = {
3
+ fsDriver?: FileSystemDriver;
4
+ };
@@ -9,7 +9,7 @@ export interface FileSystemDriver {
9
9
  fstatSync(fd: number): FS.Stats;
10
10
  mkdirSync(path: string, options?: FS.MakeDirectoryOptions): void;
11
11
  readdir(path: string, options: any, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
12
- readdirSync(path: string, options?: any): (string | Buffer)[] | Dirent[] | Dirent<Buffer>[];
12
+ readdirSync(path: string, options?: any): (string | Buffer<ArrayBufferLike>)[] | Dirent[] | Dirent<Buffer>[];
13
13
  readFileSync(path: string): string | Buffer;
14
14
  writeFileSync(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: FS.WriteFileOptions): void;
15
15
  appendFileSync(path: FS.PathOrFileDescriptor, data: string | Uint8Array, options?: FS.WriteFileOptions): void;
@@ -1,3 +1,4 @@
1
+ export * from "./ApplicationOptions";
1
2
  export * from "./DynamicModule";
2
3
  export * from "./EnvConfig";
3
4
  export * from "./FileSystemDriver";
@@ -14,6 +14,7 @@ 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("./ApplicationOptions"), exports);
17
18
  __exportStar(require("./DynamicModule"), exports);
18
19
  __exportStar(require("./EnvConfig"), exports);
19
20
  __exportStar(require("./FileSystemDriver"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
3
  "type": "commonjs",
4
- "version": "1.1.0-beta.3",
4
+ "version": "1.1.0-beta.5",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Core of the Wocker",
7
7
  "license": "MIT",