@wocker/ws 1.0.1

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 (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +155 -0
  3. package/bin/ws.js +13 -0
  4. package/lib/App.d.ts +13 -0
  5. package/lib/App.js +52 -0
  6. package/lib/controllers/ImageController.d.ts +8 -0
  7. package/lib/controllers/ImageController.js +29 -0
  8. package/lib/controllers/ProjectController.d.ts +64 -0
  9. package/lib/controllers/ProjectController.js +561 -0
  10. package/lib/controllers/index.d.ts +2 -0
  11. package/lib/controllers/index.js +27 -0
  12. package/lib/env.d.ts +7 -0
  13. package/lib/env.js +24 -0
  14. package/lib/index.d.ts +3 -0
  15. package/lib/index.js +31 -0
  16. package/lib/makes/Controller.d.ts +5 -0
  17. package/lib/makes/Controller.js +12 -0
  18. package/lib/makes/Docker.d.ts +58 -0
  19. package/lib/makes/Docker.js +418 -0
  20. package/lib/makes/FS.d.ts +37 -0
  21. package/lib/makes/FS.js +317 -0
  22. package/lib/makes/LineConvertStream.d.ts +13 -0
  23. package/lib/makes/LineConvertStream.js +45 -0
  24. package/lib/makes/Logger.d.ts +7 -0
  25. package/lib/makes/Logger.js +39 -0
  26. package/lib/makes/Model.d.ts +5 -0
  27. package/lib/makes/Model.js +16 -0
  28. package/lib/makes/MySQL.d.ts +15 -0
  29. package/lib/makes/MySQL.js +31 -0
  30. package/lib/makes/Plugin.d.ts +13 -0
  31. package/lib/makes/Plugin.js +43 -0
  32. package/lib/makes/Repository.d.ts +11 -0
  33. package/lib/makes/Repository.js +25 -0
  34. package/lib/makes/index.d.ts +6 -0
  35. package/lib/makes/index.js +71 -0
  36. package/lib/models/Preset.d.ts +19 -0
  37. package/lib/models/Preset.js +60 -0
  38. package/lib/models/Project.d.ts +38 -0
  39. package/lib/models/Project.js +151 -0
  40. package/lib/models/index.d.ts +2 -0
  41. package/lib/models/index.js +27 -0
  42. package/lib/plugins/LocaltunnelPlugin.d.ts +36 -0
  43. package/lib/plugins/LocaltunnelPlugin.js +273 -0
  44. package/lib/plugins/MaildevPlugin.d.ts +10 -0
  45. package/lib/plugins/MaildevPlugin.js +45 -0
  46. package/lib/plugins/MariadbPlugin.d.ts +25 -0
  47. package/lib/plugins/MariadbPlugin.js +297 -0
  48. package/lib/plugins/MongodbPlugin.d.ts +20 -0
  49. package/lib/plugins/MongodbPlugin.js +271 -0
  50. package/lib/plugins/NgrokPlugin.d.ts +37 -0
  51. package/lib/plugins/NgrokPlugin.js +248 -0
  52. package/lib/plugins/PageKitePlugin.d.ts +31 -0
  53. package/lib/plugins/PageKitePlugin.js +158 -0
  54. package/lib/plugins/PostgresPlugin.d.ts +16 -0
  55. package/lib/plugins/PostgresPlugin.js +94 -0
  56. package/lib/plugins/PresetPlugin.d.ts +19 -0
  57. package/lib/plugins/PresetPlugin.js +164 -0
  58. package/lib/plugins/ProjectPlugin.d.ts +12 -0
  59. package/lib/plugins/ProjectPlugin.js +54 -0
  60. package/lib/plugins/ProxmoxPlugin.d.ts +9 -0
  61. package/lib/plugins/ProxmoxPlugin.js +55 -0
  62. package/lib/plugins/ProxyPlugin.d.ts +33 -0
  63. package/lib/plugins/ProxyPlugin.js +257 -0
  64. package/lib/plugins/RedisPlugin.d.ts +10 -0
  65. package/lib/plugins/RedisPlugin.js +42 -0
  66. package/lib/plugins/ServeoPlugin.d.ts +36 -0
  67. package/lib/plugins/ServeoPlugin.js +260 -0
  68. package/lib/plugins/TestPlugin.d.ts +10 -0
  69. package/lib/plugins/TestPlugin.js +75 -0
  70. package/lib/plugins/index.d.ts +14 -0
  71. package/lib/plugins/index.js +159 -0
  72. package/lib/services/AppConfigService.d.ts +18 -0
  73. package/lib/services/AppConfigService.js +77 -0
  74. package/lib/services/AppEventsService.d.ts +13 -0
  75. package/lib/services/AppEventsService.js +29 -0
  76. package/lib/services/ProjectService.d.ts +13 -0
  77. package/lib/services/ProjectService.js +91 -0
  78. package/lib/services/index.d.ts +3 -0
  79. package/lib/services/index.js +38 -0
  80. package/lib/types/Config.d.ts +11 -0
  81. package/lib/types/Config.js +5 -0
  82. package/lib/types/EnvConfig.d.ts +3 -0
  83. package/lib/types/EnvConfig.js +5 -0
  84. package/lib/types/index.d.ts +2 -0
  85. package/lib/types/index.js +27 -0
  86. package/lib/utils/buildOptions.d.ts +1 -0
  87. package/lib/utils/buildOptions.js +12 -0
  88. package/lib/utils/demuxOutput.d.ts +2 -0
  89. package/lib/utils/demuxOutput.js +25 -0
  90. package/lib/utils/escapeRegExp.d.ts +2 -0
  91. package/lib/utils/escapeRegExp.js +10 -0
  92. package/lib/utils/exec.d.ts +2 -0
  93. package/lib/utils/exec.js +44 -0
  94. package/lib/utils/fetch.d.ts +5 -0
  95. package/lib/utils/fetch.js +37 -0
  96. package/lib/utils/followProgress.d.ts +6 -0
  97. package/lib/utils/followProgress.js +80 -0
  98. package/lib/utils/format-size-units.d.ts +1 -0
  99. package/lib/utils/format-size-units.js +19 -0
  100. package/lib/utils/get-config.d.ts +2 -0
  101. package/lib/utils/get-config.js +20 -0
  102. package/lib/utils/get-cursor-position.d.ts +4 -0
  103. package/lib/utils/get-cursor-position.js +34 -0
  104. package/lib/utils/image-build.d.ts +13 -0
  105. package/lib/utils/image-build.js +34 -0
  106. package/lib/utils/index.d.ts +21 -0
  107. package/lib/utils/index.js +236 -0
  108. package/lib/utils/injectVariables.d.ts +5 -0
  109. package/lib/utils/injectVariables.js +17 -0
  110. package/lib/utils/parse-table.d.ts +2 -0
  111. package/lib/utils/parse-table.js +27 -0
  112. package/lib/utils/promptConfirm.d.ts +6 -0
  113. package/lib/utils/promptConfirm.js +21 -0
  114. package/lib/utils/promptGroup.d.ts +16 -0
  115. package/lib/utils/promptGroup.js +39 -0
  116. package/lib/utils/promptSelect.d.ts +12 -0
  117. package/lib/utils/promptSelect.js +47 -0
  118. package/lib/utils/promptText.d.ts +13 -0
  119. package/lib/utils/promptText.js +53 -0
  120. package/lib/utils/set-config.d.ts +2 -0
  121. package/lib/utils/set-config.js +18 -0
  122. package/lib/utils/spawn.d.ts +2 -0
  123. package/lib/utils/spawn.js +24 -0
  124. package/lib/utils/tty.d.ts +2 -0
  125. package/lib/utils/tty.js +10 -0
  126. package/lib/utils/volumeFormat.d.ts +6 -0
  127. package/lib/utils/volumeFormat.js +15 -0
  128. package/lib/utils/volumeParse.d.ts +2 -0
  129. package/lib/utils/volumeParse.js +16 -0
  130. package/package.json +90 -0
  131. package/plugins/localtunnel/Dockerfile +37 -0
  132. package/plugins/localtunnel/Ubuntu.dockerfile +34 -0
  133. package/plugins/localtunnel/config.json +3 -0
  134. package/plugins/maildev/Dockerfile +5 -0
  135. package/plugins/maildev/config.json +3 -0
  136. package/plugins/mariadb/admin/conf/config.user.inc.php +9 -0
  137. package/plugins/ngrok/Dockerfile +2 -0
  138. package/plugins/pagekite/Dockerfile +3 -0
  139. package/plugins/proxmox/Dockerfile +35 -0
  140. package/plugins/proxy/Dockerfile +7 -0
  141. package/plugins/proxy/config.json +3 -0
  142. package/plugins/serveo/Dockerfile +17 -0
  143. package/presets/apache/.docker/apache2/apache2.conf +230 -0
  144. package/presets/apache/.docker/apache2/mods-available/mpm_prefork.conf +16 -0
  145. package/presets/apache/.docker/apache2/sites-available/000-default.conf.conf +21 -0
  146. package/presets/apache/Dockerfile +110 -0
  147. package/presets/apache/bin/compare-version +3 -0
  148. package/presets/apache/config.json +47 -0
  149. package/presets/go/Dockerfile +19 -0
  150. package/presets/go/config.json +13 -0
  151. package/presets/node/Dockerfile +37 -0
  152. package/presets/node/config.json +36 -0
  153. package/presets/php-apache/Dockerfile +133 -0
  154. package/presets/php-apache/bin/compare-version +3 -0
  155. package/presets/php-apache/config.json +56 -0
  156. package/presets/php-apache/etc/apache2/apache2.conf +230 -0
  157. package/presets/php-apache/etc/apache2/mods-available/mpm_prefork.conf +16 -0
  158. package/presets/php-apache/etc/apache2/sites-available/000-default.conf +21 -0
  159. package/presets/shopify/Dockerfile +160 -0
  160. package/presets/shopify/bin/compare-version +3 -0
  161. package/presets/shopify/config.json +24 -0
  162. package/presets/shopify/etc/apache2/apache2.conf +230 -0
  163. package/presets/shopify/etc/apache2/mods-available/mpm_prefork.conf +16 -0
  164. package/presets/shopify/etc/apache2/sites-available/000-default.conf +21 -0
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NgrokPlugin = void 0;
7
+ var _makes = require("../makes");
8
+ var _utils = require("../utils");
9
+ class NgrokPlugin extends _makes.Plugin {
10
+ constructor(appEventsService, projectService) {
11
+ super("ngrok");
12
+ this.appEventsService = appEventsService;
13
+ this.projectService = projectService;
14
+ }
15
+ install(cli) {
16
+ super.install(cli);
17
+ this.appEventsService.on("project:start", project => this.onProjectStart(project));
18
+ this.appEventsService.on("project:stop", project => this.onProjectStop(project));
19
+ cli.command("ngrok:init").option("name", {
20
+ alias: "n",
21
+ type: "string",
22
+ description: "Project name"
23
+ }).action(options => this.init(options));
24
+ cli.command("ngrok:start").option("name", {
25
+ type: "string",
26
+ alias: "n",
27
+ description: "Project name"
28
+ }).option("detach", {
29
+ type: "boolean",
30
+ alias: "d",
31
+ description: "Detach"
32
+ }).action(options => this.start(options));
33
+ cli.command("ngrok:stop").option("name", {
34
+ type: "string",
35
+ alias: "n",
36
+ description: "Project name"
37
+ }).action(options => this.stop(options));
38
+ cli.command("ngrok:restart").option("name", {
39
+ type: "string",
40
+ alias: "n",
41
+ description: "Project name"
42
+ }).option("detach", {
43
+ type: "boolean",
44
+ alias: "d",
45
+ description: "Detach"
46
+ }).action(options => this.restart(options));
47
+ cli.command("ngrok:logs").option("name", {
48
+ type: "string",
49
+ alias: "n",
50
+ description: "Project name"
51
+ }).action(options => this.logs(options));
52
+ cli.command("ngrok:attach").option("name", {
53
+ type: "string",
54
+ alias: "n",
55
+ description: "Project name"
56
+ }).action(options => this.attach(options));
57
+ cli.command("ngrok:forwarding").option("name", {
58
+ type: "string",
59
+ alias: "n",
60
+ description: "Project name"
61
+ }).action(options => this.forwarding(options));
62
+ }
63
+ async init(options) {
64
+ const {
65
+ name
66
+ } = options;
67
+ if (name) {
68
+ await this.projectService.cdProject(name);
69
+ }
70
+ const project = await this.projectService.get();
71
+ const enable = await (0, _utils.promptConfirm)({
72
+ message: "Enable ngrok?",
73
+ default: true
74
+ });
75
+ if (enable) {
76
+ const token = await (0, _utils.promptText)({
77
+ message: "Token",
78
+ default: project.getEnv("NGROK_AUTHTOKEN")
79
+ });
80
+ project.setEnv("NGROK_AUTHTOKEN", token);
81
+ project.setEnv("NGROK_ENABLE", "true");
82
+ } else {
83
+ project.setEnv("NGROK_ENABLE", "false");
84
+ }
85
+ await project.save();
86
+ }
87
+ async getForwarding(project) {
88
+ const container = await _makes.Docker.getContainer(`ngrok-${project.name}`);
89
+ if (!container) {
90
+ throw new Error(`Ngrok for "${project.name}" not started`);
91
+ }
92
+ const {
93
+ NetworkSettings: {
94
+ Networks: {
95
+ workspace
96
+ }
97
+ }
98
+ } = await container.inspect();
99
+ const stream = await _makes.Docker.exec("proxy.workspace", ["curl", `http://${workspace.IPAddress}:4040/api/tunnels/command_line`], false);
100
+ const res = await new Promise((resolve, reject) => {
101
+ let res = "";
102
+ stream.on("data", data => {
103
+ res += (0, _utils.demuxOutput)(data).toString();
104
+ });
105
+ stream.on("end", () => resolve(res));
106
+ stream.on("error", reject);
107
+ });
108
+ const tunnel = JSON.parse(res);
109
+ return tunnel.public_url;
110
+ }
111
+ async onProjectStart(project) {
112
+ if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
113
+ return;
114
+ }
115
+ const container1 = await _makes.Docker.getContainer(`ngrok-${project.name}`);
116
+ if (container1) {
117
+ const {
118
+ State: {
119
+ Running
120
+ }
121
+ } = await container1.inspect();
122
+ if (Running) {
123
+ console.log("Ngrok is already running");
124
+ const forwarding = await this.getForwarding(project);
125
+ console.log(`Forwarding: ${forwarding}`);
126
+ return;
127
+ } else {
128
+ await _makes.Docker.removeContainer(`ngrok-${project.name}`);
129
+ }
130
+ }
131
+ console.log("Ngrok starting...");
132
+ _makes.Logger.info(`Ngrok start: ${project.name}`);
133
+ await _makes.Docker.pullImage("ngrok/ngrok:latest");
134
+ const container = await _makes.Docker.createContainer({
135
+ name: `ngrok-${project.name}`,
136
+ image: "ngrok/ngrok:latest",
137
+ tty: true,
138
+ restart: "always",
139
+ env: {
140
+ NGROK_AUTHTOKEN: project.getEnv("NGROK_AUTHTOKEN")
141
+ },
142
+ cmd: ["http", `${project.name}.workspace:80`]
143
+ });
144
+ const stream = await container.attach({
145
+ logs: true,
146
+ stream: true,
147
+ hijack: true,
148
+ stdin: true,
149
+ stdout: true,
150
+ stderr: true
151
+ });
152
+ stream.setEncoding("utf8");
153
+ await container.start();
154
+ await container.resize({
155
+ w: 90,
156
+ h: 40
157
+ });
158
+ await new Promise((resolve, reject) => {
159
+ stream.on("data", data => {
160
+ const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
161
+ if (regLink.test(data.toString())) {
162
+ const [link] = regLink.exec(data.toString());
163
+ if (link.includes(".ngrok")) {
164
+ _makes.Logger.info(`${project.name} forwarding: ${link}`);
165
+ console.log(`Forwarding: ${link}`);
166
+ stream.end();
167
+ }
168
+ }
169
+ });
170
+ stream.on("end", resolve);
171
+ stream.on("error", reject);
172
+ });
173
+ }
174
+ async onProjectStop(project) {
175
+ if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
176
+ return;
177
+ }
178
+ console.log("Ngrok stopping...");
179
+ await _makes.Docker.removeContainer(`ngrok-${project.name}`);
180
+ }
181
+ async start(options) {
182
+ const {
183
+ name,
184
+ detach
185
+ } = options;
186
+ if (name) {
187
+ await this.projectService.cdProject(name);
188
+ }
189
+ const project = await this.projectService.get();
190
+ await this.onProjectStart(project);
191
+ if (!detach) {
192
+ await _makes.Docker.attach(`ngrok-${project.name}`);
193
+ }
194
+ }
195
+ async stop(options) {
196
+ const {
197
+ name
198
+ } = options;
199
+ if (name) {
200
+ await this.projectService.cdProject(name);
201
+ }
202
+ const project = await this.projectService.get();
203
+ await this.onProjectStop(project);
204
+ }
205
+ async restart(options) {
206
+ const {
207
+ name
208
+ } = options;
209
+ await this.stop({
210
+ name
211
+ });
212
+ await this.start(options);
213
+ }
214
+ async logs(options) {
215
+ const {
216
+ name
217
+ } = options;
218
+ if (name) {
219
+ await this.projectService.cdProject(name);
220
+ }
221
+ const project = await this.projectService.get();
222
+ const container = await _makes.Docker.getContainer(`ngrok-${project.name}`);
223
+ if (!container) {
224
+ throw new Error("Ngrok not started");
225
+ }
226
+ }
227
+ async attach(options) {
228
+ const {
229
+ name
230
+ } = options;
231
+ if (name) {
232
+ await this.projectService.cdProject(name);
233
+ }
234
+ const project = await this.projectService.get();
235
+ await _makes.Docker.attach(`ngrok-${project.name}`);
236
+ }
237
+ async forwarding(options) {
238
+ const {
239
+ name
240
+ } = options;
241
+ if (name) {
242
+ await this.projectService.cdProject(name);
243
+ }
244
+ const project = await this.projectService.get();
245
+ return this.getForwarding(project);
246
+ }
247
+ }
248
+ exports.NgrokPlugin = NgrokPlugin;
@@ -0,0 +1,31 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Plugin } from "src/makes";
3
+ import { Project } from "src/models";
4
+ import { AppConfigService, AppEventsService, ProjectService } from "src/services";
5
+ type InitOptions = {};
6
+ type StartOptions = {
7
+ name?: string;
8
+ detach?: boolean;
9
+ restart?: boolean;
10
+ rebuild?: boolean;
11
+ };
12
+ type StopOptions = {
13
+ name?: string;
14
+ };
15
+ type BuildOptions = {
16
+ rebuild?: boolean;
17
+ };
18
+ declare class PageKitePlugin extends Plugin {
19
+ protected appConfigService: AppConfigService;
20
+ protected appEventsService: AppEventsService;
21
+ protected projectService: ProjectService;
22
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
23
+ install(cli: Cli): void;
24
+ onProjectStart(project: Project): Promise<void>;
25
+ onProjectStop(project: Project): Promise<void>;
26
+ init(options: InitOptions): Promise<void>;
27
+ start(options: StartOptions): Promise<void>;
28
+ stop(options: StopOptions): Promise<void>;
29
+ build(options?: BuildOptions): Promise<void>;
30
+ }
31
+ export { PageKitePlugin };
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PageKitePlugin = void 0;
7
+ var _makes = require("../makes");
8
+ var _utils = require("../utils");
9
+ class PageKitePlugin extends _makes.Plugin {
10
+ constructor(appConfigService, appEventsService, projectService) {
11
+ super("pagekite");
12
+ this.appConfigService = appConfigService;
13
+ this.appEventsService = appEventsService;
14
+ this.projectService = 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("pagekite:init").action(options => this.init(options));
21
+ cli.command("pagekite:start").option("name", {
22
+ type: "string",
23
+ alias: "n",
24
+ description: "Project name"
25
+ }).option("restart", {
26
+ type: "boolean",
27
+ alias: "r",
28
+ description: "Restart"
29
+ }).action(options => this.start(options));
30
+ cli.command("pagekite:stop").option("name", {
31
+ type: "string",
32
+ alias: "n",
33
+ description: "Project name"
34
+ }).action(options => this.stop(options));
35
+ cli.command("pagekite:build").option("rebuild", {
36
+ type: "boolean",
37
+ alias: "r",
38
+ description: "Rebuild"
39
+ }).action(options => this.build(options));
40
+ }
41
+ async onProjectStart(project) {
42
+ if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
43
+ return;
44
+ }
45
+ console.info("Pagekite starting...");
46
+ await this.build();
47
+ let container = await _makes.Docker.getContainer(`pagekite-${project.name}`);
48
+ if (container) {
49
+ const {
50
+ State: {
51
+ Running
52
+ }
53
+ } = await container.inspect();
54
+ if (Running) {
55
+ console.info("Pagekite is already running");
56
+ return;
57
+ } else {
58
+ await _makes.Docker.removeContainer(`pagekite-${project.name}`);
59
+ }
60
+ }
61
+ const subdomain = project.getEnv("PAGEKITE_SUBDOMAIN");
62
+ container = await _makes.Docker.createContainer({
63
+ name: `pagekite-${project.name}`,
64
+ image: "ws-pagekite",
65
+ tty: true,
66
+ restart: "always",
67
+ cmd: ["python", "pagekite.py", `${project.name}.workspace:80`, `${subdomain}.pagekite.me`]
68
+ });
69
+ await container.start();
70
+ await container.resize({
71
+ w: process.stdout.columns,
72
+ h: process.stdout.rows
73
+ });
74
+ const stream = await container.attach({
75
+ stream: true,
76
+ stdin: true,
77
+ stdout: true,
78
+ stderr: true,
79
+ hijack: true,
80
+ logs: true
81
+ });
82
+ stream.on("data", data => {
83
+ if (/Kites are flying and all is well\./.test(data.toString())) {
84
+ stream.end();
85
+ }
86
+ });
87
+ await _makes.Docker.attachStream(stream);
88
+ }
89
+ async onProjectStop(project) {
90
+ if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
91
+ return;
92
+ }
93
+ console.info("Pagekite stopping...");
94
+ await _makes.Docker.removeContainer(`pagekite-${project.name}`);
95
+ }
96
+ async init(options) {
97
+ const project = await this.projectService.get();
98
+ const enabled = await (0, _utils.promptConfirm)({
99
+ message: "Enable pagekite",
100
+ default: project.getEnv("PAGEKITE_ENABLE", "true") === "true"
101
+ });
102
+ if (enabled) {
103
+ project.setEnv("PAGEKITE_ENABLE", "true");
104
+ const subdomain = await (0, _utils.promptText)({
105
+ message: "Subdomain",
106
+ prefix: "https://",
107
+ suffix: ".pagekite.me",
108
+ default: project.getEnv("PAGEKITE_SUBDOMAIN", project.name)
109
+ });
110
+ project.setEnv("PAGEKITE_SUBDOMAIN", subdomain);
111
+ } else {
112
+ project.setEnv("PAGEKITE_ENABLE", "false");
113
+ }
114
+ await project.save();
115
+ }
116
+ async start(options) {
117
+ const {
118
+ name,
119
+ restart
120
+ } = options;
121
+ if (name) {
122
+ await this.projectService.cdProject(name);
123
+ }
124
+ const project = await this.projectService.get();
125
+ if (restart) {
126
+ await _makes.Docker.removeContainer(`pagekite-${project.name}`);
127
+ }
128
+ await this.onProjectStart(project);
129
+ }
130
+ async stop(options) {
131
+ const {
132
+ name
133
+ } = options;
134
+ if (name) {
135
+ await this.projectService.cdProject(name);
136
+ }
137
+ const project = await this.projectService.get();
138
+ await this.onProjectStop(project);
139
+ }
140
+ async build(options = {}) {
141
+ const {
142
+ rebuild
143
+ } = options;
144
+ const exists = await _makes.Docker.imageExists("ws-pagekite");
145
+ if (rebuild) {
146
+ await _makes.Docker.removeContainer("ws-pagekite");
147
+ }
148
+ if (!exists || rebuild) {
149
+ const stream = await _makes.Docker.imageBuild2({
150
+ tag: "ws-pagekite",
151
+ context: this.pluginPath(),
152
+ src: "./Dockerfile"
153
+ });
154
+ await (0, _utils.followProgress)(stream);
155
+ }
156
+ }
157
+ }
158
+ exports.PageKitePlugin = PageKitePlugin;
@@ -0,0 +1,16 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Plugin } from "src/makes";
3
+ declare class PostgresPlugin extends Plugin {
4
+ protected container: string;
5
+ protected adminContainer: string;
6
+ constructor();
7
+ install(cli: Cli): void;
8
+ start(): Promise<void>;
9
+ protected startDB(): Promise<void>;
10
+ protected startAdmin(): Promise<void>;
11
+ stop(): Promise<void>;
12
+ protected stopDB(): Promise<void>;
13
+ protected stopAdmin(): Promise<void>;
14
+ restart(): Promise<void>;
15
+ }
16
+ export { PostgresPlugin };
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PostgresPlugin = void 0;
7
+ var Path = _interopRequireWildcard(require("path"));
8
+ var _env = require("../env");
9
+ var _makes = require("../makes");
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+ class PostgresPlugin extends _makes.Plugin {
13
+ container = "postgres.workspace";
14
+ adminContainer = "dbadmin-postgres.workspace";
15
+ constructor() {
16
+ super("postgres");
17
+ this.dataDir = Path.join(_env.DATA_DIR, "db/postgres");
18
+ }
19
+ install(cli) {
20
+ super.install(cli);
21
+ cli.command("postgres:start").action(() => this.start());
22
+ cli.command("postgres:stop").action(() => this.stop());
23
+ cli.command("postgres:restart").action(() => this.restart());
24
+ }
25
+ async start() {
26
+ await this.startDB();
27
+ await this.startAdmin();
28
+ }
29
+ async startDB() {
30
+ console.log("Postgres starting...");
31
+ await _makes.Docker.pullImage("postgres:latest");
32
+ const container = await _makes.Docker.createContainer({
33
+ name: this.container,
34
+ restart: "always",
35
+ image: "postgres:latest",
36
+ volumes: [`${this.dataPath()}:/var/lib/postgresql/data`],
37
+ ports: ["5432:5432"],
38
+ env: {
39
+ POSTGRES_USER: "root",
40
+ POSTGRES_PASSWORD: "toor"
41
+ }
42
+ });
43
+ await container.start();
44
+ }
45
+ async startAdmin() {
46
+ console.log("Postgres Admin starting...");
47
+ await _makes.Docker.pullImage("dpage/pgadmin4:latest");
48
+ const container = await _makes.Docker.createContainer({
49
+ name: this.adminContainer,
50
+ restart: "always",
51
+ links: [`${this.container}:postgres`],
52
+ env: {
53
+ PGADMIN_DEFAULT_EMAIL: "postgres@workspace.com.ua",
54
+ PGADMIN_DEFAULT_PASSWORD: "toor",
55
+ VIRTUAL_HOST: this.adminContainer
56
+ },
57
+ image: "dpage/pgadmin4:latest"
58
+ });
59
+ await container.start();
60
+ }
61
+ async stop() {
62
+ await this.stopDB();
63
+ await this.stopAdmin();
64
+ }
65
+ async stopDB() {
66
+ console.log("Postgres stopping...");
67
+ const container = await _makes.Docker.getContainer(this.container);
68
+ if (container) {
69
+ try {
70
+ await container.stop();
71
+ await container.remove();
72
+ } catch (err) {
73
+ _makes.Logger.error(err.message);
74
+ }
75
+ }
76
+ }
77
+ async stopAdmin() {
78
+ console.log("Stopping postgres admin...");
79
+ const container = await _makes.Docker.getContainer(this.adminContainer);
80
+ if (container) {
81
+ try {
82
+ await container.stop();
83
+ await container.remove();
84
+ } catch (err) {
85
+ _makes.Logger.error(err.message);
86
+ }
87
+ }
88
+ }
89
+ async restart() {
90
+ await this.stop();
91
+ await this.start();
92
+ }
93
+ }
94
+ exports.PostgresPlugin = PostgresPlugin;
@@ -0,0 +1,19 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Plugin } from "src/makes";
3
+ import { Project } from "src/models";
4
+ import { AppConfigService, AppEventsService } from "src/services";
5
+ type BuildOptions = {
6
+ rebuild?: boolean;
7
+ };
8
+ declare class PresetPlugin extends Plugin {
9
+ protected appConfigService: AppConfigService;
10
+ protected appEventsService: AppEventsService;
11
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService);
12
+ install(cli: Cli): void;
13
+ presets(): Promise<string[]>;
14
+ protected onInit(project: Project): Promise<void>;
15
+ protected onRebuild(project: Project): Promise<void>;
16
+ protected onBeforeStart(project: Project): Promise<void>;
17
+ build(options: BuildOptions, presetName: string): Promise<void>;
18
+ }
19
+ export { PresetPlugin };