@wocker/core 1.1.9-beta.0 → 1.1.9-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/makes/JsonEditor.js +6 -4
- package/lib/makes/LayerResolver.d.ts +33 -0
- package/lib/makes/LayerResolver.js +112 -0
- package/lib/makes/Project.d.ts +12 -8
- package/lib/makes/Project.js +86 -57
- package/lib/makes/ProjectConfig.d.ts +10 -11
- package/lib/makes/ProjectConfig.js +63 -20
- package/lib/services/ProjectRepository.d.ts +2 -2
- package/lib/services/ProjectRepository.js +17 -12
- package/lib/types/ProjectLayerType.d.ts +11 -0
- package/lib/types/ProjectLayerType.js +33 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +1 -1
- package/package.json +1 -1
- package/lib/makes/ServiceConfig.d.ts +0 -23
- package/lib/makes/ServiceConfig.js +0 -57
- package/lib/types/ProjectConfigScope.d.ts +0 -9
- package/lib/types/ProjectConfigScope.js +0 -20
package/lib/makes/JsonEditor.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonEditor = void 0;
|
|
4
4
|
const jsonc_parser_1 = require("jsonc-parser");
|
|
5
|
+
const MUTATORS = new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
5
6
|
class JsonEditor {
|
|
6
7
|
constructor(original, orderMap = {}) {
|
|
7
8
|
this.original = original;
|
|
@@ -22,7 +23,9 @@ class JsonEditor {
|
|
|
22
23
|
if (typeof target[property] === "function") {
|
|
23
24
|
return (...args) => {
|
|
24
25
|
const res = target[property](...args);
|
|
25
|
-
|
|
26
|
+
if (MUTATORS.has(property)) {
|
|
27
|
+
this.set(keys, target);
|
|
28
|
+
}
|
|
26
29
|
return res;
|
|
27
30
|
};
|
|
28
31
|
}
|
|
@@ -92,8 +95,7 @@ class JsonEditor {
|
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
97
|
get(key) {
|
|
95
|
-
const path = typeof key === "string" ? key.split(".") : key;
|
|
96
|
-
const node = (0, jsonc_parser_1.findNodeAtLocation)(this.root, path);
|
|
98
|
+
const path = typeof key === "string" ? key.split(".") : key, node = (0, jsonc_parser_1.findNodeAtLocation)(this.root, path);
|
|
97
99
|
if (!node) {
|
|
98
100
|
return undefined;
|
|
99
101
|
}
|
|
@@ -104,7 +106,7 @@ class JsonEditor {
|
|
|
104
106
|
this.content = (0, jsonc_parser_1.applyEdits)(this.content, (0, jsonc_parser_1.modify)(this.content, path, value, options || {
|
|
105
107
|
formattingOptions: {
|
|
106
108
|
insertSpaces: true,
|
|
107
|
-
keepLines:
|
|
109
|
+
keepLines: true,
|
|
108
110
|
insertFinalNewline: true
|
|
109
111
|
},
|
|
110
112
|
getInsertionIndex: this.getInsertionIndex(path)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type Layer<D> = {
|
|
2
|
+
name: string;
|
|
3
|
+
priority: number;
|
|
4
|
+
data: D;
|
|
5
|
+
};
|
|
6
|
+
export type ResolveRule<T = any> = {
|
|
7
|
+
apply(values: T[]): T | undefined;
|
|
8
|
+
empty?(): T;
|
|
9
|
+
};
|
|
10
|
+
type KeysOfUnion<T> = T extends unknown ? keyof T : never;
|
|
11
|
+
export type Rules<D> = {
|
|
12
|
+
[K in KeysOfUnion<D>]-?: ResolveRule;
|
|
13
|
+
};
|
|
14
|
+
export declare const first: <T>() => ResolveRule<T>;
|
|
15
|
+
export declare const merge: <T extends object>() => ResolveRule<T>;
|
|
16
|
+
export declare const concat: <T>(options?: {
|
|
17
|
+
by?: (item: T) => unknown;
|
|
18
|
+
}) => ResolveRule<T[]>;
|
|
19
|
+
export declare const record: <T extends object>(rules: Rules<T>) => ResolveRule<Record<string, T>>;
|
|
20
|
+
export declare const resolveObject: <D>(rules: Rules<D>, sources: D[]) => D;
|
|
21
|
+
export declare class LayerResolver<D, L extends D = D> {
|
|
22
|
+
protected readonly rules: Rules<D>;
|
|
23
|
+
protected readonly _layers: Layer<L>[];
|
|
24
|
+
constructor(rules: Rules<D>, layers: Layer<L>[]);
|
|
25
|
+
get layers(): Layer<L>[];
|
|
26
|
+
layer(name: string): Layer<L> | undefined;
|
|
27
|
+
origin(path: keyof D | string[]): string | undefined;
|
|
28
|
+
resolve<K extends keyof D>(path: K | [K]): D[K];
|
|
29
|
+
resolve<K extends keyof D, K2 extends keyof NonNullable<D[K]>>(path: [K, K2]): NonNullable<D[K]>[K2];
|
|
30
|
+
resolve<K extends keyof D, K2 extends keyof NonNullable<D[K]>, K3 extends keyof NonNullable<NonNullable<D[K]>[K2]>>(path: [K, K2, K3]): NonNullable<NonNullable<D[K]>[K2]>[K3];
|
|
31
|
+
resolve(path: string[]): any;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LayerResolver = exports.resolveObject = exports.record = exports.concat = exports.merge = exports.first = void 0;
|
|
4
|
+
const isDefined = (value) => {
|
|
5
|
+
return value !== undefined && value !== null;
|
|
6
|
+
};
|
|
7
|
+
const first = () => ({
|
|
8
|
+
apply: (values) => values[0]
|
|
9
|
+
});
|
|
10
|
+
exports.first = first;
|
|
11
|
+
const merge = () => ({
|
|
12
|
+
apply: (values) => {
|
|
13
|
+
if (values.length === 0) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return Object.assign({}, ...[...values].reverse());
|
|
17
|
+
},
|
|
18
|
+
empty: () => ({})
|
|
19
|
+
});
|
|
20
|
+
exports.merge = merge;
|
|
21
|
+
const concat = (options = {}) => ({
|
|
22
|
+
apply: (values) => {
|
|
23
|
+
if (values.length === 0) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const { by } = options;
|
|
27
|
+
return [...values].reverse().reduce((result, items) => {
|
|
28
|
+
if (!by) {
|
|
29
|
+
return [...result, ...items];
|
|
30
|
+
}
|
|
31
|
+
const keys = new Set(items.map(by));
|
|
32
|
+
return [
|
|
33
|
+
...result.filter((item) => !keys.has(by(item))),
|
|
34
|
+
...items
|
|
35
|
+
];
|
|
36
|
+
}, []);
|
|
37
|
+
},
|
|
38
|
+
empty: () => []
|
|
39
|
+
});
|
|
40
|
+
exports.concat = concat;
|
|
41
|
+
const record = (rules) => ({
|
|
42
|
+
apply: (values) => {
|
|
43
|
+
if (values.length === 0) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const names = new Set(values.flatMap((value) => Object.keys(value)).reverse());
|
|
47
|
+
const result = {};
|
|
48
|
+
for (const name of names) {
|
|
49
|
+
result[name] = (0, exports.resolveObject)(rules, values.map((value) => value[name]).filter(isDefined));
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
},
|
|
53
|
+
empty: () => ({})
|
|
54
|
+
});
|
|
55
|
+
exports.record = record;
|
|
56
|
+
const resolveObject = (rules, sources) => {
|
|
57
|
+
const result = {};
|
|
58
|
+
const ruleMap = rules;
|
|
59
|
+
for (const key of Object.keys(ruleMap)) {
|
|
60
|
+
const values = sources.map((source) => source[key]).filter(isDefined);
|
|
61
|
+
const value = ruleMap[key].apply(values);
|
|
62
|
+
if (value !== undefined) {
|
|
63
|
+
result[key] = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
exports.resolveObject = resolveObject;
|
|
69
|
+
class LayerResolver {
|
|
70
|
+
constructor(rules, layers) {
|
|
71
|
+
this.rules = rules;
|
|
72
|
+
this._layers = [...layers].sort((a, b) => a.priority - b.priority);
|
|
73
|
+
}
|
|
74
|
+
get layers() {
|
|
75
|
+
return this._layers;
|
|
76
|
+
}
|
|
77
|
+
layer(name) {
|
|
78
|
+
return this._layers.find((l) => l.name === name);
|
|
79
|
+
}
|
|
80
|
+
origin(path) {
|
|
81
|
+
const segments = Array.isArray(path) ? path : [path];
|
|
82
|
+
for (const layer of this._layers) {
|
|
83
|
+
let value = layer.data;
|
|
84
|
+
for (const segment of segments) {
|
|
85
|
+
if (value === null || typeof value !== "object") {
|
|
86
|
+
value = undefined;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
value = value[segment];
|
|
90
|
+
}
|
|
91
|
+
if (isDefined(value)) {
|
|
92
|
+
return layer.name;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
resolve(path) {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
const [field, ...rest] = Array.isArray(path) ? path : [path];
|
|
100
|
+
const rule = this.rules[field];
|
|
101
|
+
const values = this._layers.map((layer) => layer.data[field]).filter(isDefined);
|
|
102
|
+
let value = (_a = rule.apply(values)) !== null && _a !== void 0 ? _a : (_b = rule.empty) === null || _b === void 0 ? void 0 : _b.call(rule);
|
|
103
|
+
for (const segment of rest) {
|
|
104
|
+
if (value === null || typeof value !== "object") {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
value = value[segment];
|
|
108
|
+
}
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.LayerResolver = LayerResolver;
|
package/lib/makes/Project.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { ProjectConfig } from "./ProjectConfig";
|
|
2
|
-
import {
|
|
2
|
+
import { LayerResolver } from "./LayerResolver";
|
|
3
|
+
import { EnvConfig, ProjectLayerType, ProjectRef, ProjectType, PresetMode } from "../types";
|
|
3
4
|
export declare class Project {
|
|
4
5
|
name: string;
|
|
5
6
|
path: string;
|
|
6
7
|
protected _ref?: ProjectRef;
|
|
7
|
-
readonly
|
|
8
|
+
protected readonly resolver: LayerResolver<ProjectConfig.Resolvable, ProjectConfig>;
|
|
8
9
|
constructor(name: string, path: string);
|
|
9
10
|
get ref(): ProjectRef | undefined;
|
|
10
11
|
get type(): ProjectType;
|
|
11
12
|
set type(type: ProjectType);
|
|
12
13
|
get containerName(): string;
|
|
13
|
-
get scripts():
|
|
14
|
+
get scripts(): {
|
|
15
|
+
[script: string]: string;
|
|
16
|
+
};
|
|
14
17
|
get preset(): string | undefined;
|
|
15
18
|
set preset(preset: string | undefined);
|
|
16
19
|
get presetMode(): PresetMode;
|
|
@@ -56,17 +59,18 @@ export declare class Project {
|
|
|
56
59
|
getVolumeByDestination(destination: string): string | undefined;
|
|
57
60
|
volumeMount(...volumes: string[]): void;
|
|
58
61
|
volumeUnmount(...volumes: string[]): void;
|
|
59
|
-
get extraHosts():
|
|
62
|
+
get extraHosts(): EnvConfig;
|
|
60
63
|
addExtraHost(host: string, domain: string): void;
|
|
61
64
|
removeExtraHost(host: string): void;
|
|
62
|
-
get metadata():
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
get services(): any;
|
|
65
|
+
get metadata(): EnvConfig;
|
|
66
|
+
get services(): Record<string, ProjectConfig.Service> | undefined;
|
|
66
67
|
getSecret(key: string): Promise<string | undefined>;
|
|
67
68
|
getSecret(key: string, byDefault: string): Promise<string>;
|
|
68
69
|
setSecret(key: string, value: string): Promise<void>;
|
|
69
70
|
getSecrets(): Promise<string[]>;
|
|
70
71
|
unsetSecret(key: string): Promise<void>;
|
|
72
|
+
layer(key: ProjectLayerType): ProjectConfig;
|
|
73
|
+
layers(): Map<ProjectLayerType, ProjectConfig>;
|
|
74
|
+
origin(path: keyof ProjectConfig.Resolvable | string[]): ProjectLayerType | undefined;
|
|
71
75
|
save(): void;
|
|
72
76
|
}
|
package/lib/makes/Project.js
CHANGED
|
@@ -4,7 +4,9 @@ exports.Project = void 0;
|
|
|
4
4
|
const AsyncStorage_1 = require("../core/AsyncStorage");
|
|
5
5
|
const AppService_1 = require("../services/AppService");
|
|
6
6
|
const ProjectRepository_1 = require("../services/ProjectRepository");
|
|
7
|
+
const ProjectConfig_1 = require("./ProjectConfig");
|
|
7
8
|
const volumeParse_1 = require("../utils/volumeParse");
|
|
9
|
+
const LayerResolver_1 = require("./LayerResolver");
|
|
8
10
|
const types_1 = require("../types");
|
|
9
11
|
class Project {
|
|
10
12
|
constructor(name, path) {
|
|
@@ -12,47 +14,60 @@ class Project {
|
|
|
12
14
|
this.path = path;
|
|
13
15
|
const container = AsyncStorage_1.AsyncStorage.getContainer(), appService = container.get(AppService_1.AppService), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
|
|
14
16
|
this._ref = appService.getProject(this.name);
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
this.resolver = new LayerResolver_1.LayerResolver(ProjectConfig_1.ProjectConfig.rules, [
|
|
18
|
+
{
|
|
19
|
+
name: types_1.ProjectLayerType.DATA,
|
|
20
|
+
priority: 10,
|
|
21
|
+
data: projectRepository.getConfig(types_1.ProjectLayerType.DATA, this.name, this.path)
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: types_1.ProjectLayerType.REPOSITORY,
|
|
25
|
+
priority: 50,
|
|
26
|
+
data: projectRepository.getConfig(types_1.ProjectLayerType.REPOSITORY, this.name, this.path)
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: types_1.ProjectLayerType.GLOBAL,
|
|
30
|
+
priority: 100,
|
|
31
|
+
data: projectRepository.getConfig(types_1.ProjectLayerType.GLOBAL, this.name, this.path)
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
19
34
|
}
|
|
20
35
|
get ref() {
|
|
21
36
|
return this._ref;
|
|
22
37
|
}
|
|
23
38
|
get type() {
|
|
24
|
-
return this.
|
|
39
|
+
return this.resolver.resolve("type");
|
|
25
40
|
}
|
|
26
41
|
set type(type) {
|
|
27
|
-
this.
|
|
42
|
+
this.layer(types_1.ProjectLayerType.DATA).type = type;
|
|
28
43
|
}
|
|
29
44
|
get containerName() {
|
|
30
45
|
return `${this.name}.workspace`;
|
|
31
46
|
}
|
|
32
47
|
get scripts() {
|
|
33
|
-
return
|
|
48
|
+
return this.resolver.resolve("scripts");
|
|
34
49
|
}
|
|
35
50
|
get preset() {
|
|
36
|
-
return this.
|
|
51
|
+
return this.resolver.resolve("preset");
|
|
37
52
|
}
|
|
38
53
|
set preset(preset) {
|
|
39
|
-
this.
|
|
54
|
+
this.layer(types_1.ProjectLayerType.DATA).preset = preset;
|
|
40
55
|
}
|
|
41
56
|
get presetMode() {
|
|
42
|
-
return this.
|
|
57
|
+
return this.resolver.resolve("presetMode");
|
|
43
58
|
}
|
|
44
59
|
set presetMode(mode) {
|
|
45
|
-
this.
|
|
60
|
+
this.layer(types_1.ProjectLayerType.DATA).presetMode = mode;
|
|
46
61
|
}
|
|
47
62
|
get image() {
|
|
48
|
-
return this.
|
|
63
|
+
return this.resolver.resolve("image");
|
|
49
64
|
}
|
|
50
65
|
set image(image) {
|
|
51
66
|
if (!image) {
|
|
52
|
-
delete this.
|
|
67
|
+
delete this.layer(types_1.ProjectLayerType.DATA).image;
|
|
53
68
|
return;
|
|
54
69
|
}
|
|
55
|
-
this.
|
|
70
|
+
this.layer(types_1.ProjectLayerType.DATA).image = image;
|
|
56
71
|
}
|
|
57
72
|
/** @deprecated */
|
|
58
73
|
get imageName() {
|
|
@@ -63,19 +78,19 @@ class Project {
|
|
|
63
78
|
this.image = image;
|
|
64
79
|
}
|
|
65
80
|
get dockerfile() {
|
|
66
|
-
return this.
|
|
81
|
+
return this.resolver.resolve("dockerfile");
|
|
67
82
|
}
|
|
68
83
|
set dockerfile(dockerfile) {
|
|
69
|
-
this.
|
|
84
|
+
this.layer(types_1.ProjectLayerType.DATA).dockerfile = dockerfile;
|
|
70
85
|
}
|
|
71
86
|
get composefile() {
|
|
72
|
-
return this.
|
|
87
|
+
return this.resolver.resolve("composefile");
|
|
73
88
|
}
|
|
74
89
|
set composefile(composefile) {
|
|
75
|
-
this.
|
|
90
|
+
this.layer(types_1.ProjectLayerType.DATA).composefile = composefile;
|
|
76
91
|
}
|
|
77
92
|
get cmd() {
|
|
78
|
-
return this.
|
|
93
|
+
return this.resolver.resolve("cmd");
|
|
79
94
|
}
|
|
80
95
|
get domains() {
|
|
81
96
|
const host = this.getEnv("VIRTUAL_HOST");
|
|
@@ -109,108 +124,106 @@ class Project {
|
|
|
109
124
|
this.unsetEnv("VIRTUAL_HOST");
|
|
110
125
|
}
|
|
111
126
|
get volumes() {
|
|
112
|
-
return
|
|
113
|
-
...this.configs.project.volumes.filter((volume) => {
|
|
114
|
-
return !this.configs.app.getVolumeByDestination((0, volumeParse_1.volumeParse)(volume).destination);
|
|
115
|
-
}),
|
|
116
|
-
...this.configs.app.volumes
|
|
117
|
-
];
|
|
127
|
+
return this.resolver.resolve("volumes");
|
|
118
128
|
}
|
|
119
129
|
get ports() {
|
|
120
|
-
return
|
|
121
|
-
...this.configs.project.ports,
|
|
122
|
-
...this.configs.app.ports
|
|
123
|
-
];
|
|
130
|
+
return this.resolver.resolve("ports");
|
|
124
131
|
}
|
|
125
132
|
set ports(ports) {
|
|
126
|
-
this.
|
|
133
|
+
this.layer(types_1.ProjectLayerType.DATA).ports = ports;
|
|
127
134
|
}
|
|
128
135
|
linkPort(hostPort, containerPort) {
|
|
129
|
-
this.
|
|
130
|
-
...this.
|
|
136
|
+
this.layer(types_1.ProjectLayerType.DATA).ports = [
|
|
137
|
+
...(this.layer(types_1.ProjectLayerType.DATA).ports || []).filter((link) => {
|
|
131
138
|
return link !== `${hostPort}:${containerPort}`;
|
|
132
139
|
}),
|
|
133
140
|
`${hostPort}:${containerPort}`
|
|
134
141
|
];
|
|
135
142
|
}
|
|
136
143
|
unlinkPort(hostPort, containerPort) {
|
|
137
|
-
this.
|
|
144
|
+
this.layer(types_1.ProjectLayerType.DATA).ports = (this.layer(types_1.ProjectLayerType.DATA).ports || []).filter((link) => {
|
|
138
145
|
return link !== `${hostPort}:${containerPort}`;
|
|
139
146
|
});
|
|
140
147
|
}
|
|
141
148
|
get buildArgs() {
|
|
142
|
-
return
|
|
149
|
+
return this.resolver.resolve("buildArgs");
|
|
143
150
|
}
|
|
144
151
|
set buildArgs(buildArgs) {
|
|
145
|
-
this.
|
|
152
|
+
this.layer(types_1.ProjectLayerType.DATA).buildArgs = buildArgs;
|
|
146
153
|
}
|
|
147
154
|
setBuildArg(key, value, service) {
|
|
148
|
-
this.
|
|
155
|
+
this.layer(types_1.ProjectLayerType.DATA).setBuildArg(key, value, service);
|
|
149
156
|
}
|
|
150
157
|
unsetBuildArg(name, service) {
|
|
151
|
-
this.
|
|
158
|
+
this.layer(types_1.ProjectLayerType.DATA).unsetBuildArg(name, service);
|
|
152
159
|
}
|
|
153
160
|
get env() {
|
|
154
|
-
return
|
|
161
|
+
return this.resolver.resolve("env");
|
|
155
162
|
}
|
|
156
163
|
set env(env) {
|
|
157
|
-
this.
|
|
164
|
+
this.layer(types_1.ProjectLayerType.DATA).env = env;
|
|
158
165
|
}
|
|
159
166
|
hasEnv(name) {
|
|
160
|
-
return
|
|
167
|
+
return name in this.env;
|
|
161
168
|
}
|
|
162
169
|
getEnv(key, byDefault) {
|
|
163
|
-
|
|
170
|
+
var _a;
|
|
171
|
+
return (_a = this.resolver.resolve(["env", key])) !== null && _a !== void 0 ? _a : byDefault;
|
|
164
172
|
}
|
|
165
173
|
setEnv(key, value, service) {
|
|
166
|
-
this.
|
|
174
|
+
this.layer(types_1.ProjectLayerType.DATA).setEnv(key, value, service);
|
|
167
175
|
}
|
|
168
176
|
unsetEnv(key, service) {
|
|
169
|
-
this.
|
|
177
|
+
this.layer(types_1.ProjectLayerType.DATA).unsetEnv(key, service);
|
|
170
178
|
}
|
|
171
179
|
hasMeta(key) {
|
|
172
|
-
return key in this.
|
|
180
|
+
return key in this.metadata;
|
|
173
181
|
}
|
|
174
182
|
getMeta(key, byDefault) {
|
|
175
|
-
|
|
183
|
+
var _a;
|
|
184
|
+
return (_a = this.resolver.resolve(["metadata", key])) !== null && _a !== void 0 ? _a : byDefault;
|
|
176
185
|
}
|
|
177
186
|
setMeta(name, value) {
|
|
178
|
-
this.
|
|
187
|
+
this.layer(types_1.ProjectLayerType.DATA).metadata[name] = typeof value === "boolean"
|
|
179
188
|
? (value ? "true" : "false")
|
|
180
189
|
: value;
|
|
181
190
|
}
|
|
182
191
|
unsetMeta(name) {
|
|
183
|
-
if (name in this.
|
|
184
|
-
delete this.
|
|
192
|
+
if (name in this.layer(types_1.ProjectLayerType.DATA).metadata) {
|
|
193
|
+
delete this.layer(types_1.ProjectLayerType.DATA).metadata[name];
|
|
185
194
|
}
|
|
186
195
|
}
|
|
187
196
|
getVolumeBySource(source) {
|
|
188
|
-
return this.
|
|
197
|
+
return [...this.volumes].reverse().find((volume) => {
|
|
198
|
+
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
199
|
+
});
|
|
189
200
|
}
|
|
190
201
|
getVolumeByDestination(destination) {
|
|
191
|
-
return this.
|
|
202
|
+
return [...this.volumes].reverse().find((volume) => {
|
|
203
|
+
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
204
|
+
});
|
|
192
205
|
}
|
|
193
206
|
volumeMount(...volumes) {
|
|
194
|
-
this.
|
|
207
|
+
this.layer(types_1.ProjectLayerType.DATA).volumeMount(...volumes);
|
|
195
208
|
}
|
|
196
209
|
volumeUnmount(...volumes) {
|
|
197
|
-
this.
|
|
210
|
+
this.layer(types_1.ProjectLayerType.DATA).volumeUnmount(...volumes);
|
|
198
211
|
}
|
|
199
212
|
get extraHosts() {
|
|
200
|
-
return
|
|
213
|
+
return this.resolver.resolve("extraHosts");
|
|
201
214
|
}
|
|
202
215
|
;
|
|
203
216
|
addExtraHost(host, domain) {
|
|
204
|
-
this.
|
|
217
|
+
this.layer(types_1.ProjectLayerType.DATA).addExtraHost(host, domain);
|
|
205
218
|
}
|
|
206
219
|
removeExtraHost(host) {
|
|
207
|
-
this.
|
|
220
|
+
this.layer(types_1.ProjectLayerType.DATA).removeExtraHost(host);
|
|
208
221
|
}
|
|
209
222
|
get metadata() {
|
|
210
|
-
return
|
|
223
|
+
return this.resolver.resolve("metadata");
|
|
211
224
|
}
|
|
212
225
|
get services() {
|
|
213
|
-
return this.
|
|
226
|
+
return this.resolver.resolve("services");
|
|
214
227
|
}
|
|
215
228
|
async getSecret(key, byDefault) {
|
|
216
229
|
const container = AsyncStorage_1.AsyncStorage.getContainer(), keystoreService = container.get("KEYSTORE_SERVICE");
|
|
@@ -230,6 +243,22 @@ class Project {
|
|
|
230
243
|
const container = AsyncStorage_1.AsyncStorage.getContainer(), keystoreService = container.get("KEYSTORE_SERVICE");
|
|
231
244
|
return keystoreService.delete(`p:${this.name}:${key}`);
|
|
232
245
|
}
|
|
246
|
+
layer(key) {
|
|
247
|
+
const layer = this.resolver.layer(key);
|
|
248
|
+
if (!layer) {
|
|
249
|
+
throw new Error(`Layer "${key}" not found`);
|
|
250
|
+
}
|
|
251
|
+
return layer.data;
|
|
252
|
+
}
|
|
253
|
+
layers() {
|
|
254
|
+
return this.resolver.layers.reduce((res, layer) => {
|
|
255
|
+
res.set(layer.name, layer.data);
|
|
256
|
+
return res;
|
|
257
|
+
}, new Map());
|
|
258
|
+
}
|
|
259
|
+
origin(path) {
|
|
260
|
+
return this.resolver.origin(path);
|
|
261
|
+
}
|
|
233
262
|
save() {
|
|
234
263
|
const container = AsyncStorage_1.AsyncStorage.getContainer(), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
|
|
235
264
|
projectRepository.save(this);
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { JsonEditor } from "./JsonEditor";
|
|
2
|
-
import {
|
|
3
|
-
import { EnvConfig, ProjectType,
|
|
2
|
+
import { Rules } from "./LayerResolver";
|
|
3
|
+
import { EnvConfig, ProjectType, PresetMode } from "../types";
|
|
4
4
|
export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
constructor(content: string);
|
|
6
|
+
protected migrateImageName(): void;
|
|
7
7
|
get type(): ProjectType | undefined;
|
|
8
8
|
set type(type: ProjectType | undefined);
|
|
9
9
|
get image(): string | undefined;
|
|
10
10
|
set image(image: string | undefined);
|
|
11
|
-
get imageName(): string | undefined;
|
|
12
|
-
set imageName(image: string | undefined);
|
|
13
11
|
get dockerfile(): string | undefined;
|
|
14
12
|
set dockerfile(dockerfile: string | undefined);
|
|
15
13
|
get composefile(): string | undefined;
|
|
@@ -26,9 +24,9 @@ export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
|
|
|
26
24
|
set metadata(metadata: EnvConfig);
|
|
27
25
|
get cmd(): string[] | undefined;
|
|
28
26
|
set cmd(cmd: string[] | undefined);
|
|
29
|
-
get scripts():
|
|
30
|
-
set scripts(scripts:
|
|
31
|
-
get services():
|
|
27
|
+
get scripts(): Record<string, string> | undefined;
|
|
28
|
+
set scripts(scripts: Record<string, string> | undefined);
|
|
29
|
+
get services(): Record<string, ProjectConfig.Service>;
|
|
32
30
|
get extraHosts(): any;
|
|
33
31
|
set extraHosts(extraHosts: any);
|
|
34
32
|
get volumes(): string[];
|
|
@@ -48,8 +46,6 @@ export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
|
|
|
48
46
|
volumeUnmount(...volumes: string[]): void;
|
|
49
47
|
addExtraHost(host: string, domain: string): void;
|
|
50
48
|
removeExtraHost(host: string): void;
|
|
51
|
-
addService(name: string, data: ServiceConfig.Data): void;
|
|
52
|
-
service(name: string): any;
|
|
53
49
|
}
|
|
54
50
|
export declare namespace ProjectConfig {
|
|
55
51
|
type Data = {
|
|
@@ -81,4 +77,7 @@ export declare namespace ProjectConfig {
|
|
|
81
77
|
ports?: string[];
|
|
82
78
|
volumes?: string[];
|
|
83
79
|
};
|
|
80
|
+
type Resolvable = Omit<Data, "imageName">;
|
|
81
|
+
const serviceRules: Rules<Service>;
|
|
82
|
+
const rules: Rules<Resolvable>;
|
|
84
83
|
}
|
|
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ProjectConfig = void 0;
|
|
4
4
|
const volumeParse_1 = require("../utils/volumeParse");
|
|
5
5
|
const JsonEditor_1 = require("./JsonEditor");
|
|
6
|
+
const LayerResolver_1 = require("./LayerResolver");
|
|
6
7
|
class ProjectConfig extends JsonEditor_1.JsonEditor {
|
|
7
|
-
constructor(
|
|
8
|
+
constructor(content) {
|
|
8
9
|
super(content, {
|
|
9
10
|
"": [
|
|
10
|
-
|
|
11
|
+
"name",
|
|
12
|
+
"version",
|
|
11
13
|
"type",
|
|
12
14
|
"image",
|
|
13
15
|
"dockerfile",
|
|
@@ -29,7 +31,17 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
|
|
|
29
31
|
"VIRTUAL_PORT"
|
|
30
32
|
]
|
|
31
33
|
});
|
|
32
|
-
this.
|
|
34
|
+
this.migrateImageName();
|
|
35
|
+
}
|
|
36
|
+
migrateImageName() {
|
|
37
|
+
const imageName = this.get(["imageName"]);
|
|
38
|
+
if (imageName === undefined) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (this.get(["image"]) === undefined) {
|
|
42
|
+
this.set(["image"], imageName);
|
|
43
|
+
}
|
|
44
|
+
this.unset(["imageName"]);
|
|
33
45
|
}
|
|
34
46
|
get type() {
|
|
35
47
|
return this.state.type;
|
|
@@ -38,17 +50,10 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
|
|
|
38
50
|
this.state.type = type;
|
|
39
51
|
}
|
|
40
52
|
get image() {
|
|
41
|
-
return this.state.image
|
|
53
|
+
return this.state.image;
|
|
42
54
|
}
|
|
43
55
|
set image(image) {
|
|
44
56
|
this.state.image = image;
|
|
45
|
-
this.state.imageName = undefined;
|
|
46
|
-
}
|
|
47
|
-
get imageName() {
|
|
48
|
-
return this.image;
|
|
49
|
-
}
|
|
50
|
-
set imageName(image) {
|
|
51
|
-
this.image = image;
|
|
52
57
|
}
|
|
53
58
|
get dockerfile() {
|
|
54
59
|
return this.state.dockerfile;
|
|
@@ -110,10 +115,12 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
|
|
|
110
115
|
});
|
|
111
116
|
}
|
|
112
117
|
set scripts(scripts) {
|
|
113
|
-
this.
|
|
118
|
+
this.set(["scripts"], scripts);
|
|
114
119
|
}
|
|
115
120
|
get services() {
|
|
116
|
-
return {
|
|
121
|
+
return this.createProxy(["services"], {
|
|
122
|
+
removeOnEmpty: true
|
|
123
|
+
});
|
|
117
124
|
}
|
|
118
125
|
get extraHosts() {
|
|
119
126
|
return this.createProxy(["extraHosts"], {
|
|
@@ -239,12 +246,48 @@ class ProjectConfig extends JsonEditor_1.JsonEditor {
|
|
|
239
246
|
delete this.state.extraHosts[host];
|
|
240
247
|
}
|
|
241
248
|
}
|
|
242
|
-
addService(name, data) {
|
|
243
|
-
}
|
|
244
|
-
service(name) {
|
|
245
|
-
return this.createProxy(["services", name], {
|
|
246
|
-
removeOnEmpty: true
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
249
|
}
|
|
250
250
|
exports.ProjectConfig = ProjectConfig;
|
|
251
|
+
(function (ProjectConfig) {
|
|
252
|
+
ProjectConfig.serviceRules = {
|
|
253
|
+
type: (0, LayerResolver_1.first)(),
|
|
254
|
+
containerName: (0, LayerResolver_1.first)(),
|
|
255
|
+
buildArgs: (0, LayerResolver_1.merge)(),
|
|
256
|
+
env: (0, LayerResolver_1.merge)(),
|
|
257
|
+
ports: (0, LayerResolver_1.concat)({
|
|
258
|
+
by: (port) => {
|
|
259
|
+
var _a;
|
|
260
|
+
const m = /^(\d+):\d+(?:\/(\w+))?$/.exec(port);
|
|
261
|
+
return m ? `${m[1]}/${(_a = m[2]) !== null && _a !== void 0 ? _a : "tcp"}` : port;
|
|
262
|
+
}
|
|
263
|
+
}),
|
|
264
|
+
volumes: (0, LayerResolver_1.concat)({
|
|
265
|
+
by: (volume) => (0, volumeParse_1.volumeParse)(volume).destination
|
|
266
|
+
})
|
|
267
|
+
};
|
|
268
|
+
ProjectConfig.rules = {
|
|
269
|
+
type: (0, LayerResolver_1.first)(),
|
|
270
|
+
image: (0, LayerResolver_1.first)(),
|
|
271
|
+
dockerfile: (0, LayerResolver_1.first)(),
|
|
272
|
+
composefile: (0, LayerResolver_1.first)(),
|
|
273
|
+
preset: (0, LayerResolver_1.first)(),
|
|
274
|
+
presetMode: (0, LayerResolver_1.first)(),
|
|
275
|
+
scripts: (0, LayerResolver_1.merge)(),
|
|
276
|
+
cmd: (0, LayerResolver_1.first)(),
|
|
277
|
+
buildArgs: (0, LayerResolver_1.merge)(),
|
|
278
|
+
env: (0, LayerResolver_1.merge)(),
|
|
279
|
+
metadata: (0, LayerResolver_1.merge)(),
|
|
280
|
+
volumes: (0, LayerResolver_1.concat)({
|
|
281
|
+
by: (volume) => (0, volumeParse_1.volumeParse)(volume).destination
|
|
282
|
+
}),
|
|
283
|
+
ports: (0, LayerResolver_1.concat)({
|
|
284
|
+
by: (port) => {
|
|
285
|
+
var _a;
|
|
286
|
+
const m = /^(\d+):\d+(?:\/(\w+))?$/.exec(port);
|
|
287
|
+
return m ? `${m[1]}/${(_a = m[2]) !== null && _a !== void 0 ? _a : "tcp"}` : port;
|
|
288
|
+
}
|
|
289
|
+
}),
|
|
290
|
+
extraHosts: (0, LayerResolver_1.merge)(),
|
|
291
|
+
services: (0, LayerResolver_1.record)(ProjectConfig.serviceRules)
|
|
292
|
+
};
|
|
293
|
+
})(ProjectConfig || (exports.ProjectConfig = ProjectConfig = {}));
|
|
@@ -2,13 +2,13 @@ import { Project } from "../makes/Project";
|
|
|
2
2
|
import { ProjectConfig } from "../makes/ProjectConfig";
|
|
3
3
|
import { AppService } from "./AppService";
|
|
4
4
|
import { AppFileSystemService } from "./AppFileSystemService";
|
|
5
|
-
import { FileSystemDriver,
|
|
5
|
+
import { FileSystemDriver, ProjectLayerType } from "../types";
|
|
6
6
|
export declare class ProjectRepository {
|
|
7
7
|
protected readonly appService: AppService;
|
|
8
8
|
protected readonly fs: AppFileSystemService;
|
|
9
9
|
protected readonly driver: FileSystemDriver;
|
|
10
10
|
constructor(appService: AppService, fs: AppFileSystemService, driver: FileSystemDriver);
|
|
11
|
-
getConfig(scope:
|
|
11
|
+
getConfig(scope: ProjectLayerType, name: string, path?: string): ProjectConfig;
|
|
12
12
|
getByName(name: string): Project;
|
|
13
13
|
save(project: Project): void;
|
|
14
14
|
search(params: ProjectRepository.SearchParams): Project[];
|
|
@@ -31,26 +31,30 @@ let ProjectRepository = class ProjectRepository {
|
|
|
31
31
|
getConfig(scope, name, path) {
|
|
32
32
|
const ref = this.appService.getProject(name);
|
|
33
33
|
switch (scope) {
|
|
34
|
-
case types_1.
|
|
34
|
+
case types_1.ProjectLayerType.DATA: {
|
|
35
35
|
if (!ref) {
|
|
36
|
-
return new ProjectConfig_1.ProjectConfig(
|
|
36
|
+
return new ProjectConfig_1.ProjectConfig("{}");
|
|
37
37
|
}
|
|
38
38
|
const fs = this.fs.cd(`projects/${ref.name}`);
|
|
39
39
|
if (!fs.exists("config.json")) {
|
|
40
|
-
return new ProjectConfig_1.ProjectConfig(
|
|
40
|
+
return new ProjectConfig_1.ProjectConfig("{}");
|
|
41
41
|
}
|
|
42
|
-
return new ProjectConfig_1.ProjectConfig(
|
|
42
|
+
return new ProjectConfig_1.ProjectConfig(fs.readFile("config.json").toString());
|
|
43
43
|
}
|
|
44
|
-
case types_1.
|
|
44
|
+
case types_1.ProjectLayerType.REPOSITORY:
|
|
45
45
|
path = path || (ref === null || ref === void 0 ? void 0 : ref.path);
|
|
46
46
|
if (!path) {
|
|
47
|
-
return new ProjectConfig_1.ProjectConfig(
|
|
47
|
+
return new ProjectConfig_1.ProjectConfig("{}");
|
|
48
48
|
}
|
|
49
49
|
const fs = new makes_1.FileSystem(path);
|
|
50
50
|
if (!fs.exists("wocker.config.json")) {
|
|
51
|
-
return new ProjectConfig_1.ProjectConfig(
|
|
51
|
+
return new ProjectConfig_1.ProjectConfig("{}");
|
|
52
52
|
}
|
|
53
|
-
return new ProjectConfig_1.ProjectConfig(
|
|
53
|
+
return new ProjectConfig_1.ProjectConfig(fs.readFile("wocker.config.json").toString());
|
|
54
|
+
case types_1.ProjectLayerType.GLOBAL:
|
|
55
|
+
return new ProjectConfig_1.ProjectConfig(JSON.stringify({
|
|
56
|
+
env: this.appService.config.env
|
|
57
|
+
}));
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
getByName(name) {
|
|
@@ -67,12 +71,13 @@ let ProjectRepository = class ProjectRepository {
|
|
|
67
71
|
if (!this.fs.exists(`projects/${project.name}`)) {
|
|
68
72
|
this.fs.mkdir(`projects/${project.name}`);
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
const appLayer = project.layer(types_1.ProjectLayerType.DATA), projectLayer = project.layer(types_1.ProjectLayerType.REPOSITORY);
|
|
75
|
+
if (appLayer.isDirty()) {
|
|
76
|
+
this.fs.writeFile(`projects/${project.name}/config.json`, appLayer.toString());
|
|
72
77
|
}
|
|
73
|
-
if (
|
|
78
|
+
if (projectLayer.isDirty()) {
|
|
74
79
|
const projectFS = new makes_1.FileSystem(project.path, this.driver);
|
|
75
|
-
projectFS.writeFile("wocker.config.json",
|
|
80
|
+
projectFS.writeFile("wocker.config.json", projectLayer.toString());
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
search(params) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ProjectRef } from "../types";
|
|
2
|
+
export declare enum ProjectLayerTypeEnum {
|
|
3
|
+
DATA = "app",
|
|
4
|
+
REPOSITORY = "project",
|
|
5
|
+
GLOBAL = "global"
|
|
6
|
+
}
|
|
7
|
+
export type ProjectLayerType = ProjectLayerTypeEnum;
|
|
8
|
+
export declare const ProjectLayerType: typeof ProjectLayerTypeEnum & {
|
|
9
|
+
label(type: ProjectLayerTypeEnum): string;
|
|
10
|
+
fileName(type: ProjectLayerTypeEnum, projectRef: ProjectRef): string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProjectLayerType = exports.ProjectLayerTypeEnum = void 0;
|
|
4
|
+
var ProjectLayerTypeEnum;
|
|
5
|
+
(function (ProjectLayerTypeEnum) {
|
|
6
|
+
ProjectLayerTypeEnum["DATA"] = "app";
|
|
7
|
+
ProjectLayerTypeEnum["REPOSITORY"] = "project";
|
|
8
|
+
ProjectLayerTypeEnum["GLOBAL"] = "global";
|
|
9
|
+
})(ProjectLayerTypeEnum || (exports.ProjectLayerTypeEnum = ProjectLayerTypeEnum = {}));
|
|
10
|
+
exports.ProjectLayerType = Object.assign({}, ProjectLayerTypeEnum, {
|
|
11
|
+
label(type) {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case ProjectLayerTypeEnum.DATA:
|
|
14
|
+
return "Data";
|
|
15
|
+
case ProjectLayerTypeEnum.GLOBAL:
|
|
16
|
+
return "Global";
|
|
17
|
+
case ProjectLayerTypeEnum.REPOSITORY:
|
|
18
|
+
return "Repository";
|
|
19
|
+
default:
|
|
20
|
+
return type;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
fileName(type, projectRef) {
|
|
24
|
+
switch (type) {
|
|
25
|
+
case ProjectLayerTypeEnum.DATA:
|
|
26
|
+
return `projects/${projectRef.name}/config.json`;
|
|
27
|
+
case ProjectLayerTypeEnum.REPOSITORY:
|
|
28
|
+
return `wocker.config.json`;
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(`Unknown config layer: ${type}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
package/lib/types/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from "./PackageManagerType";
|
|
|
9
9
|
export * from "./PickProperties";
|
|
10
10
|
export * from "./Permissions";
|
|
11
11
|
export * from "./PluginMetadata";
|
|
12
|
-
export * from "./
|
|
12
|
+
export * from "./ProjectLayerType";
|
|
13
13
|
export * from "./PluginRef";
|
|
14
14
|
export * from "./PresetRef";
|
|
15
15
|
export * from "./PresetMode";
|
package/lib/types/index.js
CHANGED
|
@@ -25,7 +25,7 @@ __exportStar(require("./PackageManagerType"), exports);
|
|
|
25
25
|
__exportStar(require("./PickProperties"), exports);
|
|
26
26
|
__exportStar(require("./Permissions"), exports);
|
|
27
27
|
__exportStar(require("./PluginMetadata"), exports);
|
|
28
|
-
__exportStar(require("./
|
|
28
|
+
__exportStar(require("./ProjectLayerType"), exports);
|
|
29
29
|
__exportStar(require("./PluginRef"), exports);
|
|
30
30
|
__exportStar(require("./PresetRef"), exports);
|
|
31
31
|
__exportStar(require("./PresetMode"), exports);
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { EnvConfig } from "../types";
|
|
2
|
-
export declare class ServiceConfig {
|
|
3
|
-
protected readonly original: ServiceConfig.Data;
|
|
4
|
-
protected readonly state: ServiceConfig.Data;
|
|
5
|
-
constructor(original: ServiceConfig.Data);
|
|
6
|
-
get buildArgs(): EnvConfig;
|
|
7
|
-
set buildArgs(buildArgs: EnvConfig);
|
|
8
|
-
get env(): EnvConfig;
|
|
9
|
-
set env(env: EnvConfig);
|
|
10
|
-
isDirty(): boolean;
|
|
11
|
-
toObject(): ServiceConfig.Data;
|
|
12
|
-
}
|
|
13
|
-
export declare namespace ServiceConfig {
|
|
14
|
-
type Data = {
|
|
15
|
-
type?: "compose" | "plugin";
|
|
16
|
-
image?: string;
|
|
17
|
-
containerName?: string;
|
|
18
|
-
buildArgs?: EnvConfig;
|
|
19
|
-
env?: EnvConfig;
|
|
20
|
-
ports?: string[];
|
|
21
|
-
volumes?: string[];
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ServiceConfig = void 0;
|
|
4
|
-
class ServiceConfig {
|
|
5
|
-
constructor(original) {
|
|
6
|
-
this.original = original;
|
|
7
|
-
this.state = JSON.parse(JSON.stringify(this.original));
|
|
8
|
-
}
|
|
9
|
-
get buildArgs() {
|
|
10
|
-
if (!this.state.buildArgs) {
|
|
11
|
-
this.state.buildArgs = {};
|
|
12
|
-
}
|
|
13
|
-
return this.state.buildArgs;
|
|
14
|
-
}
|
|
15
|
-
set buildArgs(buildArgs) {
|
|
16
|
-
this.state.buildArgs = Object.assign({}, buildArgs);
|
|
17
|
-
}
|
|
18
|
-
get env() {
|
|
19
|
-
if (!this.state.env) {
|
|
20
|
-
this.state.env = {};
|
|
21
|
-
}
|
|
22
|
-
return this.state.env;
|
|
23
|
-
}
|
|
24
|
-
set env(env) {
|
|
25
|
-
this.state.env = Object.assign({}, env);
|
|
26
|
-
}
|
|
27
|
-
isDirty() {
|
|
28
|
-
return JSON.stringify(this.toObject()) !== JSON.stringify(this.original);
|
|
29
|
-
}
|
|
30
|
-
toObject() {
|
|
31
|
-
const { type, image, containerName, buildArgs, env, volumes, ports } = this.state;
|
|
32
|
-
const object = {};
|
|
33
|
-
if (type) {
|
|
34
|
-
object.type = type;
|
|
35
|
-
}
|
|
36
|
-
if (image) {
|
|
37
|
-
object.image = image;
|
|
38
|
-
}
|
|
39
|
-
if (containerName) {
|
|
40
|
-
object.containerName = containerName;
|
|
41
|
-
}
|
|
42
|
-
if (buildArgs && Object.keys(buildArgs).length > 0) {
|
|
43
|
-
object.buildArgs = Object.assign({}, buildArgs);
|
|
44
|
-
}
|
|
45
|
-
if (env && Object.keys(env).length > 0) {
|
|
46
|
-
object.env = Object.assign({}, env);
|
|
47
|
-
}
|
|
48
|
-
if (volumes && volumes.length > 0) {
|
|
49
|
-
object.volumes = [...volumes];
|
|
50
|
-
}
|
|
51
|
-
if (ports && ports.length > 0) {
|
|
52
|
-
object.ports = [...ports];
|
|
53
|
-
}
|
|
54
|
-
return object;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.ServiceConfig = ServiceConfig;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ProjectRef } from "../types";
|
|
2
|
-
export declare enum ProjectConfigScopeEnum {
|
|
3
|
-
APP = "app",
|
|
4
|
-
LOCAL = "project"
|
|
5
|
-
}
|
|
6
|
-
export type ProjectConfigScope = ProjectConfigScopeEnum;
|
|
7
|
-
export declare const ProjectConfigScope: typeof ProjectConfigScopeEnum & {
|
|
8
|
-
fileName(scope: ProjectConfigScopeEnum, projectRef: ProjectRef): string;
|
|
9
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectConfigScope = exports.ProjectConfigScopeEnum = void 0;
|
|
4
|
-
var ProjectConfigScopeEnum;
|
|
5
|
-
(function (ProjectConfigScopeEnum) {
|
|
6
|
-
ProjectConfigScopeEnum["APP"] = "app";
|
|
7
|
-
ProjectConfigScopeEnum["LOCAL"] = "project";
|
|
8
|
-
})(ProjectConfigScopeEnum || (exports.ProjectConfigScopeEnum = ProjectConfigScopeEnum = {}));
|
|
9
|
-
exports.ProjectConfigScope = Object.assign({}, ProjectConfigScopeEnum, {
|
|
10
|
-
fileName(scope, projectRef) {
|
|
11
|
-
switch (scope) {
|
|
12
|
-
case ProjectConfigScopeEnum.APP:
|
|
13
|
-
return `projects/${projectRef.name}/config.json`;
|
|
14
|
-
case ProjectConfigScopeEnum.LOCAL:
|
|
15
|
-
return `wocker.config.json`;
|
|
16
|
-
default:
|
|
17
|
-
throw new Error(`Unknown config scope: ${scope}`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|