@wocker/ws 1.0.2 → 1.0.4

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.
Files changed (107) hide show
  1. package/README.md +1 -1
  2. package/lib/App.d.ts +4 -3
  3. package/lib/App.js +98 -77
  4. package/lib/controllers/ImageController.d.ts +2 -2
  5. package/lib/controllers/ImageController.js +27 -27
  6. package/lib/controllers/PluginController.d.ts +2 -2
  7. package/lib/controllers/PluginController.js +78 -56
  8. package/lib/controllers/PresetController.d.ts +3 -1
  9. package/lib/controllers/PresetController.js +155 -136
  10. package/lib/controllers/ProjectController.d.ts +5 -5
  11. package/lib/controllers/ProjectController.js +653 -603
  12. package/lib/controllers/ProxyController.d.ts +4 -1
  13. package/lib/controllers/ProxyController.js +269 -245
  14. package/lib/controllers/index.js +19 -58
  15. package/lib/decorators/Inject.d.ts +1 -0
  16. package/lib/decorators/Inject.js +8 -0
  17. package/lib/decorators/Injectable.d.ts +4 -0
  18. package/lib/decorators/Injectable.js +17 -0
  19. package/lib/decorators/index.d.ts +1 -0
  20. package/lib/decorators/index.js +17 -0
  21. package/lib/env.js +33 -15
  22. package/lib/index.d.ts +3 -0
  23. package/lib/index.js +31 -16
  24. package/lib/makes/Controller.js +4 -8
  25. package/lib/makes/DI.d.ts +7 -0
  26. package/lib/makes/DI.js +27 -0
  27. package/lib/makes/Docker.js +298 -382
  28. package/lib/makes/FS.d.ts +3 -9
  29. package/lib/makes/FS.js +277 -305
  30. package/lib/makes/LineConvertStream.js +37 -40
  31. package/lib/makes/Logger.d.ts +9 -1
  32. package/lib/makes/Logger.js +22 -11
  33. package/lib/makes/Model.js +8 -12
  34. package/lib/makes/MySQL.js +6 -27
  35. package/lib/makes/Plugin.d.ts +1 -1
  36. package/lib/makes/Plugin.js +55 -37
  37. package/lib/makes/Preset.d.ts +46 -0
  38. package/lib/makes/Preset.js +33 -0
  39. package/lib/makes/Project.d.ts +45 -0
  40. package/lib/makes/Project.js +127 -0
  41. package/lib/makes/Repository.js +18 -21
  42. package/lib/makes/index.d.ts +3 -0
  43. package/lib/makes/index.js +23 -69
  44. package/lib/plugins/ElasticSearchPlugin.d.ts +3 -1
  45. package/lib/plugins/ElasticSearchPlugin.js +66 -66
  46. package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
  47. package/lib/plugins/LocaltunnelPlugin.js +256 -257
  48. package/lib/plugins/MaildevPlugin.d.ts +2 -2
  49. package/lib/plugins/MaildevPlugin.js +45 -44
  50. package/lib/plugins/MongodbPlugin.d.ts +2 -2
  51. package/lib/plugins/MongodbPlugin.js +303 -248
  52. package/lib/plugins/NgrokPlugin.d.ts +2 -2
  53. package/lib/plugins/NgrokPlugin.js +221 -231
  54. package/lib/plugins/PageKitePlugin.d.ts +2 -2
  55. package/lib/plugins/PageKitePlugin.js +150 -149
  56. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  57. package/lib/plugins/PostgresPlugin.js +115 -89
  58. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  59. package/lib/plugins/ProxmoxPlugin.js +50 -38
  60. package/lib/plugins/RedisPlugin.d.ts +3 -1
  61. package/lib/plugins/RedisPlugin.js +73 -72
  62. package/lib/plugins/index.js +25 -103
  63. package/lib/services/AppConfigService.d.ts +3 -3
  64. package/lib/services/AppConfigService.js +162 -157
  65. package/lib/services/AppEventsService.js +26 -24
  66. package/lib/services/DockerService.d.ts +37 -2
  67. package/lib/services/DockerService.js +185 -205
  68. package/lib/services/LogService.d.ts +3 -2
  69. package/lib/services/LogService.js +33 -34
  70. package/lib/services/PluginService.d.ts +2 -1
  71. package/lib/services/PluginService.js +11 -14
  72. package/lib/services/PresetService.d.ts +8 -3
  73. package/lib/services/PresetService.js +60 -59
  74. package/lib/services/ProjectService.d.ts +11 -4
  75. package/lib/services/ProjectService.js +140 -129
  76. package/lib/services/index.js +21 -80
  77. package/lib/types/Config.d.ts +4 -3
  78. package/lib/types/Config.js +1 -4
  79. package/lib/types/EnvConfig.js +1 -4
  80. package/lib/types/index.js +16 -25
  81. package/lib/utils/buildOptions.js +5 -8
  82. package/lib/utils/demuxOutput.js +16 -20
  83. package/lib/utils/escapeRegExp.js +4 -7
  84. package/lib/utils/exec.js +38 -39
  85. package/lib/utils/fetch.js +46 -30
  86. package/lib/utils/followProgress.js +66 -77
  87. package/lib/utils/format-size-units.js +16 -16
  88. package/lib/utils/get-config.d.ts +1 -1
  89. package/lib/utils/get-config.js +13 -16
  90. package/lib/utils/get-cursor-position.js +22 -29
  91. package/lib/utils/image-build.js +35 -23
  92. package/lib/utils/index.js +32 -191
  93. package/lib/utils/injectVariables.js +10 -13
  94. package/lib/utils/parse-table.js +20 -23
  95. package/lib/utils/set-config.d.ts +1 -1
  96. package/lib/utils/set-config.js +12 -15
  97. package/lib/utils/spawn.js +17 -20
  98. package/lib/utils/tty.js +2 -6
  99. package/lib/utils/volumeFormat.js +5 -12
  100. package/lib/utils/volumeParse.js +10 -13
  101. package/package.json +13 -39
  102. package/presets/bun/Dockerfile +11 -0
  103. package/presets/bun/config.json +3 -0
  104. package/presets/node/Dockerfile +4 -2
  105. package/presets/php-apache/Dockerfile +3 -2
  106. package/.github/workflows/publish.yml +0 -31
  107. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
@@ -1,249 +1,239 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.NgrokPlugin = void 0;
7
- var _core = require("@wocker/core");
8
- var _utils = require("@wocker/utils");
9
- var _makes = require("../makes");
10
- class NgrokPlugin extends _makes.Plugin {
11
- constructor(di) {
12
- super("ngrok");
13
- this.appEventsService = di.resolveService(_core.AppEventsService);
14
- this.projectService = di.resolveService(_core.ProjectService);
15
- }
16
- install(cli) {
17
- super.install(cli);
18
- this.appEventsService.on("project:start", project => this.onProjectStart(project));
19
- this.appEventsService.on("project:stop", project => this.onProjectStop(project));
20
- cli.command("ngrok:init").option("name", {
21
- alias: "n",
22
- type: "string",
23
- description: "Project name"
24
- }).action(options => this.init(options));
25
- cli.command("ngrok:start").option("name", {
26
- type: "string",
27
- alias: "n",
28
- description: "Project name"
29
- }).option("detach", {
30
- type: "boolean",
31
- alias: "d",
32
- description: "Detach"
33
- }).action(options => this.start(options));
34
- cli.command("ngrok:stop").option("name", {
35
- type: "string",
36
- alias: "n",
37
- description: "Project name"
38
- }).action(options => this.stop(options));
39
- cli.command("ngrok:restart").option("name", {
40
- type: "string",
41
- alias: "n",
42
- description: "Project name"
43
- }).option("detach", {
44
- type: "boolean",
45
- alias: "d",
46
- description: "Detach"
47
- }).action(options => this.restart(options));
48
- cli.command("ngrok:logs").option("name", {
49
- type: "string",
50
- alias: "n",
51
- description: "Project name"
52
- }).action(options => this.logs(options));
53
- cli.command("ngrok:attach").option("name", {
54
- type: "string",
55
- alias: "n",
56
- description: "Project name"
57
- }).action(options => this.attach(options));
58
- cli.command("ngrok:forwarding").option("name", {
59
- type: "string",
60
- alias: "n",
61
- description: "Project name"
62
- }).action(options => this.forwarding(options));
63
- }
64
- async init(options) {
65
- const {
66
- name
67
- } = options;
68
- if (name) {
69
- await this.projectService.cdProject(name);
4
+ const utils_1 = require("@wocker/utils");
5
+ const makes_1 = require("../makes");
6
+ const services_1 = require("../services");
7
+ class NgrokPlugin extends makes_1.Plugin {
8
+ constructor(di) {
9
+ super("ngrok");
10
+ this.appEventsService = di.resolveService(services_1.AppEventsService);
11
+ this.projectService = di.resolveService(services_1.ProjectService);
70
12
  }
71
- const project = await this.projectService.get();
72
- const enable = await (0, _utils.promptConfirm)({
73
- message: "Enable ngrok?",
74
- default: true
75
- });
76
- if (enable) {
77
- const token = await (0, _utils.promptText)({
78
- message: "Token",
79
- default: project.getEnv("NGROK_AUTHTOKEN")
80
- });
81
- project.setEnv("NGROK_AUTHTOKEN", token);
82
- project.setEnv("NGROK_ENABLE", "true");
83
- } else {
84
- project.setEnv("NGROK_ENABLE", "false");
13
+ install(cli) {
14
+ super.install(cli);
15
+ this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
16
+ this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
17
+ cli.command("ngrok:init")
18
+ .option("name", {
19
+ alias: "n",
20
+ type: "string",
21
+ description: "Project name"
22
+ })
23
+ .action((options) => this.init(options));
24
+ cli.command("ngrok:start")
25
+ .option("name", {
26
+ type: "string",
27
+ alias: "n",
28
+ description: "Project name"
29
+ })
30
+ .option("detach", {
31
+ type: "boolean",
32
+ alias: "d",
33
+ description: "Detach"
34
+ })
35
+ .action((options) => this.start(options));
36
+ cli.command("ngrok:stop")
37
+ .option("name", {
38
+ type: "string",
39
+ alias: "n",
40
+ description: "Project name"
41
+ })
42
+ .action((options) => this.stop(options));
43
+ cli.command("ngrok:restart")
44
+ .option("name", {
45
+ type: "string",
46
+ alias: "n",
47
+ description: "Project name"
48
+ })
49
+ .option("detach", {
50
+ type: "boolean",
51
+ alias: "d",
52
+ description: "Detach"
53
+ })
54
+ .action((options) => this.restart(options));
55
+ cli.command("ngrok:logs")
56
+ .option("name", {
57
+ type: "string",
58
+ alias: "n",
59
+ description: "Project name"
60
+ })
61
+ .action((options) => this.logs(options));
62
+ cli.command("ngrok:attach")
63
+ .option("name", {
64
+ type: "string",
65
+ alias: "n",
66
+ description: "Project name"
67
+ })
68
+ .action((options) => this.attach(options));
69
+ cli.command("ngrok:forwarding")
70
+ .option("name", {
71
+ type: "string",
72
+ alias: "n",
73
+ description: "Project name"
74
+ })
75
+ .action((options) => this.forwarding(options));
85
76
  }
86
- await project.save();
87
- }
88
- async getForwarding(project) {
89
- const container = await _makes.Docker.getContainer(`ngrok-${project.name}`);
90
- if (!container) {
91
- throw new Error(`Ngrok for "${project.name}" not started`);
92
- }
93
- const {
94
- NetworkSettings: {
95
- Networks: {
96
- workspace
77
+ async init(options) {
78
+ const { name } = options;
79
+ if (name) {
80
+ await this.projectService.cdProject(name);
81
+ }
82
+ const project = await this.projectService.get();
83
+ const enable = await (0, utils_1.promptConfirm)({
84
+ message: "Enable ngrok?",
85
+ default: true
86
+ });
87
+ if (enable) {
88
+ const token = await (0, utils_1.promptText)({
89
+ message: "Token",
90
+ default: project.getEnv("NGROK_AUTHTOKEN")
91
+ });
92
+ project.setEnv("NGROK_AUTHTOKEN", token);
93
+ project.setEnv("NGROK_ENABLE", "true");
94
+ }
95
+ else {
96
+ project.setEnv("NGROK_ENABLE", "false");
97
97
  }
98
- }
99
- } = await container.inspect();
100
- const stream = await _makes.Docker.exec("proxy.workspace", ["curl", `http://${workspace.IPAddress}:4040/api/tunnels/command_line`], false);
101
- const res = await new Promise((resolve, reject) => {
102
- let res = "";
103
- stream.on("data", data => {
104
- res += (0, _utils.demuxOutput)(data).toString();
105
- });
106
- stream.on("end", () => resolve(res));
107
- stream.on("error", reject);
108
- });
109
- const tunnel = JSON.parse(res);
110
- return tunnel.public_url;
111
- }
112
- async onProjectStart(project) {
113
- if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
114
- return;
98
+ await project.save();
115
99
  }
116
- const container1 = await _makes.Docker.getContainer(`ngrok-${project.name}`);
117
- if (container1) {
118
- const {
119
- State: {
120
- Running
100
+ async getForwarding(project) {
101
+ const container = await makes_1.Docker.getContainer(`ngrok-${project.name}`);
102
+ if (!container) {
103
+ throw new Error(`Ngrok for "${project.name}" not started`);
121
104
  }
122
- } = await container1.inspect();
123
- if (Running) {
124
- console.log("Ngrok is already running");
125
- const forwarding = await this.getForwarding(project);
126
- console.log(`Forwarding: ${forwarding}`);
127
- return;
128
- } else {
129
- await _makes.Docker.removeContainer(`ngrok-${project.name}`);
130
- }
105
+ const { NetworkSettings: { Networks: { workspace } } } = await container.inspect();
106
+ const stream = await makes_1.Docker.exec("proxy.workspace", [
107
+ "curl", `http://${workspace.IPAddress}:4040/api/tunnels/command_line`
108
+ ], false);
109
+ const res = await new Promise((resolve, reject) => {
110
+ let res = "";
111
+ stream.on("data", (data) => {
112
+ res += (0, utils_1.demuxOutput)(data).toString();
113
+ });
114
+ stream.on("end", () => resolve(res));
115
+ stream.on("error", reject);
116
+ });
117
+ const tunnel = JSON.parse(res);
118
+ return tunnel.public_url;
131
119
  }
132
- console.log("Ngrok starting...");
133
- _core.Logger.info(`Ngrok start: ${project.name}`);
134
- await _makes.Docker.pullImage("ngrok/ngrok:latest");
135
- const container = await _makes.Docker.createContainer({
136
- name: `ngrok-${project.name}`,
137
- image: "ngrok/ngrok:latest",
138
- tty: true,
139
- restart: "always",
140
- env: {
141
- NGROK_AUTHTOKEN: project.getEnv("NGROK_AUTHTOKEN")
142
- },
143
- cmd: ["http", `${project.name}.workspace:80`]
144
- });
145
- const stream = await container.attach({
146
- logs: true,
147
- stream: true,
148
- hijack: true,
149
- stdin: true,
150
- stdout: true,
151
- stderr: true
152
- });
153
- stream.setEncoding("utf8");
154
- await container.start();
155
- await container.resize({
156
- w: 90,
157
- h: 40
158
- });
159
- await new Promise((resolve, reject) => {
160
- stream.on("data", data => {
161
- const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
162
- if (regLink.test(data.toString())) {
163
- const [link] = regLink.exec(data.toString());
164
- if (link.includes(".ngrok")) {
165
- _core.Logger.info(`${project.name} forwarding: ${link}`);
166
- console.log(`Forwarding: ${link}`);
167
- stream.end();
168
- }
120
+ async onProjectStart(project) {
121
+ if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
122
+ return;
169
123
  }
170
- });
171
- stream.on("end", resolve);
172
- stream.on("error", reject);
173
- });
174
- }
175
- async onProjectStop(project) {
176
- if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
177
- return;
124
+ const container1 = await makes_1.Docker.getContainer(`ngrok-${project.name}`);
125
+ if (container1) {
126
+ const { State: { Running } } = await container1.inspect();
127
+ if (Running) {
128
+ console.log("Ngrok is already running");
129
+ const forwarding = await this.getForwarding(project);
130
+ console.log(`Forwarding: ${forwarding}`);
131
+ return;
132
+ }
133
+ else {
134
+ await makes_1.Docker.removeContainer(`ngrok-${project.name}`);
135
+ }
136
+ }
137
+ console.log("Ngrok starting...");
138
+ makes_1.Logger.info(`Ngrok start: ${project.name}`);
139
+ await makes_1.Docker.pullImage("ngrok/ngrok:latest");
140
+ const container = await makes_1.Docker.createContainer({
141
+ name: `ngrok-${project.name}`,
142
+ image: "ngrok/ngrok:latest",
143
+ tty: true,
144
+ restart: "always",
145
+ env: {
146
+ NGROK_AUTHTOKEN: project.getEnv("NGROK_AUTHTOKEN")
147
+ },
148
+ cmd: ["http", `${project.name}.workspace:80`]
149
+ });
150
+ const stream = await container.attach({
151
+ logs: true,
152
+ stream: true,
153
+ hijack: true,
154
+ stdin: true,
155
+ stdout: true,
156
+ stderr: true
157
+ });
158
+ stream.setEncoding("utf8");
159
+ await container.start();
160
+ await container.resize({
161
+ w: 90,
162
+ h: 40
163
+ });
164
+ await new Promise((resolve, reject) => {
165
+ stream.on("data", (data) => {
166
+ const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
167
+ if (regLink.test(data.toString())) {
168
+ const [link] = regLink.exec(data.toString());
169
+ if (link.includes(".ngrok")) {
170
+ makes_1.Logger.info(`${project.name} forwarding: ${link}`);
171
+ console.log(`Forwarding: ${link}`);
172
+ stream.end();
173
+ }
174
+ }
175
+ });
176
+ stream.on("end", resolve);
177
+ stream.on("error", reject);
178
+ });
178
179
  }
179
- console.log("Ngrok stopping...");
180
- await _makes.Docker.removeContainer(`ngrok-${project.name}`);
181
- }
182
- async start(options) {
183
- const {
184
- name,
185
- detach
186
- } = options;
187
- if (name) {
188
- await this.projectService.cdProject(name);
180
+ async onProjectStop(project) {
181
+ if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
182
+ return;
183
+ }
184
+ console.log("Ngrok stopping...");
185
+ await makes_1.Docker.removeContainer(`ngrok-${project.name}`);
189
186
  }
190
- const project = await this.projectService.get();
191
- await this.onProjectStart(project);
192
- if (!detach) {
193
- await _makes.Docker.attach(`ngrok-${project.name}`);
187
+ async start(options) {
188
+ const { name, detach } = options;
189
+ if (name) {
190
+ await this.projectService.cdProject(name);
191
+ }
192
+ const project = await this.projectService.get();
193
+ await this.onProjectStart(project);
194
+ if (!detach) {
195
+ await makes_1.Docker.attach(`ngrok-${project.name}`);
196
+ }
194
197
  }
195
- }
196
- async stop(options) {
197
- const {
198
- name
199
- } = options;
200
- if (name) {
201
- await this.projectService.cdProject(name);
198
+ async stop(options) {
199
+ const { name } = options;
200
+ if (name) {
201
+ await this.projectService.cdProject(name);
202
+ }
203
+ const project = await this.projectService.get();
204
+ await this.onProjectStop(project);
202
205
  }
203
- const project = await this.projectService.get();
204
- await this.onProjectStop(project);
205
- }
206
- async restart(options) {
207
- const {
208
- name
209
- } = options;
210
- await this.stop({
211
- name
212
- });
213
- await this.start(options);
214
- }
215
- async logs(options) {
216
- const {
217
- name
218
- } = options;
219
- if (name) {
220
- await this.projectService.cdProject(name);
206
+ async restart(options) {
207
+ const { name } = options;
208
+ await this.stop({ name });
209
+ await this.start(options);
221
210
  }
222
- const project = await this.projectService.get();
223
- const container = await _makes.Docker.getContainer(`ngrok-${project.name}`);
224
- if (!container) {
225
- throw new Error("Ngrok not started");
211
+ async logs(options) {
212
+ const { name } = options;
213
+ if (name) {
214
+ await this.projectService.cdProject(name);
215
+ }
216
+ const project = await this.projectService.get();
217
+ const container = await makes_1.Docker.getContainer(`ngrok-${project.name}`);
218
+ if (!container) {
219
+ throw new Error("Ngrok not started");
220
+ }
226
221
  }
227
- }
228
- async attach(options) {
229
- const {
230
- name
231
- } = options;
232
- if (name) {
233
- await this.projectService.cdProject(name);
222
+ async attach(options) {
223
+ const { name } = options;
224
+ if (name) {
225
+ await this.projectService.cdProject(name);
226
+ }
227
+ const project = await this.projectService.get();
228
+ await makes_1.Docker.attach(`ngrok-${project.name}`);
234
229
  }
235
- const project = await this.projectService.get();
236
- await _makes.Docker.attach(`ngrok-${project.name}`);
237
- }
238
- async forwarding(options) {
239
- const {
240
- name
241
- } = options;
242
- if (name) {
243
- await this.projectService.cdProject(name);
230
+ async forwarding(options) {
231
+ const { name } = options;
232
+ if (name) {
233
+ await this.projectService.cdProject(name);
234
+ }
235
+ const project = await this.projectService.get();
236
+ return this.getForwarding(project);
244
237
  }
245
- const project = await this.projectService.get();
246
- return this.getForwarding(project);
247
- }
248
238
  }
249
- exports.NgrokPlugin = NgrokPlugin;
239
+ exports.NgrokPlugin = NgrokPlugin;
@@ -1,6 +1,6 @@
1
- import { DI, AppConfigService, AppEventsService, ProjectService, Project } from "@wocker/core";
2
1
  import { Cli } from "@kearisp/cli";
3
- import { Plugin } from "src/makes";
2
+ import { DI, Plugin, Project } from "../makes";
3
+ import { AppConfigService, AppEventsService, ProjectService } from "../services";
4
4
  type InitOptions = {};
5
5
  type StartOptions = {
6
6
  name?: string;