@wocker/ws 1.0.1 → 1.0.2

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 (98) hide show
  1. package/.github/workflows/publish.yml +31 -0
  2. package/README.md +11 -137
  3. package/bin/ws.js +7 -3
  4. package/lib/App.d.ts +7 -5
  5. package/lib/App.js +45 -11
  6. package/lib/controllers/ImageController.d.ts +3 -1
  7. package/lib/controllers/ImageController.js +3 -1
  8. package/lib/controllers/PluginController.d.ts +14 -0
  9. package/lib/controllers/PluginController.js +62 -0
  10. package/lib/controllers/PresetController.d.ts +19 -0
  11. package/lib/controllers/PresetController.js +150 -0
  12. package/lib/controllers/ProjectController.d.ts +13 -5
  13. package/lib/controllers/ProjectController.js +92 -25
  14. package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +9 -11
  15. package/lib/{plugins/ProxyPlugin.js → controllers/ProxyController.js} +120 -128
  16. package/lib/controllers/index.d.ts +3 -0
  17. package/lib/controllers/index.js +33 -0
  18. package/lib/env.js +9 -16
  19. package/lib/index.js +11 -24
  20. package/lib/makes/Docker.js +11 -25
  21. package/lib/makes/FS.d.ts +1 -1
  22. package/lib/makes/FS.js +13 -10
  23. package/lib/makes/Logger.d.ts +1 -7
  24. package/lib/makes/Logger.js +6 -33
  25. package/lib/makes/Plugin.js +2 -2
  26. package/lib/plugins/ElasticSearchPlugin.d.ts +16 -0
  27. package/lib/plugins/ElasticSearchPlugin.js +72 -0
  28. package/lib/plugins/LocaltunnelPlugin.d.ts +3 -3
  29. package/lib/plugins/LocaltunnelPlugin.js +17 -15
  30. package/lib/plugins/MaildevPlugin.d.ts +3 -1
  31. package/lib/plugins/MaildevPlugin.js +8 -5
  32. package/lib/plugins/MongodbPlugin.d.ts +5 -3
  33. package/lib/plugins/MongodbPlugin.js +10 -16
  34. package/lib/plugins/NgrokPlugin.d.ts +2 -3
  35. package/lib/plugins/NgrokPlugin.js +7 -6
  36. package/lib/plugins/PageKitePlugin.d.ts +2 -3
  37. package/lib/plugins/PageKitePlugin.js +8 -6
  38. package/lib/plugins/PostgresPlugin.js +5 -4
  39. package/lib/plugins/ProxmoxPlugin.js +2 -2
  40. package/lib/plugins/RedisPlugin.d.ts +8 -2
  41. package/lib/plugins/RedisPlugin.js +57 -20
  42. package/lib/plugins/index.d.ts +2 -6
  43. package/lib/plugins/index.js +11 -66
  44. package/lib/services/AppConfigService.d.ts +14 -4
  45. package/lib/services/AppConfigService.js +88 -3
  46. package/lib/services/AppEventsService.d.ts +5 -8
  47. package/lib/services/AppEventsService.js +2 -3
  48. package/lib/services/DockerService.d.ts +16 -0
  49. package/lib/services/DockerService.js +220 -0
  50. package/lib/services/LogService.d.ts +11 -0
  51. package/lib/services/LogService.js +39 -0
  52. package/lib/services/PluginService.d.ts +10 -0
  53. package/lib/services/PluginService.js +18 -0
  54. package/lib/services/PresetService.d.ts +9 -0
  55. package/lib/services/PresetService.js +63 -0
  56. package/lib/services/ProjectService.d.ts +8 -7
  57. package/lib/services/ProjectService.js +64 -12
  58. package/lib/services/index.d.ts +4 -0
  59. package/lib/services/index.js +44 -0
  60. package/lib/utils/demuxOutput.js +0 -2
  61. package/lib/utils/exec.d.ts +1 -1
  62. package/lib/utils/exec.js +4 -5
  63. package/lib/utils/fetch.js +3 -4
  64. package/lib/utils/image-build.js +2 -2
  65. package/lib/utils/index.d.ts +0 -4
  66. package/lib/utils/index.js +0 -44
  67. package/lib/utils/injectVariables.js +1 -1
  68. package/package.json +13 -13
  69. package/presets/node/config.json +9 -7
  70. package/presets/php-apache/Dockerfile +37 -36
  71. package/presets/php-apache/config.json +10 -15
  72. package/presets/php-fpm/Dockerfile +21 -0
  73. package/presets/php-fpm/config.json +25 -0
  74. package/lib/models/Preset.d.ts +0 -19
  75. package/lib/models/Preset.js +0 -60
  76. package/lib/models/Project.d.ts +0 -38
  77. package/lib/models/Project.js +0 -151
  78. package/lib/models/index.d.ts +0 -2
  79. package/lib/models/index.js +0 -27
  80. package/lib/plugins/MariadbPlugin.d.ts +0 -25
  81. package/lib/plugins/MariadbPlugin.js +0 -297
  82. package/lib/plugins/PresetPlugin.d.ts +0 -19
  83. package/lib/plugins/PresetPlugin.js +0 -164
  84. package/lib/plugins/ProjectPlugin.d.ts +0 -12
  85. package/lib/plugins/ProjectPlugin.js +0 -54
  86. package/lib/plugins/ServeoPlugin.d.ts +0 -36
  87. package/lib/plugins/ServeoPlugin.js +0 -260
  88. package/lib/plugins/TestPlugin.d.ts +0 -10
  89. package/lib/plugins/TestPlugin.js +0 -75
  90. package/lib/utils/promptConfirm.d.ts +0 -6
  91. package/lib/utils/promptConfirm.js +0 -21
  92. package/lib/utils/promptGroup.d.ts +0 -16
  93. package/lib/utils/promptGroup.js +0 -39
  94. package/lib/utils/promptSelect.d.ts +0 -12
  95. package/lib/utils/promptSelect.js +0 -47
  96. package/lib/utils/promptText.d.ts +0 -13
  97. package/lib/utils/promptText.js +0 -53
  98. package/plugins/serveo/Dockerfile +0 -17
@@ -4,23 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ProjectController = void 0;
7
+ var _core = require("@wocker/core");
8
+ var _utils = require("@wocker/utils");
7
9
  var _cliTable = _interopRequireDefault(require("cli-table3"));
8
10
  var _chalk = _interopRequireDefault(require("chalk"));
9
11
  var Path = _interopRequireWildcard(require("path"));
10
12
  var _asyncMutex = require("async-mutex");
11
13
  var _env = require("../env");
12
14
  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; }
15
+ var _utils2 = require("../utils");
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19
  class ProjectController extends _makes.Controller {
19
- constructor(appConfigService, appEventsService, projectService) {
20
+ constructor(di) {
20
21
  super();
21
- this.appConfigService = appConfigService;
22
- this.appEventsService = appEventsService;
23
- this.projectService = projectService;
22
+ this.di = di;
23
+ this.appConfigService = this.di.resolveService(_core.AppConfigService);
24
+ this.appEventsService = this.di.resolveService(_core.AppEventsService);
25
+ this.projectService = this.di.resolveService(_core.ProjectService);
26
+ this.dockerService = this.di.resolveService(_core.DockerService);
24
27
  }
25
28
  install(cli) {
26
29
  super.install(cli);
@@ -40,6 +43,11 @@ class ProjectController extends _makes.Controller {
40
43
  description: "Preset",
41
44
  default: ""
42
45
  }).action(options => this.init(options));
46
+ cli.command("ps").option("all", {
47
+ type: "boolean",
48
+ alias: "a",
49
+ description: "All projects"
50
+ }).action(options => this.projectList(options));
43
51
  cli.command("start").help({
44
52
  description: "Run project"
45
53
  }).option("name", {
@@ -56,6 +64,7 @@ class ProjectController extends _makes.Controller {
56
64
  type: "string",
57
65
  alias: "n"
58
66
  }).completion("name", () => this.getProjectNames()).action(options => this.stop(options));
67
+ cli.command("run <script>").completion("script", options => this.getScripts()).action((options, script) => this.run(script));
59
68
  cli.command("attach").option("name", {
60
69
  type: "string",
61
70
  alias: "n"
@@ -139,17 +148,25 @@ class ProjectController extends _makes.Controller {
139
148
  }).completion("name", () => this.getProjectNames()).action((options, command) => this.exec(options, command));
140
149
  }
141
150
  async getProjectNames() {
142
- const projects = await _models.Project.search();
151
+ const projects = await _core.Project.search();
143
152
  return projects.map(project => {
144
153
  return project.name;
145
154
  });
146
155
  }
156
+ async getScripts() {
157
+ try {
158
+ const project = await this.projectService.get();
159
+ return Object.keys(project.scripts || {});
160
+ } catch (ignore) {
161
+ return [];
162
+ }
163
+ }
147
164
  async init(options) {
148
- let project = await _models.Project.searchOne({
149
- src: this.appConfigService.getPWD()
165
+ let project = await _core.Project.searchOne({
166
+ path: this.appConfigService.getPWD()
150
167
  });
151
168
  if (!project) {
152
- project = new _models.Project();
169
+ project = new _core.Project({});
153
170
  }
154
171
  if (options.name) {
155
172
  project.name = options.name;
@@ -158,7 +175,7 @@ class ProjectController extends _makes.Controller {
158
175
  project.name = await (0, _utils.promptText)({
159
176
  type: "string",
160
177
  required: true,
161
- label: "Project name",
178
+ message: "Project name",
162
179
  default: project.name
163
180
  });
164
181
  }
@@ -174,7 +191,7 @@ class ProjectController extends _makes.Controller {
174
191
  });
175
192
  }
176
193
  switch (project.type) {
177
- case _models.PROJECT_TYPE_DOCKERFILE:
194
+ case _core.PROJECT_TYPE_DOCKERFILE:
178
195
  {
179
196
  const files = await _makes.FS.readdirFiles(this.appConfigService.getPWD());
180
197
  const dockerfiles = files.filter(fileName => {
@@ -194,7 +211,7 @@ class ProjectController extends _makes.Controller {
194
211
  });
195
212
  break;
196
213
  }
197
- case _models.PROJECT_TYPE_IMAGE:
214
+ case _core.PROJECT_TYPE_IMAGE:
198
215
  {
199
216
  project.imageName = await (0, _utils.promptText)({
200
217
  message: "Image Name",
@@ -209,6 +226,32 @@ class ProjectController extends _makes.Controller {
209
226
  project.path = this.appConfigService.getPWD();
210
227
  await project.save();
211
228
  }
229
+ async projectList(options) {
230
+ const {
231
+ all
232
+ } = options;
233
+ const table = new _cliTable.default({
234
+ head: ["Name", "Type", "Status"],
235
+ colAligns: ["left", "center", "center"]
236
+ });
237
+ const projects = await this.projectService.search({});
238
+ for (const project of projects) {
239
+ const container = await this.dockerService.getContainer(`${project.name}.workspace`);
240
+ if (!container) {
241
+ if (all) {
242
+ table.push([project.name, project.type, "-"]);
243
+ }
244
+ continue;
245
+ }
246
+ const {
247
+ State: {
248
+ Status = "stopped"
249
+ } = {}
250
+ } = await container.inspect();
251
+ table.push([project.name, project.type, Status]);
252
+ }
253
+ return table.toString() + "\n";
254
+ }
212
255
  async start(options) {
213
256
  const {
214
257
  name,
@@ -218,11 +261,11 @@ class ProjectController extends _makes.Controller {
218
261
  if (name) {
219
262
  await this.projectService.cdProject(name);
220
263
  }
264
+ const project = await this.projectService.get();
221
265
  if (rebuild) {
222
- const project = await this.projectService.get();
223
266
  await this.appEventsService.emit("project:rebuild", project);
224
267
  }
225
- await this.projectService.start();
268
+ await this.projectService.start(project);
226
269
  if (!detach) {
227
270
  const project = await this.projectService.get();
228
271
  const containerName = `${project.name}.workspace`;
@@ -241,7 +284,31 @@ class ProjectController extends _makes.Controller {
241
284
  if (name) {
242
285
  await this.projectService.cdProject(name);
243
286
  }
244
- await this.projectService.stop();
287
+ const project = await this.projectService.get();
288
+ await this.projectService.stop(project);
289
+ }
290
+ async run(script) {
291
+ const project = await this.projectService.get();
292
+ if (!project.scripts || !project.scripts[script]) {
293
+ throw new Error(`Script ${script} not found`);
294
+ }
295
+ const container = await this.dockerService.getContainer(`${project.name}.workspace`);
296
+ if (!container) {
297
+ throw new Error("The project is not started");
298
+ }
299
+ const exec = await container.exec({
300
+ Cmd: ["bash", "-i", "-c", project.scripts[script]],
301
+ AttachStdin: true,
302
+ AttachStdout: true,
303
+ AttachStderr: true,
304
+ Tty: process.stdin.isTTY
305
+ });
306
+ const stream = await exec.start({
307
+ hijack: true,
308
+ stdin: true,
309
+ Tty: process.stdin.isTTY
310
+ });
311
+ await this.dockerService.attachStream(stream);
245
312
  }
246
313
  async attach(options) {
247
314
  const {
@@ -266,7 +333,7 @@ class ProjectController extends _makes.Controller {
266
333
  const project = await this.projectService.get();
267
334
  env = project.env || {};
268
335
  } else {
269
- const config = await (0, _utils.getConfig)();
336
+ const config = await (0, _utils2.getConfig)();
270
337
  env = config.env || {};
271
338
  }
272
339
  const table = new _cliTable.default({
@@ -287,7 +354,7 @@ class ProjectController extends _makes.Controller {
287
354
  }
288
355
  let value = "";
289
356
  if (global) {
290
- const config = await (0, _utils.getConfig)();
357
+ const config = await (0, _utils2.getConfig)();
291
358
  value = config[key] || "";
292
359
  } else {
293
360
  const project = await this.projectService.get();
@@ -310,8 +377,8 @@ class ProjectController extends _makes.Controller {
310
377
  return env;
311
378
  }, {});
312
379
  if (global) {
313
- const config = await (0, _utils.getConfig)();
314
- await (0, _utils.setConfig)({
380
+ const config = await (0, _utils2.getConfig)();
381
+ await (0, _utils2.setConfig)({
315
382
  ...config,
316
383
  env: {
317
384
  ...(config.env || {}),
@@ -364,7 +431,7 @@ class ProjectController extends _makes.Controller {
364
431
  });
365
432
  const buildArgs = project.buildArgs || {};
366
433
  for (const i in buildArgs) {
367
- table.push([i, buildArgs[i]]);
434
+ table.push([i, typeof buildArgs[i] === "string" ? buildArgs[i] : JSON.stringify(buildArgs[i])]);
368
435
  }
369
436
  return table.toString() + "\n";
370
437
  }
@@ -535,7 +602,7 @@ class ProjectController extends _makes.Controller {
535
602
  follow: true
536
603
  });
537
604
  stream.on("data", data => {
538
- process.stdout.write((0, _utils.demuxOutput)(data));
605
+ process.stdout.write((0, _utils2.demuxOutput)(data));
539
606
  });
540
607
  } else {
541
608
  const buffer = await container.logs({
@@ -543,7 +610,7 @@ class ProjectController extends _makes.Controller {
543
610
  stderr: true,
544
611
  follow: false
545
612
  });
546
- process.stdout.write((0, _utils.demuxOutput)(buffer));
613
+ process.stdout.write((0, _utils2.demuxOutput)(buffer));
547
614
  }
548
615
  }
549
616
  async exec(options, command) {
@@ -1,7 +1,4 @@
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";
1
+ import { DI, AppConfigService, AppEventsService, ProjectService, DockerService, Controller, Cli, Project } from "@wocker/core";
5
2
  type InitOptions = {
6
3
  "http-port"?: number;
7
4
  "https-port"?: number;
@@ -9,25 +6,26 @@ type InitOptions = {
9
6
  type DomainsOptions = {
10
7
  name?: string;
11
8
  };
12
- declare class ProxyPlugin extends Plugin {
9
+ declare class ProxyController extends Controller {
10
+ protected containerName: string;
13
11
  protected appConfigService: AppConfigService;
14
12
  protected appEventsService: AppEventsService;
15
13
  protected projectService: ProjectService;
16
- protected containerName: string;
17
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
14
+ protected dockerService: DockerService;
15
+ constructor(di: DI);
18
16
  install(cli: Cli): void;
19
17
  getProjectNames(): Promise<string[]>;
20
18
  onProjectStart(project: Project): Promise<void>;
21
- createNetwork(): Promise<void>;
19
+ onProjectStop(project: Project): Promise<void>;
22
20
  init(options: InitOptions): Promise<void>;
23
21
  start(): Promise<void>;
24
22
  stop(): Promise<void>;
25
23
  restart(): Promise<void>;
26
- logs(): Promise<void>;
27
24
  domainList(options: DomainsOptions): Promise<string>;
25
+ setDomains(options: DomainsOptions, domains: string[]): Promise<void>;
28
26
  addDomain(options: DomainsOptions, addDomains: string[]): Promise<void>;
29
27
  removeDomain(options: DomainsOptions, removeDomains: string[]): Promise<void>;
30
- setDomains(options: DomainsOptions, domains: string[]): Promise<void>;
31
28
  clearDomains(options: DomainsOptions): Promise<void>;
29
+ logs(): Promise<void>;
32
30
  }
33
- export { ProxyPlugin };
31
+ export { ProxyController };
@@ -3,24 +3,27 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ProxyPlugin = void 0;
7
- var _chalk = _interopRequireDefault(require("chalk"));
6
+ exports.ProxyController = void 0;
7
+ var _core = require("@wocker/core");
8
+ var _utils = require("@wocker/utils");
8
9
  var _cliTable = _interopRequireDefault(require("cli-table3"));
10
+ var _chalk = _interopRequireDefault(require("chalk"));
9
11
  var _makes = require("../makes");
10
- var _models = require("../models");
11
- var _utils = require("../utils");
12
+ var _utils2 = require("../utils");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- class ProxyPlugin extends _makes.Plugin {
14
+ class ProxyController extends _core.Controller {
14
15
  containerName = "proxy.workspace";
15
- constructor(appConfigService, appEventsService, projectService) {
16
- super("proxy");
17
- this.appConfigService = appConfigService;
18
- this.appEventsService = appEventsService;
19
- this.projectService = projectService;
16
+ constructor(di) {
17
+ super();
18
+ this.appConfigService = di.resolveService(_core.AppConfigService);
19
+ this.appEventsService = di.resolveService(_core.AppEventsService);
20
+ this.projectService = di.resolveService(_core.ProjectService);
21
+ this.dockerService = di.resolveService(_core.DockerService);
20
22
  }
21
23
  install(cli) {
22
24
  super.install(cli);
23
25
  this.appEventsService.on("project:beforeStart", project => this.onProjectStart(project));
26
+ this.appEventsService.on("project:stop", project => this.onProjectStop(project));
24
27
  cli.command("proxy:init").option("http-port", {
25
28
  type: "number",
26
29
  description: "Http port"
@@ -31,70 +34,65 @@ class ProxyPlugin extends _makes.Plugin {
31
34
  cli.command("proxy:start").action(() => this.start());
32
35
  cli.command("proxy:stop").action(() => this.stop());
33
36
  cli.command("proxy:restart").action(() => this.restart());
34
- cli.command("proxy:logs").action(() => this.logs());
35
37
  cli.command("domains").option("name", {
36
38
  type: "string",
37
- alias: "n"
38
- }).completion("name", () => this.getProjectNames()).action(options => this.domainList(options));
39
+ alias: "n",
40
+ description: "Project name"
41
+ }).action(options => this.domainList(options));
42
+ cli.command("domain:set [...domains]").option("name", {
43
+ type: "string",
44
+ alias: "n",
45
+ description: "Project name"
46
+ }).completion("name", () => this.getProjectNames()).action((options, domains) => this.setDomains(options, domains));
39
47
  cli.command("domain:add [...domains]").option("name", {
40
48
  type: "string",
41
- alias: "n"
49
+ alias: "n",
50
+ description: "Project name"
42
51
  }).completion("name", () => this.getProjectNames()).action((options, domains) => this.addDomain(options, domains));
43
52
  cli.command("domain:remove [...domains]").option("name", {
44
53
  type: "string",
45
- alias: "n"
54
+ alias: "n",
55
+ description: "Project name"
46
56
  }).completion("name", () => this.getProjectNames()).action((options, domains) => this.removeDomain(options, domains));
47
- cli.command("domain:set [...domains]").option("name", {
48
- type: "string",
49
- alias: "n"
50
- }).completion("name", () => this.getProjectNames()).action((options, domains) => this.setDomains(options, domains));
51
57
  cli.command("domain:clear").option("name", {
52
58
  type: "string",
53
- alias: "n"
54
- }).action(options => this.clearDomains(options));
59
+ alias: "n",
60
+ description: "Project name"
61
+ }).completion("name", () => this.getProjectNames()).action(options => this.clearDomains(options));
62
+ cli.command("proxy:logs").action(() => this.logs());
55
63
  }
56
64
  async getProjectNames() {
57
- const projects = await _models.Project.search();
58
- return projects.map(project => {
59
- return project.name;
60
- });
65
+ const projects = await _core.Project.search();
66
+ return projects.map(project => project.name);
61
67
  }
62
68
  async onProjectStart(project) {
63
- await this.createNetwork();
64
- if (!project.getEnv("VIRTUAL_HOST")) {
69
+ if (!project.hasEnv("VIRTUAL_HOST")) {
65
70
  project.setEnv("VIRTUAL_HOST", `${project.name}.workspace`);
66
71
  }
72
+ await this.start();
67
73
  }
68
- async createNetwork() {
69
- const networks = await _makes.Docker.docker.listNetworks();
70
- const workspaceNetwork = networks.find(network => network.Name === "workspace");
71
- if (!workspaceNetwork) {
72
- console.info("Creating \"workspace\" network.");
73
- await _makes.Docker.docker.createNetwork({
74
- Name: "workspace"
75
- });
76
- }
74
+ async onProjectStop(project) {
75
+ //
77
76
  }
78
77
  async init(options) {
79
78
  let {
80
79
  "http-port": httpPort,
81
80
  "https-port": httpsPort
82
81
  } = options;
83
- _makes.Logger.log(typeof httpPort, typeof httpsPort);
84
82
  if (typeof httpPort === "undefined" || isNaN(httpPort)) {
85
83
  httpPort = await (0, _utils.promptText)({
86
84
  required: true,
87
- label: "Http port",
88
- type: "integer",
85
+ message: "Http port:",
86
+ type: "int",
89
87
  default: await this.appConfigService.getEnvVariable("PROXY_HTTP_PORT", "80")
90
88
  });
91
89
  }
92
90
  await this.appConfigService.setEnvVariable("PROXY_HTTP_PORT", httpPort);
93
- if (typeof httpsPort === "undefined" || httpsPort === null) {
91
+ if (typeof httpsPort === "undefined" || isNaN(httpsPort)) {
94
92
  httpsPort = await (0, _utils.promptText)({
95
93
  required: true,
96
- label: "Https port",
97
- type: "integer",
94
+ message: "Https port:",
95
+ type: "int",
98
96
  default: await this.appConfigService.getEnvVariable("PROXY_HTTPS_PORT", "443")
99
97
  });
100
98
  }
@@ -102,68 +100,55 @@ class ProxyPlugin extends _makes.Plugin {
102
100
  }
103
101
  async start() {
104
102
  console.info("Proxy starting...");
105
- await _makes.Docker.pullImage("nginxproxy/nginx-proxy");
103
+ await this.dockerService.pullImage("nginxproxy/nginx-proxy");
106
104
  const httpPort = await this.appConfigService.getEnvVariable("PROXY_HTTP_PORT", "80");
107
105
  const httpsPort = await this.appConfigService.getEnvVariable("PROXY_HTTPS_PORT", "443");
108
- const container = await _makes.Docker.createContainer({
109
- name: this.containerName,
110
- image: "nginxproxy/nginx-proxy",
111
- restart: "always",
112
- volumes: ["/var/run/docker.sock:/tmp/docker.sock:ro", `${this.certsPath()}:/etc/nginx/certs`],
113
- ports: [`${httpPort}:${httpPort}`, `${httpsPort}:${httpsPort}`],
114
- env: {
115
- DEFAULT_HOST: "index.workspace",
116
- HTTP_PORT: httpPort,
117
- HTTPS_PORT: httpsPort
106
+ let container = await this.dockerService.getContainer(this.containerName);
107
+ if (!container) {
108
+ const certsDir = this.appConfigService.dataPath("certs");
109
+ if (!_makes.FS.existsSync(certsDir)) {
110
+ _makes.FS.mkdirSync(certsDir, {
111
+ recursive: true
112
+ });
118
113
  }
119
- });
120
- await container.start();
114
+ container = await this.dockerService.createContainer({
115
+ name: this.containerName,
116
+ image: "nginxproxy/nginx-proxy",
117
+ volumes: ["/var/run/docker.sock:/tmp/docker.sock:ro", `${certsDir}:/etc/nginx/certs`],
118
+ ports: [`${httpPort}:80`, `${httpsPort}:443`],
119
+ env: {
120
+ DEFAULT_HOST: "index.workspace"
121
+ }
122
+ });
123
+ } else {
124
+ console.info("Container already exists");
125
+ }
126
+ const {
127
+ State: {
128
+ Status
129
+ }
130
+ } = await container.inspect();
131
+ if (["created", "exited"].includes(Status)) {
132
+ console.info("Starting...", Status);
133
+ await container.start();
134
+ }
121
135
  }
122
136
  async stop() {
123
137
  console.info("Proxy stopping...");
124
- const container = await _makes.Docker.getContainer(this.containerName);
125
- if (container) {
126
- try {
127
- await container.stop();
128
- } catch (err) {
129
- //
130
- }
131
- try {
132
- await container.remove();
133
- } catch (err) {
134
- //
135
- }
136
- }
138
+ await this.dockerService.removeContainer(this.containerName);
137
139
  }
138
140
  async restart() {
139
141
  await this.stop();
140
142
  await this.start();
141
143
  }
142
- async logs() {
143
- const container = await _makes.Docker.getContainer(this.containerName);
144
- if (container) {
145
- const stream = await container.logs({
146
- follow: true,
147
- stdout: true,
148
- stderr: true
149
- });
150
- stream.on("data", data => {
151
- process.stdout.write((0, _utils.demuxOutput)(data));
152
- });
153
- }
154
- }
155
144
  async domainList(options) {
156
145
  const {
157
146
  name
158
147
  } = options;
159
- const project = await _models.Project.searchOne(name ? {
160
- name
161
- } : {
162
- src: this.appConfigService.getPWD()
163
- });
164
- if (!project) {
165
- throw new Error("Project not found");
148
+ if (name) {
149
+ await this.projectService.cdProject(name);
166
150
  }
151
+ const project = await this.projectService.get();
167
152
  const table = new _cliTable.default({
168
153
  head: [_chalk.default.yellow("Domain")]
169
154
  });
@@ -171,9 +156,9 @@ class ProxyPlugin extends _makes.Plugin {
171
156
  for (const domain of domains) {
172
157
  table.push([domain]);
173
158
  }
174
- return table.toString();
159
+ return table.toString() + "\n";
175
160
  }
176
- async addDomain(options, addDomains) {
161
+ async setDomains(options, domains) {
177
162
  const {
178
163
  name
179
164
  } = options;
@@ -181,9 +166,22 @@ class ProxyPlugin extends _makes.Plugin {
181
166
  await this.projectService.cdProject(name);
182
167
  }
183
168
  const project = await this.projectService.get();
184
- if (!project) {
185
- throw new Error("Project not found");
169
+ project.setEnv("VIRTUAL_HOST", domains.join(","));
170
+ project.save();
171
+ const container = await this.dockerService.getContainer(`${project.name}.workspace`);
172
+ if (container) {
173
+ await this.projectService.stop(project);
174
+ await this.projectService.start(project);
175
+ }
176
+ }
177
+ async addDomain(options, addDomains) {
178
+ const {
179
+ name
180
+ } = options;
181
+ if (name) {
182
+ await this.projectService.cdProject(name);
186
183
  }
184
+ const project = await this.projectService.get();
187
185
  let domains = project.getEnv("VIRTUAL_HOST", "").split(",").filter(domain => {
188
186
  return !!domain;
189
187
  });
@@ -194,47 +192,26 @@ class ProxyPlugin extends _makes.Plugin {
194
192
  })];
195
193
  project.setEnv("VIRTUAL_HOST", domains.join(","));
196
194
  await project.save();
197
- const container = await _makes.Docker.getContainer(`${project.name}.workspace`);
195
+ const container = await this.dockerService.getContainer(`${project.name}.workspace`);
198
196
  if (container) {
199
- await this.projectService.stop();
200
- await this.projectService.start();
197
+ await this.projectService.stop(project);
198
+ await this.projectService.start(project);
201
199
  }
202
200
  }
203
201
  async removeDomain(options, removeDomains) {
204
202
  const {
205
203
  name
206
204
  } = options;
207
- const project = await _models.Project.searchOne(name ? {
208
- name
209
- } : {
210
- src: this.appConfigService.getPWD()
211
- });
212
- if (!project) {
213
- throw new Error("Project not found");
205
+ if (name) {
206
+ await this.projectService.cdProject(name);
214
207
  }
208
+ const project = await this.projectService.get();
215
209
  let domains = project.getEnv("VIRTUAL_HOST", "").split(",").filter(domain => {
216
210
  return !!domain;
217
211
  });
218
212
  domains = domains.filter(domain => {
219
- return !removeDomains.find(removeDomain => {
220
- return removeDomain === domain;
221
- });
222
- });
223
- project.setEnv("VIRTUAL_HOST", domains.join(","));
224
- await project.save();
225
- }
226
- async setDomains(options, domains) {
227
- const {
228
- name
229
- } = options;
230
- const project = await _models.Project.searchOne(name ? {
231
- name
232
- } : {
233
- src: this.appConfigService.getPWD()
213
+ return !removeDomains.includes(domain);
234
214
  });
235
- if (!project) {
236
- throw new Error("Project not found");
237
- }
238
215
  project.setEnv("VIRTUAL_HOST", domains.join(","));
239
216
  await project.save();
240
217
  }
@@ -242,16 +219,31 @@ class ProxyPlugin extends _makes.Plugin {
242
219
  const {
243
220
  name
244
221
  } = options;
245
- const project = await _models.Project.searchOne(name ? {
246
- name
247
- } : {
248
- src: this.appConfigService.getPWD()
249
- });
250
- if (!project) {
251
- throw new Error("Project not found");
222
+ if (name) {
223
+ await this.projectService.cdProject(name);
252
224
  }
225
+ const project = await this.projectService.get();
253
226
  project.unsetEnv("VIRTUAL_HOST");
254
227
  await project.save();
228
+ const container = await this.dockerService.getContainer(`${project.name}.workspace`);
229
+ if (container) {
230
+ await this.projectService.stop(project);
231
+ await this.projectService.start(project);
232
+ }
233
+ }
234
+ async logs() {
235
+ const container = await this.dockerService.getContainer(this.containerName);
236
+ if (!container) {
237
+ return;
238
+ }
239
+ const stream = await container.logs({
240
+ follow: true,
241
+ stdout: true,
242
+ stderr: true
243
+ });
244
+ stream.on("data", data => {
245
+ process.stdout.write((0, _utils2.demuxOutput)(data));
246
+ });
255
247
  }
256
248
  }
257
- exports.ProxyPlugin = ProxyPlugin;
249
+ exports.ProxyController = ProxyController;
@@ -1,2 +1,5 @@
1
1
  export * from "./ImageController";
2
+ export * from "./PluginController";
3
+ export * from "./PresetController";
2
4
  export * from "./ProjectController";
5
+ export * from "./ProxyController";