@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,18 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MongodbPlugin = void 0;
7
+ var _core = require("@wocker/core");
8
+ var _utils = require("@wocker/utils");
7
9
  var Path = _interopRequireWildcard(require("path"));
8
10
  var dateFns = _interopRequireWildcard(require("date-fns"));
9
11
  var _env = require("../env");
10
- var _utils = require("../utils");
11
12
  var _makes = require("../makes");
12
- 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); }
13
- 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; }
13
+ 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); }
14
+ 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; }
14
15
  class MongodbPlugin extends _makes.Plugin {
15
16
  container = "mongodb.workspace";
16
17
  adminContainer = "dbadmin-mongodb.workspace";
17
- constructor() {
18
+ constructor(di) {
18
19
  super("mongodb");
20
+ this.dockerService = di.resolveService(_core.DockerService);
19
21
  this.dataDir = Path.join(_env.DATA_DIR, "db/mongodb");
20
22
  }
21
23
  install(cli) {
@@ -88,7 +90,7 @@ class MongodbPlugin extends _makes.Plugin {
88
90
  async start() {
89
91
  console.log("Mongidb starting...");
90
92
  await _makes.Docker.pullImage("mongo:latest");
91
- const container = await _makes.Docker.createContainer({
93
+ const container = await this.dockerService.createContainer({
92
94
  name: this.container,
93
95
  restart: "always",
94
96
  image: "mongo:latest",
@@ -107,7 +109,7 @@ class MongodbPlugin extends _makes.Plugin {
107
109
  async startAdmin() {
108
110
  console.log("Mongodb Admin starting...");
109
111
  await _makes.Docker.pullImage("mongo-express:latest");
110
- const container = await _makes.Docker.createContainer({
112
+ const container = await this.dockerService.createContainer({
111
113
  name: this.adminContainer,
112
114
  restart: "always",
113
115
  env: {
@@ -134,7 +136,7 @@ class MongodbPlugin extends _makes.Plugin {
134
136
  }
135
137
  async stopDB() {
136
138
  console.log("Mongodb stopping...");
137
- const container = await _makes.Docker.getContainer(this.container);
139
+ const container = await this.dockerService.getContainer(this.container);
138
140
  if (container) {
139
141
  try {
140
142
  await container.stop();
@@ -146,15 +148,7 @@ class MongodbPlugin extends _makes.Plugin {
146
148
  }
147
149
  async stopAdmin() {
148
150
  console.log("Mongodb Admin stopping...");
149
- const container = await _makes.Docker.getContainer(this.adminContainer);
150
- if (container) {
151
- await container.stop().catch(() => {
152
- //
153
- });
154
- await container.remove().catch(() => {
155
- //
156
- });
157
- }
151
+ await this.dockerService.removeContainer(this.adminContainer);
158
152
  }
159
153
  async restart() {
160
154
  await this.stop();
@@ -1,7 +1,6 @@
1
+ import { DI, Project, AppEventsService, ProjectService } from "@wocker/core";
1
2
  import { Cli } from "@kearisp/cli";
2
3
  import { Plugin } from "src/makes";
3
- import { Project } from "src/models";
4
- import { AppEventsService, ProjectService } from "src/services";
5
4
  type StartOptions = {
6
5
  name?: string;
7
6
  detach?: string;
@@ -21,7 +20,7 @@ type ForwardingOptions = {
21
20
  declare class NgrokPlugin extends Plugin {
22
21
  protected appEventsService: AppEventsService;
23
22
  protected projectService: ProjectService;
24
- constructor(appEventsService: AppEventsService, projectService: ProjectService);
23
+ constructor(di: DI);
25
24
  install(cli: Cli): void;
26
25
  init(options: any): Promise<void>;
27
26
  getForwarding(project: Project): Promise<string | undefined>;
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.NgrokPlugin = void 0;
7
+ var _core = require("@wocker/core");
8
+ var _utils = require("@wocker/utils");
7
9
  var _makes = require("../makes");
8
- var _utils = require("../utils");
9
10
  class NgrokPlugin extends _makes.Plugin {
10
- constructor(appEventsService, projectService) {
11
+ constructor(di) {
11
12
  super("ngrok");
12
- this.appEventsService = appEventsService;
13
- this.projectService = projectService;
13
+ this.appEventsService = di.resolveService(_core.AppEventsService);
14
+ this.projectService = di.resolveService(_core.ProjectService);
14
15
  }
15
16
  install(cli) {
16
17
  super.install(cli);
@@ -129,7 +130,7 @@ class NgrokPlugin extends _makes.Plugin {
129
130
  }
130
131
  }
131
132
  console.log("Ngrok starting...");
132
- _makes.Logger.info(`Ngrok start: ${project.name}`);
133
+ _core.Logger.info(`Ngrok start: ${project.name}`);
133
134
  await _makes.Docker.pullImage("ngrok/ngrok:latest");
134
135
  const container = await _makes.Docker.createContainer({
135
136
  name: `ngrok-${project.name}`,
@@ -161,7 +162,7 @@ class NgrokPlugin extends _makes.Plugin {
161
162
  if (regLink.test(data.toString())) {
162
163
  const [link] = regLink.exec(data.toString());
163
164
  if (link.includes(".ngrok")) {
164
- _makes.Logger.info(`${project.name} forwarding: ${link}`);
165
+ _core.Logger.info(`${project.name} forwarding: ${link}`);
165
166
  console.log(`Forwarding: ${link}`);
166
167
  stream.end();
167
168
  }
@@ -1,7 +1,6 @@
1
+ import { DI, AppConfigService, AppEventsService, ProjectService, Project } from "@wocker/core";
1
2
  import { Cli } from "@kearisp/cli";
2
3
  import { Plugin } from "src/makes";
3
- import { Project } from "src/models";
4
- import { AppConfigService, AppEventsService, ProjectService } from "src/services";
5
4
  type InitOptions = {};
6
5
  type StartOptions = {
7
6
  name?: string;
@@ -19,7 +18,7 @@ declare class PageKitePlugin extends Plugin {
19
18
  protected appConfigService: AppConfigService;
20
19
  protected appEventsService: AppEventsService;
21
20
  protected projectService: ProjectService;
22
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
21
+ constructor(di: DI);
23
22
  install(cli: Cli): void;
24
23
  onProjectStart(project: Project): Promise<void>;
25
24
  onProjectStop(project: Project): Promise<void>;
@@ -4,14 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PageKitePlugin = void 0;
7
+ var _core = require("@wocker/core");
8
+ var _utils = require("@wocker/utils");
7
9
  var _makes = require("../makes");
8
- var _utils = require("../utils");
10
+ var _utils2 = require("../utils");
9
11
  class PageKitePlugin extends _makes.Plugin {
10
- constructor(appConfigService, appEventsService, projectService) {
12
+ constructor(di) {
11
13
  super("pagekite");
12
- this.appConfigService = appConfigService;
13
- this.appEventsService = appEventsService;
14
- this.projectService = projectService;
14
+ this.appConfigService = di.resolveService(_core.AppConfigService);
15
+ this.appEventsService = di.resolveService(_core.AppEventsService);
16
+ this.projectService = di.resolveService(_core.ProjectService);
15
17
  }
16
18
  install(cli) {
17
19
  super.install(cli);
@@ -151,7 +153,7 @@ class PageKitePlugin extends _makes.Plugin {
151
153
  context: this.pluginPath(),
152
154
  src: "./Dockerfile"
153
155
  });
154
- await (0, _utils.followProgress)(stream);
156
+ await (0, _utils2.followProgress)(stream);
155
157
  }
156
158
  }
157
159
  }
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PostgresPlugin = void 0;
7
+ var _core = require("@wocker/core");
7
8
  var Path = _interopRequireWildcard(require("path"));
8
9
  var _env = require("../env");
9
10
  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; }
11
+ 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); }
12
+ 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; }
12
13
  class PostgresPlugin extends _makes.Plugin {
13
14
  container = "postgres.workspace";
14
15
  adminContainer = "dbadmin-postgres.workspace";
@@ -70,7 +71,7 @@ class PostgresPlugin extends _makes.Plugin {
70
71
  await container.stop();
71
72
  await container.remove();
72
73
  } catch (err) {
73
- _makes.Logger.error(err.message);
74
+ _core.Logger.error(err.message);
74
75
  }
75
76
  }
76
77
  }
@@ -82,7 +83,7 @@ class PostgresPlugin extends _makes.Plugin {
82
83
  await container.stop();
83
84
  await container.remove();
84
85
  } catch (err) {
85
- _makes.Logger.error(err.message);
86
+ _core.Logger.error(err.message);
86
87
  }
87
88
  }
88
89
  }
@@ -7,8 +7,8 @@ exports.ProxmoxPlugin = void 0;
7
7
  var Path = _interopRequireWildcard(require("path"));
8
8
  var _makes = require("../makes");
9
9
  var _utils = require("../utils");
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; }
10
+ 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); }
11
+ 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; }
12
12
  class ProxmoxPlugin extends _makes.Plugin {
13
13
  constructor() {
14
14
  super("proxmox");
@@ -1,10 +1,16 @@
1
+ import { DI, AppConfigService, DockerService, Plugin, FSManager } from "@wocker/core";
1
2
  import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
3
3
  declare class RedisPlugin extends Plugin {
4
4
  protected container: string;
5
- constructor();
5
+ protected commander: string;
6
+ protected appConfigService: AppConfigService;
7
+ protected dockerService: DockerService;
8
+ protected fs: FSManager;
9
+ constructor(di: DI);
6
10
  install(cli: Cli): void;
7
11
  up(): Promise<void>;
12
+ protected startCommander(): Promise<void>;
8
13
  down(): Promise<void>;
14
+ protected stopCommander(): Promise<void>;
9
15
  }
10
16
  export { RedisPlugin };
@@ -4,11 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.RedisPlugin = void 0;
7
- var _makes = require("../makes");
8
- class RedisPlugin extends _makes.Plugin {
7
+ var _core = require("@wocker/core");
8
+ class RedisPlugin extends _core.Plugin {
9
9
  container = "redis.workspace";
10
- constructor() {
11
- super("redis");
10
+ commander = "redis-commander.workspace";
11
+ constructor(di) {
12
+ super();
13
+ this.appConfigService = di.resolveService(_core.AppConfigService);
14
+ this.dockerService = di.resolveService(_core.DockerService);
15
+ this.fs = new _core.FSManager(this.appConfigService.pluginsPath("redis"), this.appConfigService.dataPath("plugins/redis"));
12
16
  }
13
17
  install(cli) {
14
18
  super.install(cli);
@@ -17,26 +21,59 @@ class RedisPlugin extends _makes.Plugin {
17
21
  }
18
22
  async up() {
19
23
  console.log("Redis up...");
20
- await _makes.Docker.pullImage("redis");
21
- const container = await _makes.Docker.createContainer({
22
- name: this.container,
23
- restart: "always",
24
- env: {
25
- VIRTUAL_HOST: this.container
26
- },
27
- volumes: [`${this.dataPath()}:/data`],
28
- ports: ["6379:6379"],
29
- image: "redis"
30
- });
24
+ await this.dockerService.pullImage("redis");
25
+ let container = await this.dockerService.getContainer(this.container);
26
+ if (!container) {
27
+ await this.fs.mkdir("", {
28
+ recursive: true
29
+ });
30
+ container = await this.dockerService.createContainer({
31
+ name: this.container,
32
+ image: "redis",
33
+ restart: "always",
34
+ env: {
35
+ VIRTUAL_HOST: this.container
36
+ },
37
+ volumes: [`${this.fs.path()}:/data`],
38
+ ports: ["6379:6379"]
39
+ });
40
+ }
31
41
  await container.start();
42
+ await this.startCommander();
43
+ }
44
+ async startCommander() {
45
+ console.info("RedisCommander starting...");
46
+ let container = await this.dockerService.getContainer(this.commander);
47
+ if (!container) {
48
+ await this.dockerService.pullImage("rediscommander/redis-commander:latest");
49
+ container = await this.dockerService.createContainer({
50
+ name: this.commander,
51
+ image: "rediscommander/redis-commander:latest",
52
+ restart: "always",
53
+ env: {
54
+ VIRTUAL_HOST: this.commander,
55
+ VIRTUAL_PORT: "8081",
56
+ REDIS_HOSTS: this.container
57
+ }
58
+ });
59
+ }
60
+ const {
61
+ State: {
62
+ Status
63
+ }
64
+ } = await container.inspect();
65
+ if (Status === "created" || Status === "exited") {
66
+ await container.start();
67
+ }
32
68
  }
33
69
  async down() {
34
70
  console.log("Redis down...");
35
- const container = await _makes.Docker.getContainer(this.container);
36
- await container.stop().catch(() => {
37
- //
38
- });
39
- await container.remove();
71
+ await this.dockerService.removeContainer(this.container);
72
+ await this.stopCommander();
73
+ }
74
+ async stopCommander() {
75
+ console.info("RedisCommander stopping...");
76
+ await this.dockerService.removeContainer(this.commander);
40
77
  }
41
78
  }
42
79
  exports.RedisPlugin = RedisPlugin;
@@ -1,14 +1,10 @@
1
+ export * from "./ElasticSearchPlugin";
1
2
  export * from "./LocaltunnelPlugin";
2
3
  export * from "./MaildevPlugin";
3
- export * from "./MariadbPlugin";
4
4
  export * from "./MongodbPlugin";
5
5
  export * from "./NgrokPlugin";
6
6
  export * from "./PageKitePlugin";
7
7
  export * from "./PostgresPlugin";
8
- export * from "./PresetPlugin";
9
- export * from "./ProjectPlugin";
8
+ export * from "./PostgresPlugin";
10
9
  export * from "./ProxmoxPlugin";
11
- export * from "./ProxyPlugin";
12
10
  export * from "./RedisPlugin";
13
- export * from "./ServeoPlugin";
14
- export * from "./TestPlugin";
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _ElasticSearchPlugin = require("./ElasticSearchPlugin");
7
+ Object.keys(_ElasticSearchPlugin).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ElasticSearchPlugin[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ElasticSearchPlugin[key];
14
+ }
15
+ });
16
+ });
6
17
  var _LocaltunnelPlugin = require("./LocaltunnelPlugin");
7
18
  Object.keys(_LocaltunnelPlugin).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -25,17 +36,6 @@ Object.keys(_MaildevPlugin).forEach(function (key) {
25
36
  }
26
37
  });
27
38
  });
28
- var _MariadbPlugin = require("./MariadbPlugin");
29
- Object.keys(_MariadbPlugin).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _MariadbPlugin[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _MariadbPlugin[key];
36
- }
37
- });
38
- });
39
39
  var _MongodbPlugin = require("./MongodbPlugin");
40
40
  Object.keys(_MongodbPlugin).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
@@ -80,28 +80,6 @@ Object.keys(_PostgresPlugin).forEach(function (key) {
80
80
  }
81
81
  });
82
82
  });
83
- var _PresetPlugin = require("./PresetPlugin");
84
- Object.keys(_PresetPlugin).forEach(function (key) {
85
- if (key === "default" || key === "__esModule") return;
86
- if (key in exports && exports[key] === _PresetPlugin[key]) return;
87
- Object.defineProperty(exports, key, {
88
- enumerable: true,
89
- get: function () {
90
- return _PresetPlugin[key];
91
- }
92
- });
93
- });
94
- var _ProjectPlugin = require("./ProjectPlugin");
95
- Object.keys(_ProjectPlugin).forEach(function (key) {
96
- if (key === "default" || key === "__esModule") return;
97
- if (key in exports && exports[key] === _ProjectPlugin[key]) return;
98
- Object.defineProperty(exports, key, {
99
- enumerable: true,
100
- get: function () {
101
- return _ProjectPlugin[key];
102
- }
103
- });
104
- });
105
83
  var _ProxmoxPlugin = require("./ProxmoxPlugin");
106
84
  Object.keys(_ProxmoxPlugin).forEach(function (key) {
107
85
  if (key === "default" || key === "__esModule") return;
@@ -113,17 +91,6 @@ Object.keys(_ProxmoxPlugin).forEach(function (key) {
113
91
  }
114
92
  });
115
93
  });
116
- var _ProxyPlugin = require("./ProxyPlugin");
117
- Object.keys(_ProxyPlugin).forEach(function (key) {
118
- if (key === "default" || key === "__esModule") return;
119
- if (key in exports && exports[key] === _ProxyPlugin[key]) return;
120
- Object.defineProperty(exports, key, {
121
- enumerable: true,
122
- get: function () {
123
- return _ProxyPlugin[key];
124
- }
125
- });
126
- });
127
94
  var _RedisPlugin = require("./RedisPlugin");
128
95
  Object.keys(_RedisPlugin).forEach(function (key) {
129
96
  if (key === "default" || key === "__esModule") return;
@@ -134,26 +101,4 @@ Object.keys(_RedisPlugin).forEach(function (key) {
134
101
  return _RedisPlugin[key];
135
102
  }
136
103
  });
137
- });
138
- var _ServeoPlugin = require("./ServeoPlugin");
139
- Object.keys(_ServeoPlugin).forEach(function (key) {
140
- if (key === "default" || key === "__esModule") return;
141
- if (key in exports && exports[key] === _ServeoPlugin[key]) return;
142
- Object.defineProperty(exports, key, {
143
- enumerable: true,
144
- get: function () {
145
- return _ServeoPlugin[key];
146
- }
147
- });
148
- });
149
- var _TestPlugin = require("./TestPlugin");
150
- Object.keys(_TestPlugin).forEach(function (key) {
151
- if (key === "default" || key === "__esModule") return;
152
- if (key in exports && exports[key] === _TestPlugin[key]) return;
153
- Object.defineProperty(exports, key, {
154
- enumerable: true,
155
- get: function () {
156
- return _TestPlugin[key];
157
- }
158
- });
159
104
  });
@@ -1,18 +1,28 @@
1
+ import { AppConfigService as CoreAppConfigService, AppConfig, EnvConfig } from "@wocker/core";
1
2
  type TypeMap = {
2
3
  [type: string]: string;
3
4
  };
4
- declare class AppConfigService {
5
+ declare class AppConfigService extends CoreAppConfigService {
5
6
  protected pwd: string;
6
7
  protected mapTypes: TypeMap;
7
8
  constructor();
9
+ dataPath(...args: string[]): string;
10
+ pluginsPath(...args: string[]): string;
8
11
  getPWD(): string;
9
12
  setPWD(pwd: string): void;
10
- getAllEnvVariables(): Promise<any>;
11
- getEnvVariable(name: string, defaultValue?: string): Promise<any>;
13
+ getAppConfig(): Promise<AppConfig>;
14
+ private saveAppConfig;
15
+ getMeta(name: string, defaultValue?: string): Promise<string>;
16
+ setMeta(name: string, value?: string | number): Promise<void>;
17
+ getAllEnvVariables(): Promise<EnvConfig>;
18
+ getEnvVariable(name: string, defaultValue?: string): Promise<string>;
12
19
  setEnv(env: any): Promise<void>;
13
20
  setEnvVariable(name: string, value: string | number): Promise<void>;
14
21
  unsetEnv(...keys: string[]): Promise<void>;
15
- registerProjectType(name: string, title?: string): void;
16
22
  getProjectTypes(): TypeMap;
23
+ registerProjectType(name: string, title?: string): void;
24
+ setProjectConfig(id: string, path: string): Promise<void>;
25
+ activatePlugin(name: string): Promise<void>;
26
+ deactivatePlugin(name: string): Promise<void>;
17
27
  }
18
28
  export { AppConfigService };
@@ -4,22 +4,55 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AppConfigService = void 0;
7
+ var _core = require("@wocker/core");
8
+ var Path = _interopRequireWildcard(require("path"));
7
9
  var _env = require("../env");
8
10
  var _makes = require("../makes");
9
- class AppConfigService {
11
+ 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); }
12
+ 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; }
13
+ class AppConfigService extends _core.AppConfigService {
10
14
  mapTypes = {
11
15
  image: "Image",
12
16
  dockerfile: "Dockerfile"
13
17
  };
14
18
  constructor() {
19
+ super();
15
20
  this.pwd = process.cwd() || process.env.PWD;
16
21
  }
22
+ dataPath(...args) {
23
+ return Path.join(_env.DATA_DIR, ...args);
24
+ }
25
+ pluginsPath(...args) {
26
+ return Path.join(_env.PLUGINS_DIR, ...args);
27
+ }
17
28
  getPWD() {
18
29
  return this.pwd;
19
30
  }
20
31
  setPWD(pwd) {
21
32
  this.pwd = pwd;
22
33
  }
34
+ async getAppConfig() {
35
+ return _makes.FS.readJSON(_env.MAP_PATH);
36
+ }
37
+ async saveAppConfig(config) {
38
+ await _makes.FS.writeJSON(_env.MAP_PATH, config);
39
+ }
40
+ async getMeta(name, defaultValue) {
41
+ const config = await this.getAppConfig();
42
+ const value = (config.meta || {})[name];
43
+ if (!value) {
44
+ return defaultValue;
45
+ }
46
+ return value;
47
+ }
48
+ async setMeta(name, value) {
49
+ const config = await this.getAppConfig();
50
+ if (!config.meta) {
51
+ config.meta = {};
52
+ }
53
+ config.meta[name] = value ? value.toString() : undefined;
54
+ await this.saveAppConfig(config);
55
+ }
23
56
  async getAllEnvVariables() {
24
57
  const {
25
58
  env = {}
@@ -67,11 +100,63 @@ class AppConfigService {
67
100
  }, {})
68
101
  });
69
102
  }
103
+ getProjectTypes() {
104
+ return this.mapTypes;
105
+ }
70
106
  registerProjectType(name, title) {
71
107
  this.mapTypes[name] = title || name;
72
108
  }
73
- getProjectTypes() {
74
- return this.mapTypes;
109
+ async setProjectConfig(id, path) {
110
+ const {
111
+ projects,
112
+ ...rest
113
+ } = await this.getAppConfig();
114
+ await _makes.FS.writeJSON(_env.MAP_PATH, {
115
+ ...rest,
116
+ projects: [...(projects || []).filter(project => {
117
+ return project.id !== id;
118
+ }).filter(project => {
119
+ return project.src !== path;
120
+ }), {
121
+ id: id,
122
+ src: path
123
+ }]
124
+ });
125
+ }
126
+ async activatePlugin(name) {
127
+ const {
128
+ default: Plugin
129
+ } = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(name);
130
+
131
+ // this.use
132
+ if (!Plugin) {
133
+ throw new Error("No plugin");
134
+ }
135
+ const {
136
+ plugins = [],
137
+ ...rest
138
+ } = await this.getAppConfig();
139
+ await _makes.FS.writeJSON(_env.MAP_PATH, {
140
+ plugins: [...plugins.filter(plugin => {
141
+ return plugin !== name;
142
+ }), name],
143
+ ...rest
144
+ });
145
+ }
146
+ async deactivatePlugin(name) {
147
+ const {
148
+ plugins = [],
149
+ ...rest
150
+ } = await this.getAppConfig();
151
+ if (!plugins.includes(name)) {
152
+ return;
153
+ }
154
+ await _makes.FS.writeJSON(_env.MAP_PATH, {
155
+ plugins: plugins.filter(plugin => {
156
+ return plugin !== name;
157
+ }),
158
+ ...rest
159
+ });
75
160
  }
76
161
  }
77
162
  exports.AppConfigService = AppConfigService;
@@ -1,13 +1,10 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from "events";
3
- type EventHandle = (...args: any[]) => Promise<void> | void;
4
- declare class AppEventsService {
5
- protected emitter: EventEmitter;
1
+ import { AppEventsService as CoreAppEventsService, AppEventHandle } from "@wocker/core";
2
+ declare class AppEventsService extends CoreAppEventsService {
6
3
  protected handles: ({
7
- [event: string]: EventHandle[];
4
+ [event: string]: AppEventHandle[];
8
5
  });
9
- on(event: string, handle: EventHandle): () => void;
10
- off(event: string, handle: EventHandle): void;
6
+ on(event: string, handle: AppEventHandle): () => void;
7
+ off(event: string, handle: AppEventHandle): void;
11
8
  emit(event: string, ...args: any[]): Promise<void>;
12
9
  }
13
10
  export { AppEventsService };
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AppEventsService = void 0;
7
- var _events = require("events");
8
- class AppEventsService {
9
- emitter = new _events.EventEmitter();
7
+ var _core = require("@wocker/core");
8
+ class AppEventsService extends _core.AppEventsService {
10
9
  handles = {};
11
10
  on(event, handle) {
12
11
  this.handles[event] = [...(this.handles[event] || []), handle];