@wocker/ws 1.0.1 → 1.0.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/README.md +11 -137
- package/bin/ws.js +7 -3
- package/lib/App.d.ts +10 -7
- package/lib/App.js +99 -44
- package/lib/controllers/ImageController.d.ts +4 -2
- package/lib/controllers/ImageController.js +27 -25
- package/lib/controllers/PluginController.d.ts +14 -0
- package/lib/controllers/PluginController.js +84 -0
- package/lib/controllers/PresetController.d.ts +21 -0
- package/lib/controllers/PresetController.js +169 -0
- package/lib/controllers/ProjectController.d.ts +11 -3
- package/lib/controllers/ProjectController.js +653 -536
- package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +12 -11
- package/lib/controllers/ProxyController.js +273 -0
- package/lib/controllers/index.d.ts +3 -0
- package/lib/controllers/index.js +19 -25
- package/lib/env.js +33 -22
- package/lib/index.d.ts +2 -0
- package/lib/index.js +29 -28
- package/lib/makes/Controller.js +4 -8
- package/lib/makes/DI.d.ts +7 -0
- package/lib/makes/DI.js +27 -0
- package/lib/makes/Docker.js +299 -397
- package/lib/makes/FS.d.ts +1 -1
- package/lib/makes/FS.js +328 -301
- package/lib/makes/LineConvertStream.js +37 -40
- package/lib/makes/Logger.d.ts +5 -3
- package/lib/makes/Logger.js +18 -34
- package/lib/makes/Model.js +8 -12
- package/lib/makes/MySQL.js +6 -27
- package/lib/makes/Plugin.d.ts +1 -1
- package/lib/makes/Plugin.js +55 -37
- package/lib/makes/Preset.d.ts +46 -0
- package/lib/makes/Preset.js +33 -0
- package/lib/{models → makes}/Project.d.ts +23 -16
- package/lib/makes/Project.js +127 -0
- package/lib/makes/Repository.js +18 -21
- package/lib/makes/index.d.ts +3 -0
- package/lib/makes/index.js +23 -69
- package/lib/plugins/ElasticSearchPlugin.d.ts +18 -0
- package/lib/plugins/ElasticSearchPlugin.js +72 -0
- package/lib/plugins/LocaltunnelPlugin.d.ts +4 -4
- package/lib/plugins/LocaltunnelPlugin.js +256 -255
- package/lib/plugins/MaildevPlugin.d.ts +4 -2
- package/lib/plugins/MaildevPlugin.js +45 -41
- package/lib/plugins/MongodbPlugin.d.ts +6 -4
- package/lib/plugins/MongodbPlugin.js +303 -254
- package/lib/plugins/NgrokPlugin.d.ts +3 -4
- package/lib/plugins/NgrokPlugin.js +221 -230
- package/lib/plugins/PageKitePlugin.d.ts +3 -4
- package/lib/plugins/PageKitePlugin.js +150 -147
- package/lib/plugins/PostgresPlugin.d.ts +1 -1
- package/lib/plugins/PostgresPlugin.js +115 -88
- package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
- package/lib/plugins/ProxmoxPlugin.js +50 -38
- package/lib/plugins/RedisPlugin.d.ts +10 -2
- package/lib/plugins/RedisPlugin.js +77 -39
- package/lib/plugins/index.d.ts +2 -6
- package/lib/plugins/index.js +25 -158
- package/lib/services/AppConfigService.d.ts +13 -3
- package/lib/services/AppConfigService.js +161 -71
- package/lib/services/AppEventsService.d.ts +5 -8
- package/lib/services/AppEventsService.js +26 -25
- package/lib/services/DockerService.d.ts +51 -0
- package/lib/services/DockerService.js +200 -0
- package/lib/services/LogService.d.ts +12 -0
- package/lib/services/LogService.js +38 -0
- package/lib/services/PluginService.d.ts +11 -0
- package/lib/services/PluginService.js +15 -0
- package/lib/services/PresetService.d.ts +14 -0
- package/lib/services/PresetService.js +64 -0
- package/lib/services/ProjectService.d.ts +12 -4
- package/lib/services/ProjectService.js +141 -78
- package/lib/services/index.d.ts +4 -0
- package/lib/services/index.js +21 -36
- package/lib/types/Config.d.ts +4 -3
- package/lib/types/Config.js +1 -4
- package/lib/types/EnvConfig.js +1 -4
- package/lib/types/index.js +16 -25
- package/lib/utils/buildOptions.js +5 -8
- package/lib/utils/demuxOutput.js +16 -22
- package/lib/utils/escapeRegExp.js +4 -7
- package/lib/utils/exec.d.ts +1 -1
- package/lib/utils/exec.js +38 -40
- package/lib/utils/fetch.js +45 -30
- package/lib/utils/followProgress.js +66 -77
- package/lib/utils/format-size-units.js +16 -16
- package/lib/utils/get-config.d.ts +1 -1
- package/lib/utils/get-config.js +13 -16
- package/lib/utils/get-cursor-position.js +22 -29
- package/lib/utils/image-build.js +35 -23
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +32 -235
- package/lib/utils/injectVariables.js +10 -13
- package/lib/utils/parse-table.js +20 -23
- package/lib/utils/set-config.d.ts +1 -1
- package/lib/utils/set-config.js +12 -15
- package/lib/utils/spawn.js +17 -20
- package/lib/utils/tty.js +2 -6
- package/lib/utils/volumeFormat.js +5 -12
- package/lib/utils/volumeParse.js +10 -13
- package/package.json +21 -47
- package/presets/bun/Dockerfile +11 -0
- package/presets/bun/config.json +3 -0
- package/presets/node/Dockerfile +4 -2
- package/presets/node/config.json +9 -7
- package/presets/php-apache/Dockerfile +40 -38
- package/presets/php-apache/config.json +10 -15
- package/presets/php-fpm/Dockerfile +21 -0
- package/presets/php-fpm/config.json +25 -0
- package/lib/models/Preset.d.ts +0 -19
- package/lib/models/Preset.js +0 -60
- package/lib/models/Project.js +0 -151
- package/lib/models/index.d.ts +0 -2
- package/lib/models/index.js +0 -27
- package/lib/plugins/MariadbPlugin.d.ts +0 -25
- package/lib/plugins/MariadbPlugin.js +0 -297
- package/lib/plugins/PresetPlugin.d.ts +0 -19
- package/lib/plugins/PresetPlugin.js +0 -164
- package/lib/plugins/ProjectPlugin.d.ts +0 -12
- package/lib/plugins/ProjectPlugin.js +0 -54
- package/lib/plugins/ProxyPlugin.js +0 -257
- package/lib/plugins/ServeoPlugin.d.ts +0 -36
- package/lib/plugins/ServeoPlugin.js +0 -260
- package/lib/plugins/TestPlugin.d.ts +0 -10
- package/lib/plugins/TestPlugin.js +0 -75
- package/lib/utils/promptConfirm.d.ts +0 -6
- package/lib/utils/promptConfirm.js +0 -21
- package/lib/utils/promptGroup.d.ts +0 -16
- package/lib/utils/promptGroup.js +0 -39
- package/lib/utils/promptSelect.d.ts +0 -12
- package/lib/utils/promptSelect.js +0 -47
- package/lib/utils/promptText.d.ts +0 -13
- package/lib/utils/promptText.js +0 -53
- package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
- package/plugins/serveo/Dockerfile +0 -17
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.AppEventsService = void 0;
|
|
7
|
-
|
|
8
|
-
class AppEventsService {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
const core_1 = require("@wocker/core");
|
|
5
|
+
class AppEventsService extends core_1.AppEventsService {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.handles = {};
|
|
9
|
+
}
|
|
10
|
+
on(event, handle) {
|
|
11
|
+
this.handles[event] = [
|
|
12
|
+
...this.handles[event] || [],
|
|
13
|
+
handle
|
|
14
|
+
];
|
|
15
|
+
return () => {
|
|
16
|
+
this.handles[event] = this.handles[event].filter((filterHandle) => {
|
|
17
|
+
return filterHandle !== handle;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
off(event, handle) {
|
|
22
|
+
}
|
|
23
|
+
async emit(event, ...args) {
|
|
24
|
+
const handles = this.handles[event] || [];
|
|
25
|
+
for (const i in handles) {
|
|
26
|
+
await handles[i](...args);
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
|
-
}
|
|
28
29
|
}
|
|
29
|
-
exports.AppEventsService = AppEventsService;
|
|
30
|
+
exports.AppEventsService = AppEventsService;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Docker, { Container } from "dockerode";
|
|
3
|
+
import { DI } from "../makes";
|
|
4
|
+
declare namespace Params {
|
|
5
|
+
type CreateContainer = {
|
|
6
|
+
name: string;
|
|
7
|
+
image: string;
|
|
8
|
+
restart?: "always";
|
|
9
|
+
projectId?: string;
|
|
10
|
+
tty?: boolean;
|
|
11
|
+
ulimits?: {
|
|
12
|
+
[key: string]: {
|
|
13
|
+
hard?: number;
|
|
14
|
+
soft?: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
links?: string[];
|
|
18
|
+
env?: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
networkMode?: string;
|
|
22
|
+
extraHosts?: any;
|
|
23
|
+
volumes?: string[];
|
|
24
|
+
ports?: string[];
|
|
25
|
+
cmd?: string[];
|
|
26
|
+
};
|
|
27
|
+
type BuildImage = {
|
|
28
|
+
tag: string;
|
|
29
|
+
buildArgs?: {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
};
|
|
32
|
+
labels?: {
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
};
|
|
35
|
+
context: string;
|
|
36
|
+
src: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
declare class DockerService {
|
|
40
|
+
protected docker: Docker;
|
|
41
|
+
constructor(di: DI);
|
|
42
|
+
createContainer(params: Params.CreateContainer): Promise<Container>;
|
|
43
|
+
getContainer(name: string): Promise<Container | null>;
|
|
44
|
+
removeContainer(name: string): Promise<void>;
|
|
45
|
+
buildImage(params: Params.BuildImage): Promise<void>;
|
|
46
|
+
imageExists(tag: string): Promise<boolean>;
|
|
47
|
+
imageRm(tag: string): Promise<void>;
|
|
48
|
+
pullImage(tag: string): Promise<void>;
|
|
49
|
+
attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export { DockerService };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DockerService = void 0;
|
|
7
|
+
const dockerode_1 = __importDefault(require("dockerode"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const makes_1 = require("../makes");
|
|
10
|
+
class DockerService {
|
|
11
|
+
constructor(di) {
|
|
12
|
+
this.docker = new dockerode_1.default({
|
|
13
|
+
socketPath: "/var/run/docker.sock"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async createContainer(params) {
|
|
17
|
+
const { name, tty, image, projectId, restart, ulimits, extraHosts, networkMode, links = [], env = {}, volumes = [], ports = [], cmd = [] } = params;
|
|
18
|
+
const network = this.docker.getNetwork("workspace");
|
|
19
|
+
try {
|
|
20
|
+
await network.inspect();
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (err.statusCode === 404) {
|
|
24
|
+
await this.docker.createNetwork({
|
|
25
|
+
Name: "workspace"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
await this.pullImage(image);
|
|
30
|
+
return this.docker.createContainer({
|
|
31
|
+
name,
|
|
32
|
+
Image: image,
|
|
33
|
+
Hostname: name,
|
|
34
|
+
Labels: {
|
|
35
|
+
...projectId ? { projectId } : {}
|
|
36
|
+
},
|
|
37
|
+
AttachStdin: true,
|
|
38
|
+
AttachStdout: true,
|
|
39
|
+
AttachStderr: true,
|
|
40
|
+
OpenStdin: true,
|
|
41
|
+
StdinOnce: false,
|
|
42
|
+
Tty: tty,
|
|
43
|
+
Cmd: cmd,
|
|
44
|
+
Env: Object.keys(env).map((key) => {
|
|
45
|
+
const value = env[key];
|
|
46
|
+
return `${key}=${value}`;
|
|
47
|
+
}),
|
|
48
|
+
ExposedPorts: ports.reduce((res, value) => {
|
|
49
|
+
const [, , containerPort] = /(\d+):(\d+)/.exec(value) || [];
|
|
50
|
+
if (containerPort) {
|
|
51
|
+
res[`${containerPort}/tcp`] = {};
|
|
52
|
+
}
|
|
53
|
+
return res;
|
|
54
|
+
}, {}),
|
|
55
|
+
HostConfig: {
|
|
56
|
+
NetworkMode: networkMode,
|
|
57
|
+
ExtraHosts: extraHosts,
|
|
58
|
+
Ulimits: ulimits ? Object.keys(ulimits).reduce((res, name) => {
|
|
59
|
+
return [
|
|
60
|
+
...res,
|
|
61
|
+
{
|
|
62
|
+
Name: name,
|
|
63
|
+
Hard: ulimits[name].hard,
|
|
64
|
+
Soft: ulimits[name].soft
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
}, []) : [],
|
|
68
|
+
...restart ? {
|
|
69
|
+
RestartPolicy: {
|
|
70
|
+
Name: restart
|
|
71
|
+
}
|
|
72
|
+
} : {},
|
|
73
|
+
Binds: volumes,
|
|
74
|
+
PortBindings: ports.reduce((res, value) => {
|
|
75
|
+
const [, hostPort, containerPort] = /(\d+):(\d+)/.exec(value) || [];
|
|
76
|
+
if (hostPort && containerPort) {
|
|
77
|
+
res[`${containerPort}/tcp`] = [
|
|
78
|
+
{ HostPort: hostPort }
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
return res;
|
|
82
|
+
}, {}),
|
|
83
|
+
},
|
|
84
|
+
NetworkingConfig: {
|
|
85
|
+
EndpointsConfig: networkMode === "host" ? {} : {
|
|
86
|
+
workspace: {
|
|
87
|
+
Links: links
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async getContainer(name) {
|
|
94
|
+
const containers = await this.docker.listContainers({
|
|
95
|
+
all: true,
|
|
96
|
+
filters: {
|
|
97
|
+
name: [name]
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const container = containers.find((container) => {
|
|
101
|
+
return container.Names.indexOf("/" + name) >= 0;
|
|
102
|
+
});
|
|
103
|
+
if (container) {
|
|
104
|
+
return this.docker.getContainer(container.Id);
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
async removeContainer(name) {
|
|
109
|
+
const container = await this.getContainer(name);
|
|
110
|
+
if (!container) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const { State: { Status } } = await container.inspect();
|
|
114
|
+
if (Status === "running" || Status === "restarting") {
|
|
115
|
+
try {
|
|
116
|
+
await container.stop();
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
makes_1.Logger.error("DockerService.removeContainer", err.message);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
await container.remove();
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
makes_1.Logger.error("DockerService.removeContainer: ", err.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async buildImage(params) {
|
|
130
|
+
const { tag, labels = {}, buildArgs = {}, context, src } = params;
|
|
131
|
+
const files = await makes_1.FS.readdirFiles(context, {
|
|
132
|
+
recursive: true
|
|
133
|
+
});
|
|
134
|
+
const stream = await this.docker.buildImage({
|
|
135
|
+
context,
|
|
136
|
+
src: files
|
|
137
|
+
}, {
|
|
138
|
+
t: tag,
|
|
139
|
+
labels,
|
|
140
|
+
buildargs: Object.keys(buildArgs).reduce((res, key) => {
|
|
141
|
+
res[key] = typeof buildArgs[key] !== "string"
|
|
142
|
+
? buildArgs[key].toString()
|
|
143
|
+
: buildArgs[key];
|
|
144
|
+
return res;
|
|
145
|
+
}, {}),
|
|
146
|
+
dockerfile: src
|
|
147
|
+
});
|
|
148
|
+
await (0, utils_1.followProgress)(stream);
|
|
149
|
+
}
|
|
150
|
+
async imageExists(tag) {
|
|
151
|
+
const image = this.docker.getImage(tag);
|
|
152
|
+
try {
|
|
153
|
+
await image.inspect();
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch (ignore) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async imageRm(tag) {
|
|
161
|
+
const image = await this.docker.getImage(tag);
|
|
162
|
+
if (!image) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
await image.remove();
|
|
166
|
+
}
|
|
167
|
+
async pullImage(tag) {
|
|
168
|
+
const exists = await this.imageExists(tag);
|
|
169
|
+
if (exists) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const stream = await this.docker.pull(tag);
|
|
173
|
+
await (0, utils_1.followProgress)(stream);
|
|
174
|
+
}
|
|
175
|
+
async attachStream(stream) {
|
|
176
|
+
process.stdin.resume();
|
|
177
|
+
process.stdin.setEncoding("utf8");
|
|
178
|
+
process.stdin.pipe(stream);
|
|
179
|
+
if (process.stdin.isTTY) {
|
|
180
|
+
process.stdin.setRawMode(true);
|
|
181
|
+
}
|
|
182
|
+
stream.setEncoding("utf8");
|
|
183
|
+
stream.pipe(process.stdout);
|
|
184
|
+
const end = () => {
|
|
185
|
+
process.stdin.pause();
|
|
186
|
+
process.stdin.unpipe(stream);
|
|
187
|
+
if (process.stdin.isTTY) {
|
|
188
|
+
process.stdin.setRawMode(false);
|
|
189
|
+
}
|
|
190
|
+
stream.unpipe(process.stdout);
|
|
191
|
+
};
|
|
192
|
+
await new Promise((resolve, reject) => {
|
|
193
|
+
stream.on("end", end);
|
|
194
|
+
stream.on("error", end);
|
|
195
|
+
stream.on("end", resolve);
|
|
196
|
+
stream.on("error", reject);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.DockerService = DockerService;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DI } from "../makes";
|
|
2
|
+
import { AppConfigService } from "./AppConfigService";
|
|
3
|
+
declare class LogService {
|
|
4
|
+
protected appConfigService: AppConfigService;
|
|
5
|
+
constructor(di: DI);
|
|
6
|
+
log(...data: any[]): void;
|
|
7
|
+
info(...data: any[]): void;
|
|
8
|
+
warn(...data: any[]): void;
|
|
9
|
+
error(...data: any[]): void;
|
|
10
|
+
protected _log(type: string, ...data: any[]): void;
|
|
11
|
+
}
|
|
12
|
+
export { LogService };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LogService = void 0;
|
|
7
|
+
const format_1 = __importDefault(require("date-fns/format"));
|
|
8
|
+
const makes_1 = require("../makes");
|
|
9
|
+
const AppConfigService_1 = require("./AppConfigService");
|
|
10
|
+
class LogService {
|
|
11
|
+
constructor(di) {
|
|
12
|
+
this.appConfigService = di.resolveService(AppConfigService_1.AppConfigService);
|
|
13
|
+
}
|
|
14
|
+
log(...data) {
|
|
15
|
+
this._log("log", ...data);
|
|
16
|
+
}
|
|
17
|
+
info(...data) {
|
|
18
|
+
this._log("info", ...data);
|
|
19
|
+
}
|
|
20
|
+
warn(...data) {
|
|
21
|
+
this._log("warn", ...data);
|
|
22
|
+
}
|
|
23
|
+
error(...data) {
|
|
24
|
+
this._log("error", ...data);
|
|
25
|
+
}
|
|
26
|
+
_log(type, ...data) {
|
|
27
|
+
const time = (0, format_1.default)(new Date(), "yyyy-MM-dd hh:mm:ss");
|
|
28
|
+
const logPath = this.appConfigService.dataPath("ws.log");
|
|
29
|
+
const logData = data.map((item) => {
|
|
30
|
+
return typeof item !== "string" ? JSON.stringify(item) : item;
|
|
31
|
+
}).join(" ");
|
|
32
|
+
if (!makes_1.FS.existsSync(logPath)) {
|
|
33
|
+
makes_1.FS.writeFileSync(logPath, "");
|
|
34
|
+
}
|
|
35
|
+
makes_1.FS.appendFileSync(logPath, `[${time}] ${type}: ${logData}\n`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.LogService = LogService;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Cli } from "@wocker/core";
|
|
2
|
+
import { DI, Controller } from "../makes";
|
|
3
|
+
declare class PluginService {
|
|
4
|
+
protected di: DI;
|
|
5
|
+
protected cli: Cli;
|
|
6
|
+
constructor(di: DI);
|
|
7
|
+
use(Constructor: {
|
|
8
|
+
new (...params: any[]): Controller;
|
|
9
|
+
}): void;
|
|
10
|
+
}
|
|
11
|
+
export { PluginService };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginService = void 0;
|
|
4
|
+
const core_1 = require("@wocker/core");
|
|
5
|
+
class PluginService {
|
|
6
|
+
constructor(di) {
|
|
7
|
+
this.di = di;
|
|
8
|
+
this.cli = di.resolveService(core_1.Cli);
|
|
9
|
+
}
|
|
10
|
+
use(Constructor) {
|
|
11
|
+
const controller = new Constructor(this.di);
|
|
12
|
+
controller.install(this.cli);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.PluginService = PluginService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EnvConfig } from "../types";
|
|
2
|
+
import { DI, Preset } from "../makes";
|
|
3
|
+
type SearchOptions = Partial<{
|
|
4
|
+
name: string;
|
|
5
|
+
}>;
|
|
6
|
+
declare class PresetService {
|
|
7
|
+
constructor(di: DI);
|
|
8
|
+
getImageName(preset: Preset, buildArgs?: EnvConfig): string;
|
|
9
|
+
save(preset: Preset): Promise<void>;
|
|
10
|
+
get(name: string): Promise<Preset>;
|
|
11
|
+
search(options?: SearchOptions): Promise<Preset[]>;
|
|
12
|
+
searchOne(options?: SearchOptions): Promise<Preset | null>;
|
|
13
|
+
}
|
|
14
|
+
export { PresetService, SearchOptions as PresetServiceSearchOptions };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PresetService = void 0;
|
|
7
|
+
const md5_1 = __importDefault(require("md5"));
|
|
8
|
+
const env_1 = require("../env");
|
|
9
|
+
const makes_1 = require("../makes");
|
|
10
|
+
class PresetService {
|
|
11
|
+
constructor(di) { }
|
|
12
|
+
getImageName(preset, buildArgs = {}) {
|
|
13
|
+
const rawValues = [];
|
|
14
|
+
const hashValues = [];
|
|
15
|
+
Object.keys(preset.buildArgsOptions || {}).forEach((key) => {
|
|
16
|
+
const hash = (preset.buildArgsOptions[key] || {}).hash || true;
|
|
17
|
+
const value = buildArgs[key];
|
|
18
|
+
if (hash) {
|
|
19
|
+
hashValues.push(value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
rawValues.push(value);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const version = [
|
|
26
|
+
...rawValues,
|
|
27
|
+
(0, md5_1.default)(hashValues.join(",")).substr(0, 6)
|
|
28
|
+
].filter((value) => {
|
|
29
|
+
return !!value;
|
|
30
|
+
}).join("-");
|
|
31
|
+
return `ws-preset-${preset.name}:${version}`;
|
|
32
|
+
}
|
|
33
|
+
async save(preset) {
|
|
34
|
+
}
|
|
35
|
+
async get(name) {
|
|
36
|
+
const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
|
|
37
|
+
return new makes_1.Preset({
|
|
38
|
+
name,
|
|
39
|
+
...config
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async search(options = {}) {
|
|
43
|
+
const { name } = options;
|
|
44
|
+
const presets = [];
|
|
45
|
+
const dirs = await makes_1.FS.readdir(env_1.PRESETS_DIR);
|
|
46
|
+
for (const dir of dirs) {
|
|
47
|
+
if (name && name !== dir) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, dir, "config.json");
|
|
51
|
+
const preset = new makes_1.Preset({
|
|
52
|
+
name: dir,
|
|
53
|
+
...config
|
|
54
|
+
});
|
|
55
|
+
presets.push(preset);
|
|
56
|
+
}
|
|
57
|
+
return presets;
|
|
58
|
+
}
|
|
59
|
+
async searchOne(options = {}) {
|
|
60
|
+
const [preset] = await this.search(options);
|
|
61
|
+
return preset || null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.PresetService = PresetService;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { Project } from "
|
|
2
|
-
import { AppConfigService } from "
|
|
3
|
-
|
|
1
|
+
import { DI, Project } from "../makes";
|
|
2
|
+
import { DockerService, AppConfigService, AppEventsService } from "../services";
|
|
3
|
+
type SearchParams = Partial<{
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
}>;
|
|
4
8
|
declare class ProjectService {
|
|
5
9
|
protected appConfigService: AppConfigService;
|
|
6
10
|
protected appEventsService: AppEventsService;
|
|
7
|
-
|
|
11
|
+
protected dockerService: DockerService;
|
|
12
|
+
constructor(di: DI);
|
|
8
13
|
cdProject(name: string): Promise<void>;
|
|
9
14
|
get(): Promise<Project>;
|
|
15
|
+
getContainer(): Promise<import("dockerode").Container>;
|
|
10
16
|
start(): Promise<void>;
|
|
11
17
|
stop(): Promise<void>;
|
|
18
|
+
save(project: Project): Promise<void>;
|
|
19
|
+
search(params?: Partial<SearchParams>): Promise<Project[]>;
|
|
12
20
|
}
|
|
13
21
|
export { ProjectService };
|