@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,561 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ProjectController = void 0;
7
+ var _cliTable = _interopRequireDefault(require("cli-table3"));
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ var Path = _interopRequireWildcard(require("path"));
10
+ var _asyncMutex = require("async-mutex");
11
+ var _env = require("../env");
12
+ var _makes = require("../makes");
13
+ var _models = require("../models");
14
+ var _utils = require("../utils");
15
+ 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); }
16
+ 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; }
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ class ProjectController extends _makes.Controller {
19
+ constructor(appConfigService, appEventsService, projectService) {
20
+ super();
21
+ this.appConfigService = appConfigService;
22
+ this.appEventsService = appEventsService;
23
+ this.projectService = projectService;
24
+ }
25
+ install(cli) {
26
+ super.install(cli);
27
+ cli.command("init").help({
28
+ description: "Init project"
29
+ }).option("name", {
30
+ type: "string",
31
+ description: "Ім'я контейнеру",
32
+ alias: "n"
33
+ }).option("type", {
34
+ type: "string",
35
+ description: "Тип запуску контейнеру"
36
+ }).completion("type", () => {
37
+ return [];
38
+ }).option("preset", {
39
+ type: "string",
40
+ description: "Preset",
41
+ default: ""
42
+ }).action(options => this.init(options));
43
+ cli.command("start").help({
44
+ description: "Run project"
45
+ }).option("name", {
46
+ type: "string",
47
+ alias: "n"
48
+ }).completion("name", () => this.getProjectNames()).option("rebuild", {
49
+ type: "boolean",
50
+ alias: "r"
51
+ }).option("detach", {
52
+ type: "boolean",
53
+ alias: "d"
54
+ }).action(options => this.start(options));
55
+ cli.command("stop").option("name", {
56
+ type: "string",
57
+ alias: "n"
58
+ }).completion("name", () => this.getProjectNames()).action(options => this.stop(options));
59
+ cli.command("attach").option("name", {
60
+ type: "string",
61
+ alias: "n"
62
+ }).completion("name", () => this.getProjectNames()).action(options => this.attach(options));
63
+ cli.command("config").option("name", {
64
+ type: "string",
65
+ alias: "n"
66
+ }).completion("name", () => this.getProjectNames()).option("global", {
67
+ type: "boolean",
68
+ alias: "g"
69
+ }).action(options => this.configList(options));
70
+ cli.command("config:get <key>").help({
71
+ description: "Get project env variable"
72
+ }).option("global", {
73
+ alias: "g",
74
+ description: "Global"
75
+ }).option("name", {
76
+ type: "string",
77
+ alias: "n"
78
+ }).completion("name", () => this.getProjectNames()).action((options, key) => this.configGet(options, key));
79
+ cli.command("config:set [...configs]").option("name", {
80
+ type: "string",
81
+ alias: "n"
82
+ }).option("global", {
83
+ type: "boolean",
84
+ alias: "g"
85
+ }).completion("name", () => this.getProjectNames()).action((options, configs) => this.configSet(options, configs));
86
+ cli.command("config:unset [...configs]").option("name", {
87
+ type: "string",
88
+ alias: "n"
89
+ }).completion("name", () => this.getProjectNames()).option("global", {
90
+ type: "boolean",
91
+ alias: "g"
92
+ }).action((options, configs) => this.configUnset(options, configs));
93
+ cli.command("build-args").option("name", {
94
+ type: "string",
95
+ alias: "n"
96
+ }).completion("name", () => this.getProjectNames()).action(options => this.buildArgsList(options));
97
+ cli.command("build-args:get [...buildArgs]").option("name", {
98
+ type: "string",
99
+ alias: "n"
100
+ }).completion("name", () => this.getProjectNames()).action((options, buildArgs) => this.buildArgsGet(options, buildArgs));
101
+ cli.command("build-args:set [...buildArgs]").option("name", {
102
+ type: "string",
103
+ alias: "n"
104
+ }).completion("name", () => this.getProjectNames()).action((options, buildArgs) => this.buildArgsSet(options, buildArgs));
105
+ cli.command("build-args:unset [...buildArgs]").option("name", {
106
+ type: "string",
107
+ alias: "n"
108
+ }).completion("name", () => this.getProjectNames()).action((options, buildArgs) => this.buildArgsUnset(options, buildArgs));
109
+ cli.command("volumes").option("name", {
110
+ type: "string",
111
+ alias: "n"
112
+ }).completion("name", () => this.getProjectNames()).action(options => this.volumeList(options));
113
+ cli.command("volume:mount <...volumes>").option("name", {
114
+ type: "string",
115
+ alias: "n"
116
+ }).completion("name", () => this.getProjectNames()).action((options, volumes) => this.volumeMount(options, volumes));
117
+ cli.command("volume:unmount <...volumes>").option("name", {
118
+ type: "string",
119
+ alias: "n"
120
+ }).completion("name", () => this.getProjectNames()).action((options, volumes) => this.volumeUnmount(options, volumes));
121
+ cli.command("logs").help({
122
+ description: "Logs"
123
+ }).option("name", {
124
+ type: "boolean",
125
+ alias: "n"
126
+ }).option("global", {
127
+ type: "boolean",
128
+ alias: "g"
129
+ }).option("follow", {
130
+ type: "boolean",
131
+ alias: "f"
132
+ }).option("detach", {
133
+ type: "boolean",
134
+ alias: "d"
135
+ }).completion("name", () => this.getProjectNames()).action(options => this.logs(options));
136
+ cli.command("exec [...command]").option("name", {
137
+ type: "string",
138
+ alias: "n"
139
+ }).completion("name", () => this.getProjectNames()).action((options, command) => this.exec(options, command));
140
+ }
141
+ async getProjectNames() {
142
+ const projects = await _models.Project.search();
143
+ return projects.map(project => {
144
+ return project.name;
145
+ });
146
+ }
147
+ async init(options) {
148
+ let project = await _models.Project.searchOne({
149
+ src: this.appConfigService.getPWD()
150
+ });
151
+ if (!project) {
152
+ project = new _models.Project();
153
+ }
154
+ if (options.name) {
155
+ project.name = options.name;
156
+ }
157
+ if (!options.name || !project.name) {
158
+ project.name = await (0, _utils.promptText)({
159
+ type: "string",
160
+ required: true,
161
+ label: "Project name",
162
+ default: project.name
163
+ });
164
+ }
165
+ if (options.type) {
166
+ project.type = options.type;
167
+ }
168
+ const mapTypes = this.appConfigService.getProjectTypes();
169
+ if (!options.type || !project.type || !mapTypes[project.type]) {
170
+ project.type = await (0, _utils.promptSelect)({
171
+ message: "Project type",
172
+ options: mapTypes,
173
+ default: project.type
174
+ });
175
+ }
176
+ switch (project.type) {
177
+ case _models.PROJECT_TYPE_DOCKERFILE:
178
+ {
179
+ const files = await _makes.FS.readdirFiles(this.appConfigService.getPWD());
180
+ const dockerfiles = files.filter(fileName => {
181
+ if (new RegExp("^(.*)\\.dockerfile$").test(fileName)) {
182
+ return true;
183
+ }
184
+ return new RegExp("^Dockerfile(\\..*)?").test(fileName);
185
+ });
186
+ project.dockerfile = await (0, _utils.promptSelect)({
187
+ options: dockerfiles.map(dockerfile => {
188
+ return {
189
+ value: dockerfile
190
+ };
191
+ }),
192
+ message: "Dockerfile",
193
+ default: project.dockerfile
194
+ });
195
+ break;
196
+ }
197
+ case _models.PROJECT_TYPE_IMAGE:
198
+ {
199
+ project.imageName = await (0, _utils.promptText)({
200
+ message: "Image Name",
201
+ default: project.imageName
202
+ });
203
+ break;
204
+ }
205
+ default:
206
+ break;
207
+ }
208
+ await this.appEventsService.emit("project:init", project);
209
+ project.path = this.appConfigService.getPWD();
210
+ await project.save();
211
+ }
212
+ async start(options) {
213
+ const {
214
+ name,
215
+ rebuild,
216
+ detach
217
+ } = options;
218
+ if (name) {
219
+ await this.projectService.cdProject(name);
220
+ }
221
+ if (rebuild) {
222
+ const project = await this.projectService.get();
223
+ await this.appEventsService.emit("project:rebuild", project);
224
+ }
225
+ await this.projectService.start();
226
+ if (!detach) {
227
+ const project = await this.projectService.get();
228
+ const containerName = `${project.name}.workspace`;
229
+ const container = await _makes.Docker.getContainer(containerName);
230
+ await container.resize({
231
+ w: process.stdout.columns,
232
+ h: process.stdout.rows
233
+ });
234
+ await _makes.Docker.attach(containerName);
235
+ }
236
+ }
237
+ async stop(options) {
238
+ const {
239
+ name
240
+ } = options;
241
+ if (name) {
242
+ await this.projectService.cdProject(name);
243
+ }
244
+ await this.projectService.stop();
245
+ }
246
+ async attach(options) {
247
+ const {
248
+ name
249
+ } = options;
250
+ if (name) {
251
+ await this.projectService.cdProject(name);
252
+ }
253
+ const containerName = `${name}.workspace`;
254
+ await _makes.Docker.attach(containerName);
255
+ }
256
+ async configList(options) {
257
+ const {
258
+ name,
259
+ global
260
+ } = options;
261
+ if (name) {
262
+ await this.projectService.cdProject(name);
263
+ }
264
+ let env = {};
265
+ if (!global) {
266
+ const project = await this.projectService.get();
267
+ env = project.env || {};
268
+ } else {
269
+ const config = await (0, _utils.getConfig)();
270
+ env = config.env || {};
271
+ }
272
+ const table = new _cliTable.default({
273
+ head: ["KEY", "VALUE"]
274
+ });
275
+ for (const i in env) {
276
+ table.push([i, env[i]]);
277
+ }
278
+ return table.toString() + "\n";
279
+ }
280
+ async configGet(options, key) {
281
+ const {
282
+ name,
283
+ global
284
+ } = options;
285
+ if (name) {
286
+ await this.projectService.cdProject(name);
287
+ }
288
+ let value = "";
289
+ if (global) {
290
+ const config = await (0, _utils.getConfig)();
291
+ value = config[key] || "";
292
+ } else {
293
+ const project = await this.projectService.get();
294
+ value = project.getEnv(key);
295
+ }
296
+ const table = new _cliTable.default({
297
+ head: ["KEY", "VALUE"]
298
+ });
299
+ table.push([key, value]);
300
+ return table.toString() + "\n";
301
+ }
302
+ async configSet(options, configs) {
303
+ const {
304
+ name,
305
+ global
306
+ } = options;
307
+ const env = configs.reduce((env, config) => {
308
+ const [key, value] = config.split("=");
309
+ env[key.trim()] = value.trim();
310
+ return env;
311
+ }, {});
312
+ if (global) {
313
+ const config = await (0, _utils.getConfig)();
314
+ await (0, _utils.setConfig)({
315
+ ...config,
316
+ env: {
317
+ ...(config.env || {}),
318
+ ...env
319
+ }
320
+ });
321
+ return;
322
+ }
323
+ if (name) {
324
+ await this.projectService.cdProject(name);
325
+ }
326
+ const project = await this.projectService.get();
327
+ for (const i in env) {
328
+ project.setEnv(i, env[i]);
329
+ }
330
+ await project.save();
331
+ }
332
+ async configUnset(options, configs) {
333
+ const {
334
+ name,
335
+ global
336
+ } = options;
337
+ const env = configs.reduce((env, config) => {
338
+ const [key] = config.split("=");
339
+ env[key.trim()] = null;
340
+ return env;
341
+ }, {});
342
+ if (global) {
343
+ return;
344
+ }
345
+ if (name) {
346
+ await this.projectService.cdProject(name);
347
+ }
348
+ const project = await this.projectService.get();
349
+ for (const i in env) {
350
+ project.unsetEnv(i);
351
+ }
352
+ await project.save();
353
+ }
354
+ async buildArgsList(options) {
355
+ const {
356
+ name
357
+ } = options;
358
+ if (name) {
359
+ await this.projectService.cdProject(name);
360
+ }
361
+ const project = await this.projectService.get();
362
+ const table = new _cliTable.default({
363
+ head: ["KEY", "VALUE"]
364
+ });
365
+ const buildArgs = project.buildArgs || {};
366
+ for (const i in buildArgs) {
367
+ table.push([i, buildArgs[i]]);
368
+ }
369
+ return table.toString() + "\n";
370
+ }
371
+ async buildArgsGet(options, args) {
372
+ const {
373
+ name
374
+ } = options;
375
+ if (name) {
376
+ await this.projectService.cdProject(name);
377
+ }
378
+ const project = await this.projectService.get();
379
+ const table = new _cliTable.default({
380
+ head: ["KEY", "VALUE"]
381
+ });
382
+ _makes.Logger.info("...");
383
+ for (const key of args) {
384
+ if (project.buildArgs && typeof project.buildArgs[key] !== "undefined") {
385
+ const value = project.buildArgs[key] || "";
386
+ table.push([key, value]);
387
+ }
388
+ }
389
+ return table.toString() + "\n";
390
+ }
391
+ async buildArgsSet(options, args) {
392
+ const {
393
+ name
394
+ } = options;
395
+ if (name) {
396
+ await this.projectService.cdProject(name);
397
+ }
398
+ const project = await this.projectService.get();
399
+ const buildArgs = args.reduce((env, config) => {
400
+ const [key, value] = config.split("=");
401
+ env[key.trim()] = value.trim();
402
+ return env;
403
+ }, {});
404
+ for (const key in buildArgs) {
405
+ if (!project.buildArgs) {
406
+ project.buildArgs = {};
407
+ }
408
+ project.buildArgs[key] = buildArgs[key];
409
+ }
410
+ await project.save();
411
+ }
412
+ async buildArgsUnset(options, args) {
413
+ const {
414
+ name
415
+ } = options;
416
+ if (name) {
417
+ await this.projectService.cdProject(name);
418
+ }
419
+ const project = await this.projectService.get();
420
+ const buildArgs = args.reduce((env, config) => {
421
+ const [key, value] = config.split("=");
422
+ env[key.trim()] = value.trim();
423
+ return env;
424
+ }, {});
425
+ for (const key in buildArgs) {
426
+ if (!project.buildArgs) {
427
+ break;
428
+ }
429
+ if (typeof project.buildArgs[key] !== "undefined") {
430
+ delete project.buildArgs[key];
431
+ }
432
+ }
433
+ await project.save();
434
+ }
435
+ async volumeList(options) {
436
+ const {
437
+ name
438
+ } = options;
439
+ if (name) {
440
+ await this.projectService.cdProject(name);
441
+ }
442
+ const project = await this.projectService.get();
443
+ const table = new _cliTable.default({
444
+ head: ["Volume"]
445
+ });
446
+ const volumes = project.volumes || [];
447
+ for (const volume of volumes) {
448
+ table.push([volume]);
449
+ }
450
+ return table.toString() + "\n";
451
+ }
452
+ async volumeMount(options, volumes) {
453
+ const {
454
+ name
455
+ } = options;
456
+ if (name) {
457
+ await this.projectService.cdProject(name);
458
+ }
459
+ const project = await this.projectService.get();
460
+ console.log(volumes);
461
+ project.volumeMount(...volumes);
462
+ await project.save();
463
+ }
464
+ async volumeUnmount(options, volumes) {
465
+ const {
466
+ name
467
+ } = options;
468
+ if (name) {
469
+ await this.projectService.cdProject(name);
470
+ }
471
+ const project = await this.projectService.get();
472
+ project.volumeUnmount(...volumes);
473
+ await project.save();
474
+ }
475
+ async logs(options) {
476
+ const {
477
+ name,
478
+ global,
479
+ detach,
480
+ follow
481
+ } = options;
482
+ if (global) {
483
+ const logFilepath = Path.join(_env.DATA_DIR, "ws.log");
484
+ const prepareLog = str => {
485
+ return str.replace(/^\[.*]\s([^:]+):\s.*$/gm, (substring, type) => {
486
+ switch (type) {
487
+ case "info":
488
+ return _chalk.default.green(substring);
489
+ case "warning":
490
+ return _chalk.default.yellow(substring);
491
+ case "error":
492
+ return _chalk.default.red(substring);
493
+ default:
494
+ return substring;
495
+ }
496
+ });
497
+ };
498
+ const stream = _makes.FS.createReadLinesStream(logFilepath, follow ? -10 : undefined);
499
+ stream.on("data", data => {
500
+ process.stdout.write(prepareLog(data.toString()));
501
+ process.stdout.write("\n");
502
+ });
503
+ if (follow) {
504
+ const stats = await _makes.FS.stat(logFilepath);
505
+ const watcher = _makes.FS.watch(logFilepath);
506
+ const mutex = new _asyncMutex.Mutex();
507
+ let position = BigInt(stats.size);
508
+ watcher.on("change", async () => {
509
+ await mutex.acquire();
510
+ try {
511
+ const stats = await _makes.FS.stat(logFilepath);
512
+ if (BigInt(stats.size) < position) {
513
+ console.log("file truncated");
514
+ position = 0n;
515
+ }
516
+ const buffer = await _makes.FS.readBytes(logFilepath, position);
517
+ position += BigInt(buffer.length);
518
+ process.stdout.write(prepareLog(buffer.toString("utf-8")));
519
+ } finally {
520
+ mutex.release();
521
+ }
522
+ });
523
+ }
524
+ return;
525
+ }
526
+ if (name) {
527
+ await this.projectService.cdProject(name);
528
+ }
529
+ const project = await this.projectService.get();
530
+ const container = await _makes.Docker.getContainer(`${project.name}.workspace`);
531
+ if (!detach) {
532
+ const stream = await container.logs({
533
+ stdout: true,
534
+ stderr: true,
535
+ follow: true
536
+ });
537
+ stream.on("data", data => {
538
+ process.stdout.write((0, _utils.demuxOutput)(data));
539
+ });
540
+ } else {
541
+ const buffer = await container.logs({
542
+ stdout: true,
543
+ stderr: true,
544
+ follow: false
545
+ });
546
+ process.stdout.write((0, _utils.demuxOutput)(buffer));
547
+ }
548
+ }
549
+ async exec(options, command) {
550
+ const {
551
+ name
552
+ } = options;
553
+ if (name) {
554
+ await this.projectService.cdProject(name);
555
+ }
556
+ const project = await this.projectService.get();
557
+ const containerName = `${project.name}.workspace`;
558
+ await _makes.Docker.exec(containerName, command);
559
+ }
560
+ }
561
+ exports.ProjectController = ProjectController;
@@ -0,0 +1,2 @@
1
+ export * from "./ImageController";
2
+ export * from "./ProjectController";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ImageController = require("./ImageController");
7
+ Object.keys(_ImageController).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ImageController[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ImageController[key];
14
+ }
15
+ });
16
+ });
17
+ var _ProjectController = require("./ProjectController");
18
+ Object.keys(_ProjectController).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _ProjectController[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _ProjectController[key];
25
+ }
26
+ });
27
+ });
package/lib/env.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare const NODE_ENV: string;
2
+ export declare const ROOT_DIR: string;
3
+ export declare const PRESETS_DIR: string;
4
+ export declare const SERVICES_DIR: string;
5
+ export declare const PLUGINS_DIR: string;
6
+ export declare const DATA_DIR: string;
7
+ export declare const MAP_PATH: string;
package/lib/env.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SERVICES_DIR = exports.ROOT_DIR = exports.PRESETS_DIR = exports.PLUGINS_DIR = exports.NODE_ENV = exports.MAP_PATH = exports.DATA_DIR = void 0;
7
+ var OS = _interopRequireWildcard(require("os"));
8
+ var Path = _interopRequireWildcard(require("path"));
9
+ 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); }
10
+ 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; }
11
+ const NODE_ENV = process.env.NODE_ENV;
12
+ exports.NODE_ENV = NODE_ENV;
13
+ const ROOT_DIR = Path.join(__dirname, "..");
14
+ exports.ROOT_DIR = ROOT_DIR;
15
+ const PRESETS_DIR = Path.join(ROOT_DIR, "presets");
16
+ exports.PRESETS_DIR = PRESETS_DIR;
17
+ const SERVICES_DIR = Path.join(ROOT_DIR, "services");
18
+ exports.SERVICES_DIR = SERVICES_DIR;
19
+ const PLUGINS_DIR = Path.join(ROOT_DIR, "plugins");
20
+ exports.PLUGINS_DIR = PLUGINS_DIR;
21
+ const DATA_DIR = process.env.WS_DIR || Path.join(OS.homedir(), ".workspace");
22
+ exports.DATA_DIR = DATA_DIR;
23
+ const MAP_PATH = Path.join(DATA_DIR, "data.json");
24
+ exports.MAP_PATH = MAP_PATH;
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { App } from "./App";
2
+ declare const app: App;
3
+ export { app };
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.app = void 0;
7
+ var _controllers = require("./controllers");
8
+ var _plugins = require("./plugins");
9
+ var _services = require("./services");
10
+ var _App = require("./App");
11
+ const appConfigService = new _services.AppConfigService();
12
+ const appEventsService = new _services.AppEventsService();
13
+ const projectService = new _services.ProjectService(appConfigService, appEventsService);
14
+ const app = new _App.App(appConfigService);
15
+ exports.app = app;
16
+ app.useController(new _controllers.ImageController());
17
+ app.useController(new _controllers.ProjectController(appConfigService, appEventsService, projectService));
18
+ app.usePlugin(new _plugins.LocaltunnelPlugin(appConfigService, appEventsService, projectService));
19
+ app.usePlugin(new _plugins.MaildevPlugin());
20
+ app.usePlugin(new _plugins.MariadbPlugin());
21
+ app.usePlugin(new _plugins.MongodbPlugin());
22
+ app.usePlugin(new _plugins.NgrokPlugin(appEventsService, projectService));
23
+ app.usePlugin(new _plugins.PageKitePlugin(appConfigService, appEventsService, projectService));
24
+ app.usePlugin(new _plugins.PostgresPlugin());
25
+ app.usePlugin(new _plugins.PresetPlugin(appConfigService, appEventsService));
26
+ app.usePlugin(new _plugins.ProxmoxPlugin());
27
+ app.usePlugin(new _plugins.ProxyPlugin(appConfigService, appEventsService, projectService));
28
+ app.usePlugin(new _plugins.ProjectPlugin());
29
+ app.usePlugin(new _plugins.RedisPlugin());
30
+ app.usePlugin(new _plugins.ServeoPlugin(appConfigService, appEventsService, projectService));
31
+ app.usePlugin(new _plugins.TestPlugin());
@@ -0,0 +1,5 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ declare class Controller {
3
+ install(cli: Cli): void;
4
+ }
5
+ export { Controller };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Controller = void 0;
7
+ class Controller {
8
+ install() {
9
+ // TODO: Do something on install
10
+ }
11
+ }
12
+ exports.Controller = Controller;