@wocker/core 1.1.0-beta.4 → 1.1.0-beta.6

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.
@@ -8,4 +8,5 @@ export declare class ApplicationContext {
8
8
  constructor(module: Type, container: Container, options?: ApplicationOptions);
9
9
  get<TInput = any, TResult = TInput>(typeOrToken: InjectionToken<TInput>): TResult;
10
10
  run(args: string[]): Promise<string>;
11
+ protected process(args: string[]): Promise<string>;
11
12
  }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ApplicationContext = void 0;
13
13
  const cli_1 = require("@kearisp/cli");
14
14
  const AsyncStorage_1 = require("./AsyncStorage");
15
+ const EventService_1 = require("../services/EventService");
15
16
  const env_1 = require("../env");
16
17
  class ApplicationContext {
17
18
  constructor(module, container, options = {}) {
@@ -34,43 +35,53 @@ class ApplicationContext {
34
35
  return __awaiter(this, void 0, void 0, function* () {
35
36
  return new Promise((resolve) => {
36
37
  AsyncStorage_1.AsyncStorage.run(this.container, () => {
37
- const cli = this.get(cli_1.Cli);
38
- cli.command("")
39
- .option("version", {
40
- type: "boolean",
41
- alias: "v"
42
- })
43
- .action((input) => {
44
- if (input.option("version")) {
45
- return env_1.WOCKER_VERSION;
38
+ return resolve(this.process(args));
39
+ });
40
+ });
41
+ });
42
+ }
43
+ process(args) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const cli = this.get(cli_1.Cli), eventService = this.get(EventService_1.EventService);
46
+ cli.command("")
47
+ .option("version", {
48
+ type: "boolean",
49
+ alias: "v"
50
+ })
51
+ .action((input) => {
52
+ if (input.option("version")) {
53
+ return env_1.WOCKER_VERSION;
54
+ }
55
+ for (const [, module] of this.container.modules) {
56
+ for (const [, container] of module.controllers) {
57
+ if (!container.description) {
58
+ continue;
46
59
  }
47
- for (const [, module] of this.container.modules) {
48
- for (const [, container] of module.controllers) {
49
- if (!container.description) {
50
- continue;
51
- }
52
- console.info(`${container.description}:`);
53
- const spaceLength = container.commands.reduce((space, route) => {
54
- return route.commandNames.reduce((space, command) => {
55
- return Math.max(space, command.length + 2);
56
- }, space);
57
- }, 0);
58
- for (const route of container.commands) {
59
- if (!route.description) {
60
- continue;
61
- }
62
- for (const commandName of route.commandNames) {
63
- const space = " ".repeat(Math.max(0, spaceLength - commandName.length));
64
- console.info(` ${commandName} ${space} ${route.description}`);
65
- }
66
- }
67
- console.info("");
60
+ console.info(`${container.description}:`);
61
+ const spaceLength = container.commands.reduce((space, route) => {
62
+ return route.commandNames.reduce((space, command) => {
63
+ return Math.max(space, command.length + 2);
64
+ }, space);
65
+ }, 0);
66
+ for (const route of container.commands) {
67
+ if (!route.description) {
68
+ continue;
69
+ }
70
+ for (const commandName of route.commandNames) {
71
+ const space = " ".repeat(Math.max(0, spaceLength - commandName.length));
72
+ console.info(` ${commandName} ${space} ${route.description}`);
68
73
  }
69
74
  }
70
- });
71
- return resolve(cli.run(args));
72
- });
75
+ console.info("");
76
+ }
77
+ }
73
78
  });
79
+ try {
80
+ return yield cli.run(args);
81
+ }
82
+ finally {
83
+ yield eventService.emit("finish");
84
+ }
74
85
  });
75
86
  }
76
87
  }
@@ -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
  });
package/lib/core/Route.js CHANGED
@@ -11,7 +11,7 @@ class Route {
11
11
  this.commandNames = [];
12
12
  this.completions = [];
13
13
  const descriptor = Object.getOwnPropertyDescriptor(this.type.prototype, this.method);
14
- if (!descriptor) {
14
+ if (!descriptor || !descriptor.value) {
15
15
  return;
16
16
  }
17
17
  this.description = Reflect.getMetadata(env_1.DESCRIPTION_METADATA, descriptor.value) || "";
@@ -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,16 +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;
11
16
  unset(key: string | JSONPath): void;
12
17
  isDirty(): boolean;
13
18
  toString(): string;
19
+ static getNodeValue(node: Node): any;
14
20
  }
15
21
  export declare namespace JsonEditor {
16
22
  type CreateProxyOptions = {
@@ -18,3 +24,4 @@ export declare namespace JsonEditor {
18
24
  removeOnEmpty?: boolean;
19
25
  };
20
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,33 +57,57 @@ 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
102
  set(key, value, options) {
90
103
  const path = typeof key === "string" ? key.split(".") : key;
91
104
  this.content = (0, jsonc_parser_1.applyEdits)(this.content, (0, jsonc_parser_1.modify)(this.content, path, value, options || {
92
105
  formattingOptions: {
93
106
  insertSpaces: true,
94
- keepLines: false
95
- }
107
+ keepLines: false,
108
+ insertFinalNewline: true
109
+ },
110
+ getInsertionIndex: this.getInsertionIndex(path)
96
111
  }));
97
112
  this.root = (0, jsonc_parser_1.parseTree)(this.content);
98
113
  }
@@ -105,5 +120,31 @@ class JsonEditor {
105
120
  toString() {
106
121
  return this.content;
107
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
+ }
108
149
  }
109
150
  exports.JsonEditor = JsonEditor;
@@ -0,0 +1,7 @@
1
+ import { FileSystem } from "./FileSystem";
2
+ export declare abstract class PluginConfig {
3
+ constructor(_data: any);
4
+ save(): void;
5
+ toObject(): any;
6
+ static make<C extends typeof PluginConfig>(fs: FileSystem, configPath?: string): InstanceType<C>;
7
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginConfig = void 0;
4
+ class PluginConfig {
5
+ constructor(_data) { }
6
+ save() {
7
+ throw new Error("Method not implemented");
8
+ }
9
+ toObject() {
10
+ throw new Error("Method not implemented");
11
+ }
12
+ static make(fs, configPath = "config.json") {
13
+ const data = fs.exists(configPath)
14
+ ? fs.readJSON(configPath)
15
+ : {};
16
+ return new class extends this {
17
+ constructor(data) {
18
+ super(data);
19
+ }
20
+ save() {
21
+ if (!fs.exists()) {
22
+ fs.mkdir("", {
23
+ recursive: true
24
+ });
25
+ }
26
+ fs.writeJSON(configPath, this.toObject());
27
+ }
28
+ }(data);
29
+ }
30
+ }
31
+ exports.PluginConfig = PluginConfig;
@@ -1,20 +1,24 @@
1
1
  import { ProjectConfig } from "./ProjectConfig";
2
- import { EnvConfig, ProjectConfigScope, ProjectRef, ProjectType } from "../types";
2
+ import { EnvConfig, ProjectConfigScope, ProjectRef, ProjectType, PresetMode } 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;
12
13
  get scripts(): any;
13
14
  get preset(): string | undefined;
14
15
  set preset(preset: string | undefined);
15
- get presetMode(): "project" | "global";
16
- set presetMode(mode: "project" | "global");
16
+ get presetMode(): PresetMode;
17
+ set presetMode(mode: PresetMode);
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
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,10 +1,9 @@
1
- import { FileSystem } from "./FileSystem";
2
- import { EnvConfig, ProjectType } from "../types";
3
1
  import { JsonEditor } from "./JsonEditor";
4
2
  import { ServiceConfig } from "./ServiceConfig";
3
+ import { EnvConfig, ProjectType, ProjectConfigScope, PresetMode } from "../types";
5
4
  export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
6
- readonly filename: string;
7
- constructor(filename: string, content: string);
5
+ readonly _scope: ProjectConfigScope;
6
+ constructor(_scope: ProjectConfigScope, content: string);
8
7
  get type(): ProjectType | undefined;
9
8
  set type(type: ProjectType | undefined);
10
9
  get image(): string | undefined;
@@ -37,7 +36,7 @@ export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
37
36
  get ports(): string[];
38
37
  set ports(ports: string[]);
39
38
  setBuildArg(key: string, value: string, service?: string): void;
40
- unsetBuildArg(name: string, service?: string): void;
39
+ unsetBuildArg(key: string, service?: string): void;
41
40
  getEnv(key: string): string | undefined;
42
41
  getEnv(key: string, byDefault: string): string;
43
42
  hasEnv(key: string): boolean;
@@ -51,7 +50,6 @@ export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
51
50
  removeExtraHost(host: string): void;
52
51
  addService(name: string, data: ServiceConfig.Data): void;
53
52
  service(name: string): any;
54
- static make(fs: FileSystem, filename: string): ProjectConfig;
55
53
  }
56
54
  export declare namespace ProjectConfig {
57
55
  type Data = {
@@ -62,7 +60,7 @@ export declare namespace ProjectConfig {
62
60
  dockerfile?: string;
63
61
  composefile?: string;
64
62
  preset?: string;
65
- presetMode?: "global" | "project";
63
+ presetMode?: PresetMode;
66
64
  scripts?: {
67
65
  [script: string]: string;
68
66
  };
@@ -4,9 +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
- constructor(filename, content) {
8
- super(content);
9
- this.filename = filename;
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;
10
33
  }
11
34
  get type() {
12
35
  return this.state.type;
@@ -120,33 +143,17 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
120
143
  }
121
144
  setBuildArg(key, value, service) {
122
145
  if (service) {
123
- // if(!this.services[service]) {
124
- // this.services[service] = {};
125
- // }
126
- //
127
- // if(!this.services[service].buildArgs) {
128
- // this.services[service].buildArgs = {};
129
- // }
130
- //
131
- // this.services[service].buildArgs[key] = value;
146
+ this.set(["services", service, "buildArgs", key], value);
132
147
  return;
133
148
  }
134
149
  this.buildArgs[key] = value;
135
150
  }
136
- unsetBuildArg(name, service) {
151
+ unsetBuildArg(key, service) {
137
152
  if (service) {
138
- // if(!this.services[service]) {
139
- // return;
140
- // }
141
- //
142
- // if(this.services[service].buildArgs && name in this.services[service].buildArgs) {
143
- // delete this.services[service].buildArgs[name];
144
- // }
153
+ this.unset(["services", service, "buildArgs", key]);
145
154
  return;
146
155
  }
147
- if (name in this.buildArgs) {
148
- delete this.buildArgs[name];
149
- }
156
+ delete this.buildArgs[key];
150
157
  }
151
158
  getEnv(key, byDefault) {
152
159
  if (key in this.env) {
@@ -173,7 +180,9 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
173
180
  this.unset(["services", service, "env", key]);
174
181
  return;
175
182
  }
176
- this.unset(["env", key]);
183
+ if (key in this.env) {
184
+ delete this.env[key];
185
+ }
177
186
  }
178
187
  getVolumeBySource(source) {
179
188
  return (this.state.volumes || []).find((volume) => {
@@ -232,12 +241,5 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
232
241
  removeOnEmpty: true
233
242
  });
234
243
  }
235
- static make(fs, filename) {
236
- let content = "{}";
237
- if (fs.exists(filename)) {
238
- content = fs.readFile(filename).toString();
239
- }
240
- return new ProjectConfig(filename, content);
241
- }
242
244
  }
243
245
  exports.ProjectConfig = ProjectConfig;
@@ -4,6 +4,7 @@ export * from "./ConfigCollection";
4
4
  export * from "./FileSystem";
5
5
  export * from "./FileSystemManager";
6
6
  export * from "./Logger";
7
+ export * from "./PluginConfig";
7
8
  export * from "./Project";
8
9
  export * from "./Version";
9
10
  export * from "./VersionRange";
@@ -20,6 +20,7 @@ __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("./PluginConfig"), exports);
23
24
  __exportStar(require("./Project"), exports);
24
25
  __exportStar(require("./Version"), exports);
25
26
  __exportStar(require("./VersionRange"), exports);
@@ -1,7 +1,7 @@
1
1
  import { WriteFileOptions, MakeDirectoryOptions, RmOptions, WriteStream, ReadStream } from "fs";
2
2
  import { FileSystemDriver } from "../../../types";
3
3
  import { AppConfigService } from "../../../services/AppConfigService";
4
- import { FileSystem } from "../../../makes";
4
+ import { FileSystem, PluginConfig } from "../../../makes";
5
5
  export declare class PluginConfigService {
6
6
  protected readonly appConfigService: AppConfigService;
7
7
  protected readonly pluginDir: string;
@@ -9,6 +9,7 @@ export declare class PluginConfigService {
9
9
  protected _fs?: FileSystem;
10
10
  constructor(appConfigService: AppConfigService, pluginDir: string, driver: FileSystemDriver);
11
11
  get fs(): FileSystem;
12
+ getConfig<T extends typeof PluginConfig>(Config: T): InstanceType<T>;
12
13
  isVersionGTE(version: string): boolean;
13
14
  /** @deprecated */
14
15
  dataPath(...parts: string[]): string;
@@ -46,6 +46,9 @@ let PluginConfigService = class PluginConfigService {
46
46
  }
47
47
  return this._fs;
48
48
  }
49
+ getConfig(Config) {
50
+ return Config.make(this.fs);
51
+ }
49
52
  isVersionGTE(version) {
50
53
  if (!this.appConfigService.isVersionGTE) {
51
54
  return false;
@@ -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[];
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ProjectRepository = void 0;
16
16
  const decorators_1 = require("../decorators");
17
17
  const makes_1 = require("../makes");
18
+ // noinspection ES6PreferShortImport
18
19
  const Project_1 = require("../makes/Project");
19
20
  const ProjectConfig_1 = require("../makes/ProjectConfig");
20
21
  const AppService_1 = require("./AppService");
@@ -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");
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
+ }
38
44
  case types_1.ProjectConfigScope.LOCAL:
39
- return ProjectConfig_1.ProjectConfig.make(new makes_1.FileSystem(ref.path, this.driver), "wocker.config.json");
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;
@@ -0,0 +1,14 @@
1
+ declare enum PresetModeEnum {
2
+ PROJECT = "project",
3
+ GLOBAL = "global"
4
+ }
5
+ export type PresetMode = PresetModeEnum;
6
+ export declare const PresetMode: typeof PresetModeEnum & {
7
+ values: () => PresetModeEnum[];
8
+ options: () => {
9
+ label: string;
10
+ value: PresetModeEnum;
11
+ }[];
12
+ label: (mode: PresetModeEnum) => string;
13
+ };
14
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PresetMode = void 0;
4
+ var PresetModeEnum;
5
+ (function (PresetModeEnum) {
6
+ PresetModeEnum["PROJECT"] = "project";
7
+ PresetModeEnum["GLOBAL"] = "global";
8
+ })(PresetModeEnum || (PresetModeEnum = {}));
9
+ exports.PresetMode = Object.assign({}, PresetModeEnum, {
10
+ values: () => {
11
+ return Object.values(PresetModeEnum);
12
+ },
13
+ options: () => {
14
+ return exports.PresetMode.values().map((mode) => {
15
+ return {
16
+ label: exports.PresetMode.label(mode),
17
+ value: mode
18
+ };
19
+ });
20
+ },
21
+ label: (mode) => {
22
+ switch (mode) {
23
+ case PresetModeEnum.PROJECT:
24
+ return "For project only";
25
+ case PresetModeEnum.GLOBAL:
26
+ return "Global usage";
27
+ default:
28
+ throw new Error(`Unsupported mode "${mode}"`);
29
+ }
30
+ }
31
+ });
@@ -1,3 +1,4 @@
1
+ export * from "./ApplicationOptions";
1
2
  export * from "./DynamicModule";
2
3
  export * from "./EnvConfig";
3
4
  export * from "./FileSystemDriver";
@@ -10,6 +11,7 @@ export * from "./PluginMetadata";
10
11
  export * from "./ProjectConfigScope";
11
12
  export * from "./PluginRef";
12
13
  export * from "./PresetRef";
14
+ export * from "./PresetMode";
13
15
  export * from "./PresetSource";
14
16
  export * from "./ProviderType";
15
17
  export * from "./ProjectRef";
@@ -21,8 +23,3 @@ export type {
21
23
  * @deprecated
22
24
  */
23
25
  ModuleMetadata as ModuleConfig } from "./ModuleMetadata";
24
- export type {
25
- /**
26
- * @deprecated
27
- */
28
- PluginMetadata as PluginConfig } from "./PluginMetadata";
@@ -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);
@@ -26,6 +27,7 @@ __exportStar(require("./PluginMetadata"), exports);
26
27
  __exportStar(require("./ProjectConfigScope"), exports);
27
28
  __exportStar(require("./PluginRef"), exports);
28
29
  __exportStar(require("./PresetRef"), exports);
30
+ __exportStar(require("./PresetMode"), exports);
29
31
  __exportStar(require("./PresetSource"), exports);
30
32
  __exportStar(require("./ProviderType"), exports);
31
33
  __exportStar(require("./ProjectRef"), 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.4",
4
+ "version": "1.1.0-beta.6",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Core of the Wocker",
7
7
  "license": "MIT",