@wocker/core 1.1.0-beta.2 → 1.1.0-beta.3
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/Container.js +2 -2
- package/lib/core/CoreModule.js +3 -0
- package/lib/makes/JsonEditor.d.ts +19 -0
- package/lib/makes/JsonEditor.js +101 -0
- package/lib/{modules/project/makes → makes}/Project.d.ts +7 -12
- package/lib/{modules/project/makes → makes}/Project.js +13 -30
- package/lib/makes/ProjectConfig.d.ts +85 -0
- package/lib/makes/ProjectConfig.js +329 -0
- package/lib/makes/ServiceConfig.d.ts +23 -0
- package/lib/makes/ServiceConfig.js +57 -0
- package/lib/makes/index.d.ts +1 -0
- package/lib/makes/index.js +1 -0
- package/lib/modules/project/index.d.ts +0 -4
- package/lib/modules/project/index.js +0 -3
- package/lib/modules/project/services/ProjectService.d.ts +2 -2
- package/lib/{modules/project/repositories → services}/ProjectRepository.d.ts +3 -3
- package/lib/{modules/project/repositories → services}/ProjectRepository.js +21 -8
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.js +1 -0
- package/lib/{modules/project/types → types}/ProjectConfigScope.d.ts +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +2 -1
- package/lib/modules/project/makes/ProjectConfig.d.ts +0 -61
- package/lib/modules/project/makes/ProjectConfig.js +0 -164
- package/lib/modules/project/makes/ServiceConfig.d.ts +0 -2
- package/lib/modules/project/makes/ServiceConfig.js +0 -6
- package/lib/modules/project/types/ProjectV1.d.ts +0 -25
- package/lib/modules/project/types/ProjectV1.js +0 -2
- package/lib/modules/project/types/ServiceProperties.d.ts +0 -9
- package/lib/modules/project/types/ServiceProperties.js +0 -2
- package/lib/modules/project/types/index.d.ts +0 -3
- package/lib/modules/project/types/index.js +0 -19
- /package/lib/{modules/project/types → types}/ProjectConfigScope.js +0 -0
package/lib/core/Container.js
CHANGED
|
@@ -55,8 +55,8 @@ let Container = class Container {
|
|
|
55
55
|
if (wrapper) {
|
|
56
56
|
wrapper.replace(provider);
|
|
57
57
|
}
|
|
58
|
-
this.modules.forEach((
|
|
59
|
-
|
|
58
|
+
this.modules.forEach((moduleWrapper) => {
|
|
59
|
+
moduleWrapper.replace(token, provider);
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
};
|
package/lib/core/CoreModule.js
CHANGED
|
@@ -19,6 +19,7 @@ const AppFileSystemService_1 = require("../services/AppFileSystemService");
|
|
|
19
19
|
const ProcessService_1 = require("../services/ProcessService");
|
|
20
20
|
const EventService_1 = require("../services/EventService");
|
|
21
21
|
const LogService_1 = require("../services/LogService");
|
|
22
|
+
const ProjectRepository_1 = require("../services/ProjectRepository");
|
|
22
23
|
const env_1 = require("../env");
|
|
23
24
|
let CoreModule = class CoreModule {
|
|
24
25
|
};
|
|
@@ -43,6 +44,7 @@ exports.CoreModule = CoreModule = __decorate([
|
|
|
43
44
|
AppService_1.AppService,
|
|
44
45
|
AppConfigService_1.AppConfigService,
|
|
45
46
|
AppFileSystemService_1.AppFileSystemService,
|
|
47
|
+
ProjectRepository_1.ProjectRepository,
|
|
46
48
|
ProcessService_1.ProcessService,
|
|
47
49
|
EventService_1.EventService,
|
|
48
50
|
LogService_1.LogService
|
|
@@ -55,6 +57,7 @@ exports.CoreModule = CoreModule = __decorate([
|
|
|
55
57
|
AppService_1.AppService,
|
|
56
58
|
AppConfigService_1.AppConfigService,
|
|
57
59
|
AppFileSystemService_1.AppFileSystemService,
|
|
60
|
+
ProjectRepository_1.ProjectRepository,
|
|
58
61
|
ProcessService_1.ProcessService,
|
|
59
62
|
EventService_1.EventService,
|
|
60
63
|
LogService_1.LogService
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JSONPath, Node, ModificationOptions } from "jsonc-parser";
|
|
2
|
+
export declare class JsonEditor<T extends object> {
|
|
3
|
+
protected readonly original: string;
|
|
4
|
+
protected content: string;
|
|
5
|
+
protected root: Node;
|
|
6
|
+
state: T;
|
|
7
|
+
constructor(original: string);
|
|
8
|
+
protected createProxy(keys: JSONPath, options?: JsonEditor.CreateProxyOptions): any;
|
|
9
|
+
get(key: string | JSONPath): any;
|
|
10
|
+
set(key: string | JSONPath, value: any, options?: ModificationOptions): void;
|
|
11
|
+
isDirty(): boolean;
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace JsonEditor {
|
|
15
|
+
type CreateProxyOptions = {
|
|
16
|
+
isArray?: boolean;
|
|
17
|
+
removeOnEmpty?: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonEditor = void 0;
|
|
4
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
5
|
+
class JsonEditor {
|
|
6
|
+
constructor(original) {
|
|
7
|
+
this.original = original;
|
|
8
|
+
this.content = this.original;
|
|
9
|
+
this.root = (0, jsonc_parser_1.parseTree)(this.content);
|
|
10
|
+
this.state = this.createProxy([]);
|
|
11
|
+
}
|
|
12
|
+
createProxy(keys, options = {}) {
|
|
13
|
+
const { isArray, removeOnEmpty } = options;
|
|
14
|
+
let target = this.get(keys);
|
|
15
|
+
if (!target) {
|
|
16
|
+
target = isArray ? [] : {};
|
|
17
|
+
}
|
|
18
|
+
return new Proxy(target, {
|
|
19
|
+
get: (target, property) => {
|
|
20
|
+
if (target && target.__proto__ && property in target.__proto__) {
|
|
21
|
+
if (typeof target[property] === "function") {
|
|
22
|
+
return (...args) => {
|
|
23
|
+
const res = target[property](...args);
|
|
24
|
+
this.set(keys, target, {
|
|
25
|
+
formattingOptions: {
|
|
26
|
+
keepLines: false,
|
|
27
|
+
insertSpaces: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return res;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return target[property];
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(target)) {
|
|
36
|
+
property = parseInt(property);
|
|
37
|
+
}
|
|
38
|
+
const value = this.get([...keys, property]);
|
|
39
|
+
if (value !== null && typeof value === "object") {
|
|
40
|
+
return this.createProxy([...keys, property]);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
},
|
|
44
|
+
set: (_, property, value) => {
|
|
45
|
+
if (Array.isArray(_)) {
|
|
46
|
+
property = parseInt(property);
|
|
47
|
+
}
|
|
48
|
+
this.set([...keys, property], value, {
|
|
49
|
+
formattingOptions: {
|
|
50
|
+
keepLines: false,
|
|
51
|
+
insertSpaces: true
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (removeOnEmpty) {
|
|
55
|
+
const value = this.get(keys);
|
|
56
|
+
if (typeof value === "object" && Object.keys(value).length === 0) {
|
|
57
|
+
this.set(keys, undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
has: (target, property) => {
|
|
63
|
+
return property in target;
|
|
64
|
+
},
|
|
65
|
+
deleteProperty: (_, property) => {
|
|
66
|
+
if (Array.isArray(_)) {
|
|
67
|
+
property = parseInt(property);
|
|
68
|
+
}
|
|
69
|
+
this.set([...keys, property], undefined);
|
|
70
|
+
if (removeOnEmpty) {
|
|
71
|
+
const value = this.get(keys);
|
|
72
|
+
if (typeof value === "object" && Object.keys(value).length === 0) {
|
|
73
|
+
this.set(keys, undefined);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
;
|
|
81
|
+
get(key) {
|
|
82
|
+
const path = typeof key === "string" ? key.split(".") : key;
|
|
83
|
+
const node = (0, jsonc_parser_1.findNodeAtLocation)(this.root, path);
|
|
84
|
+
if (!node) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return (0, jsonc_parser_1.getNodeValue)(node);
|
|
88
|
+
}
|
|
89
|
+
set(key, value, options = {}) {
|
|
90
|
+
const path = typeof key === "string" ? key.split(".") : key;
|
|
91
|
+
this.content = (0, jsonc_parser_1.applyEdits)(this.content, (0, jsonc_parser_1.modify)(this.content, path, value, options));
|
|
92
|
+
this.root = (0, jsonc_parser_1.parseTree)(this.content);
|
|
93
|
+
}
|
|
94
|
+
isDirty() {
|
|
95
|
+
return this.content !== this.original;
|
|
96
|
+
}
|
|
97
|
+
toString() {
|
|
98
|
+
return this.content;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.JsonEditor = JsonEditor;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { EnvConfig, ProjectType } from "../../../types";
|
|
2
|
-
import { ProjectConfigScope } from "../types";
|
|
3
1
|
import { ProjectConfig } from "./ProjectConfig";
|
|
2
|
+
import { EnvConfig, ProjectConfigScope, ProjectRef, ProjectType } from "../types";
|
|
4
3
|
export declare class Project {
|
|
5
4
|
name: string;
|
|
6
5
|
path: string;
|
|
7
|
-
|
|
6
|
+
readonly ref?: ProjectRef;
|
|
7
|
+
readonly configs: Record<ProjectConfigScope, ProjectConfig>;
|
|
8
8
|
constructor(name: string, path: string);
|
|
9
|
-
protected getConfig(scope: ProjectConfigScope): ProjectConfig;
|
|
10
9
|
get type(): ProjectType;
|
|
11
10
|
set type(type: ProjectType);
|
|
12
11
|
get containerName(): string;
|
|
13
|
-
get scripts():
|
|
14
|
-
[x: string]: string;
|
|
15
|
-
};
|
|
12
|
+
get scripts(): any;
|
|
16
13
|
get preset(): string | undefined;
|
|
17
14
|
set preset(preset: string | undefined);
|
|
18
15
|
get presetMode(): "project" | "global";
|
|
@@ -36,7 +33,7 @@ export declare class Project {
|
|
|
36
33
|
unlinkPort(hostPort: number, containerPort: number): void;
|
|
37
34
|
get buildArgs(): EnvConfig;
|
|
38
35
|
set buildArgs(buildArgs: EnvConfig);
|
|
39
|
-
setBuildArg(
|
|
36
|
+
setBuildArg(key: string, value: string, service?: string): void;
|
|
40
37
|
unsetBuildArg(name: string, service?: string): void;
|
|
41
38
|
get env(): EnvConfig;
|
|
42
39
|
set env(env: EnvConfig);
|
|
@@ -54,12 +51,10 @@ export declare class Project {
|
|
|
54
51
|
getVolumeByDestination(destination: string): string | undefined;
|
|
55
52
|
volumeMount(...volumes: string[]): void;
|
|
56
53
|
volumeUnmount(...volumes: string[]): void;
|
|
57
|
-
get extraHosts():
|
|
58
|
-
[x: string]: string;
|
|
59
|
-
};
|
|
54
|
+
get extraHosts(): any;
|
|
60
55
|
addExtraHost(host: string, domain: string): void;
|
|
61
56
|
removeExtraHost(host: string): void;
|
|
62
|
-
get services():
|
|
57
|
+
get services(): any;
|
|
63
58
|
getSecret(key: string): Promise<string | undefined>;
|
|
64
59
|
getSecret(key: string, byDefault: string): Promise<string>;
|
|
65
60
|
setSecret(key: string, value: string): Promise<void>;
|
|
@@ -10,24 +10,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Project = void 0;
|
|
13
|
-
const AsyncStorage_1 = require("
|
|
14
|
-
const AppService_1 = require("
|
|
15
|
-
const
|
|
16
|
-
const
|
|
13
|
+
const AsyncStorage_1 = require("../core/AsyncStorage");
|
|
14
|
+
const AppService_1 = require("../services/AppService");
|
|
15
|
+
const ProjectRepository_1 = require("../services/ProjectRepository");
|
|
16
|
+
const volumeParse_1 = require("../utils/volumeParse");
|
|
17
17
|
const types_1 = require("../types");
|
|
18
18
|
class Project {
|
|
19
19
|
constructor(name, path) {
|
|
20
20
|
this.name = name;
|
|
21
21
|
this.path = path;
|
|
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);
|
|
22
24
|
this.configs = {
|
|
23
|
-
[types_1.ProjectConfigScope.APP]:
|
|
24
|
-
[types_1.ProjectConfigScope.LOCAL]:
|
|
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
27
|
};
|
|
26
28
|
}
|
|
27
|
-
getConfig(scope) {
|
|
28
|
-
const container = AsyncStorage_1.AsyncStorage.getContainer(), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
|
|
29
|
-
return projectRepository.getConfig(this.name, scope);
|
|
30
|
-
}
|
|
31
29
|
get type() {
|
|
32
30
|
return this.configs.app.type || this.configs.project.type;
|
|
33
31
|
}
|
|
@@ -41,7 +39,7 @@ class Project {
|
|
|
41
39
|
return Object.assign(Object.assign({}, this.configs.project.scripts), this.configs.app.scripts);
|
|
42
40
|
}
|
|
43
41
|
get preset() {
|
|
44
|
-
return this.configs.app.preset;
|
|
42
|
+
return this.configs.project.preset || this.configs.app.preset;
|
|
45
43
|
}
|
|
46
44
|
set preset(preset) {
|
|
47
45
|
this.configs.app.preset = preset;
|
|
@@ -140,18 +138,8 @@ class Project {
|
|
|
140
138
|
set buildArgs(buildArgs) {
|
|
141
139
|
this.configs.app.buildArgs = buildArgs;
|
|
142
140
|
}
|
|
143
|
-
setBuildArg(
|
|
144
|
-
|
|
145
|
-
if (!this.configs.app.services[service]) {
|
|
146
|
-
throw new Error(`Service "${service}" not found`);
|
|
147
|
-
}
|
|
148
|
-
if (!this.configs.app.services[service].buildArgs) {
|
|
149
|
-
this.configs.app.services[service].buildArgs = {};
|
|
150
|
-
}
|
|
151
|
-
this.configs.app.services[service].buildArgs[name] = value;
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
this.configs.app.buildArgs[name] = value;
|
|
141
|
+
setBuildArg(key, value, service) {
|
|
142
|
+
this.configs.app.setBuildArg(key, value, service);
|
|
155
143
|
}
|
|
156
144
|
unsetBuildArg(name, service) {
|
|
157
145
|
this.configs.app.unsetBuildArg(name, service);
|
|
@@ -234,13 +222,8 @@ class Project {
|
|
|
234
222
|
});
|
|
235
223
|
}
|
|
236
224
|
save() {
|
|
237
|
-
const container = AsyncStorage_1.AsyncStorage.getContainer(),
|
|
238
|
-
|
|
239
|
-
this.configs.app.save();
|
|
240
|
-
// const container = AsyncStorage.getContainer(),
|
|
241
|
-
// projectRepository = container.get(ProjectRepository);
|
|
242
|
-
//
|
|
243
|
-
// projectRepository.save(this);
|
|
225
|
+
const container = AsyncStorage_1.AsyncStorage.getContainer(), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
|
|
226
|
+
projectRepository.save(this);
|
|
244
227
|
}
|
|
245
228
|
}
|
|
246
229
|
exports.Project = Project;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FileSystem } from "./FileSystem";
|
|
2
|
+
import { EnvConfig, ProjectType } from "../types";
|
|
3
|
+
import { JsonEditor } from "./JsonEditor";
|
|
4
|
+
import { ServiceConfig } from "./ServiceConfig";
|
|
5
|
+
export declare class ProjectConfig extends JsonEditor<ProjectConfig.Data> {
|
|
6
|
+
constructor(content: string);
|
|
7
|
+
get type(): ProjectType | undefined;
|
|
8
|
+
set type(type: ProjectType | undefined);
|
|
9
|
+
get buildArgs(): EnvConfig;
|
|
10
|
+
set buildArgs(buildArgs: EnvConfig);
|
|
11
|
+
get env(): EnvConfig;
|
|
12
|
+
set env(env: EnvConfig | undefined);
|
|
13
|
+
get metadata(): EnvConfig;
|
|
14
|
+
set metadata(metadata: EnvConfig);
|
|
15
|
+
get preset(): string | undefined;
|
|
16
|
+
set preset(preset: string | undefined);
|
|
17
|
+
get presetMode(): "project" | "global" | undefined;
|
|
18
|
+
set presetMode(presetMode: "project" | "global" | undefined);
|
|
19
|
+
get image(): string | undefined;
|
|
20
|
+
set image(image: string | undefined);
|
|
21
|
+
get imageName(): string | undefined;
|
|
22
|
+
set imageName(image: string | undefined);
|
|
23
|
+
get composefile(): string | undefined;
|
|
24
|
+
set composefile(composefile: string | undefined);
|
|
25
|
+
get dockerfile(): string | undefined;
|
|
26
|
+
set dockerfile(dockerfile: string | undefined);
|
|
27
|
+
get cmd(): string[] | undefined;
|
|
28
|
+
set cmd(cmd: string[] | undefined);
|
|
29
|
+
get scripts(): any;
|
|
30
|
+
get services(): any;
|
|
31
|
+
get extraHosts(): any;
|
|
32
|
+
set extraHosts(extraHosts: any);
|
|
33
|
+
get volumes(): string[];
|
|
34
|
+
set volumes(volumes: string[]);
|
|
35
|
+
get ports(): string[];
|
|
36
|
+
set ports(ports: string[]);
|
|
37
|
+
setBuildArg(key: string, value: string, service?: string): void;
|
|
38
|
+
unsetBuildArg(name: string, service?: string): void;
|
|
39
|
+
getEnv(key: string): string | undefined;
|
|
40
|
+
getEnv(key: string, byDefault: string): string;
|
|
41
|
+
hasEnv(key: string): boolean;
|
|
42
|
+
setEnv(key: string, value: string | boolean, service?: string): void;
|
|
43
|
+
unsetEnv(key: string, service?: string): void;
|
|
44
|
+
getVolumeBySource(source: string): string | undefined;
|
|
45
|
+
getVolumeByDestination(destination: string): string | undefined;
|
|
46
|
+
volumeMount(...volumes: string[]): void;
|
|
47
|
+
volumeUnmount(...volumes: string[]): void;
|
|
48
|
+
addExtraHost(host: string, domain: string): void;
|
|
49
|
+
removeExtraHost(host: string): void;
|
|
50
|
+
addService(name: string, data: ServiceConfig.Data): void;
|
|
51
|
+
service(name: string): any;
|
|
52
|
+
toObject(): ProjectConfig.Data;
|
|
53
|
+
static make(fs: FileSystem, filename: string): ProjectConfig;
|
|
54
|
+
}
|
|
55
|
+
export declare namespace ProjectConfig {
|
|
56
|
+
type Data = {
|
|
57
|
+
type?: ProjectType;
|
|
58
|
+
image?: string;
|
|
59
|
+
/** @deprecated */
|
|
60
|
+
imageName?: string;
|
|
61
|
+
dockerfile?: string;
|
|
62
|
+
composefile?: string;
|
|
63
|
+
preset?: string;
|
|
64
|
+
presetMode?: "global" | "project";
|
|
65
|
+
scripts?: {
|
|
66
|
+
[script: string]: string;
|
|
67
|
+
};
|
|
68
|
+
cmd?: string[];
|
|
69
|
+
buildArgs?: EnvConfig;
|
|
70
|
+
env?: EnvConfig;
|
|
71
|
+
metadata?: EnvConfig;
|
|
72
|
+
volumes?: string[];
|
|
73
|
+
ports?: string[];
|
|
74
|
+
extraHosts?: EnvConfig;
|
|
75
|
+
services?: Record<string, ProjectConfig.Service>;
|
|
76
|
+
};
|
|
77
|
+
type Service = {
|
|
78
|
+
type?: "compose" | "plugin";
|
|
79
|
+
containerName?: string;
|
|
80
|
+
buildArgs?: EnvConfig;
|
|
81
|
+
env?: EnvConfig;
|
|
82
|
+
ports?: string[];
|
|
83
|
+
volumes?: string[];
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProjectConfig = void 0;
|
|
4
|
+
const volumeParse_1 = require("../utils/volumeParse");
|
|
5
|
+
const JsonEditor_1 = require("./JsonEditor");
|
|
6
|
+
class ProjectConfig extends JsonEditor_1.JsonEditor {
|
|
7
|
+
// public editor: JsonEditor<ProjectConfig.Data>;
|
|
8
|
+
// protected state: ProjectConfig.Data;
|
|
9
|
+
// public type?: ProjectType;
|
|
10
|
+
// public image?: string;
|
|
11
|
+
// public dockerfile?: string;
|
|
12
|
+
// public composefile?: string;
|
|
13
|
+
// public preset?: string;
|
|
14
|
+
// public presetMode?: "global" | "project";
|
|
15
|
+
// public scripts: {
|
|
16
|
+
// [script: string]: string;
|
|
17
|
+
// };
|
|
18
|
+
// public cmd?: string[];
|
|
19
|
+
// public metadata: EnvConfig;
|
|
20
|
+
// public ports: string[];
|
|
21
|
+
// public volumes: string[];
|
|
22
|
+
// public extraHosts: EnvConfig;
|
|
23
|
+
// public services: Record<string, ProjectConfig.Service>;
|
|
24
|
+
constructor(content) {
|
|
25
|
+
super(content);
|
|
26
|
+
// this.editor = new JsonEditor<ProjectConfig.Data>(content);
|
|
27
|
+
// const {
|
|
28
|
+
// type,
|
|
29
|
+
// imageName,
|
|
30
|
+
// image = imageName,
|
|
31
|
+
// dockerfile,
|
|
32
|
+
// composefile,
|
|
33
|
+
// preset,
|
|
34
|
+
// presetMode,
|
|
35
|
+
// scripts = {},
|
|
36
|
+
// cmd,
|
|
37
|
+
// metadata = {},
|
|
38
|
+
// volumes = [],
|
|
39
|
+
// ports = [],
|
|
40
|
+
// extraHosts = {},
|
|
41
|
+
// services = {}
|
|
42
|
+
// } = data;
|
|
43
|
+
// this.type = type;
|
|
44
|
+
// this.image = image;
|
|
45
|
+
// this.dockerfile = dockerfile;
|
|
46
|
+
// this.composefile = composefile;
|
|
47
|
+
// this.preset = preset;
|
|
48
|
+
// this.presetMode = presetMode;
|
|
49
|
+
// this.scripts = scripts;
|
|
50
|
+
// this.cmd = cmd;
|
|
51
|
+
// this.metadata = metadata;
|
|
52
|
+
// this.volumes = volumes;
|
|
53
|
+
// this.ports = ports;
|
|
54
|
+
// this.extraHosts = extraHosts;
|
|
55
|
+
// this.services = services;
|
|
56
|
+
}
|
|
57
|
+
get type() {
|
|
58
|
+
return this.state.type;
|
|
59
|
+
}
|
|
60
|
+
set type(type) {
|
|
61
|
+
this.state.type = type;
|
|
62
|
+
}
|
|
63
|
+
get buildArgs() {
|
|
64
|
+
return this.createProxy(["buildArgs"], {
|
|
65
|
+
removeOnEmpty: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
set buildArgs(buildArgs) {
|
|
69
|
+
this.state.buildArgs = Object.assign({}, buildArgs);
|
|
70
|
+
}
|
|
71
|
+
get env() {
|
|
72
|
+
return this.createProxy(["env"], {
|
|
73
|
+
removeOnEmpty: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
set env(env) {
|
|
77
|
+
this.state.env = env ? Object.assign({}, env) : env;
|
|
78
|
+
}
|
|
79
|
+
get metadata() {
|
|
80
|
+
return this.createProxy(["metadata"], {
|
|
81
|
+
removeOnEmpty: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
set metadata(metadata) {
|
|
85
|
+
this.state.metadata = Object.assign({}, metadata);
|
|
86
|
+
}
|
|
87
|
+
get preset() {
|
|
88
|
+
return this.state.preset;
|
|
89
|
+
}
|
|
90
|
+
set preset(preset) {
|
|
91
|
+
this.state.preset = preset;
|
|
92
|
+
}
|
|
93
|
+
get presetMode() {
|
|
94
|
+
return this.state.presetMode;
|
|
95
|
+
}
|
|
96
|
+
set presetMode(presetMode) {
|
|
97
|
+
this.state.presetMode = presetMode;
|
|
98
|
+
}
|
|
99
|
+
get image() {
|
|
100
|
+
return this.state.image;
|
|
101
|
+
}
|
|
102
|
+
set image(image) {
|
|
103
|
+
this.state.image = image;
|
|
104
|
+
}
|
|
105
|
+
get imageName() {
|
|
106
|
+
return this.state.imageName;
|
|
107
|
+
}
|
|
108
|
+
set imageName(image) {
|
|
109
|
+
this.state.imageName = image;
|
|
110
|
+
}
|
|
111
|
+
get composefile() {
|
|
112
|
+
return this.state.composefile;
|
|
113
|
+
}
|
|
114
|
+
set composefile(composefile) {
|
|
115
|
+
this.state.composefile = composefile;
|
|
116
|
+
}
|
|
117
|
+
get dockerfile() {
|
|
118
|
+
return this.state.dockerfile;
|
|
119
|
+
}
|
|
120
|
+
set dockerfile(dockerfile) {
|
|
121
|
+
this.state.dockerfile = dockerfile;
|
|
122
|
+
}
|
|
123
|
+
get cmd() {
|
|
124
|
+
return this.state.cmd;
|
|
125
|
+
}
|
|
126
|
+
set cmd(cmd) {
|
|
127
|
+
this.state.cmd = cmd;
|
|
128
|
+
}
|
|
129
|
+
get scripts() {
|
|
130
|
+
return {};
|
|
131
|
+
}
|
|
132
|
+
get services() {
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
get extraHosts() {
|
|
136
|
+
return this.createProxy(["extraHosts"]);
|
|
137
|
+
}
|
|
138
|
+
set extraHosts(extraHosts) {
|
|
139
|
+
this.state.extraHosts = Object.assign({}, extraHosts);
|
|
140
|
+
}
|
|
141
|
+
get volumes() {
|
|
142
|
+
return this.createProxy(["volumes"], {
|
|
143
|
+
removeOnEmpty: true,
|
|
144
|
+
isArray: true
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
set volumes(volumes) {
|
|
148
|
+
this.state.volumes = volumes;
|
|
149
|
+
}
|
|
150
|
+
get ports() {
|
|
151
|
+
return this.createProxy(["ports"], {
|
|
152
|
+
isArray: true,
|
|
153
|
+
removeOnEmpty: true
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
set ports(ports) {
|
|
157
|
+
this.state.ports = [...ports];
|
|
158
|
+
}
|
|
159
|
+
setBuildArg(key, value, service) {
|
|
160
|
+
if (service) {
|
|
161
|
+
// if(!this.services[service]) {
|
|
162
|
+
// this.services[service] = {};
|
|
163
|
+
// }
|
|
164
|
+
//
|
|
165
|
+
// if(!this.services[service].buildArgs) {
|
|
166
|
+
// this.services[service].buildArgs = {};
|
|
167
|
+
// }
|
|
168
|
+
//
|
|
169
|
+
// this.services[service].buildArgs[key] = value;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.buildArgs[key] = value;
|
|
173
|
+
}
|
|
174
|
+
unsetBuildArg(name, service) {
|
|
175
|
+
if (service) {
|
|
176
|
+
// if(!this.services[service]) {
|
|
177
|
+
// return;
|
|
178
|
+
// }
|
|
179
|
+
//
|
|
180
|
+
// if(this.services[service].buildArgs && name in this.services[service].buildArgs) {
|
|
181
|
+
// delete this.services[service].buildArgs[name];
|
|
182
|
+
// }
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (name in this.buildArgs) {
|
|
186
|
+
delete this.buildArgs[name];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
getEnv(key, byDefault) {
|
|
190
|
+
if (key in this.env) {
|
|
191
|
+
return this.env[key];
|
|
192
|
+
}
|
|
193
|
+
return byDefault;
|
|
194
|
+
}
|
|
195
|
+
hasEnv(key) {
|
|
196
|
+
// return this.env.hasOwnProperty(key);
|
|
197
|
+
return key in this.env;
|
|
198
|
+
}
|
|
199
|
+
setEnv(key, value, service) {
|
|
200
|
+
const sValue = typeof value === "boolean"
|
|
201
|
+
? (value ? "true" : "false")
|
|
202
|
+
: value;
|
|
203
|
+
if (service) {
|
|
204
|
+
// if(!this.services[service]) {
|
|
205
|
+
// return;
|
|
206
|
+
// }
|
|
207
|
+
//
|
|
208
|
+
// if(!this.services[service].env) {
|
|
209
|
+
// this.services[service].env = {};
|
|
210
|
+
// }
|
|
211
|
+
//
|
|
212
|
+
// this.services[service].env[key] = sValue;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.env[key] = sValue;
|
|
216
|
+
}
|
|
217
|
+
unsetEnv(key, service) {
|
|
218
|
+
if (service) {
|
|
219
|
+
// if(!this.services[service]) {
|
|
220
|
+
// throw new Error(`Service "${service}" not found`);
|
|
221
|
+
// }
|
|
222
|
+
//
|
|
223
|
+
// if(this.services[service].env && key in this.services[service].env) {
|
|
224
|
+
// delete this.services[service].env[key];
|
|
225
|
+
//
|
|
226
|
+
// if(Object.keys(this.services[service].env).length === 0) {
|
|
227
|
+
// delete this.services[service].env;
|
|
228
|
+
// }
|
|
229
|
+
// }
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (key in this.env) {
|
|
233
|
+
delete this.env[key];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
getVolumeBySource(source) {
|
|
237
|
+
return (this.state.volumes || []).find((volume) => {
|
|
238
|
+
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
getVolumeByDestination(destination) {
|
|
242
|
+
return (this.state.volumes || []).find((volume) => {
|
|
243
|
+
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
volumeMount(...volumes) {
|
|
247
|
+
if (volumes.length === 0) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const [volume, ...restVolumes] = volumes;
|
|
251
|
+
const { destination } = (0, volumeParse_1.volumeParse)(volume);
|
|
252
|
+
this.state.volumes = [
|
|
253
|
+
...(this.state.volumes || []).filter((v) => {
|
|
254
|
+
return v !== this.getVolumeByDestination(destination);
|
|
255
|
+
}),
|
|
256
|
+
volume
|
|
257
|
+
];
|
|
258
|
+
this.volumeMount(...restVolumes);
|
|
259
|
+
}
|
|
260
|
+
volumeUnmount(...volumes) {
|
|
261
|
+
if (!this.state.volumes || volumes.length === 0) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const [volume, ...restVolumes] = volumes;
|
|
265
|
+
const v = (0, volumeParse_1.volumeParse)(volume);
|
|
266
|
+
this.state.volumes = this.state.volumes.filter((mounted) => {
|
|
267
|
+
const m = (0, volumeParse_1.volumeParse)(mounted);
|
|
268
|
+
return v.source !== m.source && v.destination !== m.destination;
|
|
269
|
+
});
|
|
270
|
+
if (this.state.volumes.length === 0) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this.volumeUnmount(...restVolumes);
|
|
274
|
+
}
|
|
275
|
+
addExtraHost(host, domain) {
|
|
276
|
+
if (!this.state.extraHosts) {
|
|
277
|
+
this.state.extraHosts = {};
|
|
278
|
+
}
|
|
279
|
+
this.state.extraHosts[host] = domain;
|
|
280
|
+
}
|
|
281
|
+
removeExtraHost(host) {
|
|
282
|
+
if (this.state.extraHosts && host in this.state.extraHosts) {
|
|
283
|
+
delete this.state.extraHosts[host];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
addService(name, data) {
|
|
287
|
+
}
|
|
288
|
+
service(name) {
|
|
289
|
+
return this.createProxy(["services", name], {
|
|
290
|
+
removeOnEmpty: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
toObject() {
|
|
294
|
+
// return {
|
|
295
|
+
// type: this.type,
|
|
296
|
+
// image: this.image,
|
|
297
|
+
// dockerfile: this.dockerfile,
|
|
298
|
+
// composefile: this.composefile,
|
|
299
|
+
// preset: this.preset,
|
|
300
|
+
// presetMode: this.presetMode,
|
|
301
|
+
// scripts: Object.keys(this.scripts).length > 0 ? this.scripts : undefined,
|
|
302
|
+
// cmd: this.cmd,
|
|
303
|
+
// buildArgs: Object.keys(this.buildArgs).length > 0 ? this.buildArgs : undefined,
|
|
304
|
+
// env: Object.keys(this.env).length > 0 ? this.env : undefined,
|
|
305
|
+
// metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
|
|
306
|
+
// volumes: this.volumes.length > 0 ? this.volumes : undefined,
|
|
307
|
+
// ports: this.ports.length > 0 ? this.ports : undefined,
|
|
308
|
+
// };
|
|
309
|
+
return this.state;
|
|
310
|
+
}
|
|
311
|
+
static make(fs, filename) {
|
|
312
|
+
let content = "{}";
|
|
313
|
+
if (fs.exists(filename)) {
|
|
314
|
+
content = fs.readFile(filename).toString();
|
|
315
|
+
}
|
|
316
|
+
return new class extends ProjectConfig {
|
|
317
|
+
save() {
|
|
318
|
+
// if(!fs.exists()) {
|
|
319
|
+
// fs.mkdir("", {
|
|
320
|
+
// recursive: true
|
|
321
|
+
// });
|
|
322
|
+
// }
|
|
323
|
+
//
|
|
324
|
+
// fs.writeJSON(filename, this.toObject());
|
|
325
|
+
}
|
|
326
|
+
}(content);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
exports.ProjectConfig = ProjectConfig;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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;
|
package/lib/makes/index.d.ts
CHANGED
package/lib/makes/index.js
CHANGED
|
@@ -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("./Project"), exports);
|
|
23
24
|
__exportStar(require("./Version"), exports);
|
|
24
25
|
__exportStar(require("./VersionRange"), exports);
|
|
25
26
|
__exportStar(require("./VersionRule"), exports);
|
|
@@ -14,7 +14,4 @@ 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("./makes/Project"), exports);
|
|
18
|
-
__exportStar(require("./makes/ProjectConfig"), exports);
|
|
19
|
-
__exportStar(require("./repositories/ProjectRepository"), exports);
|
|
20
17
|
__exportStar(require("./services/ProjectService"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Project } from "
|
|
2
|
-
import { ProjectRepository } from "
|
|
1
|
+
import { Project } from "../../../makes/Project";
|
|
2
|
+
import { ProjectRepository } from "../../../services/ProjectRepository";
|
|
3
3
|
export declare abstract class ProjectService {
|
|
4
4
|
abstract get(name?: string): Project;
|
|
5
5
|
abstract save(project: Project): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Project } from "../makes/Project";
|
|
2
2
|
import { ProjectConfig } from "../makes/ProjectConfig";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ProjectConfigScope } from "../types";
|
|
3
|
+
import { AppService } from "./AppService";
|
|
4
|
+
import { AppFileSystemService } from "./AppFileSystemService";
|
|
5
|
+
import { FileSystemDriver, ProjectConfigScope } from "../types";
|
|
6
6
|
export declare class ProjectRepository {
|
|
7
7
|
protected readonly appService: AppService;
|
|
8
8
|
protected readonly fs: AppFileSystemService;
|
|
@@ -13,13 +13,14 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ProjectRepository = void 0;
|
|
16
|
-
const decorators_1 = require("
|
|
16
|
+
const decorators_1 = require("../decorators");
|
|
17
17
|
const Project_1 = require("../makes/Project");
|
|
18
18
|
const ProjectConfig_1 = require("../makes/ProjectConfig");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const makes_1 = require("../makes");
|
|
20
|
+
const AppService_1 = require("./AppService");
|
|
21
|
+
const AppFileSystemService_1 = require("./AppFileSystemService");
|
|
22
22
|
const types_1 = require("../types");
|
|
23
|
+
const env_1 = require("../env");
|
|
23
24
|
let ProjectRepository = class ProjectRepository {
|
|
24
25
|
constructor(appService, fs, driver) {
|
|
25
26
|
this.appService = appService;
|
|
@@ -35,7 +36,7 @@ let ProjectRepository = class ProjectRepository {
|
|
|
35
36
|
case types_1.ProjectConfigScope.APP:
|
|
36
37
|
return ProjectConfig_1.ProjectConfig.make(this.fs.cd(`projects/${ref.name}`), "config.json");
|
|
37
38
|
case types_1.ProjectConfigScopeEnum.LOCAL:
|
|
38
|
-
return ProjectConfig_1.ProjectConfig.make(new
|
|
39
|
+
return ProjectConfig_1.ProjectConfig.make(new makes_1.FileSystem(ref.path, this.driver), "wocker.config.json");
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
getByName(name) {
|
|
@@ -46,7 +47,19 @@ let ProjectRepository = class ProjectRepository {
|
|
|
46
47
|
return new Project_1.Project(ref.name, ref.path);
|
|
47
48
|
}
|
|
48
49
|
save(project) {
|
|
49
|
-
project.
|
|
50
|
+
if (!project.ref) {
|
|
51
|
+
this.appService.addProject(project.name, project.path);
|
|
52
|
+
}
|
|
53
|
+
if (!this.fs.exists(`projects/${project.name}`)) {
|
|
54
|
+
this.fs.mkdir(`projects/${project.name}`);
|
|
55
|
+
}
|
|
56
|
+
if (project.configs.app.isDirty()) {
|
|
57
|
+
this.fs.writeFile(`projects/${project.name}/config.json`, project.configs.app.toString());
|
|
58
|
+
}
|
|
59
|
+
if (project.configs.project.isDirty()) {
|
|
60
|
+
const projectFS = new makes_1.FileSystem(project.path, this.driver);
|
|
61
|
+
projectFS.writeFile("wocker.config.json", project.configs.project.toString());
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
64
|
search(params) {
|
|
52
65
|
const { name, path } = params, projects = [];
|
|
@@ -71,6 +84,6 @@ exports.ProjectRepository = ProjectRepository;
|
|
|
71
84
|
exports.ProjectRepository = ProjectRepository = __decorate([
|
|
72
85
|
(0, decorators_1.Injectable)("PROJECT_REPOSITORY"),
|
|
73
86
|
__param(2, (0, decorators_1.Inject)(env_1.FILE_SYSTEM_DRIVER_KEY)),
|
|
74
|
-
__metadata("design:paramtypes", [
|
|
75
|
-
|
|
87
|
+
__metadata("design:paramtypes", [AppService_1.AppService,
|
|
88
|
+
AppFileSystemService_1.AppFileSystemService, Object])
|
|
76
89
|
], ProjectRepository);
|
package/lib/services/index.d.ts
CHANGED
package/lib/services/index.js
CHANGED
package/lib/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./ModuleMetadata";
|
|
|
7
7
|
export * from "./PackageManagerType";
|
|
8
8
|
export * from "./PickProperties";
|
|
9
9
|
export * from "./PluginMetadata";
|
|
10
|
+
export * from "./ProjectConfigScope";
|
|
10
11
|
export * from "./PluginRef";
|
|
11
12
|
export * from "./PresetRef";
|
|
12
13
|
export * from "./PresetSource";
|
package/lib/types/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./ModuleMetadata"), exports);
|
|
|
23
23
|
__exportStar(require("./PackageManagerType"), exports);
|
|
24
24
|
__exportStar(require("./PickProperties"), exports);
|
|
25
25
|
__exportStar(require("./PluginMetadata"), exports);
|
|
26
|
+
__exportStar(require("./ProjectConfigScope"), exports);
|
|
26
27
|
__exportStar(require("./PluginRef"), exports);
|
|
27
28
|
__exportStar(require("./PresetRef"), exports);
|
|
28
29
|
__exportStar(require("./PresetSource"), 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
|
+
"version": "1.1.0-beta.3",
|
|
5
5
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
6
6
|
"description": "Core of the Wocker",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@kearisp/cli": "^2.0.9",
|
|
31
31
|
"date-fns": "^4.1.0",
|
|
32
|
+
"jsonc-parser": "^3.3.1",
|
|
32
33
|
"readline": "^1.3.0",
|
|
33
34
|
"reflect-metadata": "^0.2.2",
|
|
34
35
|
"stream": "^0.0.3",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { FileSystem } from "../../../makes";
|
|
2
|
-
import { EnvConfig, ProjectType } from "../../../types";
|
|
3
|
-
import { ServiceProperties } from "../types";
|
|
4
|
-
export declare abstract class ProjectConfig {
|
|
5
|
-
type?: ProjectType;
|
|
6
|
-
image?: string;
|
|
7
|
-
dockerfile?: string;
|
|
8
|
-
composefile?: string;
|
|
9
|
-
preset?: string;
|
|
10
|
-
presetMode?: "global" | "project";
|
|
11
|
-
scripts: {
|
|
12
|
-
[script: string]: string;
|
|
13
|
-
};
|
|
14
|
-
cmd?: string[];
|
|
15
|
-
buildArgs: EnvConfig;
|
|
16
|
-
env: EnvConfig;
|
|
17
|
-
metadata: EnvConfig;
|
|
18
|
-
ports: string[];
|
|
19
|
-
volumes: string[];
|
|
20
|
-
extraHosts: EnvConfig;
|
|
21
|
-
services: Record<string, ServiceProperties>;
|
|
22
|
-
constructor(data: ProjectConfig.Data);
|
|
23
|
-
unsetBuildArg(name: string, service?: string): void;
|
|
24
|
-
getEnv(key: string): string | undefined;
|
|
25
|
-
getEnv(key: string, byDefault: string): string;
|
|
26
|
-
hasEnv(key: string): boolean;
|
|
27
|
-
setEnv(key: string, value: string | boolean, service?: string): void;
|
|
28
|
-
unsetEnv(key: string, service?: string): void;
|
|
29
|
-
abstract save(): void;
|
|
30
|
-
getVolumeBySource(source: string): string | undefined;
|
|
31
|
-
getVolumeByDestination(destination: string): string | undefined;
|
|
32
|
-
volumeMount(...volumes: string[]): void;
|
|
33
|
-
volumeUnmount(...volumes: string[]): void;
|
|
34
|
-
addExtraHost(host: string, domain: string): void;
|
|
35
|
-
removeExtraHost(host: string): void;
|
|
36
|
-
toObject(): ProjectConfig.Data;
|
|
37
|
-
static make(fs: FileSystem, filename: string): ProjectConfig;
|
|
38
|
-
}
|
|
39
|
-
export declare namespace ProjectConfig {
|
|
40
|
-
type Data = {
|
|
41
|
-
type?: ProjectType;
|
|
42
|
-
image?: string;
|
|
43
|
-
/** @deprecated */
|
|
44
|
-
imageName?: string;
|
|
45
|
-
dockerfile?: string;
|
|
46
|
-
composefile?: string;
|
|
47
|
-
preset?: string;
|
|
48
|
-
presetMode?: "global" | "project";
|
|
49
|
-
scripts?: {
|
|
50
|
-
[script: string]: string;
|
|
51
|
-
};
|
|
52
|
-
cmd?: string[];
|
|
53
|
-
buildArgs?: EnvConfig;
|
|
54
|
-
env?: EnvConfig;
|
|
55
|
-
metadata?: EnvConfig;
|
|
56
|
-
volumes?: string[];
|
|
57
|
-
ports?: string[];
|
|
58
|
-
extraHosts?: EnvConfig;
|
|
59
|
-
services?: Record<string, ServiceProperties>;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectConfig = void 0;
|
|
4
|
-
const volumeParse_1 = require("../../../utils/volumeParse");
|
|
5
|
-
class ProjectConfig {
|
|
6
|
-
constructor(data) {
|
|
7
|
-
const { type, imageName, image = imageName, dockerfile, composefile, preset, presetMode, scripts = {}, cmd, buildArgs = {}, env = {}, metadata = {}, volumes = [], ports = [], extraHosts = {}, services = {} } = data;
|
|
8
|
-
this.type = type;
|
|
9
|
-
this.image = image;
|
|
10
|
-
this.dockerfile = dockerfile;
|
|
11
|
-
this.composefile = composefile;
|
|
12
|
-
this.preset = preset;
|
|
13
|
-
this.presetMode = presetMode;
|
|
14
|
-
this.scripts = scripts;
|
|
15
|
-
this.cmd = cmd;
|
|
16
|
-
this.buildArgs = buildArgs;
|
|
17
|
-
this.env = env;
|
|
18
|
-
this.metadata = metadata;
|
|
19
|
-
this.volumes = volumes;
|
|
20
|
-
this.ports = ports;
|
|
21
|
-
this.extraHosts = extraHosts;
|
|
22
|
-
this.services = services;
|
|
23
|
-
}
|
|
24
|
-
unsetBuildArg(name, service) {
|
|
25
|
-
if (service) {
|
|
26
|
-
if (!this.services[service]) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (this.services[service].buildArgs && name in this.services[service].buildArgs) {
|
|
30
|
-
delete this.services[service].buildArgs[name];
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (name in this.buildArgs) {
|
|
35
|
-
delete this.buildArgs[name];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
getEnv(key, byDefault) {
|
|
39
|
-
if (key in this.env) {
|
|
40
|
-
return this.env[key];
|
|
41
|
-
}
|
|
42
|
-
return byDefault;
|
|
43
|
-
}
|
|
44
|
-
hasEnv(key) {
|
|
45
|
-
return this.env.hasOwnProperty(key);
|
|
46
|
-
}
|
|
47
|
-
setEnv(key, value, service) {
|
|
48
|
-
const sValue = typeof value === "boolean"
|
|
49
|
-
? (value ? "true" : "false")
|
|
50
|
-
: value;
|
|
51
|
-
if (service) {
|
|
52
|
-
if (!this.services[service]) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (!this.services[service].env) {
|
|
56
|
-
this.services[service].env = {};
|
|
57
|
-
}
|
|
58
|
-
this.services[service].env[key] = sValue;
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.env[key] = sValue;
|
|
62
|
-
}
|
|
63
|
-
unsetEnv(key, service) {
|
|
64
|
-
if (service) {
|
|
65
|
-
if (!this.services[service]) {
|
|
66
|
-
throw new Error(`Service "${service}" not found`);
|
|
67
|
-
}
|
|
68
|
-
if (this.services[service].env && key in this.services[service].env) {
|
|
69
|
-
delete this.services[service].env[key];
|
|
70
|
-
if (Object.keys(this.services[service].env).length === 0) {
|
|
71
|
-
delete this.services[service].env;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (key in this.env) {
|
|
77
|
-
delete this.env[key];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
getVolumeBySource(source) {
|
|
81
|
-
return (this.volumes || []).find((volume) => {
|
|
82
|
-
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
getVolumeByDestination(destination) {
|
|
86
|
-
return (this.volumes || []).find((volume) => {
|
|
87
|
-
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
volumeMount(...volumes) {
|
|
91
|
-
if (volumes.length === 0) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const [volume, ...restVolumes] = volumes;
|
|
95
|
-
const { destination } = (0, volumeParse_1.volumeParse)(volume);
|
|
96
|
-
this.volumes = [
|
|
97
|
-
...(this.volumes || []).filter((v) => {
|
|
98
|
-
return v !== this.getVolumeByDestination(destination);
|
|
99
|
-
}),
|
|
100
|
-
volume
|
|
101
|
-
];
|
|
102
|
-
this.volumeMount(...restVolumes);
|
|
103
|
-
}
|
|
104
|
-
volumeUnmount(...volumes) {
|
|
105
|
-
if (!this.volumes || volumes.length === 0) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const [volume, ...restVolumes] = volumes;
|
|
109
|
-
const v = (0, volumeParse_1.volumeParse)(volume);
|
|
110
|
-
this.volumes = this.volumes.filter((mounted) => {
|
|
111
|
-
const m = (0, volumeParse_1.volumeParse)(mounted);
|
|
112
|
-
return v.source !== m.source && v.destination !== m.destination;
|
|
113
|
-
});
|
|
114
|
-
if (this.volumes.length === 0) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
this.volumeUnmount(...restVolumes);
|
|
118
|
-
}
|
|
119
|
-
addExtraHost(host, domain) {
|
|
120
|
-
this.extraHosts[host] = domain;
|
|
121
|
-
}
|
|
122
|
-
removeExtraHost(host) {
|
|
123
|
-
if (host in this.extraHosts) {
|
|
124
|
-
delete this.extraHosts[host];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
toObject() {
|
|
128
|
-
return {
|
|
129
|
-
type: this.type,
|
|
130
|
-
image: this.image,
|
|
131
|
-
dockerfile: this.dockerfile,
|
|
132
|
-
composefile: this.composefile,
|
|
133
|
-
preset: this.preset,
|
|
134
|
-
presetMode: this.presetMode,
|
|
135
|
-
scripts: Object.keys(this.scripts).length > 0 ? this.scripts : undefined,
|
|
136
|
-
cmd: this.cmd,
|
|
137
|
-
buildArgs: Object.keys(this.buildArgs).length > 0 ? this.buildArgs : undefined,
|
|
138
|
-
env: Object.keys(this.env).length > 0 ? this.env : undefined,
|
|
139
|
-
metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
|
|
140
|
-
volumes: this.volumes.length > 0 ? this.volumes : undefined,
|
|
141
|
-
ports: this.ports.length > 0 ? this.ports : undefined,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
static make(fs, filename) {
|
|
145
|
-
let data = {};
|
|
146
|
-
if (fs.exists(filename)) {
|
|
147
|
-
data = fs.readJSON(filename);
|
|
148
|
-
}
|
|
149
|
-
return new class extends ProjectConfig {
|
|
150
|
-
constructor(data) {
|
|
151
|
-
super(data);
|
|
152
|
-
}
|
|
153
|
-
save() {
|
|
154
|
-
if (!fs.exists()) {
|
|
155
|
-
fs.mkdir("", {
|
|
156
|
-
recursive: true
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
fs.writeJSON(filename, this.toObject());
|
|
160
|
-
}
|
|
161
|
-
}(data);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.ProjectConfig = ProjectConfig;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EnvConfig, ProjectType } from "../../../types";
|
|
2
|
-
import { ServiceProperties } from "./ServiceProperties";
|
|
3
|
-
export type ProjectV1 = {
|
|
4
|
-
name: string;
|
|
5
|
-
type: ProjectType;
|
|
6
|
-
path: string;
|
|
7
|
-
imageName?: string;
|
|
8
|
-
dockerfile?: string;
|
|
9
|
-
composefile?: string;
|
|
10
|
-
preset?: string;
|
|
11
|
-
presetMode?: "global" | "project";
|
|
12
|
-
cmd?: string[];
|
|
13
|
-
scripts?: {
|
|
14
|
-
[script: string]: string;
|
|
15
|
-
};
|
|
16
|
-
services?: {
|
|
17
|
-
[service: string]: ServiceProperties;
|
|
18
|
-
};
|
|
19
|
-
buildArgs?: EnvConfig;
|
|
20
|
-
env?: EnvConfig;
|
|
21
|
-
metadata?: EnvConfig;
|
|
22
|
-
ports?: string[];
|
|
23
|
-
extraHosts?: EnvConfig;
|
|
24
|
-
volumes?: string[];
|
|
25
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ProjectConfigScope"), exports);
|
|
18
|
-
__exportStar(require("./ProjectV1"), exports);
|
|
19
|
-
__exportStar(require("./ServiceProperties"), exports);
|
|
File without changes
|