@wocker/ws 1.1.0 → 1.1.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/modules/preset/controllers/PresetController.js +1 -1
- package/lib/modules/preset/controllers/PresetListener.d.ts +0 -1
- package/lib/modules/preset/controllers/PresetListener.js +0 -27
- package/lib/modules/preset/repositories/PresetRepository.js +4 -4
- package/lib/modules/preset/services/PresetService.js +4 -4
- package/lib/modules/project/controllers/MetadataController.d.ts +5 -3
- package/lib/modules/project/controllers/MetadataController.js +34 -10
- package/lib/modules/project/controllers/ProjectController.d.ts +1 -1
- package/lib/modules/project/controllers/ProjectController.js +5 -3
- package/lib/modules/project/services/ProjectService.d.ts +1 -1
- package/lib/modules/project/services/ProjectService.js +21 -14
- package/package.json +5 -5
|
@@ -45,7 +45,7 @@ let PresetController = class PresetController {
|
|
|
45
45
|
table.push([
|
|
46
46
|
preset.name,
|
|
47
47
|
preset.source,
|
|
48
|
-
preset.source === core_1.
|
|
48
|
+
preset.source === core_1.PresetSource.EXTERNAL ? preset.path : ""
|
|
49
49
|
]);
|
|
50
50
|
}
|
|
51
51
|
return table.toString();
|
|
@@ -97,27 +97,6 @@ let PresetListener = class PresetListener {
|
|
|
97
97
|
await this.dockerService.imageRm(imageName);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
async onBeforeStart(project) {
|
|
101
|
-
if (project.type !== core_1.ProjectType.PRESET) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const preset = this.presetService.get(project.preset);
|
|
105
|
-
if (preset.dockerfile) {
|
|
106
|
-
project.imageName = this.presetService.getImageNameForProject(project, preset);
|
|
107
|
-
if (!await this.dockerService.imageExists(project.imageName)) {
|
|
108
|
-
await this.dockerService.buildImage({
|
|
109
|
-
version: this.appService.isExperimentalEnabled("buildKit") ? "2" : "1",
|
|
110
|
-
tag: project.imageName,
|
|
111
|
-
labels: {
|
|
112
|
-
presetName: preset.name
|
|
113
|
-
},
|
|
114
|
-
buildArgs: project.buildArgs,
|
|
115
|
-
context: preset.path,
|
|
116
|
-
dockerfile: preset.dockerfile
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
100
|
};
|
|
122
101
|
exports.PresetListener = PresetListener;
|
|
123
102
|
__decorate([
|
|
@@ -132,12 +111,6 @@ __decorate([
|
|
|
132
111
|
__metadata("design:paramtypes", [core_1.Project]),
|
|
133
112
|
__metadata("design:returntype", Promise)
|
|
134
113
|
], PresetListener.prototype, "onRebuild", null);
|
|
135
|
-
__decorate([
|
|
136
|
-
(0, core_1.Event)("project:beforeStart"),
|
|
137
|
-
__metadata("design:type", Function),
|
|
138
|
-
__metadata("design:paramtypes", [core_1.Project]),
|
|
139
|
-
__metadata("design:returntype", Promise)
|
|
140
|
-
], PresetListener.prototype, "onBeforeStart", null);
|
|
141
114
|
exports.PresetListener = PresetListener = __decorate([
|
|
142
115
|
(0, core_1.Controller)(),
|
|
143
116
|
__metadata("design:paramtypes", [core_1.AppService,
|
|
@@ -35,7 +35,7 @@ let PresetRepository = class PresetRepository {
|
|
|
35
35
|
}
|
|
36
36
|
save() {
|
|
37
37
|
switch (this.source) {
|
|
38
|
-
case core_1.
|
|
38
|
+
case core_1.PresetSource.EXTERNAL:
|
|
39
39
|
fs.writeJSON("config.json", this.toObject());
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
@@ -43,7 +43,7 @@ let PresetRepository = class PresetRepository {
|
|
|
43
43
|
}
|
|
44
44
|
delete() {
|
|
45
45
|
switch (this.source) {
|
|
46
|
-
case core_1.
|
|
46
|
+
case core_1.PresetSource.GITHUB:
|
|
47
47
|
if (fs.exists()) {
|
|
48
48
|
fs.rm("", {
|
|
49
49
|
recursive: true
|
|
@@ -62,12 +62,12 @@ let PresetRepository = class PresetRepository {
|
|
|
62
62
|
...dirs.map((name) => {
|
|
63
63
|
return {
|
|
64
64
|
name,
|
|
65
|
-
source: core_1.
|
|
65
|
+
source: core_1.PresetSource.INTERNAL,
|
|
66
66
|
path: fs.path(name)
|
|
67
67
|
};
|
|
68
68
|
}),
|
|
69
69
|
...presets.map((item) => {
|
|
70
|
-
if (item.source === core_1.
|
|
70
|
+
if (item.source === core_1.PresetSource.GITHUB) {
|
|
71
71
|
return {
|
|
72
72
|
...item,
|
|
73
73
|
path: this.appService.fs.path("presets", item.name)
|
|
@@ -145,7 +145,7 @@ let PresetService = class PresetService {
|
|
|
145
145
|
}
|
|
146
146
|
if (fs.exists("config.json")) {
|
|
147
147
|
const config = fs.readJSON("config.json");
|
|
148
|
-
this.appService.registerPreset(config.name, core_1.
|
|
148
|
+
this.appService.registerPreset(config.name, core_1.PresetSource.EXTERNAL, fs.path());
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
let config = {};
|
|
@@ -214,7 +214,7 @@ let PresetService = class PresetService {
|
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
216
|
fs.writeJSON("config.json", config);
|
|
217
|
-
this.appService.registerPreset(config.name, core_1.
|
|
217
|
+
this.appService.registerPreset(config.name, core_1.PresetSource.EXTERNAL, fs.path());
|
|
218
218
|
}
|
|
219
219
|
async deinit() {
|
|
220
220
|
const preset = this.presetRepository.searchOne({
|
|
@@ -272,7 +272,7 @@ let PresetService = class PresetService {
|
|
|
272
272
|
let preset = this.presetRepository.searchOne({
|
|
273
273
|
name: config.name
|
|
274
274
|
});
|
|
275
|
-
if (preset && satisfyingTag && preset.source === core_1.
|
|
275
|
+
if (preset && satisfyingTag && preset.source === core_1.PresetSource.GITHUB && core_1.Version.parse(ref).compare(preset.version) === 0) {
|
|
276
276
|
console.info("Preset already installed");
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
@@ -288,7 +288,7 @@ let PresetService = class PresetService {
|
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
this.fs.mv(`presets/.tmp/${config.name}`, `presets/${config.name}`);
|
|
291
|
-
this.appService.registerPreset(config.name, core_1.
|
|
291
|
+
this.appService.registerPreset(config.name, core_1.PresetSource.GITHUB);
|
|
292
292
|
console.info("Preset installed successfully");
|
|
293
293
|
}
|
|
294
294
|
finally {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { AppService } from "@wocker/core";
|
|
1
2
|
import { ProjectService } from "../services/ProjectService";
|
|
2
3
|
export declare class MetadataController {
|
|
4
|
+
protected readonly appService: AppService;
|
|
3
5
|
protected readonly projectService: ProjectService;
|
|
4
|
-
constructor(projectService: ProjectService);
|
|
5
|
-
list(projectName?: string): string;
|
|
6
|
-
set(meta: string[], projectName?: string): void;
|
|
6
|
+
constructor(appService: AppService, projectService: ProjectService);
|
|
7
|
+
list(projectName?: string, global?: boolean): string;
|
|
8
|
+
set(meta: string[], projectName?: string, global?: boolean): void;
|
|
7
9
|
unset(meta: string[], projectName?: string): void;
|
|
8
10
|
}
|
|
@@ -20,10 +20,18 @@ const core_1 = require("@wocker/core");
|
|
|
20
20
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
21
21
|
const ProjectService_1 = require("../services/ProjectService");
|
|
22
22
|
let MetadataController = class MetadataController {
|
|
23
|
-
constructor(projectService) {
|
|
23
|
+
constructor(appService, projectService) {
|
|
24
|
+
this.appService = appService;
|
|
24
25
|
this.projectService = projectService;
|
|
25
26
|
}
|
|
26
|
-
list(projectName) {
|
|
27
|
+
list(projectName, global) {
|
|
28
|
+
if (global) {
|
|
29
|
+
const table = new cli_table3_1.default();
|
|
30
|
+
for (const key in this.appService.config.meta) {
|
|
31
|
+
table.push([key, this.appService.config.meta[key]]);
|
|
32
|
+
}
|
|
33
|
+
return table.toString();
|
|
34
|
+
}
|
|
27
35
|
const project = this.projectService.get(projectName);
|
|
28
36
|
const table = new cli_table3_1.default();
|
|
29
37
|
for (const key in project.metadata) {
|
|
@@ -31,16 +39,29 @@ let MetadataController = class MetadataController {
|
|
|
31
39
|
}
|
|
32
40
|
return table.toString();
|
|
33
41
|
}
|
|
34
|
-
set(meta, projectName) {
|
|
35
|
-
const
|
|
36
|
-
for (const field of meta) {
|
|
42
|
+
set(meta, projectName, global) {
|
|
43
|
+
const fields = meta.reduce((res, field) => {
|
|
37
44
|
let [, key = "", value = ""] = field.split(/^([^=]+)=(.*)$/);
|
|
38
45
|
key = key.trim();
|
|
39
46
|
value = value.trim();
|
|
40
47
|
if (!key) {
|
|
41
|
-
|
|
48
|
+
return res;
|
|
42
49
|
}
|
|
43
|
-
|
|
50
|
+
return {
|
|
51
|
+
...res,
|
|
52
|
+
[key]: value
|
|
53
|
+
};
|
|
54
|
+
}, {});
|
|
55
|
+
if (global) {
|
|
56
|
+
for (const key in fields) {
|
|
57
|
+
this.appService.config.setMeta(key, fields[key]);
|
|
58
|
+
}
|
|
59
|
+
this.appService.save();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const project = this.projectService.get(projectName);
|
|
63
|
+
for (const key in fields) {
|
|
64
|
+
project.setMeta(key, fields[key]);
|
|
44
65
|
}
|
|
45
66
|
project.save();
|
|
46
67
|
}
|
|
@@ -60,8 +81,9 @@ __decorate([
|
|
|
60
81
|
(0, core_1.Description)("List of metafields"),
|
|
61
82
|
__param(0, (0, core_1.Option)("name", "n")),
|
|
62
83
|
__param(0, (0, core_1.Description)("The name of the project")),
|
|
84
|
+
__param(1, (0, core_1.Option)("global", "g")),
|
|
63
85
|
__metadata("design:type", Function),
|
|
64
|
-
__metadata("design:paramtypes", [String]),
|
|
86
|
+
__metadata("design:paramtypes", [String, Boolean]),
|
|
65
87
|
__metadata("design:returntype", void 0)
|
|
66
88
|
], MetadataController.prototype, "list", null);
|
|
67
89
|
__decorate([
|
|
@@ -69,8 +91,9 @@ __decorate([
|
|
|
69
91
|
__param(0, (0, core_1.Param)("meta")),
|
|
70
92
|
__param(1, (0, core_1.Option)("name", "n")),
|
|
71
93
|
__param(1, (0, core_1.Description)("The name of the project")),
|
|
94
|
+
__param(2, (0, core_1.Option)("global", "g")),
|
|
72
95
|
__metadata("design:type", Function),
|
|
73
|
-
__metadata("design:paramtypes", [Array, String]),
|
|
96
|
+
__metadata("design:paramtypes", [Array, String, Boolean]),
|
|
74
97
|
__metadata("design:returntype", void 0)
|
|
75
98
|
], MetadataController.prototype, "set", null);
|
|
76
99
|
__decorate([
|
|
@@ -85,5 +108,6 @@ __decorate([
|
|
|
85
108
|
exports.MetadataController = MetadataController = __decorate([
|
|
86
109
|
(0, core_1.Controller)(),
|
|
87
110
|
(0, core_1.Description)("Metadata commands"),
|
|
88
|
-
__metadata("design:paramtypes", [
|
|
111
|
+
__metadata("design:paramtypes", [core_1.AppService,
|
|
112
|
+
ProjectService_1.ProjectService])
|
|
89
113
|
], MetadataController);
|
|
@@ -16,7 +16,7 @@ export declare class ProjectController {
|
|
|
16
16
|
getScriptNames(): Promise<string[]>;
|
|
17
17
|
init(name: string, type: ProjectType): Promise<void>;
|
|
18
18
|
destroy(name?: string, yes?: boolean): Promise<void>;
|
|
19
|
-
start(name?: string, restart?: boolean, build?: boolean, attach?: boolean): Promise<void>;
|
|
19
|
+
start(name?: string, restart?: boolean, build?: boolean, attach?: boolean, detach?: boolean): Promise<void>;
|
|
20
20
|
stop(name?: string): Promise<void>;
|
|
21
21
|
projectList(all: boolean): Promise<string>;
|
|
22
22
|
buildArgsList(name?: string, service?: string): Promise<string>;
|
|
@@ -168,9 +168,9 @@ let ProjectController = class ProjectController {
|
|
|
168
168
|
recursive: true
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
|
-
async start(name, restart, build, attach) {
|
|
171
|
+
async start(name, restart, build, attach, detach) {
|
|
172
172
|
const project = this.projectService.get(name);
|
|
173
|
-
await this.projectService.start(project, restart, build, attach);
|
|
173
|
+
await this.projectService.start(project, restart, build, attach, detach);
|
|
174
174
|
}
|
|
175
175
|
async stop(name) {
|
|
176
176
|
const project = this.projectService.get(name);
|
|
@@ -657,8 +657,10 @@ __decorate([
|
|
|
657
657
|
__param(2, (0, core_1.Description)("Build")),
|
|
658
658
|
__param(3, (0, core_1.Option)("attach", "a")),
|
|
659
659
|
__param(3, (0, core_1.Description)("Attach")),
|
|
660
|
+
__param(4, (0, core_1.Option)("detach", "d")),
|
|
661
|
+
__param(4, (0, core_1.Description)("Detach")),
|
|
660
662
|
__metadata("design:type", Function),
|
|
661
|
-
__metadata("design:paramtypes", [String, Boolean, Boolean, Boolean]),
|
|
663
|
+
__metadata("design:paramtypes", [String, Boolean, Boolean, Boolean, Boolean]),
|
|
662
664
|
__metadata("design:returntype", Promise)
|
|
663
665
|
], ProjectController.prototype, "start", null);
|
|
664
666
|
__decorate([
|
|
@@ -16,7 +16,7 @@ export declare class ProjectService extends CoreProjectService {
|
|
|
16
16
|
search(params?: ProjectRepository.SearchParams): Project[];
|
|
17
17
|
searchOne(params?: ProjectRepository.SearchParams): Project | null;
|
|
18
18
|
save(project: Project): void;
|
|
19
|
-
start(project: Project, restart?: boolean, rebuild?: boolean, attach?: boolean): Promise<void>;
|
|
19
|
+
start(project: Project, restart?: boolean, rebuild?: boolean, attach?: boolean, detach?: boolean): Promise<void>;
|
|
20
20
|
stop(project: Project): Promise<void>;
|
|
21
21
|
build(project: Project, rebuild?: boolean): Promise<void>;
|
|
22
22
|
attach(project: Project): Promise<void>;
|
|
@@ -55,7 +55,7 @@ let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
|
55
55
|
save(project) {
|
|
56
56
|
this.projectRepository.save(project);
|
|
57
57
|
}
|
|
58
|
-
async start(project, restart, rebuild, attach) {
|
|
58
|
+
async start(project, restart, rebuild, attach, detach) {
|
|
59
59
|
if (restart || rebuild) {
|
|
60
60
|
await this.stop(project);
|
|
61
61
|
}
|
|
@@ -70,7 +70,7 @@ let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
|
70
70
|
if (!container) {
|
|
71
71
|
container = await this.dockerService.createContainer({
|
|
72
72
|
name: project.containerName,
|
|
73
|
-
image: project.
|
|
73
|
+
image: project.image,
|
|
74
74
|
cmd: project.cmd,
|
|
75
75
|
env: {
|
|
76
76
|
...this.appService.config.env || {},
|
|
@@ -106,7 +106,14 @@ let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
|
106
106
|
}
|
|
107
107
|
await this.eventService.emit("project:start", project);
|
|
108
108
|
await this.eventService.emit("project:afterStart", project);
|
|
109
|
-
|
|
109
|
+
let shouldAttach = (project.getMeta("start.mode") || this.appService.getMeta("start.mode")) === "attach";
|
|
110
|
+
if (typeof attach === "boolean") {
|
|
111
|
+
shouldAttach = attach;
|
|
112
|
+
}
|
|
113
|
+
if (typeof detach === "boolean") {
|
|
114
|
+
shouldAttach = !detach;
|
|
115
|
+
}
|
|
116
|
+
if (shouldAttach) {
|
|
110
117
|
switch (project.type) {
|
|
111
118
|
case core_1.ProjectType.IMAGE:
|
|
112
119
|
case core_1.ProjectType.DOCKERFILE:
|
|
@@ -139,18 +146,18 @@ let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
|
139
146
|
async build(project, rebuild) {
|
|
140
147
|
switch (project.type) {
|
|
141
148
|
case core_1.ProjectType.IMAGE:
|
|
142
|
-
await this.dockerService.pullImage(project.
|
|
149
|
+
await this.dockerService.pullImage(project.image);
|
|
143
150
|
break;
|
|
144
151
|
case core_1.ProjectType.DOCKERFILE: {
|
|
145
|
-
project.
|
|
152
|
+
project.image = `project-${project.name}:develop`;
|
|
146
153
|
project.save();
|
|
147
154
|
if (rebuild) {
|
|
148
|
-
await this.dockerService.imageRm(project.
|
|
155
|
+
await this.dockerService.imageRm(project.image);
|
|
149
156
|
}
|
|
150
|
-
if (!await this.dockerService.imageExists(project.
|
|
157
|
+
if (!await this.dockerService.imageExists(project.image)) {
|
|
151
158
|
await this.dockerService.buildImage({
|
|
152
159
|
version: this.appService.isExperimentalEnabled("buildKit") ? "2" : "1",
|
|
153
|
-
tag: project.
|
|
160
|
+
tag: project.image,
|
|
154
161
|
buildArgs: project.buildArgs,
|
|
155
162
|
context: project.path,
|
|
156
163
|
dockerfile: project.dockerfile
|
|
@@ -164,19 +171,19 @@ let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
|
164
171
|
});
|
|
165
172
|
if (preset.image) {
|
|
166
173
|
await this.dockerService.pullImage(preset.image);
|
|
167
|
-
project.
|
|
174
|
+
project.image = preset.image;
|
|
168
175
|
project.save();
|
|
169
176
|
}
|
|
170
177
|
if (preset.dockerfile) {
|
|
171
|
-
project.
|
|
178
|
+
project.image = this.presetService.getImageNameForProject(project, preset);
|
|
172
179
|
project.save();
|
|
173
180
|
if (rebuild) {
|
|
174
|
-
await this.dockerService.imageRm(project.
|
|
181
|
+
await this.dockerService.imageRm(project.image);
|
|
175
182
|
}
|
|
176
|
-
if (!await this.dockerService.imageExists(project.
|
|
183
|
+
if (!await this.dockerService.imageExists(project.image)) {
|
|
177
184
|
await this.dockerService.buildImage({
|
|
178
185
|
version: this.appService.isExperimentalEnabled("buildKit") ? "2" : "1",
|
|
179
|
-
tag: project.
|
|
186
|
+
tag: project.image,
|
|
180
187
|
labels: {
|
|
181
188
|
"org.wocker.preset": preset.name
|
|
182
189
|
},
|
|
@@ -251,7 +258,7 @@ let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
|
251
258
|
case core_1.ProjectType.IMAGE:
|
|
252
259
|
case core_1.ProjectType.DOCKERFILE:
|
|
253
260
|
case core_1.ProjectType.PRESET:
|
|
254
|
-
await this.dockerService.exec(project.containerName, command,
|
|
261
|
+
await this.dockerService.exec(project.containerName, command, this.processService.stdout.isTTY ?? false);
|
|
255
262
|
break;
|
|
256
263
|
case core_1.ProjectType.COMPOSE: {
|
|
257
264
|
const [service, ...args] = command;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/ws",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
6
6
|
"description": "Docker workspace for web projects",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"make-coverage-badge": "make-coverage-badge"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@wocker/core": "1.1.
|
|
39
|
-
"@wocker/docker-module": "^1.0.
|
|
38
|
+
"@wocker/core": "1.1.2",
|
|
39
|
+
"@wocker/docker-module": "^1.0.1",
|
|
40
40
|
"@wocker/prompts": "^1.0.0",
|
|
41
41
|
"@wocker/utils": "^2.0.6",
|
|
42
42
|
"async-mutex": "^0.4.0",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"@types/jest": "^30.0.0",
|
|
50
50
|
"@types/node": "^24.5.2",
|
|
51
51
|
"@types/unzipper": "^0.10.10",
|
|
52
|
-
"@wocker/docker-mock-module": "^1.0.
|
|
53
|
-
"@wocker/testing": "^1.0.
|
|
52
|
+
"@wocker/docker-mock-module": "^1.0.1",
|
|
53
|
+
"@wocker/testing": "^1.0.9",
|
|
54
54
|
"jest": "^30.1.3",
|
|
55
55
|
"make-coverage-badge": "^1.2.0",
|
|
56
56
|
"memfs": "^4.49.0",
|