@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.
Files changed (136) hide show
  1. package/README.md +11 -137
  2. package/bin/ws.js +7 -3
  3. package/lib/App.d.ts +10 -7
  4. package/lib/App.js +99 -44
  5. package/lib/controllers/ImageController.d.ts +4 -2
  6. package/lib/controllers/ImageController.js +27 -25
  7. package/lib/controllers/PluginController.d.ts +14 -0
  8. package/lib/controllers/PluginController.js +84 -0
  9. package/lib/controllers/PresetController.d.ts +21 -0
  10. package/lib/controllers/PresetController.js +169 -0
  11. package/lib/controllers/ProjectController.d.ts +11 -3
  12. package/lib/controllers/ProjectController.js +653 -536
  13. package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +12 -11
  14. package/lib/controllers/ProxyController.js +273 -0
  15. package/lib/controllers/index.d.ts +3 -0
  16. package/lib/controllers/index.js +19 -25
  17. package/lib/env.js +33 -22
  18. package/lib/index.d.ts +2 -0
  19. package/lib/index.js +29 -28
  20. package/lib/makes/Controller.js +4 -8
  21. package/lib/makes/DI.d.ts +7 -0
  22. package/lib/makes/DI.js +27 -0
  23. package/lib/makes/Docker.js +299 -397
  24. package/lib/makes/FS.d.ts +1 -1
  25. package/lib/makes/FS.js +328 -301
  26. package/lib/makes/LineConvertStream.js +37 -40
  27. package/lib/makes/Logger.d.ts +5 -3
  28. package/lib/makes/Logger.js +18 -34
  29. package/lib/makes/Model.js +8 -12
  30. package/lib/makes/MySQL.js +6 -27
  31. package/lib/makes/Plugin.d.ts +1 -1
  32. package/lib/makes/Plugin.js +55 -37
  33. package/lib/makes/Preset.d.ts +46 -0
  34. package/lib/makes/Preset.js +33 -0
  35. package/lib/{models → makes}/Project.d.ts +23 -16
  36. package/lib/makes/Project.js +127 -0
  37. package/lib/makes/Repository.js +18 -21
  38. package/lib/makes/index.d.ts +3 -0
  39. package/lib/makes/index.js +23 -69
  40. package/lib/plugins/ElasticSearchPlugin.d.ts +18 -0
  41. package/lib/plugins/ElasticSearchPlugin.js +72 -0
  42. package/lib/plugins/LocaltunnelPlugin.d.ts +4 -4
  43. package/lib/plugins/LocaltunnelPlugin.js +256 -255
  44. package/lib/plugins/MaildevPlugin.d.ts +4 -2
  45. package/lib/plugins/MaildevPlugin.js +45 -41
  46. package/lib/plugins/MongodbPlugin.d.ts +6 -4
  47. package/lib/plugins/MongodbPlugin.js +303 -254
  48. package/lib/plugins/NgrokPlugin.d.ts +3 -4
  49. package/lib/plugins/NgrokPlugin.js +221 -230
  50. package/lib/plugins/PageKitePlugin.d.ts +3 -4
  51. package/lib/plugins/PageKitePlugin.js +150 -147
  52. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  53. package/lib/plugins/PostgresPlugin.js +115 -88
  54. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  55. package/lib/plugins/ProxmoxPlugin.js +50 -38
  56. package/lib/plugins/RedisPlugin.d.ts +10 -2
  57. package/lib/plugins/RedisPlugin.js +77 -39
  58. package/lib/plugins/index.d.ts +2 -6
  59. package/lib/plugins/index.js +25 -158
  60. package/lib/services/AppConfigService.d.ts +13 -3
  61. package/lib/services/AppConfigService.js +161 -71
  62. package/lib/services/AppEventsService.d.ts +5 -8
  63. package/lib/services/AppEventsService.js +26 -25
  64. package/lib/services/DockerService.d.ts +51 -0
  65. package/lib/services/DockerService.js +200 -0
  66. package/lib/services/LogService.d.ts +12 -0
  67. package/lib/services/LogService.js +38 -0
  68. package/lib/services/PluginService.d.ts +11 -0
  69. package/lib/services/PluginService.js +15 -0
  70. package/lib/services/PresetService.d.ts +14 -0
  71. package/lib/services/PresetService.js +64 -0
  72. package/lib/services/ProjectService.d.ts +12 -4
  73. package/lib/services/ProjectService.js +141 -78
  74. package/lib/services/index.d.ts +4 -0
  75. package/lib/services/index.js +21 -36
  76. package/lib/types/Config.d.ts +4 -3
  77. package/lib/types/Config.js +1 -4
  78. package/lib/types/EnvConfig.js +1 -4
  79. package/lib/types/index.js +16 -25
  80. package/lib/utils/buildOptions.js +5 -8
  81. package/lib/utils/demuxOutput.js +16 -22
  82. package/lib/utils/escapeRegExp.js +4 -7
  83. package/lib/utils/exec.d.ts +1 -1
  84. package/lib/utils/exec.js +38 -40
  85. package/lib/utils/fetch.js +45 -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.d.ts +0 -4
  93. package/lib/utils/index.js +32 -235
  94. package/lib/utils/injectVariables.js +10 -13
  95. package/lib/utils/parse-table.js +20 -23
  96. package/lib/utils/set-config.d.ts +1 -1
  97. package/lib/utils/set-config.js +12 -15
  98. package/lib/utils/spawn.js +17 -20
  99. package/lib/utils/tty.js +2 -6
  100. package/lib/utils/volumeFormat.js +5 -12
  101. package/lib/utils/volumeParse.js +10 -13
  102. package/package.json +21 -47
  103. package/presets/bun/Dockerfile +11 -0
  104. package/presets/bun/config.json +3 -0
  105. package/presets/node/Dockerfile +4 -2
  106. package/presets/node/config.json +9 -7
  107. package/presets/php-apache/Dockerfile +40 -38
  108. package/presets/php-apache/config.json +10 -15
  109. package/presets/php-fpm/Dockerfile +21 -0
  110. package/presets/php-fpm/config.json +25 -0
  111. package/lib/models/Preset.d.ts +0 -19
  112. package/lib/models/Preset.js +0 -60
  113. package/lib/models/Project.js +0 -151
  114. package/lib/models/index.d.ts +0 -2
  115. package/lib/models/index.js +0 -27
  116. package/lib/plugins/MariadbPlugin.d.ts +0 -25
  117. package/lib/plugins/MariadbPlugin.js +0 -297
  118. package/lib/plugins/PresetPlugin.d.ts +0 -19
  119. package/lib/plugins/PresetPlugin.js +0 -164
  120. package/lib/plugins/ProjectPlugin.d.ts +0 -12
  121. package/lib/plugins/ProjectPlugin.js +0 -54
  122. package/lib/plugins/ProxyPlugin.js +0 -257
  123. package/lib/plugins/ServeoPlugin.d.ts +0 -36
  124. package/lib/plugins/ServeoPlugin.js +0 -260
  125. package/lib/plugins/TestPlugin.d.ts +0 -10
  126. package/lib/plugins/TestPlugin.js +0 -75
  127. package/lib/utils/promptConfirm.d.ts +0 -6
  128. package/lib/utils/promptConfirm.js +0 -21
  129. package/lib/utils/promptGroup.d.ts +0 -16
  130. package/lib/utils/promptGroup.js +0 -39
  131. package/lib/utils/promptSelect.d.ts +0 -12
  132. package/lib/utils/promptSelect.js +0 -47
  133. package/lib/utils/promptText.d.ts +0 -13
  134. package/lib/utils/promptText.js +0 -53
  135. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
  136. package/plugins/serveo/Dockerfile +0 -17
@@ -1,273 +1,274 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LocaltunnelPlugin = void 0;
7
- var _axios = _interopRequireDefault(require("axios"));
8
- var _makes = require("../makes");
9
- var _utils = require("../utils");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- class LocaltunnelPlugin extends _makes.Plugin {
12
- constructor(appConfigService, appEventsService, projectService) {
13
- super("localtunnel");
14
- this.appConfigService = appConfigService;
15
- this.appEventsService = appEventsService;
16
- this.projectService = projectService;
17
- }
18
- install(cli) {
19
- super.install(cli);
20
- this.appEventsService.on("project:start", project => this.onProjectStart(project));
21
- this.appEventsService.on("project:stop", project => this.onProjectStop(project));
22
- cli.command("localtunnel:init").option("name", {
23
- alias: "n",
24
- type: "string",
25
- description: "Project name"
26
- }).action(options => this.init(options));
27
- cli.command("localtunnel:start").option("name", {
28
- alias: "n",
29
- type: "string",
30
- description: "Project name"
31
- }).option("detach", {
32
- type: "boolean",
33
- alias: "d",
34
- description: "Detach"
35
- }).action(options => this.start(options));
36
- cli.command("localtunnel:restart").option("name", {
37
- alias: "n",
38
- type: "string",
39
- description: "Project name"
40
- }).option("detach", {
41
- type: "boolean",
42
- alias: "d",
43
- description: "Detach"
44
- }).action(options => this.restart(options));
45
- cli.command("localtunnel:stop").option("name", {
46
- alias: "n",
47
- type: "string",
48
- description: "Project name"
49
- }).action(options => this.stop(options));
50
- cli.command("localtunnel:build").action(() => this.build());
51
- cli.command("localtunnel:rebuild").action(() => this.rebuild());
52
- cli.command("localtunnel:logs").option("name", {
53
- alias: "n",
54
- type: "string",
55
- description: "Project name"
56
- }).option("detach", {
57
- type: "boolean",
58
- alias: "d",
59
- description: "Detach"
60
- }).action(options => this.logs(options));
61
- }
62
- async getIp() {
63
- const res = await _axios.default.get("https://ipv4.icanhazip.com");
64
- return res.data.replace("\n", "");
65
- }
66
- async onProjectStart(project) {
67
- if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
68
- return;
7
+ const utils_1 = require("@wocker/utils");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const makes_1 = require("../makes");
10
+ const services_1 = require("../services");
11
+ class LocaltunnelPlugin extends makes_1.Plugin {
12
+ constructor(di) {
13
+ super("localtunnel");
14
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
15
+ this.appEventsService = di.resolveService(services_1.AppEventsService);
16
+ this.projectService = di.resolveService(services_1.ProjectService);
17
+ this.dockerService = di.resolveService(services_1.DockerService);
69
18
  }
70
- let container = await _makes.Docker.getContainer(`localtunnel-${project.name}`);
71
- if (container) {
72
- const {
73
- State: {
74
- Running
75
- }
76
- } = await container.inspect();
77
- if (Running) {
78
- console.info("Localtunnel is already running");
79
- return;
80
- } else {
81
- await _makes.Docker.removeContainer(`localtunnel-${project.name}`);
82
- }
19
+ install(cli) {
20
+ super.install(cli);
21
+ this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
22
+ this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
23
+ cli.command("localtunnel:init")
24
+ .option("name", {
25
+ alias: "n",
26
+ type: "string",
27
+ description: "Project name"
28
+ })
29
+ .action((options) => this.init(options));
30
+ cli.command("localtunnel:start")
31
+ .option("name", {
32
+ alias: "n",
33
+ type: "string",
34
+ description: "Project name"
35
+ })
36
+ .option("detach", {
37
+ type: "boolean",
38
+ alias: "d",
39
+ description: "Detach"
40
+ })
41
+ .action((options) => this.start(options));
42
+ cli.command("localtunnel:restart")
43
+ .option("name", {
44
+ alias: "n",
45
+ type: "string",
46
+ description: "Project name"
47
+ })
48
+ .option("detach", {
49
+ type: "boolean",
50
+ alias: "d",
51
+ description: "Detach"
52
+ })
53
+ .action((options) => this.restart(options));
54
+ cli.command("localtunnel:stop")
55
+ .option("name", {
56
+ alias: "n",
57
+ type: "string",
58
+ description: "Project name"
59
+ })
60
+ .action((options) => this.stop(options));
61
+ cli.command("localtunnel:build")
62
+ .action(() => this.build());
63
+ cli.command("localtunnel:rebuild")
64
+ .action(() => this.rebuild());
65
+ cli.command("localtunnel:logs")
66
+ .option("name", {
67
+ alias: "n",
68
+ type: "string",
69
+ description: "Project name"
70
+ })
71
+ .option("detach", {
72
+ type: "boolean",
73
+ alias: "d",
74
+ description: "Detach"
75
+ })
76
+ .action((options) => this.logs(options));
77
+ }
78
+ async getIp() {
79
+ const res = await axios_1.default.get("https://ipv4.icanhazip.com");
80
+ return res.data.replace("\n", "");
83
81
  }
84
- console.info("Localtunnel starting...");
85
- _makes.Logger.info(`Localtunnel start: ${project.name}`);
86
- await this.build();
87
- const subdomain = project.getEnv("LOCALTUNNEL_SUBDOMAIN", project.name);
88
- container = await _makes.Docker.createContainer({
89
- name: `localtunnel-${project.name}`,
90
- image: "ws-localtunnel",
91
- // tty: true,
92
- restart: "always",
93
- networkMode: "host",
94
- cmd: ["lt", `--port=80`,
95
- // `--local-host=${project.name}.workspace`,
96
- `--subdomain=${subdomain}`, "--print-requests"]
97
- });
98
- const stream = await container.attach({
99
- logs: true,
100
- stream: true,
101
- hijack: true,
102
- stdin: true,
103
- stdout: true,
104
- stderr: true
105
- });
106
- stream.setEncoding("utf8");
107
- await container.start();
108
- const link = await new Promise((resolve, reject) => {
109
- let res = "";
110
- stream.on("data", data => {
111
- const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
112
- if (regLink.test(data.toString())) {
113
- const [link] = regLink.exec(data.toString());
114
- if (link.includes(".loca.lt")) {
115
- res = link;
116
- stream.end();
117
- }
82
+ async onProjectStart(project) {
83
+ if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
84
+ return;
85
+ }
86
+ let container = await this.dockerService.getContainer(`localtunnel-${project.name}`);
87
+ if (container) {
88
+ const { State: { Running } } = await container.inspect();
89
+ if (Running) {
90
+ console.info("Localtunnel is already running");
91
+ return;
92
+ }
93
+ else {
94
+ await this.dockerService.removeContainer(`localtunnel-${project.name}`);
95
+ }
118
96
  }
119
- });
120
- stream.on("end", () => resolve(res));
121
- stream.on("error", reject);
122
- });
123
- _makes.Logger.info(`${project.name} localtunnel forwarding: ${link}`);
124
- const ip = await this.getIp();
125
- console.info(`IP: ${ip}`);
126
- console.info(`Forwarding: ${link}`);
127
- if (project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "false") === "true") {
128
- console.info("Skipping IP confirmation...");
129
- const res = await _axios.default.get(link, {
130
- headers: {
131
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
132
- },
133
- validateStatus: () => true
134
- });
135
- const [path] = /\/continue\/[\w.]+/.exec(res.data) || [];
136
- if (path) {
137
- const sendData = new URLSearchParams({
138
- endpoint: ip
97
+ console.info("Localtunnel starting...");
98
+ makes_1.Logger.info(`Localtunnel start: ${project.name}`);
99
+ await this.build();
100
+ const subdomain = project.getEnv("LOCALTUNNEL_SUBDOMAIN", project.name);
101
+ container = await this.dockerService.createContainer({
102
+ name: `localtunnel-${project.name}`,
103
+ image: "ws-localtunnel",
104
+ restart: "always",
105
+ networkMode: "host",
106
+ cmd: [
107
+ "lt",
108
+ `--port=80`,
109
+ `--subdomain=${subdomain}`,
110
+ "--print-requests"
111
+ ]
139
112
  });
140
- const res = await _axios.default.post(`${link}${path}`, sendData.toString(), {
141
- headers: {
142
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
143
- "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
144
- }
113
+ const stream = await container.attach({
114
+ logs: true,
115
+ stream: true,
116
+ hijack: true,
117
+ stdin: true,
118
+ stdout: true,
119
+ stderr: true
145
120
  });
146
- if (res.status === 200) {
147
- console.info("IP confirmed");
121
+ stream.setEncoding("utf8");
122
+ await container.start();
123
+ const link = await new Promise((resolve, reject) => {
124
+ let res = "";
125
+ stream.on("data", (data) => {
126
+ const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
127
+ if (regLink.test(data.toString())) {
128
+ const [link] = regLink.exec(data.toString());
129
+ if (link.includes(".loca.lt")) {
130
+ res = link;
131
+ stream.end();
132
+ }
133
+ }
134
+ });
135
+ stream.on("end", () => resolve(res));
136
+ stream.on("error", reject);
137
+ });
138
+ makes_1.Logger.info(`${project.name} localtunnel forwarding: ${link}`);
139
+ const ip = await this.getIp();
140
+ console.info(`IP: ${ip}`);
141
+ console.info(`Forwarding: ${link}`);
142
+ if (project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "false") === "true") {
143
+ console.info("Skipping IP confirmation...");
144
+ const res = await axios_1.default.get(link, {
145
+ headers: {
146
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
147
+ },
148
+ validateStatus: () => true
149
+ });
150
+ const [path] = /\/continue\/[\w.]+/.exec(res.data) || [];
151
+ if (path) {
152
+ const sendData = new URLSearchParams({
153
+ endpoint: ip
154
+ });
155
+ const res = await axios_1.default.post(`${link}${path}`, sendData.toString(), {
156
+ headers: {
157
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
158
+ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
159
+ }
160
+ });
161
+ if (res.status === 200) {
162
+ console.info("IP confirmed");
163
+ }
164
+ }
148
165
  }
149
- }
150
- }
151
- }
152
- async onProjectStop(project) {
153
- if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
154
- return;
155
- }
156
- console.info("Localtunnel stopping...");
157
- await _makes.Docker.removeContainer(`localtunnel-${project.name}`);
158
- }
159
- async build() {
160
- const exists = await _makes.Docker.imageExists("ws-localtunnel");
161
- if (!exists) {
162
- await _makes.Docker.imageBuild({
163
- tag: "ws-localtunnel",
164
- context: this.pluginPath(),
165
- src: "./Dockerfile"
166
- });
167
166
  }
168
- }
169
- async rebuild() {
170
- try {
171
- await _makes.Docker.imageRm("ws-localtunnel");
172
- } catch (err) {
173
- console.info(err.message);
167
+ async onProjectStop(project) {
168
+ if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
169
+ return;
170
+ }
171
+ console.info("Localtunnel stopping...");
172
+ await this.dockerService.removeContainer(`localtunnel-${project.name}`);
174
173
  }
175
- await this.build();
176
- }
177
- async init(options) {
178
- const {
179
- name
180
- } = options;
181
- if (name) {
182
- await this.projectService.cdProject(name);
174
+ async build() {
175
+ const exists = await this.dockerService.imageExists("ws-localtunnel");
176
+ if (!exists) {
177
+ await this.dockerService.buildImage({
178
+ tag: "ws-localtunnel",
179
+ context: this.pluginPath(),
180
+ src: "./Dockerfile"
181
+ });
182
+ }
183
183
  }
184
- const project = await this.projectService.get();
185
- const enabled = await (0, _utils.promptConfirm)({
186
- message: "Enable localtunnel?",
187
- default: project.getEnv("LOCALTUNNEL_ENABLE", "false") === "true"
188
- });
189
- if (enabled) {
190
- const subdomain = await (0, _utils.promptText)({
191
- message: "Subdomain",
192
- prefix: "https://",
193
- suffix: ".loca.lt",
194
- default: project.getEnv("LOCALTUNNEL_SUBDOMAIN")
195
- });
196
- if (!subdomain) {
197
- throw new Error("Subdomain can't be empty");
198
- }
199
- const autoConfirmIP = await (0, _utils.promptConfirm)({
200
- message: "Do you want to skip the IP confirmation form automatically?",
201
- default: project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "true") === "true"
202
- });
203
- project.setEnv("LOCALTUNNEL_ENABLE", "true");
204
- project.setEnv("LOCALTUNNEL_SUBDOMAIN", subdomain);
205
- project.setEnv("LOCALTUNNEL_AUTO_CONFIRM", autoConfirmIP ? "true" : "false");
206
- } else {
207
- project.setEnv("LOCALTUNNEL_ENABLE", "false");
184
+ async rebuild() {
185
+ try {
186
+ await this.dockerService.imageRm("ws-localtunnel");
187
+ }
188
+ catch (err) {
189
+ console.info(err.message);
190
+ }
191
+ await this.build();
208
192
  }
209
- await project.save();
210
- }
211
- async start(options) {
212
- const {
213
- name,
214
- detach
215
- } = options;
216
- if (name) {
217
- await this.projectService.cdProject(name);
193
+ async init(options) {
194
+ const { name } = options;
195
+ if (name) {
196
+ await this.projectService.cdProject(name);
197
+ }
198
+ const project = await this.projectService.get();
199
+ const enabled = await (0, utils_1.promptConfirm)({
200
+ message: "Enable localtunnel?",
201
+ default: project.getEnv("LOCALTUNNEL_ENABLE", "false") === "true"
202
+ });
203
+ if (enabled) {
204
+ const subdomain = await (0, utils_1.promptText)({
205
+ message: "Subdomain",
206
+ prefix: "https://",
207
+ suffix: ".loca.lt",
208
+ default: project.getEnv("LOCALTUNNEL_SUBDOMAIN")
209
+ });
210
+ if (!subdomain) {
211
+ throw new Error("Subdomain can't be empty");
212
+ }
213
+ const autoConfirmIP = await (0, utils_1.promptConfirm)({
214
+ message: "Do you want to skip the IP confirmation form automatically?",
215
+ default: project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "true") === "true"
216
+ });
217
+ project.setEnv("LOCALTUNNEL_ENABLE", "true");
218
+ project.setEnv("LOCALTUNNEL_SUBDOMAIN", subdomain);
219
+ project.setEnv("LOCALTUNNEL_AUTO_CONFIRM", autoConfirmIP ? "true" : "false");
220
+ }
221
+ else {
222
+ project.setEnv("LOCALTUNNEL_ENABLE", "false");
223
+ }
224
+ await project.save();
218
225
  }
219
- const project = await this.projectService.get();
220
- if (project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
221
- throw new Error(`Localtunnel is not initialized. Run "ws localtunnel:init${name ? ` -n=${name}` : ""}" first.`);
226
+ async start(options) {
227
+ const { name, detach } = options;
228
+ if (name) {
229
+ await this.projectService.cdProject(name);
230
+ }
231
+ const project = await this.projectService.get();
232
+ if (project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
233
+ throw new Error(`Localtunnel is not initialized. Run "ws localtunnel:init${name ? ` -n=${name}` : ""}" first.`);
234
+ }
235
+ await this.onProjectStart(project);
236
+ if (!detach) {
237
+ await this.logs({ name });
238
+ }
222
239
  }
223
- await this.onProjectStart(project);
224
- if (!detach) {
225
- await this.logs({
226
- name
227
- });
240
+ async stop(options) {
241
+ const { name } = options;
242
+ if (name) {
243
+ await this.projectService.cdProject(name);
244
+ }
245
+ const project = await this.projectService.get();
246
+ await this.onProjectStop(project);
228
247
  }
229
- }
230
- async stop(options) {
231
- const {
232
- name
233
- } = options;
234
- if (name) {
235
- await this.projectService.cdProject(name);
248
+ async restart(options) {
249
+ const { name } = options;
250
+ await this.stop({ name });
251
+ await this.start(options);
236
252
  }
237
- const project = await this.projectService.get();
238
- await this.onProjectStop(project);
239
- }
240
- async restart(options) {
241
- const {
242
- name
243
- } = options;
244
- await this.stop({
245
- name
246
- });
247
- await this.start(options);
248
- }
249
- async logs(options) {
250
- const {
251
- name
252
- // detach
253
- } = options;
254
- if (name) {
255
- await this.projectService.cdProject(name);
253
+ async logs(options) {
254
+ const { name, } = options;
255
+ if (name) {
256
+ await this.projectService.cdProject(name);
257
+ }
258
+ const project = await this.projectService.get();
259
+ const container = await this.dockerService.getContainer(`localtunnel-${project.name}`);
260
+ const stream = await container.logs({
261
+ follow: true,
262
+ stderr: true,
263
+ stdout: true,
264
+ tail: 5
265
+ });
266
+ stream.on("data", (data) => {
267
+ process.stdout.write(data);
268
+ });
269
+ stream.on("error", (data) => {
270
+ process.stderr.write(data);
271
+ });
256
272
  }
257
- const project = await this.projectService.get();
258
- const container = await _makes.Docker.getContainer(`localtunnel-${project.name}`);
259
- const stream = await container.logs({
260
- follow: true,
261
- stderr: true,
262
- stdout: true,
263
- tail: 5
264
- });
265
- stream.on("data", data => {
266
- process.stdout.write(data);
267
- });
268
- stream.on("error", data => {
269
- process.stderr.write(data);
270
- });
271
- }
272
273
  }
273
- exports.LocaltunnelPlugin = LocaltunnelPlugin;
274
+ exports.LocaltunnelPlugin = LocaltunnelPlugin;
@@ -1,8 +1,10 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
2
+ import { DI, Plugin } from "../makes";
3
+ import { DockerService } from "../services";
3
4
  declare class MaildevPlugin extends Plugin {
4
5
  protected containerName: string;
5
- constructor();
6
+ protected dockerService: DockerService;
7
+ constructor(di: DI);
6
8
  install(cli: Cli): void;
7
9
  start(): Promise<void>;
8
10
  stop(): Promise<void>;
@@ -1,45 +1,49 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.MaildevPlugin = void 0;
7
- var _makes = require("../makes");
8
- class MaildevPlugin extends _makes.Plugin {
9
- containerName = "maildev.workspace";
10
- constructor() {
11
- super("maildev");
12
- }
13
- install(cli) {
14
- super.install(cli);
15
- cli.command("maildev:start").action(() => this.start());
16
- cli.command("maildev:stop").action(() => this.stop());
17
- }
18
- async start() {
19
- console.log("Maildev starting...");
20
- const imageName = "ws-maildev";
21
- if (!(await _makes.Docker.imageExists(imageName))) {
22
- await _makes.Docker.imageBuild({
23
- tag: "ws-maildev",
24
- buildArgs: {},
25
- labels: {},
26
- context: this.pluginPath(),
27
- src: "./Dockerfile"
28
- });
4
+ const makes_1 = require("../makes");
5
+ const services_1 = require("../services");
6
+ class MaildevPlugin extends makes_1.Plugin {
7
+ constructor(di) {
8
+ super("maildev");
9
+ this.containerName = "maildev.workspace";
10
+ this.dockerService = di.resolveService(services_1.DockerService);
11
+ }
12
+ install(cli) {
13
+ super.install(cli);
14
+ cli.command("maildev:start")
15
+ .action(() => this.start());
16
+ cli.command("maildev:stop")
17
+ .action(() => this.stop());
18
+ }
19
+ async start() {
20
+ console.log("Maildev starting...");
21
+ const imageName = "ws-maildev";
22
+ if (!await this.dockerService.imageExists(imageName)) {
23
+ await this.dockerService.buildImage({
24
+ tag: "ws-maildev",
25
+ buildArgs: {},
26
+ labels: {},
27
+ context: this.pluginPath(),
28
+ src: "./Dockerfile"
29
+ });
30
+ }
31
+ let container = await this.dockerService.createContainer({
32
+ name: this.containerName,
33
+ restart: "always",
34
+ env: {
35
+ VIRTUAL_HOST: "maildev.workspace"
36
+ },
37
+ ports: [
38
+ "25:25"
39
+ ],
40
+ image: imageName
41
+ });
42
+ await container.start();
43
+ }
44
+ async stop() {
45
+ console.log("Maildev stopping...");
46
+ await this.dockerService.removeContainer(this.containerName);
29
47
  }
30
- await _makes.Docker.containerRun({
31
- name: this.containerName,
32
- restart: "always",
33
- env: {
34
- VIRTUAL_HOST: "maildev.workspace"
35
- },
36
- ports: ["25:25"],
37
- image: imageName
38
- });
39
- }
40
- async stop() {
41
- console.log("Maildev stopping...");
42
- await _makes.Docker.removeContainer(this.containerName);
43
- }
44
48
  }
45
- exports.MaildevPlugin = MaildevPlugin;
49
+ exports.MaildevPlugin = MaildevPlugin;
@@ -1,9 +1,11 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
2
+ import { DI, Plugin } from "../makes";
3
+ import { DockerService } from "../services";
3
4
  declare class MongodbPlugin extends Plugin {
4
- container: string;
5
- adminContainer: string;
6
- constructor();
5
+ protected container: string;
6
+ protected adminContainer: string;
7
+ protected dockerService: DockerService;
8
+ constructor(di: DI);
7
9
  install(cli: Cli): void;
8
10
  getDatabases(): Promise<string[]>;
9
11
  getDatabasesDumps(): Promise<string[]>;