@wocker/core 1.1.0-beta.1 → 1.1.0-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/AppConfig.d.ts +15 -15
- package/lib/makes/AppConfig.js +0 -2
- package/lib/modules/project/index.d.ts +1 -0
- package/lib/modules/project/index.js +1 -0
- package/lib/modules/project/makes/Project.d.ts +37 -28
- package/lib/modules/project/makes/Project.js +127 -163
- package/lib/modules/project/makes/ProjectConfig.d.ts +61 -0
- package/lib/modules/project/makes/ProjectConfig.js +164 -0
- package/lib/modules/project/makes/ServiceConfig.d.ts +2 -0
- package/lib/modules/project/makes/ServiceConfig.js +6 -0
- package/lib/modules/project/repositories/ProjectRepository.d.ts +14 -5
- package/lib/modules/project/repositories/ProjectRepository.js +61 -1
- package/lib/modules/project/types/ProjectConfigScope.d.ts +9 -0
- package/lib/modules/project/types/ProjectConfigScope.js +20 -0
- package/lib/modules/project/types/index.d.ts +1 -0
- package/lib/modules/project/types/index.js +1 -0
- package/lib/services/AppFileSystemService.js +1 -1
- package/lib/services/AppService.d.ts +5 -2
- package/lib/services/AppService.js +10 -4
- package/lib/services/LogService.d.ts +6 -4
- package/lib/services/LogService.js +18 -10
- package/lib/services/ProcessService.d.ts +1 -1
- package/lib/types/LogLevel.d.ts +13 -0
- package/lib/types/LogLevel.js +20 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +1 -1
package/lib/makes/AppConfig.d.ts
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef, PresetSource } from "../types";
|
|
2
1
|
import { FileSystem } from "./FileSystem";
|
|
3
|
-
|
|
4
|
-
debug?: boolean;
|
|
5
|
-
pm?: PackageManagerType;
|
|
6
|
-
keystore?: string;
|
|
7
|
-
logLevel?: "off" | "info" | "warn" | "error";
|
|
8
|
-
plugins?: PluginRef[];
|
|
9
|
-
presets?: PresetRef[];
|
|
10
|
-
projects?: ProjectOldRef[];
|
|
11
|
-
meta?: EnvConfig;
|
|
12
|
-
env?: EnvConfig;
|
|
13
|
-
};
|
|
2
|
+
import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef, PresetSource } from "../types";
|
|
14
3
|
export declare abstract class AppConfig {
|
|
15
4
|
debug?: boolean;
|
|
16
5
|
pm?: PackageManagerType;
|
|
17
6
|
keystore?: string;
|
|
18
|
-
logLevel: "off" | "info" | "warn" | "error";
|
|
19
7
|
plugins: PluginRef[];
|
|
20
8
|
presets: PresetRef[];
|
|
21
9
|
projects: ProjectRef[];
|
|
22
10
|
meta?: EnvConfig;
|
|
23
11
|
env?: EnvConfig;
|
|
24
|
-
constructor(data:
|
|
12
|
+
constructor(data: AppConfig.Data);
|
|
25
13
|
addPlugin(name: string, env?: PluginRef["env"]): void;
|
|
26
14
|
removePlugin(name: string): void;
|
|
27
15
|
getProject(name: string): ProjectRef | undefined;
|
|
@@ -39,7 +27,19 @@ export declare abstract class AppConfig {
|
|
|
39
27
|
setEnv(name: string, value: string): void;
|
|
40
28
|
unsetEnv(name: string): void;
|
|
41
29
|
abstract save(): void;
|
|
42
|
-
toObject():
|
|
30
|
+
toObject(): AppConfig.Data;
|
|
43
31
|
toJsString(): string;
|
|
44
32
|
static make(fs: FileSystem): AppConfig;
|
|
45
33
|
}
|
|
34
|
+
export declare namespace AppConfig {
|
|
35
|
+
type Data = {
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
pm?: PackageManagerType;
|
|
38
|
+
keystore?: string;
|
|
39
|
+
plugins?: PluginRef[];
|
|
40
|
+
presets?: PresetRef[];
|
|
41
|
+
projects?: ProjectOldRef[];
|
|
42
|
+
meta?: EnvConfig;
|
|
43
|
+
env?: EnvConfig;
|
|
44
|
+
};
|
|
45
|
+
}
|
package/lib/makes/AppConfig.js
CHANGED
|
@@ -15,7 +15,6 @@ exports.AppConfig = void 0;
|
|
|
15
15
|
const types_1 = require("../types");
|
|
16
16
|
class AppConfig {
|
|
17
17
|
constructor(data) {
|
|
18
|
-
this.logLevel = "off";
|
|
19
18
|
const { plugins = [], presets = [], projects = [] } = data, rest = __rest(data, ["plugins", "presets", "projects"]);
|
|
20
19
|
Object.assign(this, rest);
|
|
21
20
|
this.plugins = plugins.map((plugin) => {
|
|
@@ -167,7 +166,6 @@ class AppConfig {
|
|
|
167
166
|
return {
|
|
168
167
|
debug: this.debug,
|
|
169
168
|
pm: this.pm,
|
|
170
|
-
logLevel: this.logLevel,
|
|
171
169
|
keystore: this.keystore,
|
|
172
170
|
plugins: this.plugins.length > 0 ? this.plugins : undefined,
|
|
173
171
|
presets: this.presets.length > 0 ? this.presets : undefined,
|
|
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./makes/Project"), exports);
|
|
18
|
+
__exportStar(require("./makes/ProjectConfig"), exports);
|
|
18
19
|
__exportStar(require("./repositories/ProjectRepository"), exports);
|
|
19
20
|
__exportStar(require("./services/ProjectService"), exports);
|
|
@@ -1,59 +1,68 @@
|
|
|
1
1
|
import { EnvConfig, ProjectType } from "../../../types";
|
|
2
|
-
import {
|
|
2
|
+
import { ProjectConfigScope } from "../types";
|
|
3
|
+
import { ProjectConfig } from "./ProjectConfig";
|
|
3
4
|
export declare class Project {
|
|
4
|
-
/** @deprecated */
|
|
5
|
-
id?: string;
|
|
6
5
|
name: string;
|
|
7
|
-
type: ProjectType;
|
|
8
6
|
path: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
presetMode?: "global" | "project";
|
|
15
|
-
scripts?: {
|
|
16
|
-
[script: string]: string;
|
|
17
|
-
};
|
|
18
|
-
services: {
|
|
19
|
-
[name: string]: ServiceProperties;
|
|
20
|
-
};
|
|
21
|
-
buildArgs: EnvConfig;
|
|
22
|
-
env: EnvConfig;
|
|
23
|
-
metadata: EnvConfig;
|
|
24
|
-
ports: string[];
|
|
25
|
-
extraHosts: EnvConfig;
|
|
26
|
-
volumes: string[];
|
|
27
|
-
constructor(data: ProjectV1);
|
|
7
|
+
protected configs: Record<ProjectConfigScope, ProjectConfig>;
|
|
8
|
+
constructor(name: string, path: string);
|
|
9
|
+
protected getConfig(scope: ProjectConfigScope): ProjectConfig;
|
|
10
|
+
get type(): ProjectType;
|
|
11
|
+
set type(type: ProjectType);
|
|
28
12
|
get containerName(): string;
|
|
13
|
+
get scripts(): {
|
|
14
|
+
[x: string]: string;
|
|
15
|
+
};
|
|
16
|
+
get preset(): string | undefined;
|
|
17
|
+
set preset(preset: string | undefined);
|
|
18
|
+
get presetMode(): "project" | "global";
|
|
19
|
+
set presetMode(mode: "project" | "global");
|
|
20
|
+
get imageName(): string | undefined;
|
|
21
|
+
set imageName(image: string | undefined);
|
|
22
|
+
get dockerfile(): string | undefined;
|
|
23
|
+
set dockerfile(dockerfile: string | undefined);
|
|
24
|
+
get composefile(): string | undefined;
|
|
25
|
+
set composefile(composefile: string | undefined);
|
|
26
|
+
get cmd(): string[] | undefined;
|
|
29
27
|
get domains(): string[];
|
|
30
28
|
hasDomain(domain: string): boolean;
|
|
31
29
|
addDomain(addDomain: string): void;
|
|
32
30
|
removeDomain(removeDomain: string): void;
|
|
33
31
|
clearDomains(): void;
|
|
32
|
+
get volumes(): string[];
|
|
33
|
+
get ports(): string[];
|
|
34
|
+
set ports(ports: string[]);
|
|
34
35
|
linkPort(hostPort: number, containerPort: number): void;
|
|
35
36
|
unlinkPort(hostPort: number, containerPort: number): void;
|
|
37
|
+
get buildArgs(): EnvConfig;
|
|
38
|
+
set buildArgs(buildArgs: EnvConfig);
|
|
36
39
|
setBuildArg(name: string, value: string, service?: string): void;
|
|
37
40
|
unsetBuildArg(name: string, service?: string): void;
|
|
41
|
+
get env(): EnvConfig;
|
|
42
|
+
set env(env: EnvConfig);
|
|
38
43
|
hasEnv(name: string): boolean;
|
|
39
44
|
getEnv(key: string): string | undefined;
|
|
40
45
|
getEnv(key: string, byDefault: string): string;
|
|
41
|
-
setEnv(
|
|
42
|
-
unsetEnv(
|
|
43
|
-
hasMeta(
|
|
44
|
-
getMeta
|
|
46
|
+
setEnv(key: string, value: string | boolean, service?: string): void;
|
|
47
|
+
unsetEnv(key: string, service?: string): void;
|
|
48
|
+
hasMeta(key: string): boolean;
|
|
49
|
+
getMeta(key: string): string | undefined;
|
|
50
|
+
getMeta(key: string, byDefault: string): string;
|
|
45
51
|
setMeta(name: string, value: string | boolean): void;
|
|
46
52
|
unsetMeta(name: string): void;
|
|
47
53
|
getVolumeBySource(source: string): string | undefined;
|
|
48
54
|
getVolumeByDestination(destination: string): string | undefined;
|
|
49
55
|
volumeMount(...volumes: string[]): void;
|
|
50
56
|
volumeUnmount(...volumes: string[]): void;
|
|
57
|
+
get extraHosts(): {
|
|
58
|
+
[x: string]: string;
|
|
59
|
+
};
|
|
51
60
|
addExtraHost(host: string, domain: string): void;
|
|
52
61
|
removeExtraHost(host: string): void;
|
|
62
|
+
get services(): Record<string, import("../types").ServiceProperties>;
|
|
53
63
|
getSecret(key: string): Promise<string | undefined>;
|
|
54
64
|
getSecret(key: string, byDefault: string): Promise<string>;
|
|
55
65
|
setSecret(key: string, value: string): Promise<void>;
|
|
56
66
|
unsetSecret(key: string): Promise<void>;
|
|
57
67
|
save(): void;
|
|
58
|
-
toObject(): ProjectV1;
|
|
59
68
|
}
|
|
@@ -8,38 +8,71 @@ 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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
12
|
exports.Project = void 0;
|
|
24
13
|
const AsyncStorage_1 = require("../../../core/AsyncStorage");
|
|
14
|
+
const AppService_1 = require("../../../services/AppService");
|
|
25
15
|
const volumeParse_1 = require("../../../utils/volumeParse");
|
|
26
16
|
const ProjectRepository_1 = require("../repositories/ProjectRepository");
|
|
17
|
+
const types_1 = require("../types");
|
|
27
18
|
class Project {
|
|
28
|
-
constructor(
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
constructor(name, path) {
|
|
20
|
+
this.name = name;
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.configs = {
|
|
23
|
+
[types_1.ProjectConfigScope.APP]: this.getConfig(types_1.ProjectConfigScope.APP),
|
|
24
|
+
[types_1.ProjectConfigScope.LOCAL]: this.getConfig(types_1.ProjectConfigScope.LOCAL)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
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
|
+
get type() {
|
|
32
|
+
return this.configs.app.type || this.configs.project.type;
|
|
33
|
+
}
|
|
34
|
+
set type(type) {
|
|
35
|
+
this.configs.app.type = type;
|
|
39
36
|
}
|
|
40
37
|
get containerName() {
|
|
41
38
|
return `${this.name}.workspace`;
|
|
42
39
|
}
|
|
40
|
+
get scripts() {
|
|
41
|
+
return Object.assign(Object.assign({}, this.configs.project.scripts), this.configs.app.scripts);
|
|
42
|
+
}
|
|
43
|
+
get preset() {
|
|
44
|
+
return this.configs.app.preset;
|
|
45
|
+
}
|
|
46
|
+
set preset(preset) {
|
|
47
|
+
this.configs.app.preset = preset;
|
|
48
|
+
}
|
|
49
|
+
get presetMode() {
|
|
50
|
+
return this.configs.app.presetMode;
|
|
51
|
+
}
|
|
52
|
+
set presetMode(mode) {
|
|
53
|
+
this.configs.app.presetMode = mode;
|
|
54
|
+
}
|
|
55
|
+
get imageName() {
|
|
56
|
+
return this.configs.app.image;
|
|
57
|
+
}
|
|
58
|
+
set imageName(image) {
|
|
59
|
+
this.configs.app.image = image;
|
|
60
|
+
}
|
|
61
|
+
get dockerfile() {
|
|
62
|
+
return this.configs.project.dockerfile || this.configs.app.dockerfile;
|
|
63
|
+
}
|
|
64
|
+
set dockerfile(dockerfile) {
|
|
65
|
+
this.configs.app.dockerfile = dockerfile;
|
|
66
|
+
}
|
|
67
|
+
get composefile() {
|
|
68
|
+
return this.configs.project.composefile || this.configs.app.composefile;
|
|
69
|
+
}
|
|
70
|
+
set composefile(composefile) {
|
|
71
|
+
this.configs.app.composefile = composefile;
|
|
72
|
+
}
|
|
73
|
+
get cmd() {
|
|
74
|
+
return this.configs.app.cmd;
|
|
75
|
+
}
|
|
43
76
|
get domains() {
|
|
44
77
|
const host = this.getEnv("VIRTUAL_HOST");
|
|
45
78
|
if (!host) {
|
|
@@ -71,169 +104,116 @@ class Project {
|
|
|
71
104
|
clearDomains() {
|
|
72
105
|
this.unsetEnv("VIRTUAL_HOST");
|
|
73
106
|
}
|
|
107
|
+
get volumes() {
|
|
108
|
+
return [
|
|
109
|
+
...this.configs.project.volumes.filter((volume) => {
|
|
110
|
+
return !this.configs.app.getVolumeByDestination((0, volumeParse_1.volumeParse)(volume).destination);
|
|
111
|
+
}),
|
|
112
|
+
...this.configs.app.volumes
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
get ports() {
|
|
116
|
+
return [
|
|
117
|
+
...this.configs.project.ports,
|
|
118
|
+
...this.configs.app.ports
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
set ports(ports) {
|
|
122
|
+
this.configs.app.ports = ports;
|
|
123
|
+
}
|
|
74
124
|
linkPort(hostPort, containerPort) {
|
|
75
|
-
this.ports = [
|
|
76
|
-
...this.ports.filter((link) => {
|
|
125
|
+
this.configs.app.ports = [
|
|
126
|
+
...this.configs.app.ports.filter((link) => {
|
|
77
127
|
return link !== `${hostPort}:${containerPort}`;
|
|
78
128
|
}),
|
|
79
129
|
`${hostPort}:${containerPort}`
|
|
80
130
|
];
|
|
81
131
|
}
|
|
82
132
|
unlinkPort(hostPort, containerPort) {
|
|
83
|
-
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
this.ports = this.ports.filter((link) => {
|
|
133
|
+
this.configs.app.ports = this.configs.app.ports.filter((link) => {
|
|
87
134
|
return link !== `${hostPort}:${containerPort}`;
|
|
88
135
|
});
|
|
89
136
|
}
|
|
137
|
+
get buildArgs() {
|
|
138
|
+
return Object.assign(Object.assign({}, this.configs.project.buildArgs), this.configs.app.buildArgs);
|
|
139
|
+
}
|
|
140
|
+
set buildArgs(buildArgs) {
|
|
141
|
+
this.configs.app.buildArgs = buildArgs;
|
|
142
|
+
}
|
|
90
143
|
setBuildArg(name, value, service) {
|
|
91
144
|
if (service) {
|
|
92
|
-
if (!this.services[service]) {
|
|
145
|
+
if (!this.configs.app.services[service]) {
|
|
93
146
|
throw new Error(`Service "${service}" not found`);
|
|
94
147
|
}
|
|
95
|
-
if (!this.services[service].buildArgs) {
|
|
96
|
-
this.services[service].buildArgs = {};
|
|
148
|
+
if (!this.configs.app.services[service].buildArgs) {
|
|
149
|
+
this.configs.app.services[service].buildArgs = {};
|
|
97
150
|
}
|
|
98
|
-
this.services[service].buildArgs[name] = value;
|
|
151
|
+
this.configs.app.services[service].buildArgs[name] = value;
|
|
99
152
|
return;
|
|
100
153
|
}
|
|
101
|
-
this.buildArgs[name] = value;
|
|
154
|
+
this.configs.app.buildArgs[name] = value;
|
|
102
155
|
}
|
|
103
156
|
unsetBuildArg(name, service) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
delete this.services[service].buildArgs;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (name in this.buildArgs) {
|
|
117
|
-
delete this.buildArgs[name];
|
|
118
|
-
}
|
|
157
|
+
this.configs.app.unsetBuildArg(name, service);
|
|
158
|
+
}
|
|
159
|
+
get env() {
|
|
160
|
+
return Object.assign(Object.assign({}, this.configs.project.env), this.configs.app.env);
|
|
161
|
+
}
|
|
162
|
+
set env(env) {
|
|
163
|
+
this.configs.app.env = env;
|
|
119
164
|
}
|
|
120
165
|
hasEnv(name) {
|
|
121
|
-
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
return this.env.hasOwnProperty(name);
|
|
166
|
+
return this.configs.app.hasEnv(name) || this.configs.project.hasEnv(name);
|
|
125
167
|
}
|
|
126
|
-
getEnv(
|
|
127
|
-
|
|
128
|
-
return value;
|
|
168
|
+
getEnv(key, byDefault) {
|
|
169
|
+
return this.configs.app.env[key] || this.configs.project.env[key] || byDefault;
|
|
129
170
|
}
|
|
130
|
-
setEnv(
|
|
131
|
-
|
|
132
|
-
this.env = {};
|
|
133
|
-
}
|
|
134
|
-
if (service) {
|
|
135
|
-
if (!this.services[service]) {
|
|
136
|
-
throw new Error(`Service "${service}" not found`);
|
|
137
|
-
}
|
|
138
|
-
if (!this.services[service].env) {
|
|
139
|
-
this.services[service].env = {};
|
|
140
|
-
}
|
|
141
|
-
this.services[service].env[name] = typeof value === "boolean"
|
|
142
|
-
? (value ? "true" : "false")
|
|
143
|
-
: value;
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
this.env[name] = typeof value === "boolean"
|
|
147
|
-
? (value ? "true" : "false")
|
|
148
|
-
: value;
|
|
171
|
+
setEnv(key, value, service) {
|
|
172
|
+
this.configs.app.setEnv(key, value, service);
|
|
149
173
|
}
|
|
150
|
-
unsetEnv(
|
|
151
|
-
|
|
152
|
-
if (!this.services[service]) {
|
|
153
|
-
throw new Error(`Service "${service}" not found`);
|
|
154
|
-
}
|
|
155
|
-
if (this.services[service].env && name in this.services[service].env) {
|
|
156
|
-
delete this.services[service].env[name];
|
|
157
|
-
if (Object.keys(this.services[service].env).length === 0) {
|
|
158
|
-
delete this.services[service].env;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (name in this.env) {
|
|
164
|
-
delete this.env[name];
|
|
165
|
-
}
|
|
174
|
+
unsetEnv(key, service) {
|
|
175
|
+
this.configs.app.unsetEnv(key, service);
|
|
166
176
|
}
|
|
167
|
-
hasMeta(
|
|
168
|
-
return
|
|
177
|
+
hasMeta(key) {
|
|
178
|
+
return this.configs.app.metadata.hasOwnProperty(key) || this.configs.project.metadata.hasOwnProperty(key);
|
|
169
179
|
}
|
|
170
|
-
getMeta(
|
|
171
|
-
|
|
172
|
-
return value;
|
|
180
|
+
getMeta(key, byDefault) {
|
|
181
|
+
return this.configs.app.metadata[key] || this.configs.project.metadata[key] || byDefault;
|
|
173
182
|
}
|
|
174
183
|
setMeta(name, value) {
|
|
175
|
-
|
|
176
|
-
this.metadata = {};
|
|
177
|
-
}
|
|
178
|
-
this.metadata[name] = typeof value === "boolean"
|
|
184
|
+
this.configs.app.metadata[name] = typeof value === "boolean"
|
|
179
185
|
? (value ? "true" : "false")
|
|
180
186
|
: value;
|
|
181
187
|
}
|
|
182
188
|
unsetMeta(name) {
|
|
183
|
-
if (name in this.metadata) {
|
|
184
|
-
delete this.metadata[name];
|
|
189
|
+
if (name in this.configs.app.metadata) {
|
|
190
|
+
delete this.configs.app.metadata[name];
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
193
|
getVolumeBySource(source) {
|
|
188
|
-
return
|
|
189
|
-
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
190
|
-
});
|
|
194
|
+
return this.configs.project.getVolumeBySource(source) || this.configs.app.getVolumeBySource(source);
|
|
191
195
|
}
|
|
192
196
|
getVolumeByDestination(destination) {
|
|
193
|
-
return
|
|
194
|
-
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
195
|
-
});
|
|
197
|
+
return this.configs.project.getVolumeByDestination(destination) || this.configs.app.getVolumeByDestination(destination);
|
|
196
198
|
}
|
|
197
199
|
volumeMount(...volumes) {
|
|
198
|
-
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const [volume, ...restVolumes] = volumes;
|
|
202
|
-
const { destination } = (0, volumeParse_1.volumeParse)(volume);
|
|
203
|
-
this.volumes = [
|
|
204
|
-
...(this.volumes || []).filter((v) => {
|
|
205
|
-
return v !== this.getVolumeByDestination(destination);
|
|
206
|
-
}),
|
|
207
|
-
volume
|
|
208
|
-
];
|
|
209
|
-
this.volumeMount(...restVolumes);
|
|
200
|
+
this.configs.app.volumeMount(...volumes);
|
|
210
201
|
}
|
|
211
202
|
volumeUnmount(...volumes) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const v = (0, volumeParse_1.volumeParse)(volume);
|
|
217
|
-
this.volumes = this.volumes.filter((mounted) => {
|
|
218
|
-
const m = (0, volumeParse_1.volumeParse)(mounted);
|
|
219
|
-
return v.source !== m.source && v.destination !== m.destination;
|
|
220
|
-
});
|
|
221
|
-
if (this.volumes.length === 0) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
this.volumeUnmount(...restVolumes);
|
|
203
|
+
this.configs.app.volumeUnmount(...volumes);
|
|
204
|
+
}
|
|
205
|
+
get extraHosts() {
|
|
206
|
+
return Object.assign(Object.assign({}, this.configs.project.extraHosts), this.configs.app.extraHosts);
|
|
225
207
|
}
|
|
208
|
+
;
|
|
226
209
|
addExtraHost(host, domain) {
|
|
227
|
-
|
|
228
|
-
this.extraHosts = {};
|
|
229
|
-
}
|
|
230
|
-
this.extraHosts[host] = domain;
|
|
210
|
+
this.configs.app.addExtraHost(host, domain);
|
|
231
211
|
}
|
|
232
212
|
removeExtraHost(host) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
213
|
+
this.configs.app.removeExtraHost(host);
|
|
214
|
+
}
|
|
215
|
+
get services() {
|
|
216
|
+
return this.configs.app.services;
|
|
237
217
|
}
|
|
238
218
|
getSecret(key, byDefault) {
|
|
239
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -254,29 +234,13 @@ class Project {
|
|
|
254
234
|
});
|
|
255
235
|
}
|
|
256
236
|
save() {
|
|
257
|
-
const container = AsyncStorage_1.AsyncStorage.getContainer(), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
path: this.path,
|
|
265
|
-
imageName: this.imageName,
|
|
266
|
-
dockerfile: this.dockerfile,
|
|
267
|
-
composefile: this.composefile,
|
|
268
|
-
preset: this.preset,
|
|
269
|
-
presetMode: this.presetMode,
|
|
270
|
-
cmd: this.cmd,
|
|
271
|
-
scripts: this.scripts,
|
|
272
|
-
services: Object.keys(this.services).length > 0 ? this.services : undefined,
|
|
273
|
-
buildArgs: Object.keys(this.buildArgs).length > 0 ? this.buildArgs : undefined,
|
|
274
|
-
env: Object.keys(this.env).length > 0 ? this.env : undefined,
|
|
275
|
-
metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
|
|
276
|
-
ports: this.ports.length > 0 ? this.ports : undefined,
|
|
277
|
-
extraHosts: Object.keys(this.extraHosts).length ? this.extraHosts : undefined,
|
|
278
|
-
volumes: this.volumes.length > 0 ? this.volumes : undefined,
|
|
279
|
-
};
|
|
237
|
+
const container = AsyncStorage_1.AsyncStorage.getContainer(), appService = container.get(AppService_1.AppService), projectRepository = container.get(ProjectRepository_1.ProjectRepository);
|
|
238
|
+
appService.addProject(this.name, this.path);
|
|
239
|
+
this.configs.app.save();
|
|
240
|
+
// const container = AsyncStorage.getContainer(),
|
|
241
|
+
// projectRepository = container.get(ProjectRepository);
|
|
242
|
+
//
|
|
243
|
+
// projectRepository.save(this);
|
|
280
244
|
}
|
|
281
245
|
}
|
|
282
246
|
exports.Project = Project;
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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,9 +1,18 @@
|
|
|
1
1
|
import { Project } from "../makes/Project";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { ProjectConfig } from "../makes/ProjectConfig";
|
|
3
|
+
import { AppFileSystemService, AppService } from "../../../services";
|
|
4
|
+
import { FileSystemDriver } from "../../../types";
|
|
5
|
+
import { ProjectConfigScope } from "../types";
|
|
6
|
+
export declare class ProjectRepository {
|
|
7
|
+
protected readonly appService: AppService;
|
|
8
|
+
protected readonly fs: AppFileSystemService;
|
|
9
|
+
protected readonly driver: FileSystemDriver;
|
|
10
|
+
constructor(appService: AppService, fs: AppFileSystemService, driver: FileSystemDriver);
|
|
11
|
+
getConfig(name: string, scope: ProjectConfigScope): ProjectConfig;
|
|
12
|
+
getByName(name: string): Project;
|
|
13
|
+
save(project: Project): void;
|
|
14
|
+
search(params: ProjectRepository.SearchParams): Project[];
|
|
15
|
+
searchOne(params: ProjectRepository.SearchParams): Project | null;
|
|
7
16
|
}
|
|
8
17
|
export declare namespace ProjectRepository {
|
|
9
18
|
type SearchParams = Partial<{
|
|
@@ -5,12 +5,72 @@ 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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
8
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
15
|
exports.ProjectRepository = void 0;
|
|
10
16
|
const decorators_1 = require("../../../decorators");
|
|
17
|
+
const Project_1 = require("../makes/Project");
|
|
18
|
+
const ProjectConfig_1 = require("../makes/ProjectConfig");
|
|
19
|
+
const FileSystem_1 = require("../../../makes/FileSystem");
|
|
20
|
+
const services_1 = require("../../../services");
|
|
21
|
+
const env_1 = require("../../../env");
|
|
22
|
+
const types_1 = require("../types");
|
|
11
23
|
let ProjectRepository = class ProjectRepository {
|
|
24
|
+
constructor(appService, fs, driver) {
|
|
25
|
+
this.appService = appService;
|
|
26
|
+
this.fs = fs;
|
|
27
|
+
this.driver = driver;
|
|
28
|
+
}
|
|
29
|
+
getConfig(name, scope) {
|
|
30
|
+
const ref = this.appService.getProject(name);
|
|
31
|
+
if (!ref) {
|
|
32
|
+
throw new Error("");
|
|
33
|
+
}
|
|
34
|
+
switch (scope) {
|
|
35
|
+
case types_1.ProjectConfigScope.APP:
|
|
36
|
+
return ProjectConfig_1.ProjectConfig.make(this.fs.cd(`projects/${ref.name}`), "config.json");
|
|
37
|
+
case types_1.ProjectConfigScopeEnum.LOCAL:
|
|
38
|
+
return ProjectConfig_1.ProjectConfig.make(new FileSystem_1.FileSystem(ref.path, this.driver), "wocker.config.json");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getByName(name) {
|
|
42
|
+
const ref = this.appService.getProject(name);
|
|
43
|
+
if (!ref) {
|
|
44
|
+
throw new Error(`Project "${name}" not found`);
|
|
45
|
+
}
|
|
46
|
+
return new Project_1.Project(ref.name, ref.path);
|
|
47
|
+
}
|
|
48
|
+
save(project) {
|
|
49
|
+
project.save();
|
|
50
|
+
}
|
|
51
|
+
search(params) {
|
|
52
|
+
const { name, path } = params, projects = [];
|
|
53
|
+
for (const ref of this.appService.projects) {
|
|
54
|
+
if (name && ref.name !== name) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (path && ref.path !== path) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const project = this.getByName(ref.name);
|
|
61
|
+
projects.push(project);
|
|
62
|
+
}
|
|
63
|
+
return projects;
|
|
64
|
+
}
|
|
65
|
+
searchOne(params) {
|
|
66
|
+
const [project] = this.search(params);
|
|
67
|
+
return project || null;
|
|
68
|
+
}
|
|
12
69
|
};
|
|
13
70
|
exports.ProjectRepository = ProjectRepository;
|
|
14
71
|
exports.ProjectRepository = ProjectRepository = __decorate([
|
|
15
|
-
(0, decorators_1.Injectable)("PROJECT_REPOSITORY")
|
|
72
|
+
(0, decorators_1.Injectable)("PROJECT_REPOSITORY"),
|
|
73
|
+
__param(2, (0, decorators_1.Inject)(env_1.FILE_SYSTEM_DRIVER_KEY)),
|
|
74
|
+
__metadata("design:paramtypes", [services_1.AppService,
|
|
75
|
+
services_1.AppFileSystemService, Object])
|
|
16
76
|
], ProjectRepository);
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
});
|
|
@@ -14,5 +14,6 @@ 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("./ProjectConfigScope"), exports);
|
|
17
18
|
__exportStar(require("./ProjectV1"), exports);
|
|
18
19
|
__exportStar(require("./ServiceProperties"), exports);
|
|
@@ -23,7 +23,7 @@ let AppFileSystemService = class AppFileSystemService extends FileSystem_1.FileS
|
|
|
23
23
|
};
|
|
24
24
|
exports.AppFileSystemService = AppFileSystemService;
|
|
25
25
|
exports.AppFileSystemService = AppFileSystemService = __decorate([
|
|
26
|
-
(0, decorators_1.Injectable)(),
|
|
26
|
+
(0, decorators_1.Injectable)("APP_FILE_SYSTEM_SERVICE"),
|
|
27
27
|
__param(0, (0, decorators_1.Inject)(env_1.WOCKER_DATA_DIR_KEY)),
|
|
28
28
|
__param(1, (0, decorators_1.Inject)(env_1.FILE_SYSTEM_DRIVER_KEY)),
|
|
29
29
|
__metadata("design:paramtypes", [String, Object])
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { AppConfig } from "../makes/AppConfig";
|
|
2
2
|
import { AppFileSystemService } from "./AppFileSystemService";
|
|
3
3
|
import { ProcessService } from "./ProcessService";
|
|
4
|
+
import { LogService } from "./LogService";
|
|
4
5
|
import { ProjectRef, PluginRef, PresetRef, PresetSource } from "../types";
|
|
5
6
|
type TypeMap = {
|
|
6
7
|
[type: string]: string;
|
|
7
8
|
};
|
|
8
9
|
export declare class AppService {
|
|
9
10
|
readonly version: string;
|
|
10
|
-
protected readonly processService: ProcessService;
|
|
11
11
|
readonly fs: AppFileSystemService;
|
|
12
|
+
protected readonly processService: ProcessService;
|
|
13
|
+
protected readonly logService: LogService;
|
|
12
14
|
protected _config?: AppConfig;
|
|
13
15
|
protected readonly mapTypes: TypeMap;
|
|
14
|
-
constructor(version: string, processService: ProcessService,
|
|
16
|
+
constructor(version: string, fs: AppFileSystemService, processService: ProcessService, logService: LogService);
|
|
15
17
|
get config(): AppConfig;
|
|
16
18
|
get debug(): boolean;
|
|
17
19
|
set debug(debug: boolean);
|
|
@@ -21,6 +23,7 @@ export declare class AppService {
|
|
|
21
23
|
isVersionGT(version: string): boolean;
|
|
22
24
|
isVersionGTE(version: string): boolean;
|
|
23
25
|
getProjectTypes(): TypeMap;
|
|
26
|
+
getProject(name: string): ProjectRef | undefined;
|
|
24
27
|
addProject(name: string, path: string): void;
|
|
25
28
|
removeProject(name: string): void;
|
|
26
29
|
addPlugin(name: string, env?: PluginRef["env"]): void;
|
|
@@ -18,13 +18,15 @@ const Version_1 = require("../makes/Version");
|
|
|
18
18
|
const AppConfig_1 = require("../makes/AppConfig");
|
|
19
19
|
const AppFileSystemService_1 = require("./AppFileSystemService");
|
|
20
20
|
const ProcessService_1 = require("./ProcessService");
|
|
21
|
+
const LogService_1 = require("./LogService");
|
|
21
22
|
const types_1 = require("../types");
|
|
22
23
|
const env_1 = require("../env");
|
|
23
24
|
let AppService = class AppService {
|
|
24
|
-
constructor(version, processService,
|
|
25
|
+
constructor(version, fs, processService, logService) {
|
|
25
26
|
this.version = version;
|
|
26
|
-
this.processService = processService;
|
|
27
27
|
this.fs = fs;
|
|
28
|
+
this.processService = processService;
|
|
29
|
+
this.logService = logService;
|
|
28
30
|
this.mapTypes = {
|
|
29
31
|
[types_1.ProjectType.IMAGE]: "Image",
|
|
30
32
|
[types_1.ProjectType.PRESET]: "Preset",
|
|
@@ -64,6 +66,9 @@ let AppService = class AppService {
|
|
|
64
66
|
}
|
|
65
67
|
return this.mapTypes;
|
|
66
68
|
}
|
|
69
|
+
getProject(name) {
|
|
70
|
+
return this.config.getProject(name);
|
|
71
|
+
}
|
|
67
72
|
addProject(name, path) {
|
|
68
73
|
this.config.addProject(name, path);
|
|
69
74
|
this.config.save();
|
|
@@ -128,6 +133,7 @@ exports.AppService = AppService;
|
|
|
128
133
|
exports.AppService = AppService = __decorate([
|
|
129
134
|
(0, decorators_1.Injectable)("APP_SERVICE"),
|
|
130
135
|
__param(0, (0, decorators_1.Inject)(env_1.WOCKER_VERSION_KEY)),
|
|
131
|
-
__metadata("design:paramtypes", [String,
|
|
132
|
-
|
|
136
|
+
__metadata("design:paramtypes", [String, AppFileSystemService_1.AppFileSystemService,
|
|
137
|
+
ProcessService_1.ProcessService,
|
|
138
|
+
LogService_1.LogService])
|
|
133
139
|
], AppService);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProcessService } from "./ProcessService";
|
|
2
2
|
import { AppFileSystemService } from "./AppFileSystemService";
|
|
3
|
+
import { LogLevel } from "../types";
|
|
3
4
|
export declare class LogService {
|
|
4
|
-
protected readonly
|
|
5
|
+
protected readonly processService: ProcessService;
|
|
5
6
|
protected readonly fs: AppFileSystemService;
|
|
6
|
-
constructor(
|
|
7
|
+
constructor(processService: ProcessService, fs: AppFileSystemService);
|
|
8
|
+
get logLevel(): LogLevel;
|
|
7
9
|
protected get logName(): string;
|
|
8
|
-
protected _log(type:
|
|
10
|
+
protected _log(type: LogLevel, ...data: any[]): void;
|
|
9
11
|
debug(...data: any[]): void;
|
|
10
12
|
log(...data: any[]): void;
|
|
11
13
|
info(...data: any[]): void;
|
|
@@ -12,18 +12,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.LogService = void 0;
|
|
13
13
|
const format_1 = require("date-fns/format");
|
|
14
14
|
const decorators_1 = require("../decorators");
|
|
15
|
-
const
|
|
15
|
+
const ProcessService_1 = require("./ProcessService");
|
|
16
16
|
const AppFileSystemService_1 = require("./AppFileSystemService");
|
|
17
|
+
const types_1 = require("../types");
|
|
17
18
|
let LogService = class LogService {
|
|
18
|
-
constructor(
|
|
19
|
-
this.
|
|
19
|
+
constructor(processService, fs) {
|
|
20
|
+
this.processService = processService;
|
|
20
21
|
this.fs = fs;
|
|
21
22
|
}
|
|
23
|
+
get logLevel() {
|
|
24
|
+
const level = this.processService.getEnv("WS_LOG_LEVEL", types_1.LogLevel.WARNING);
|
|
25
|
+
if (types_1.LogLevel.values().includes(level)) {
|
|
26
|
+
return level;
|
|
27
|
+
}
|
|
28
|
+
return types_1.LogLevel.WARNING;
|
|
29
|
+
}
|
|
22
30
|
get logName() {
|
|
23
31
|
return "ws.log";
|
|
24
32
|
}
|
|
25
33
|
_log(type, ...data) {
|
|
26
|
-
if (
|
|
34
|
+
if (!types_1.LogLevel.isGTE(this.logLevel, type)) {
|
|
27
35
|
return;
|
|
28
36
|
}
|
|
29
37
|
const time = (0, format_1.format)(new Date(), "yyyy-MM-dd HH:mm:ss");
|
|
@@ -36,19 +44,19 @@ let LogService = class LogService {
|
|
|
36
44
|
this.fs.appendFile(this.logName, `[${time}] ${type}: ${logData}\n`);
|
|
37
45
|
}
|
|
38
46
|
debug(...data) {
|
|
39
|
-
this._log(
|
|
47
|
+
this._log(types_1.LogLevel.DEBUG, ...data);
|
|
40
48
|
}
|
|
41
49
|
log(...data) {
|
|
42
|
-
this._log(
|
|
50
|
+
this._log(types_1.LogLevel.LOG, ...data);
|
|
43
51
|
}
|
|
44
52
|
info(...data) {
|
|
45
|
-
this._log(
|
|
53
|
+
this._log(types_1.LogLevel.INFO, ...data);
|
|
46
54
|
}
|
|
47
55
|
warn(...data) {
|
|
48
|
-
this._log(
|
|
56
|
+
this._log(types_1.LogLevel.WARNING, ...data);
|
|
49
57
|
}
|
|
50
58
|
error(...data) {
|
|
51
|
-
this._log(
|
|
59
|
+
this._log(types_1.LogLevel.ERROR, ...data);
|
|
52
60
|
}
|
|
53
61
|
clear() {
|
|
54
62
|
this.fs.writeFile(this.logName, "");
|
|
@@ -57,6 +65,6 @@ let LogService = class LogService {
|
|
|
57
65
|
exports.LogService = LogService;
|
|
58
66
|
exports.LogService = LogService = __decorate([
|
|
59
67
|
(0, decorators_1.Injectable)("LOG_SERVICE"),
|
|
60
|
-
__metadata("design:paramtypes", [
|
|
68
|
+
__metadata("design:paramtypes", [ProcessService_1.ProcessService,
|
|
61
69
|
AppFileSystemService_1.AppFileSystemService])
|
|
62
70
|
], LogService);
|
|
@@ -8,7 +8,7 @@ export declare class ProcessService {
|
|
|
8
8
|
cd(path: string): void;
|
|
9
9
|
chdir(path: string): void;
|
|
10
10
|
write(chunk: string | Buffer): boolean;
|
|
11
|
-
getEnv(key: string
|
|
11
|
+
getEnv(key: string): string | undefined;
|
|
12
12
|
getEnv(key: string, byDefault: string): string;
|
|
13
13
|
setEnv(key: string, value: string): void;
|
|
14
14
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare enum LogLevelEnum {
|
|
2
|
+
DEBUG = "debug",
|
|
3
|
+
LOG = "log",
|
|
4
|
+
INFO = "info",
|
|
5
|
+
WARNING = "warn",
|
|
6
|
+
ERROR = "error"
|
|
7
|
+
}
|
|
8
|
+
export type LogLevel = LogLevelEnum;
|
|
9
|
+
export declare const LogLevel: typeof LogLevelEnum & {
|
|
10
|
+
values(): LogLevelEnum[];
|
|
11
|
+
isGTE(a: LogLevelEnum, b: LogLevelEnum): boolean;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevel = void 0;
|
|
4
|
+
var LogLevelEnum;
|
|
5
|
+
(function (LogLevelEnum) {
|
|
6
|
+
LogLevelEnum["DEBUG"] = "debug";
|
|
7
|
+
LogLevelEnum["LOG"] = "log";
|
|
8
|
+
LogLevelEnum["INFO"] = "info";
|
|
9
|
+
LogLevelEnum["WARNING"] = "warn";
|
|
10
|
+
LogLevelEnum["ERROR"] = "error";
|
|
11
|
+
})(LogLevelEnum || (LogLevelEnum = {}));
|
|
12
|
+
exports.LogLevel = Object.assign({}, LogLevelEnum, {
|
|
13
|
+
values() {
|
|
14
|
+
return Object.values(LogLevelEnum);
|
|
15
|
+
},
|
|
16
|
+
isGTE(a, b) {
|
|
17
|
+
const values = exports.LogLevel.values();
|
|
18
|
+
return values.indexOf(a) <= values.indexOf(b);
|
|
19
|
+
}
|
|
20
|
+
});
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./DynamicModule";
|
|
|
2
2
|
export * from "./EnvConfig";
|
|
3
3
|
export * from "./FileSystemDriver";
|
|
4
4
|
export * from "./InjectionToken";
|
|
5
|
+
export * from "./LogLevel";
|
|
5
6
|
export * from "./ModuleMetadata";
|
|
6
7
|
export * from "./PackageManagerType";
|
|
7
8
|
export * from "./PickProperties";
|
package/lib/types/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./DynamicModule"), exports);
|
|
|
18
18
|
__exportStar(require("./EnvConfig"), exports);
|
|
19
19
|
__exportStar(require("./FileSystemDriver"), exports);
|
|
20
20
|
__exportStar(require("./InjectionToken"), exports);
|
|
21
|
+
__exportStar(require("./LogLevel"), exports);
|
|
21
22
|
__exportStar(require("./ModuleMetadata"), exports);
|
|
22
23
|
__exportStar(require("./PackageManagerType"), exports);
|
|
23
24
|
__exportStar(require("./PickProperties"), exports);
|