@wocker/ws 1.0.16 → 1.0.17
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/AppModule.js +5 -2
- package/lib/controllers/PluginController.d.ts +5 -4
- package/lib/controllers/PluginController.js +28 -20
- package/lib/controllers/PresetController.d.ts +1 -0
- package/lib/controllers/PresetController.js +34 -8
- package/lib/controllers/ProjectController.d.ts +4 -1
- package/lib/controllers/ProjectController.js +125 -25
- package/lib/main.js +2 -2
- package/lib/services/AppConfigService.d.ts +1 -2
- package/lib/services/AppConfigService.js +18 -7
- package/lib/services/DockerService.js +17 -10
- package/lib/services/NpmService.d.ts +5 -0
- package/lib/services/NpmService.js +33 -0
- package/lib/services/PluginService.js +1 -1
- package/lib/services/PresetService.d.ts +4 -2
- package/lib/services/PresetService.js +57 -24
- package/lib/services/ProjectService.js +6 -27
- package/lib/services/ProxyService.js +6 -6
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.js +1 -0
- package/lib/types/PackageInfo.d.ts +20 -0
- package/lib/types/PackageInfo.js +2 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +17 -0
- package/package.json +3 -3
package/lib/AppModule.js
CHANGED
|
@@ -38,7 +38,6 @@ let AppModule = AppModule_1 = class AppModule {
|
|
|
38
38
|
async load(container) {
|
|
39
39
|
const appConfigService = container.getModule(AppModule_1).get(services_1.AppConfigService);
|
|
40
40
|
const logService = container.getModule(AppModule_1).get(services_1.LogService);
|
|
41
|
-
const pluginService = container.getModule(AppModule_1).get(services_1.PluginService);
|
|
42
41
|
const config = appConfigService.getConfig();
|
|
43
42
|
const imports = [];
|
|
44
43
|
for (const plugin of config.plugins || []) {
|
|
@@ -71,6 +70,7 @@ let AppModule = AppModule_1 = class AppModule {
|
|
|
71
70
|
};
|
|
72
71
|
exports.AppModule = AppModule;
|
|
73
72
|
exports.AppModule = AppModule = AppModule_1 = __decorate([
|
|
73
|
+
(0, core_1.Global)(),
|
|
74
74
|
(0, core_1.Module)({
|
|
75
75
|
controllers: [
|
|
76
76
|
controllers_1.CompletionController,
|
|
@@ -86,6 +86,7 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
|
|
|
86
86
|
services_1.AppEventsService,
|
|
87
87
|
services_1.DockerService,
|
|
88
88
|
services_1.LogService,
|
|
89
|
+
services_1.NpmService,
|
|
89
90
|
services_1.PluginService,
|
|
90
91
|
services_1.PresetService,
|
|
91
92
|
services_1.ProjectService,
|
|
@@ -95,7 +96,9 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
|
|
|
95
96
|
services_1.AppConfigService,
|
|
96
97
|
services_1.AppEventsService,
|
|
97
98
|
services_1.DockerService,
|
|
98
|
-
services_1.LogService
|
|
99
|
+
services_1.LogService,
|
|
100
|
+
services_1.ProjectService,
|
|
101
|
+
services_1.ProxyService
|
|
99
102
|
]
|
|
100
103
|
})
|
|
101
104
|
], AppModule);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { AppConfigService, PluginService, LogService } from "../services";
|
|
1
|
+
import { AppConfigService, PluginService, LogService, NpmService } from "../services";
|
|
2
2
|
export declare class PluginController {
|
|
3
3
|
protected readonly appConfigService: AppConfigService;
|
|
4
4
|
protected readonly pluginService: PluginService;
|
|
5
|
+
protected readonly npmService: NpmService;
|
|
5
6
|
protected readonly logService: LogService;
|
|
6
|
-
constructor(appConfigService: AppConfigService, pluginService: PluginService, logService: LogService);
|
|
7
|
+
constructor(appConfigService: AppConfigService, pluginService: PluginService, npmService: NpmService, logService: LogService);
|
|
7
8
|
list(): Promise<string>;
|
|
8
|
-
add(addName: string): Promise<void>;
|
|
9
|
+
add(addName: string, dev?: boolean): Promise<void>;
|
|
9
10
|
remove(removeName: string): Promise<void>;
|
|
10
11
|
update(): Promise<void>;
|
|
11
|
-
getInstalledPlugins():
|
|
12
|
+
getInstalledPlugins(): string[];
|
|
12
13
|
}
|
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
16
|
};
|
|
@@ -17,30 +20,31 @@ const core_1 = require("@wocker/core");
|
|
|
17
20
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
21
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
19
22
|
const services_1 = require("../services");
|
|
20
|
-
const utils_1 = require("../utils");
|
|
21
|
-
const Http_1 = require("../makes/Http");
|
|
22
23
|
let PluginController = class PluginController {
|
|
23
|
-
constructor(appConfigService, pluginService, logService) {
|
|
24
|
+
constructor(appConfigService, pluginService, npmService, logService) {
|
|
24
25
|
this.appConfigService = appConfigService;
|
|
25
26
|
this.pluginService = pluginService;
|
|
27
|
+
this.npmService = npmService;
|
|
26
28
|
this.logService = logService;
|
|
27
29
|
}
|
|
28
30
|
async list() {
|
|
29
|
-
const config =
|
|
31
|
+
const config = this.appConfigService.getConfig();
|
|
30
32
|
const table = new cli_table3_1.default({
|
|
31
33
|
head: ["Name"],
|
|
32
34
|
colWidths: [30]
|
|
33
35
|
});
|
|
36
|
+
if (!config.plugins) {
|
|
37
|
+
return chalk_1.default.gray("No plugins installed");
|
|
38
|
+
}
|
|
34
39
|
for (const name of config.plugins) {
|
|
35
40
|
table.push([name]);
|
|
36
41
|
}
|
|
37
42
|
return table.toString() + "\n";
|
|
38
43
|
}
|
|
39
|
-
async add(addName) {
|
|
44
|
+
async add(addName, dev) {
|
|
40
45
|
const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(addName) || [];
|
|
41
46
|
const fullName = `${prefix}${name}${suffix}`;
|
|
42
|
-
this.
|
|
43
|
-
const config = await this.appConfigService.getConfig();
|
|
47
|
+
const config = this.appConfigService.getConfig();
|
|
44
48
|
try {
|
|
45
49
|
if (await this.pluginService.checkPlugin(fullName)) {
|
|
46
50
|
config.addPlugin(fullName);
|
|
@@ -48,14 +52,8 @@ let PluginController = class PluginController {
|
|
|
48
52
|
console.info(`Plugin ${fullName} activated`);
|
|
49
53
|
return;
|
|
50
54
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (res.status !== 200) {
|
|
54
|
-
console.error(chalk_1.default.red(`Plugin ${fullName} not found`));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
console.info(`Installing ${fullName}`);
|
|
58
|
-
await (0, utils_1.exec)(`npm install -g ${fullName}`);
|
|
55
|
+
const packageInfo = await this.npmService.getPackageInfo(fullName);
|
|
56
|
+
await this.npmService.install(fullName, packageInfo["dist-tags"].dev && dev ? "dev" : "latest");
|
|
59
57
|
if (await this.pluginService.checkPlugin(fullName)) {
|
|
60
58
|
config.addPlugin(fullName);
|
|
61
59
|
await config.save();
|
|
@@ -70,7 +68,7 @@ let PluginController = class PluginController {
|
|
|
70
68
|
async remove(removeName) {
|
|
71
69
|
const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(removeName) || [];
|
|
72
70
|
const fullName = `${prefix}${name}${suffix}`;
|
|
73
|
-
const config =
|
|
71
|
+
const config = this.appConfigService.getConfig();
|
|
74
72
|
config.removePlugin(fullName);
|
|
75
73
|
await config.save();
|
|
76
74
|
console.info(`Plugin ${fullName} deactivated`);
|
|
@@ -78,22 +76,31 @@ let PluginController = class PluginController {
|
|
|
78
76
|
async update() {
|
|
79
77
|
await this.pluginService.update();
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
const config =
|
|
79
|
+
getInstalledPlugins() {
|
|
80
|
+
const config = this.appConfigService.getConfig();
|
|
83
81
|
return config.plugins || [];
|
|
84
82
|
}
|
|
85
83
|
};
|
|
86
84
|
exports.PluginController = PluginController;
|
|
87
85
|
__decorate([
|
|
88
86
|
(0, core_1.Command)("plugins"),
|
|
87
|
+
(0, core_1.Description)("Plugins list"),
|
|
89
88
|
__metadata("design:type", Function),
|
|
90
89
|
__metadata("design:paramtypes", []),
|
|
91
90
|
__metadata("design:returntype", Promise)
|
|
92
91
|
], PluginController.prototype, "list", null);
|
|
93
92
|
__decorate([
|
|
94
93
|
(0, core_1.Command)("plugin:add <name>"),
|
|
94
|
+
(0, core_1.Command)("plugin:install <name>"),
|
|
95
|
+
(0, core_1.Description)("Install a plugin"),
|
|
96
|
+
__param(0, (0, core_1.Param)("name")),
|
|
97
|
+
__param(1, (0, core_1.Option)("dev", {
|
|
98
|
+
type: "boolean",
|
|
99
|
+
alias: "d",
|
|
100
|
+
description: "Use dev version of plugin"
|
|
101
|
+
})),
|
|
95
102
|
__metadata("design:type", Function),
|
|
96
|
-
__metadata("design:paramtypes", [String]),
|
|
103
|
+
__metadata("design:paramtypes", [String, Boolean]),
|
|
97
104
|
__metadata("design:returntype", Promise)
|
|
98
105
|
], PluginController.prototype, "add", null);
|
|
99
106
|
__decorate([
|
|
@@ -113,11 +120,12 @@ __decorate([
|
|
|
113
120
|
(0, core_1.Completion)("name", "plugin:remove <name>"),
|
|
114
121
|
__metadata("design:type", Function),
|
|
115
122
|
__metadata("design:paramtypes", []),
|
|
116
|
-
__metadata("design:returntype",
|
|
123
|
+
__metadata("design:returntype", Array)
|
|
117
124
|
], PluginController.prototype, "getInstalledPlugins", null);
|
|
118
125
|
exports.PluginController = PluginController = __decorate([
|
|
119
126
|
(0, core_1.Controller)(),
|
|
120
127
|
__metadata("design:paramtypes", [services_1.AppConfigService,
|
|
121
128
|
services_1.PluginService,
|
|
129
|
+
services_1.NpmService,
|
|
122
130
|
services_1.LogService])
|
|
123
131
|
], PluginController);
|
|
@@ -12,6 +12,7 @@ export declare class PresetController {
|
|
|
12
12
|
protected onRebuild(project: Project): Promise<void>;
|
|
13
13
|
protected onBeforeStart(project: Project): Promise<void>;
|
|
14
14
|
init(): Promise<void>;
|
|
15
|
+
deinit(): Promise<void>;
|
|
15
16
|
add(name: string): Promise<void>;
|
|
16
17
|
delete(name: string, confirm?: boolean): Promise<void>;
|
|
17
18
|
eject(name?: string): Promise<void>;
|
|
@@ -78,6 +78,19 @@ let PresetController = class PresetController {
|
|
|
78
78
|
}),
|
|
79
79
|
default: project.preset
|
|
80
80
|
});
|
|
81
|
+
project.presetMode = await (0, utils_1.promptSelect)({
|
|
82
|
+
message: "Preset mode:",
|
|
83
|
+
options: [
|
|
84
|
+
{
|
|
85
|
+
label: "For project only",
|
|
86
|
+
value: "project"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: "Global usage",
|
|
90
|
+
value: "global"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
});
|
|
81
94
|
const preset = await this.presetService.get(project.preset);
|
|
82
95
|
if (!preset) {
|
|
83
96
|
throw new Error("Preset not found");
|
|
@@ -94,15 +107,16 @@ let PresetController = class PresetController {
|
|
|
94
107
|
...project.buildArgs || {},
|
|
95
108
|
...project.env || {}
|
|
96
109
|
});
|
|
97
|
-
const { destination, options } = (0, utils_3.volumeParse)(volume);
|
|
110
|
+
const { source, destination, options } = (0, utils_3.volumeParse)(volume);
|
|
98
111
|
let projectVolume = project.getVolumeByDestination(destination);
|
|
99
|
-
const
|
|
100
|
-
message: "Volume",
|
|
112
|
+
const newSource = await (0, utils_1.promptText)({
|
|
113
|
+
message: "Volume:",
|
|
114
|
+
required: true,
|
|
101
115
|
suffix: `:${destination}`,
|
|
102
|
-
default: projectVolume ? (0, utils_3.volumeParse)(projectVolume).source :
|
|
116
|
+
default: projectVolume ? (0, utils_3.volumeParse)(projectVolume).source : source
|
|
103
117
|
});
|
|
104
118
|
projectVolume = (0, utils_3.volumeFormat)({
|
|
105
|
-
source,
|
|
119
|
+
source: newSource,
|
|
106
120
|
destination,
|
|
107
121
|
options
|
|
108
122
|
});
|
|
@@ -110,7 +124,7 @@ let PresetController = class PresetController {
|
|
|
110
124
|
}
|
|
111
125
|
}
|
|
112
126
|
if (preset.dockerfile) {
|
|
113
|
-
project.imageName = this.presetService.
|
|
127
|
+
project.imageName = this.presetService.getImageNameForProject(project, preset);
|
|
114
128
|
}
|
|
115
129
|
}
|
|
116
130
|
async onRebuild(project) {
|
|
@@ -121,7 +135,7 @@ let PresetController = class PresetController {
|
|
|
121
135
|
if (!preset) {
|
|
122
136
|
throw new Error(`Preset ${project.preset} not found`);
|
|
123
137
|
}
|
|
124
|
-
const imageName = this.presetService.
|
|
138
|
+
const imageName = this.presetService.getImageNameForProject(project, preset);
|
|
125
139
|
const exists = await this.dockerService.imageExists(imageName);
|
|
126
140
|
if (exists) {
|
|
127
141
|
console.info(`Removing image: ${imageName}`);
|
|
@@ -134,7 +148,7 @@ let PresetController = class PresetController {
|
|
|
134
148
|
}
|
|
135
149
|
const preset = await this.presetService.get(project.preset);
|
|
136
150
|
if (preset.dockerfile) {
|
|
137
|
-
project.imageName = this.presetService.
|
|
151
|
+
project.imageName = this.presetService.getImageNameForProject(project, preset);
|
|
138
152
|
if (!await this.dockerService.imageExists(project.imageName)) {
|
|
139
153
|
await this.dockerService.buildImage({
|
|
140
154
|
tag: project.imageName,
|
|
@@ -151,6 +165,9 @@ let PresetController = class PresetController {
|
|
|
151
165
|
async init() {
|
|
152
166
|
await this.presetService.init();
|
|
153
167
|
}
|
|
168
|
+
async deinit() {
|
|
169
|
+
await this.presetService.deinit();
|
|
170
|
+
}
|
|
154
171
|
async add(name) {
|
|
155
172
|
await this.presetService.addPreset(name);
|
|
156
173
|
}
|
|
@@ -224,6 +241,9 @@ let PresetController = class PresetController {
|
|
|
224
241
|
buildArgs = await (0, utils_1.promptGroup)(preset.buildArgsOptions);
|
|
225
242
|
}
|
|
226
243
|
const imageName = this.presetService.getImageName(preset, buildArgs);
|
|
244
|
+
if (rebuild) {
|
|
245
|
+
await this.dockerService.imageRm(imageName);
|
|
246
|
+
}
|
|
227
247
|
await this.dockerService.buildImage({
|
|
228
248
|
tag: imageName,
|
|
229
249
|
labels: {
|
|
@@ -242,6 +262,12 @@ __decorate([
|
|
|
242
262
|
__metadata("design:paramtypes", []),
|
|
243
263
|
__metadata("design:returntype", Promise)
|
|
244
264
|
], PresetController.prototype, "init", null);
|
|
265
|
+
__decorate([
|
|
266
|
+
(0, core_1.Command)("preset:deinit"),
|
|
267
|
+
__metadata("design:type", Function),
|
|
268
|
+
__metadata("design:paramtypes", []),
|
|
269
|
+
__metadata("design:returntype", Promise)
|
|
270
|
+
], PresetController.prototype, "deinit", null);
|
|
245
271
|
__decorate([
|
|
246
272
|
(0, core_1.Command)("preset:add <preset>"),
|
|
247
273
|
__param(0, (0, core_1.Param)("preset")),
|
|
@@ -9,7 +9,7 @@ export declare class ProjectController {
|
|
|
9
9
|
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService, logService: LogService);
|
|
10
10
|
protected getProjectNames(): Promise<string[]>;
|
|
11
11
|
getScriptNames(): Promise<string[]>;
|
|
12
|
-
init(name: string, type: ProjectType
|
|
12
|
+
init(name: string, type: ProjectType): Promise<void>;
|
|
13
13
|
projectList(all: boolean): Promise<string>;
|
|
14
14
|
start(name?: string, detach?: boolean, attach?: boolean, rebuild?: boolean, restart?: boolean): Promise<void>;
|
|
15
15
|
stop(name: string): Promise<void>;
|
|
@@ -33,6 +33,9 @@ export declare class ProjectController {
|
|
|
33
33
|
volumeList(name?: string): Promise<string>;
|
|
34
34
|
volumeMount(name: string, volumes: string[]): Promise<void>;
|
|
35
35
|
volumeUnmount(name: string, volumes: string[]): Promise<void>;
|
|
36
|
+
extraHostList(name?: string): Promise<string>;
|
|
37
|
+
addExtraHost(extraHost: string, extraDomain: string, name?: string): Promise<void>;
|
|
38
|
+
removeExtraHost(extraHost: string, name?: string): Promise<void>;
|
|
36
39
|
logs(name?: string, global?: boolean, detach?: boolean, follow?: boolean): Promise<void>;
|
|
37
40
|
exec(name?: string, command?: string[]): Promise<void>;
|
|
38
41
|
run(name: string, script: string, args?: string[]): Promise<void>;
|
|
@@ -45,7 +45,6 @@ const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
|
45
45
|
const chalk_1 = __importDefault(require("chalk"));
|
|
46
46
|
const Path = __importStar(require("path"));
|
|
47
47
|
const async_mutex_1 = require("async-mutex");
|
|
48
|
-
const env_1 = require("../env");
|
|
49
48
|
const makes_1 = require("../makes");
|
|
50
49
|
const services_1 = require("../services");
|
|
51
50
|
let ProjectController = class ProjectController {
|
|
@@ -71,7 +70,7 @@ let ProjectController = class ProjectController {
|
|
|
71
70
|
return [];
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
|
-
async init(name, type
|
|
73
|
+
async init(name, type) {
|
|
75
74
|
let project = await this.projectService.searchOne({
|
|
76
75
|
path: this.appConfigService.pwd()
|
|
77
76
|
});
|
|
@@ -114,6 +113,9 @@ let ProjectController = class ProjectController {
|
|
|
114
113
|
}
|
|
115
114
|
return new RegExp("^Dockerfile(\\..*)?").test(fileName);
|
|
116
115
|
});
|
|
116
|
+
if (dockerfiles.length === 0) {
|
|
117
|
+
throw new Error("Dockerfiles not found");
|
|
118
|
+
}
|
|
117
119
|
project.dockerfile = await (0, utils_1.promptSelect)({
|
|
118
120
|
message: "Dockerfile:",
|
|
119
121
|
options: dockerfiles.map((dockerfile) => {
|
|
@@ -148,7 +150,7 @@ let ProjectController = class ProjectController {
|
|
|
148
150
|
});
|
|
149
151
|
const projects = await this.projectService.search({});
|
|
150
152
|
for (const project of projects) {
|
|
151
|
-
const container = await this.dockerService.getContainer(
|
|
153
|
+
const container = await this.dockerService.getContainer(project.containerName);
|
|
152
154
|
if (!container) {
|
|
153
155
|
if (all) {
|
|
154
156
|
table.push([project.name, project.type, "-"]);
|
|
@@ -287,7 +289,7 @@ let ProjectController = class ProjectController {
|
|
|
287
289
|
env = project.env || {};
|
|
288
290
|
}
|
|
289
291
|
else {
|
|
290
|
-
const config =
|
|
292
|
+
const config = this.appConfigService.getConfig();
|
|
291
293
|
env = config.env || {};
|
|
292
294
|
}
|
|
293
295
|
const table = new cli_table3_1.default({
|
|
@@ -303,7 +305,7 @@ let ProjectController = class ProjectController {
|
|
|
303
305
|
await this.projectService.cdProject(name);
|
|
304
306
|
}
|
|
305
307
|
let config = global
|
|
306
|
-
?
|
|
308
|
+
? this.appConfigService.getConfig()
|
|
307
309
|
: await this.projectService.get();
|
|
308
310
|
const table = new cli_table3_1.default({
|
|
309
311
|
head: ["KEY", "VALUE"]
|
|
@@ -322,7 +324,7 @@ let ProjectController = class ProjectController {
|
|
|
322
324
|
await this.projectService.cdProject(name);
|
|
323
325
|
}
|
|
324
326
|
const config = global
|
|
325
|
-
?
|
|
327
|
+
? this.appConfigService.getConfig()
|
|
326
328
|
: await this.projectService.get();
|
|
327
329
|
for (const variable of variables) {
|
|
328
330
|
const [key, value] = variable.split("=");
|
|
@@ -388,7 +390,6 @@ let ProjectController = class ProjectController {
|
|
|
388
390
|
const table = new cli_table3_1.default({
|
|
389
391
|
head: ["KEY", "VALUE"]
|
|
390
392
|
});
|
|
391
|
-
this.logService.info("...");
|
|
392
393
|
for (const key of args) {
|
|
393
394
|
if (project.buildArgs && typeof project.buildArgs[key] !== "undefined") {
|
|
394
395
|
const value = project.buildArgs[key] || "";
|
|
@@ -403,8 +404,12 @@ let ProjectController = class ProjectController {
|
|
|
403
404
|
}
|
|
404
405
|
const project = await this.projectService.get();
|
|
405
406
|
const buildArgs = args.reduce((env, config) => {
|
|
406
|
-
|
|
407
|
-
|
|
407
|
+
let [, key = "", value = ""] = config.split(/^([^=]+)=(.*)$/);
|
|
408
|
+
key = key.trim();
|
|
409
|
+
value = value.trim();
|
|
410
|
+
if (key) {
|
|
411
|
+
env[key] = value;
|
|
412
|
+
}
|
|
408
413
|
return env;
|
|
409
414
|
}, {});
|
|
410
415
|
for (const key in buildArgs) {
|
|
@@ -421,8 +426,10 @@ let ProjectController = class ProjectController {
|
|
|
421
426
|
}
|
|
422
427
|
const project = await this.projectService.get();
|
|
423
428
|
const buildArgs = args.reduce((env, config) => {
|
|
424
|
-
|
|
425
|
-
|
|
429
|
+
let [, key = "", value = ""] = config.split(/^([^=]+)(?:=(.*))?$/);
|
|
430
|
+
key = key.trim();
|
|
431
|
+
value = value.trim();
|
|
432
|
+
env[key] = value;
|
|
426
433
|
return env;
|
|
427
434
|
}, {});
|
|
428
435
|
for (const key in buildArgs) {
|
|
@@ -469,9 +476,43 @@ let ProjectController = class ProjectController {
|
|
|
469
476
|
await project.save();
|
|
470
477
|
}
|
|
471
478
|
}
|
|
479
|
+
async extraHostList(name) {
|
|
480
|
+
if (name) {
|
|
481
|
+
await this.projectService.cdProject(name);
|
|
482
|
+
}
|
|
483
|
+
const project = await this.projectService.get();
|
|
484
|
+
if (!project.extraHosts) {
|
|
485
|
+
return "No extra hosts found";
|
|
486
|
+
}
|
|
487
|
+
const table = new cli_table3_1.default({
|
|
488
|
+
head: ["Host", "Domain"]
|
|
489
|
+
});
|
|
490
|
+
for (const host in project.extraHosts) {
|
|
491
|
+
table.push([
|
|
492
|
+
host, project.extraHosts[host]
|
|
493
|
+
]);
|
|
494
|
+
}
|
|
495
|
+
return table.toString();
|
|
496
|
+
}
|
|
497
|
+
async addExtraHost(extraHost, extraDomain, name) {
|
|
498
|
+
if (name) {
|
|
499
|
+
await this.projectService.cdProject(name);
|
|
500
|
+
}
|
|
501
|
+
const project = await this.projectService.get();
|
|
502
|
+
project.addExtraHost(extraHost, extraDomain);
|
|
503
|
+
await project.save();
|
|
504
|
+
}
|
|
505
|
+
async removeExtraHost(extraHost, name) {
|
|
506
|
+
if (name) {
|
|
507
|
+
await this.projectService.cdProject(name);
|
|
508
|
+
}
|
|
509
|
+
const project = await this.projectService.get();
|
|
510
|
+
project.removeExtraHost(extraHost);
|
|
511
|
+
await project.save();
|
|
512
|
+
}
|
|
472
513
|
async logs(name, global, detach, follow) {
|
|
473
514
|
if (global) {
|
|
474
|
-
const logFilepath =
|
|
515
|
+
const logFilepath = this.appConfigService.dataPath("ws.log");
|
|
475
516
|
const prepareLog = (str) => {
|
|
476
517
|
return str.replace(/^\[.*]\s([^:]+):\s.*$/gm, (substring, type) => {
|
|
477
518
|
switch (type) {
|
|
@@ -524,7 +565,10 @@ let ProjectController = class ProjectController {
|
|
|
524
565
|
await this.projectService.cdProject(name);
|
|
525
566
|
}
|
|
526
567
|
const project = await this.projectService.get();
|
|
527
|
-
const container = await this.dockerService.getContainer(
|
|
568
|
+
const container = await this.dockerService.getContainer(project.containerName);
|
|
569
|
+
if (!container) {
|
|
570
|
+
throw new Error("Project not started");
|
|
571
|
+
}
|
|
528
572
|
if (!detach) {
|
|
529
573
|
const stream = await container.logs({
|
|
530
574
|
stdout: true,
|
|
@@ -533,19 +577,31 @@ let ProjectController = class ProjectController {
|
|
|
533
577
|
});
|
|
534
578
|
stream.on("data", (data) => {
|
|
535
579
|
try {
|
|
536
|
-
data
|
|
580
|
+
if (data instanceof Buffer) {
|
|
581
|
+
data = (0, utils_1.demuxOutput)(data);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
catch (err) {
|
|
585
|
+
this.logService.error(err.message, err);
|
|
537
586
|
}
|
|
538
|
-
catch (err) { }
|
|
539
587
|
process.stdout.write(data);
|
|
540
588
|
});
|
|
541
589
|
}
|
|
542
590
|
else {
|
|
543
|
-
|
|
591
|
+
let data = await container.logs({
|
|
544
592
|
stdout: true,
|
|
545
593
|
stderr: true,
|
|
546
594
|
follow: false
|
|
547
595
|
});
|
|
548
|
-
|
|
596
|
+
try {
|
|
597
|
+
if (data instanceof Buffer) {
|
|
598
|
+
data = (0, utils_1.demuxOutput)(data);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
catch (err) {
|
|
602
|
+
this.logService.error(err.message, err);
|
|
603
|
+
}
|
|
604
|
+
process.stdout.write(data);
|
|
549
605
|
}
|
|
550
606
|
}
|
|
551
607
|
async exec(name, command) {
|
|
@@ -563,7 +619,7 @@ let ProjectController = class ProjectController {
|
|
|
563
619
|
if (!project.scripts || !project.scripts[script]) {
|
|
564
620
|
throw new Error(`Script ${script} not found`);
|
|
565
621
|
}
|
|
566
|
-
const container = await this.dockerService.getContainer(
|
|
622
|
+
const container = await this.dockerService.getContainer(project.containerName);
|
|
567
623
|
if (!container) {
|
|
568
624
|
throw new Error("The project is not started");
|
|
569
625
|
}
|
|
@@ -604,6 +660,7 @@ __decorate([
|
|
|
604
660
|
], ProjectController.prototype, "getScriptNames", null);
|
|
605
661
|
__decorate([
|
|
606
662
|
(0, core_1.Command)("init"),
|
|
663
|
+
(0, core_1.Description)("Project initialisation"),
|
|
607
664
|
__param(0, (0, core_1.Option)("name", {
|
|
608
665
|
type: "string",
|
|
609
666
|
alias: "n",
|
|
@@ -614,17 +671,13 @@ __decorate([
|
|
|
614
671
|
alias: "t",
|
|
615
672
|
description: "Project type"
|
|
616
673
|
})),
|
|
617
|
-
__param(2, (0, core_1.Option)("preset", {
|
|
618
|
-
type: "string",
|
|
619
|
-
alias: "p",
|
|
620
|
-
description: "Preset"
|
|
621
|
-
})),
|
|
622
674
|
__metadata("design:type", Function),
|
|
623
|
-
__metadata("design:paramtypes", [String, String
|
|
675
|
+
__metadata("design:paramtypes", [String, String]),
|
|
624
676
|
__metadata("design:returntype", Promise)
|
|
625
677
|
], ProjectController.prototype, "init", null);
|
|
626
678
|
__decorate([
|
|
627
679
|
(0, core_1.Command)("ps"),
|
|
680
|
+
(0, core_1.Description)("Projects list"),
|
|
628
681
|
__param(0, (0, core_1.Option)("all", {
|
|
629
682
|
type: "boolean",
|
|
630
683
|
alias: "a",
|
|
@@ -669,6 +722,7 @@ __decorate([
|
|
|
669
722
|
], ProjectController.prototype, "start", null);
|
|
670
723
|
__decorate([
|
|
671
724
|
(0, core_1.Command)("stop"),
|
|
725
|
+
(0, core_1.Description)("Stopping project"),
|
|
672
726
|
__param(0, (0, core_1.Option)("name", {
|
|
673
727
|
type: "string",
|
|
674
728
|
alias: "n",
|
|
@@ -680,6 +734,7 @@ __decorate([
|
|
|
680
734
|
], ProjectController.prototype, "stop", null);
|
|
681
735
|
__decorate([
|
|
682
736
|
(0, core_1.Command)("domains"),
|
|
737
|
+
(0, core_1.Description)("Project domain list"),
|
|
683
738
|
__param(0, (0, core_1.Option)("name", {
|
|
684
739
|
type: "string",
|
|
685
740
|
alias: "n",
|
|
@@ -691,6 +746,7 @@ __decorate([
|
|
|
691
746
|
], ProjectController.prototype, "domains", null);
|
|
692
747
|
__decorate([
|
|
693
748
|
(0, core_1.Command)("domain:add [...domains]"),
|
|
749
|
+
(0, core_1.Description)("Adding project domain"),
|
|
694
750
|
__param(0, (0, core_1.Option)("name", {
|
|
695
751
|
type: "string",
|
|
696
752
|
alias: "n",
|
|
@@ -702,6 +758,7 @@ __decorate([
|
|
|
702
758
|
], ProjectController.prototype, "addDomain", null);
|
|
703
759
|
__decorate([
|
|
704
760
|
(0, core_1.Command)("domain:set [...domains]"),
|
|
761
|
+
(0, core_1.Description)("Setting project domains"),
|
|
705
762
|
__param(0, (0, core_1.Option)("name", {
|
|
706
763
|
type: "string",
|
|
707
764
|
alias: "n",
|
|
@@ -713,6 +770,7 @@ __decorate([
|
|
|
713
770
|
], ProjectController.prototype, "setDomains", null);
|
|
714
771
|
__decorate([
|
|
715
772
|
(0, core_1.Command)("domain:remove [...domains]"),
|
|
773
|
+
(0, core_1.Description)("Removing project domain"),
|
|
716
774
|
__param(0, (0, core_1.Option)("name", {
|
|
717
775
|
type: "string",
|
|
718
776
|
alias: "n",
|
|
@@ -724,6 +782,7 @@ __decorate([
|
|
|
724
782
|
], ProjectController.prototype, "removeDomain", null);
|
|
725
783
|
__decorate([
|
|
726
784
|
(0, core_1.Command)("domain:clear"),
|
|
785
|
+
(0, core_1.Description)("Clearing project domain"),
|
|
727
786
|
__param(0, (0, core_1.Option)("name", {
|
|
728
787
|
type: "string",
|
|
729
788
|
alias: "n",
|
|
@@ -920,6 +979,45 @@ __decorate([
|
|
|
920
979
|
__metadata("design:paramtypes", [String, Array]),
|
|
921
980
|
__metadata("design:returntype", Promise)
|
|
922
981
|
], ProjectController.prototype, "volumeUnmount", null);
|
|
982
|
+
__decorate([
|
|
983
|
+
(0, core_1.Command)("extra-hosts"),
|
|
984
|
+
(0, core_1.Description)("List of extra hosts"),
|
|
985
|
+
__param(0, (0, core_1.Option)("name", {
|
|
986
|
+
type: "string",
|
|
987
|
+
alias: "n",
|
|
988
|
+
description: "The name of the project"
|
|
989
|
+
})),
|
|
990
|
+
__metadata("design:type", Function),
|
|
991
|
+
__metadata("design:paramtypes", [String]),
|
|
992
|
+
__metadata("design:returntype", Promise)
|
|
993
|
+
], ProjectController.prototype, "extraHostList", null);
|
|
994
|
+
__decorate([
|
|
995
|
+
(0, core_1.Command)("extra-host:add <extraHost>:<extraDomain>"),
|
|
996
|
+
(0, core_1.Description)("Adding extra host"),
|
|
997
|
+
__param(0, (0, core_1.Param)("extraHost")),
|
|
998
|
+
__param(1, (0, core_1.Param)("extraDomain")),
|
|
999
|
+
__param(2, (0, core_1.Option)("name", {
|
|
1000
|
+
type: "string",
|
|
1001
|
+
alias: "n",
|
|
1002
|
+
description: "The name of the project"
|
|
1003
|
+
})),
|
|
1004
|
+
__metadata("design:type", Function),
|
|
1005
|
+
__metadata("design:paramtypes", [String, String, String]),
|
|
1006
|
+
__metadata("design:returntype", Promise)
|
|
1007
|
+
], ProjectController.prototype, "addExtraHost", null);
|
|
1008
|
+
__decorate([
|
|
1009
|
+
(0, core_1.Command)("extra-host:remove <extraHost>"),
|
|
1010
|
+
(0, core_1.Description)("Removing extra host"),
|
|
1011
|
+
__param(0, (0, core_1.Param)("extraHost")),
|
|
1012
|
+
__param(1, (0, core_1.Option)("name", {
|
|
1013
|
+
type: "string",
|
|
1014
|
+
alias: "n",
|
|
1015
|
+
description: "The name of the project"
|
|
1016
|
+
})),
|
|
1017
|
+
__metadata("design:type", Function),
|
|
1018
|
+
__metadata("design:paramtypes", [String, String]),
|
|
1019
|
+
__metadata("design:returntype", Promise)
|
|
1020
|
+
], ProjectController.prototype, "removeExtraHost", null);
|
|
923
1021
|
__decorate([
|
|
924
1022
|
(0, core_1.Command)("logs"),
|
|
925
1023
|
__param(0, (0, core_1.Option)("name", {
|
|
@@ -933,7 +1031,8 @@ __decorate([
|
|
|
933
1031
|
})),
|
|
934
1032
|
__param(2, (0, core_1.Option)("detach", {
|
|
935
1033
|
type: "boolean",
|
|
936
|
-
alias: "d"
|
|
1034
|
+
alias: "d",
|
|
1035
|
+
description: "Detach"
|
|
937
1036
|
})),
|
|
938
1037
|
__param(3, (0, core_1.Option)("follow", {
|
|
939
1038
|
type: "boolean",
|
|
@@ -969,6 +1068,7 @@ __decorate([
|
|
|
969
1068
|
], ProjectController.prototype, "run", null);
|
|
970
1069
|
__decorate([
|
|
971
1070
|
(0, core_1.Command)("attach"),
|
|
1071
|
+
(0, core_1.Description)("Attach local standard input, output, and error streams to a running container"),
|
|
972
1072
|
__param(0, (0, core_1.Option)("name", {
|
|
973
1073
|
type: "string",
|
|
974
1074
|
alias: "n",
|
package/lib/main.js
CHANGED
|
@@ -22,9 +22,9 @@ exports.app = {
|
|
|
22
22
|
}
|
|
23
23
|
catch (err) {
|
|
24
24
|
console.error(chalk_1.default.red(err.message));
|
|
25
|
-
const { debug } =
|
|
25
|
+
const { debug } = config.getConfig();
|
|
26
26
|
if (debug) {
|
|
27
|
-
logger.error(err.stack || err.
|
|
27
|
+
logger.error(err.stack || err.toString());
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -4,10 +4,9 @@ type TypeMap = {
|
|
|
4
4
|
};
|
|
5
5
|
export declare class AppConfigService extends CoreAppConfigService {
|
|
6
6
|
protected _pwd: string;
|
|
7
|
-
protected mapTypes: TypeMap;
|
|
7
|
+
protected readonly mapTypes: TypeMap;
|
|
8
8
|
constructor();
|
|
9
9
|
setPWD(pwd: string): void;
|
|
10
|
-
getPWD(...parts: string[]): string;
|
|
11
10
|
pwd(...parts: string[]): string;
|
|
12
11
|
dataPath(...parts: string[]): string;
|
|
13
12
|
pluginsPath(...parts: string[]): string;
|
|
@@ -49,9 +49,6 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
|
|
|
49
49
|
setPWD(pwd) {
|
|
50
50
|
this._pwd = pwd;
|
|
51
51
|
}
|
|
52
|
-
getPWD(...parts) {
|
|
53
|
-
return this.pwd(...parts);
|
|
54
|
-
}
|
|
55
52
|
pwd(...parts) {
|
|
56
53
|
return Path.join(this._pwd, ...parts);
|
|
57
54
|
}
|
|
@@ -76,13 +73,24 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
|
|
|
76
73
|
data = config;
|
|
77
74
|
}
|
|
78
75
|
catch (err) {
|
|
79
|
-
if (fs.exists("wocker.json")) {
|
|
80
|
-
|
|
76
|
+
if (fs.exists("wocker.config.json")) {
|
|
77
|
+
let json = fs.readJSON("wocker.config.json");
|
|
78
|
+
if (typeof json === "string") {
|
|
79
|
+
json = JSON.parse(json);
|
|
80
|
+
}
|
|
81
|
+
data = json;
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
}
|
|
85
|
+
else if (fs.exists("wocker.config.json")) {
|
|
86
|
+
data = fs.readJSON("wocker.config.json");
|
|
87
|
+
}
|
|
84
88
|
else if (fs.exists("wocker.json")) {
|
|
85
|
-
|
|
89
|
+
let json = fs.readJSON("wocker.json");
|
|
90
|
+
if (typeof json === "string") {
|
|
91
|
+
json = JSON.parse(json);
|
|
92
|
+
}
|
|
93
|
+
data = json;
|
|
86
94
|
}
|
|
87
95
|
else if (fs.exists("data.json")) {
|
|
88
96
|
data = fs.readJSON("data.json");
|
|
@@ -97,10 +105,13 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
|
|
|
97
105
|
}
|
|
98
106
|
const json = JSON.stringify(this.toJson(), null, 4);
|
|
99
107
|
await fs.writeFile("wocker.config.js", `// Wocker config\nexports.config = ${json};`);
|
|
100
|
-
await fs.
|
|
108
|
+
await fs.writeFile("wocker.config.json", json);
|
|
101
109
|
if (fs.exists("data.json")) {
|
|
102
110
|
await fs.rm("data.json");
|
|
103
111
|
}
|
|
112
|
+
if (fs.exists("wocker.json")) {
|
|
113
|
+
await fs.rm("wocker.json");
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
}(data);
|
|
106
117
|
}
|
|
@@ -214,15 +214,11 @@ let DockerService = class DockerService {
|
|
|
214
214
|
await (0, utils_2.followProgress)(stream);
|
|
215
215
|
}
|
|
216
216
|
async attach(containerOrName) {
|
|
217
|
-
let container
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (!containerOrName) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
container = containerOrName;
|
|
217
|
+
let container = typeof containerOrName === "string"
|
|
218
|
+
? await this.getContainer(containerOrName)
|
|
219
|
+
: containerOrName;
|
|
220
|
+
if (!container) {
|
|
221
|
+
return;
|
|
226
222
|
}
|
|
227
223
|
const stream = await container.attach({
|
|
228
224
|
logs: true,
|
|
@@ -239,10 +235,21 @@ let DockerService = class DockerService {
|
|
|
239
235
|
process.stdin.pipe(stream);
|
|
240
236
|
process.stdin.on("data", (data) => {
|
|
241
237
|
if (data.toString() === "\u0003") {
|
|
242
|
-
|
|
238
|
+
stream.end();
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
process.exit();
|
|
241
|
+
}, 5000);
|
|
243
242
|
}
|
|
244
243
|
});
|
|
245
244
|
stream.on("data", (data) => {
|
|
245
|
+
if (data instanceof Buffer) {
|
|
246
|
+
try {
|
|
247
|
+
data = (0, utils_1.demuxOutput)(data);
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
this.logService.error(err.toString(), err.stack);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
246
253
|
process.stdout.write(data);
|
|
247
254
|
});
|
|
248
255
|
stream.on("end", async () => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NpmService = void 0;
|
|
10
|
+
const core_1 = require("@wocker/core");
|
|
11
|
+
const makes_1 = require("../makes");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
let NpmService = class NpmService {
|
|
14
|
+
async getPackageInfo(name) {
|
|
15
|
+
const res = await makes_1.Http.get("https://registry.npmjs.org")
|
|
16
|
+
.send(name);
|
|
17
|
+
if (res.status === 404) {
|
|
18
|
+
throw new Error("Package not found");
|
|
19
|
+
}
|
|
20
|
+
if (res.status !== 200) {
|
|
21
|
+
throw new Error("Network error");
|
|
22
|
+
}
|
|
23
|
+
return res.data;
|
|
24
|
+
}
|
|
25
|
+
async install(name, version) {
|
|
26
|
+
console.info(`npm install -g ${version ? `${name}@${version}` : name}`);
|
|
27
|
+
await (0, utils_1.exec)(`npm install -g ${version ? `${name}@${version}` : name}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.NpmService = NpmService;
|
|
31
|
+
exports.NpmService = NpmService = __decorate([
|
|
32
|
+
(0, core_1.Injectable)()
|
|
33
|
+
], NpmService);
|
|
@@ -49,7 +49,7 @@ let PluginService = class PluginService {
|
|
|
49
49
|
const { default: Plugin } = await Promise.resolve(`${pluginName}`).then(s => __importStar(require(s)));
|
|
50
50
|
const name = Reflect.getMetadata(core_1.PLUGIN_NAME_METADATA, Plugin);
|
|
51
51
|
if (!name) {
|
|
52
|
-
console.
|
|
52
|
+
console.error("No name");
|
|
53
53
|
}
|
|
54
54
|
return !!name;
|
|
55
55
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvConfig, Preset, AppConfig, PresetProperties } from "@wocker/core";
|
|
1
|
+
import { EnvConfig, Project, Preset, AppConfig, PresetProperties } from "@wocker/core";
|
|
2
2
|
import { AppConfigService } from "./AppConfigService";
|
|
3
3
|
import { LogService } from "./LogService";
|
|
4
4
|
type SearchOptions = Partial<{
|
|
@@ -12,8 +12,10 @@ export declare class PresetService {
|
|
|
12
12
|
constructor(appConfigService: AppConfigService, logService: LogService);
|
|
13
13
|
protected toObject(config: PresetProperties): Preset;
|
|
14
14
|
protected getList(): Promise<AppConfig["presets"]>;
|
|
15
|
-
|
|
15
|
+
getImageNameForProject(project: Project, preset: Preset): string;
|
|
16
|
+
getImageName(preset: Preset, buildArgs: EnvConfig): string;
|
|
16
17
|
init(): Promise<void>;
|
|
18
|
+
deinit(): Promise<void>;
|
|
17
19
|
get(name: string): Promise<Preset>;
|
|
18
20
|
addPreset(name: string): Promise<void>;
|
|
19
21
|
search(options?: SearchOptions): Promise<Preset[]>;
|
|
@@ -113,7 +113,15 @@ let PresetService = class PresetService {
|
|
|
113
113
|
})
|
|
114
114
|
];
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
getImageNameForProject(project, preset) {
|
|
117
|
+
switch (project.presetMode) {
|
|
118
|
+
case "project":
|
|
119
|
+
return `project-${project.name}:develop`;
|
|
120
|
+
default:
|
|
121
|
+
return this.getImageName(preset, project.buildArgs || {});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getImageName(preset, buildArgs) {
|
|
117
125
|
const rawValues = [];
|
|
118
126
|
const hashValues = [];
|
|
119
127
|
Object.keys(preset.buildArgsOptions || {}).forEach((key) => {
|
|
@@ -138,17 +146,23 @@ let PresetService = class PresetService {
|
|
|
138
146
|
let preset = await this.searchOne({
|
|
139
147
|
path: this.appConfigService.pwd()
|
|
140
148
|
});
|
|
141
|
-
if (preset) {
|
|
142
|
-
throw new Error("Preset is already registered");
|
|
143
|
-
}
|
|
144
149
|
const fs = new core_1.FileSystem(this.appConfigService.pwd());
|
|
145
|
-
if (!
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (!preset) {
|
|
151
|
+
if (!fs.exists("config.json")) {
|
|
152
|
+
preset = this.toObject({
|
|
153
|
+
name: "",
|
|
154
|
+
version: "",
|
|
155
|
+
source: "external",
|
|
156
|
+
path: this.appConfigService.pwd()
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
preset = this.toObject(fs.readJSON("config.json"));
|
|
161
|
+
preset.source = "external";
|
|
162
|
+
preset.path = this.appConfigService.pwd();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!preset.name) {
|
|
152
166
|
const list = await this.getList();
|
|
153
167
|
preset.name = await (0, utils_1.promptText)({
|
|
154
168
|
message: "Preset name:",
|
|
@@ -167,6 +181,8 @@ let PresetService = class PresetService {
|
|
|
167
181
|
},
|
|
168
182
|
default: preset.name
|
|
169
183
|
});
|
|
184
|
+
}
|
|
185
|
+
if (!preset.version) {
|
|
170
186
|
preset.version = await (0, utils_1.promptText)({
|
|
171
187
|
message: "Preset version:",
|
|
172
188
|
validate: (version) => {
|
|
@@ -177,12 +193,16 @@ let PresetService = class PresetService {
|
|
|
177
193
|
},
|
|
178
194
|
default: preset.version
|
|
179
195
|
});
|
|
196
|
+
}
|
|
197
|
+
if (!preset.type) {
|
|
180
198
|
preset.type = await (0, utils_1.promptSelect)({
|
|
181
199
|
message: "Preset type:",
|
|
182
200
|
options: ["dockerfile", "image"]
|
|
183
201
|
});
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
}
|
|
203
|
+
switch (preset.type) {
|
|
204
|
+
case "dockerfile":
|
|
205
|
+
if (!preset.dockerfile) {
|
|
186
206
|
const files = await fs.readdirFiles();
|
|
187
207
|
const dockerfiles = files.filter((fileName) => {
|
|
188
208
|
if (new RegExp("^(.*)\\.dockerfile$").test(fileName)) {
|
|
@@ -197,8 +217,10 @@ let PresetService = class PresetService {
|
|
|
197
217
|
message: "Preset dockerfile:",
|
|
198
218
|
options: dockerfiles
|
|
199
219
|
});
|
|
200
|
-
|
|
201
|
-
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case "image":
|
|
223
|
+
if (preset.image) {
|
|
202
224
|
preset.image = await (0, utils_1.promptText)({
|
|
203
225
|
message: "Preset image:",
|
|
204
226
|
required: true,
|
|
@@ -209,16 +231,27 @@ let PresetService = class PresetService {
|
|
|
209
231
|
return true;
|
|
210
232
|
}
|
|
211
233
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
console.info(JSON.stringify(preset.toJSON(), null, 4));
|
|
238
|
+
const confirm = await (0, utils_1.promptConfirm)({
|
|
239
|
+
message: "Correct?"
|
|
240
|
+
});
|
|
241
|
+
if (confirm) {
|
|
242
|
+
await preset.save();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async deinit() {
|
|
246
|
+
const preset = await this.searchOne({
|
|
247
|
+
path: this.appConfigService.pwd()
|
|
248
|
+
});
|
|
249
|
+
if (!preset) {
|
|
250
|
+
return;
|
|
221
251
|
}
|
|
252
|
+
const config = this.appConfigService.getConfig();
|
|
253
|
+
config.unregisterPreset(preset.name);
|
|
254
|
+
await config.save();
|
|
222
255
|
}
|
|
223
256
|
async get(name) {
|
|
224
257
|
const list = await this.getList();
|
|
@@ -1,40 +1,16 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
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;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
10
|
};
|
|
34
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
12
|
exports.ProjectService = void 0;
|
|
36
13
|
const core_1 = require("@wocker/core");
|
|
37
|
-
const Path = __importStar(require("path"));
|
|
38
14
|
const makes_1 = require("../makes");
|
|
39
15
|
const services_1 = require("../services");
|
|
40
16
|
let ProjectService = class ProjectService {
|
|
@@ -110,7 +86,7 @@ let ProjectService = class ProjectService {
|
|
|
110
86
|
await this.appEventsService.emit("project:rebuild", project);
|
|
111
87
|
}
|
|
112
88
|
await this.appEventsService.emit("project:beforeStart", project);
|
|
113
|
-
const config =
|
|
89
|
+
const config = this.appConfigService.getConfig();
|
|
114
90
|
container = await this.dockerService.createContainer({
|
|
115
91
|
name: project.containerName,
|
|
116
92
|
image: project.imageName,
|
|
@@ -118,15 +94,18 @@ let ProjectService = class ProjectService {
|
|
|
118
94
|
...config.env || {},
|
|
119
95
|
...project.env || {}
|
|
120
96
|
},
|
|
97
|
+
ports: project.ports || [],
|
|
121
98
|
volumes: (project.volumes || []).map((volume) => {
|
|
122
99
|
const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
|
|
123
100
|
const [, source, destination, options] = regVolume.exec(volume);
|
|
124
101
|
if (source.startsWith("/")) {
|
|
125
102
|
return volume;
|
|
126
103
|
}
|
|
127
|
-
return `${
|
|
104
|
+
return `${this.appConfigService.pwd(source)}:${destination}` + (options ? `:${options}` : "");
|
|
128
105
|
}),
|
|
129
|
-
|
|
106
|
+
extraHosts: Object.keys(project.extraHosts || {}).map((host) => {
|
|
107
|
+
return `${project.extraHosts[host]}:${host}`;
|
|
108
|
+
})
|
|
130
109
|
});
|
|
131
110
|
}
|
|
132
111
|
const { State: { Status } } = await container.inspect();
|
|
@@ -46,7 +46,7 @@ let ProxyService = class ProxyService {
|
|
|
46
46
|
mode: 0o700
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
const config =
|
|
49
|
+
const config = this.appConfigService.getConfig();
|
|
50
50
|
const httpPort = config.getMeta("PROXY_HTTP_PORT", "80");
|
|
51
51
|
const httpsPort = config.getMeta("PROXY_HTTPS_PORT", "443");
|
|
52
52
|
container = await this.dockerService.createContainer({
|
|
@@ -65,11 +65,11 @@ let ProxyService = class ProxyService {
|
|
|
65
65
|
`${certsDir}:/etc/nginx/certs`
|
|
66
66
|
]
|
|
67
67
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
}
|
|
69
|
+
const { State: { Status } } = await container.inspect();
|
|
70
|
+
if (["created", "exited"].includes(Status)) {
|
|
71
|
+
await container.start();
|
|
72
|
+
console.info("Proxy started");
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async stop() {
|
package/lib/services/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./AppConfigService";
|
|
|
2
2
|
export * from "./AppEventsService";
|
|
3
3
|
export * from "./DockerService";
|
|
4
4
|
export * from "./LogService";
|
|
5
|
+
export * from "./NpmService";
|
|
5
6
|
export * from "./PluginService";
|
|
6
7
|
export * from "./PresetService";
|
|
7
8
|
export * from "./ProjectService";
|
package/lib/services/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./AppConfigService"), exports);
|
|
|
18
18
|
__exportStar(require("./AppEventsService"), exports);
|
|
19
19
|
__exportStar(require("./DockerService"), exports);
|
|
20
20
|
__exportStar(require("./LogService"), exports);
|
|
21
|
+
__exportStar(require("./NpmService"), exports);
|
|
21
22
|
__exportStar(require("./PluginService"), exports);
|
|
22
23
|
__exportStar(require("./PresetService"), exports);
|
|
23
24
|
__exportStar(require("./ProjectService"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type PackageInfo = {
|
|
2
|
+
name: string;
|
|
3
|
+
"dist-tags": {
|
|
4
|
+
[tag: string]: string;
|
|
5
|
+
};
|
|
6
|
+
versions: {
|
|
7
|
+
[version: string]: {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
time: {
|
|
13
|
+
created: string;
|
|
14
|
+
modified: string;
|
|
15
|
+
} & {
|
|
16
|
+
[version: string]: string;
|
|
17
|
+
};
|
|
18
|
+
readme: string;
|
|
19
|
+
readmeFilename: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PackageInfo";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./PackageInfo"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/ws",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Docker workspace for web projects",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@wocker/core": "1.0.
|
|
29
|
-
"@wocker/utils": "^1.0.
|
|
28
|
+
"@wocker/core": "1.0.17",
|
|
29
|
+
"@wocker/utils": "^1.0.7",
|
|
30
30
|
"async-mutex": "^0.4.0",
|
|
31
31
|
"axios": "^1.6.7",
|
|
32
32
|
"chalk": "^2.4.2",
|