@wocker/core 1.1.0-beta.4 → 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.
- package/lib/core/CoreModule.js +15 -29
- package/lib/core/Factory.d.ts +1 -2
- package/lib/core/Factory.js +1 -1
- package/lib/core/Scanner.d.ts +2 -2
- package/lib/core/Scanner.js +10 -1
- package/lib/makes/AppConfig.d.ts +1 -0
- package/lib/makes/AppConfig.js +5 -0
- package/lib/makes/JsonEditor.d.ts +8 -1
- package/lib/makes/JsonEditor.js +61 -20
- package/lib/makes/Project.d.ts +8 -1
- package/lib/makes/Project.js +19 -8
- package/lib/makes/ProjectConfig.d.ts +4 -6
- package/lib/makes/ProjectConfig.js +33 -31
- package/lib/services/ProjectRepository.d.ts +1 -1
- package/lib/services/ProjectRepository.js +21 -7
- package/lib/types/ApplicationOptions.d.ts +4 -1
- package/lib/types/FileSystemDriver.d.ts +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +1 -1
package/lib/core/CoreModule.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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);
|
package/lib/core/Factory.d.ts
CHANGED
|
@@ -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
|
}
|
package/lib/core/Factory.js
CHANGED
|
@@ -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/Scanner.d.ts
CHANGED
|
@@ -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;
|
package/lib/core/Scanner.js
CHANGED
|
@@ -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* () {
|
package/lib/makes/AppConfig.d.ts
CHANGED
|
@@ -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;
|
package/lib/makes/AppConfig.js
CHANGED
|
@@ -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 {};
|
package/lib/makes/JsonEditor.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
|
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;
|
package/lib/makes/Project.d.ts
CHANGED
|
@@ -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
|
-
|
|
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>;
|
package/lib/makes/Project.js
CHANGED
|
@@ -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.
|
|
23
|
+
this._ref = appService.getProject(this.name);
|
|
24
24
|
this.configs = {
|
|
25
|
-
[types_1.ProjectConfigScope.APP]: projectRepository.getConfig(this.name,
|
|
26
|
-
[types_1.ProjectConfigScope.LOCAL]: projectRepository.getConfig(this.name,
|
|
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.
|
|
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.
|
|
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.
|
|
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 {
|
|
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
|
-
readonly
|
|
7
|
-
constructor(
|
|
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(
|
|
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 = {
|
|
@@ -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(
|
|
8
|
-
super(content
|
|
9
|
-
|
|
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
|
-
|
|
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(
|
|
151
|
+
unsetBuildArg(key, service) {
|
|
137
152
|
if (service) {
|
|
138
|
-
|
|
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
|
-
|
|
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.
|
|
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;
|
|
@@ -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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -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;
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -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);
|