@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
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.PresetController = void 0;
|
|
27
|
+
const utils_1 = require("@wocker/utils");
|
|
28
|
+
const Path = __importStar(require("path"));
|
|
29
|
+
const env_1 = require("../env");
|
|
30
|
+
const utils_2 = require("../utils");
|
|
31
|
+
const makes_1 = require("../makes");
|
|
32
|
+
const services_1 = require("../services");
|
|
33
|
+
class PresetController extends makes_1.Controller {
|
|
34
|
+
constructor(di) {
|
|
35
|
+
super();
|
|
36
|
+
this.appConfigService = di.resolveService(services_1.AppConfigService);
|
|
37
|
+
this.appEventsService = di.resolveService(services_1.AppEventsService);
|
|
38
|
+
this.projectService = di.resolveService(services_1.ProjectService);
|
|
39
|
+
this.presetService = di.resolveService(services_1.PresetService);
|
|
40
|
+
this.dockerService = di.resolveService(services_1.DockerService);
|
|
41
|
+
}
|
|
42
|
+
install(cli) {
|
|
43
|
+
super.install(cli);
|
|
44
|
+
this.appConfigService.registerProjectType("preset", "Preset");
|
|
45
|
+
this.appEventsService.on("project:init", (project) => this.onInit(project));
|
|
46
|
+
this.appEventsService.on("project:beforeStart", (project) => this.onBeforeStart(project));
|
|
47
|
+
this.appEventsService.on("project:rebuild", (project) => this.onRebuild(project));
|
|
48
|
+
cli.command("preset:build <preset>")
|
|
49
|
+
.completion("preset", () => this.presets())
|
|
50
|
+
.option("rebuild", {
|
|
51
|
+
type: "boolean",
|
|
52
|
+
alias: "r",
|
|
53
|
+
description: "Rebuild image"
|
|
54
|
+
})
|
|
55
|
+
.action((options, preset) => this.build(options, preset));
|
|
56
|
+
}
|
|
57
|
+
async presets() {
|
|
58
|
+
const presets = await this.presetService.search();
|
|
59
|
+
return presets.map((preset) => {
|
|
60
|
+
return preset.name;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async onInit(project) {
|
|
64
|
+
if (project.type !== "preset") {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const presets = await this.presetService.search();
|
|
68
|
+
if (presets.length === 0) {
|
|
69
|
+
throw new Error("No presets");
|
|
70
|
+
}
|
|
71
|
+
project.preset = await (0, utils_1.promptSelect)({
|
|
72
|
+
message: "Choose preset:",
|
|
73
|
+
options: presets.map((preset) => {
|
|
74
|
+
return {
|
|
75
|
+
label: preset.name,
|
|
76
|
+
value: preset.name
|
|
77
|
+
};
|
|
78
|
+
}),
|
|
79
|
+
default: project.preset
|
|
80
|
+
});
|
|
81
|
+
const preset = await this.presetService.get(project.preset);
|
|
82
|
+
if (!preset) {
|
|
83
|
+
throw new Error("Preset not found");
|
|
84
|
+
}
|
|
85
|
+
if (preset.buildArgsOptions) {
|
|
86
|
+
project.buildArgs = await (0, utils_1.promptConfig)(preset.buildArgsOptions, project.buildArgs);
|
|
87
|
+
}
|
|
88
|
+
if (preset.envOptions) {
|
|
89
|
+
project.env = await (0, utils_1.promptConfig)(preset.envOptions, project.env);
|
|
90
|
+
}
|
|
91
|
+
if (preset.volumeOptions) {
|
|
92
|
+
for (let volume of preset.volumeOptions) {
|
|
93
|
+
volume = (0, utils_2.injectVariables)(volume, {
|
|
94
|
+
...project.buildArgs || {},
|
|
95
|
+
...project.env || {}
|
|
96
|
+
});
|
|
97
|
+
const { destination, options } = (0, utils_2.volumeParse)(volume);
|
|
98
|
+
let projectVolume = project.getVolumeByDestination(destination);
|
|
99
|
+
const source = await (0, utils_1.promptText)({
|
|
100
|
+
message: "Volume",
|
|
101
|
+
suffix: `:${destination}`,
|
|
102
|
+
default: projectVolume ? (0, utils_2.volumeParse)(projectVolume).source : "./"
|
|
103
|
+
});
|
|
104
|
+
projectVolume = (0, utils_2.volumeFormat)({
|
|
105
|
+
source,
|
|
106
|
+
destination,
|
|
107
|
+
options
|
|
108
|
+
});
|
|
109
|
+
project.volumeMount(projectVolume);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (preset.dockerfile) {
|
|
113
|
+
project.imageName = preset.getImageName(project.buildArgs);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async onRebuild(project) {
|
|
117
|
+
if (project.type !== "preset") {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const preset = await this.presetService.get(project.preset);
|
|
121
|
+
if (!preset) {
|
|
122
|
+
throw new Error(`Preset ${project.preset} not found`);
|
|
123
|
+
}
|
|
124
|
+
const imageName = preset.getImageName(project.buildArgs || {});
|
|
125
|
+
const exists = await this.dockerService.imageExists(imageName);
|
|
126
|
+
if (exists) {
|
|
127
|
+
console.info(`Removing image: ${imageName}`);
|
|
128
|
+
await this.dockerService.imageRm(imageName);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async onBeforeStart(project) {
|
|
132
|
+
if (project.type !== "preset") {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const preset = await this.presetService.get(project.preset);
|
|
136
|
+
if (preset.dockerfile) {
|
|
137
|
+
project.imageName = preset.getImageName(project.buildArgs);
|
|
138
|
+
if (!await this.dockerService.imageExists(project.imageName)) {
|
|
139
|
+
await this.dockerService.buildImage({
|
|
140
|
+
tag: project.imageName,
|
|
141
|
+
labels: {
|
|
142
|
+
presetName: preset.name
|
|
143
|
+
},
|
|
144
|
+
buildArgs: project.buildArgs,
|
|
145
|
+
context: Path.join(env_1.PRESETS_DIR, preset.name),
|
|
146
|
+
src: preset.dockerfile
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async build(options, presetName) {
|
|
152
|
+
const preset = await this.presetService.get(presetName);
|
|
153
|
+
let buildArgs = {};
|
|
154
|
+
if (preset.buildArgsOptions) {
|
|
155
|
+
buildArgs = await (0, utils_1.promptGroup)(preset.buildArgsOptions);
|
|
156
|
+
}
|
|
157
|
+
const imageName = preset.getImageName(buildArgs);
|
|
158
|
+
await this.dockerService.buildImage({
|
|
159
|
+
tag: imageName,
|
|
160
|
+
labels: {
|
|
161
|
+
presetName: preset.name
|
|
162
|
+
},
|
|
163
|
+
buildArgs: buildArgs,
|
|
164
|
+
context: Path.join(env_1.PRESETS_DIR, preset.name),
|
|
165
|
+
src: preset.dockerfile
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.PresetController = PresetController;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { Controller } from "
|
|
3
|
-
import { AppConfigService, AppEventsService, ProjectService } from "
|
|
2
|
+
import { DI, Controller } from "../makes";
|
|
3
|
+
import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
|
|
4
4
|
type InitOptions = {
|
|
5
5
|
name?: string;
|
|
6
6
|
type?: string;
|
|
7
7
|
preset?: string;
|
|
8
8
|
};
|
|
9
|
+
type ListOptions = {
|
|
10
|
+
all?: boolean;
|
|
11
|
+
};
|
|
9
12
|
type StartOptions = {
|
|
10
13
|
name?: string;
|
|
11
14
|
rebuild?: boolean;
|
|
@@ -37,15 +40,20 @@ type ExecOptions = {
|
|
|
37
40
|
name?: string;
|
|
38
41
|
};
|
|
39
42
|
declare class ProjectController extends Controller {
|
|
43
|
+
protected di: DI;
|
|
40
44
|
protected appConfigService: AppConfigService;
|
|
41
45
|
protected appEventsService: AppEventsService;
|
|
42
46
|
protected projectService: ProjectService;
|
|
43
|
-
|
|
47
|
+
protected dockerService: DockerService;
|
|
48
|
+
constructor(di: DI);
|
|
44
49
|
install(cli: Cli): void;
|
|
45
50
|
protected getProjectNames(): Promise<string[]>;
|
|
51
|
+
protected getScripts(): Promise<string[]>;
|
|
46
52
|
init(options: InitOptions): Promise<void>;
|
|
53
|
+
projectList(options: ListOptions): Promise<string>;
|
|
47
54
|
start(options: StartOptions): Promise<void>;
|
|
48
55
|
stop(options: StopOptions): Promise<void>;
|
|
56
|
+
run(script: string): Promise<void>;
|
|
49
57
|
attach(options: AttachOptions): Promise<void>;
|
|
50
58
|
configList(options: ConfigOptions): Promise<string>;
|
|
51
59
|
configGet(options: ConfigOptions, key: string): Promise<string>;
|