@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
@@ -14,6 +14,28 @@ Object.keys(_ImageController).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _PluginController = require("./PluginController");
18
+ Object.keys(_PluginController).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _PluginController[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _PluginController[key];
25
+ }
26
+ });
27
+ });
28
+ var _PresetController = require("./PresetController");
29
+ Object.keys(_PresetController).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _PresetController[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _PresetController[key];
36
+ }
37
+ });
38
+ });
17
39
  var _ProjectController = require("./ProjectController");
18
40
  Object.keys(_ProjectController).forEach(function (key) {
19
41
  if (key === "default" || key === "__esModule") return;
@@ -24,4 +46,15 @@ Object.keys(_ProjectController).forEach(function (key) {
24
46
  return _ProjectController[key];
25
47
  }
26
48
  });
49
+ });
50
+ var _ProxyController = require("./ProxyController");
51
+ Object.keys(_ProxyController).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _ProxyController[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _ProxyController[key];
58
+ }
59
+ });
27
60
  });
package/lib/env.js CHANGED
@@ -6,19 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
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
7
  var OS = _interopRequireWildcard(require("os"));
8
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;
9
+ 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); }
10
+ 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; }
11
+ const NODE_ENV = exports.NODE_ENV = process.env.NODE_ENV;
12
+ const ROOT_DIR = exports.ROOT_DIR = Path.join(__dirname, "..");
13
+ const PRESETS_DIR = exports.PRESETS_DIR = Path.join(ROOT_DIR, "presets");
14
+ const SERVICES_DIR = exports.SERVICES_DIR = Path.join(ROOT_DIR, "services");
15
+ const PLUGINS_DIR = exports.PLUGINS_DIR = Path.join(ROOT_DIR, "plugins");
16
+ const DATA_DIR = exports.DATA_DIR = process.env.WS_DIR || Path.join(OS.homedir(), ".workspace");
17
+ const MAP_PATH = exports.MAP_PATH = Path.join(DATA_DIR, "data.json");
package/lib/index.js CHANGED
@@ -4,28 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.app = void 0;
7
- var _controllers = require("./controllers");
8
- var _plugins = require("./plugins");
9
- var _services = require("./services");
10
7
  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());
8
+ var _plugins = require("./plugins");
9
+ const app = exports.app = new _App.App();
10
+ app.use(_plugins.ElasticSearchPlugin);
11
+ app.use(_plugins.LocaltunnelPlugin);
12
+ app.use(_plugins.MaildevPlugin);
13
+ app.use(_plugins.MongodbPlugin);
14
+ app.use(_plugins.NgrokPlugin);
15
+ app.use(_plugins.PageKitePlugin);
16
+ app.use(_plugins.PostgresPlugin);
17
+ app.use(_plugins.ProxmoxPlugin);
18
+ app.use(_plugins.RedisPlugin);
@@ -123,32 +123,7 @@ class Docker {
123
123
  return docker.getContainer(container.Id);
124
124
  }
125
125
  return null;
126
- // let res = await utils.exec(
127
- // "docker container ls" +
128
- // " --filter=name=\"" + name + "\""
129
- // );
130
-
131
- // let containers = utils.parseTable(res.stdout, {
132
- // 0: "containerId",
133
- // 1: "image",
134
- // 2: "command",
135
- // 3: "created",
136
- // 4: "status",
137
- // 5: "ports",
138
- // 6: "names"
139
- // });
140
-
141
- // await new Promise((resolve) => {
142
- // docker.listContainers({
143
- // "all": true
144
- // }, (err, containers) => {
145
- // console.log(containers);
146
- //
147
- // resolve();
148
- // });
149
- // });
150
126
  }
151
-
152
127
  static async removeContainer(name) {
153
128
  const container = await Docker.getContainer(name);
154
129
  if (!container) {
@@ -344,6 +319,17 @@ class Docker {
344
319
  ports = [],
345
320
  cmd = []
346
321
  } = options;
322
+ const network = docker.getNetwork("workspace");
323
+ try {
324
+ await network.inspect();
325
+ } catch (err) {
326
+ if (err.statusCode === 404) {
327
+ await docker.createNetwork({
328
+ Name: "workspace"
329
+ });
330
+ }
331
+ }
332
+ await this.pullImage(image);
347
333
  return await docker.createContainer({
348
334
  name,
349
335
  Image: image,
package/lib/makes/FS.d.ts CHANGED
@@ -24,7 +24,7 @@ declare class FS {
24
24
  static writeFile(filePath: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
25
25
  static writeFileSync(path: PathLike, data: any, options?: WriteFileOptions): void;
26
26
  static createWriteStream(path: PathLike): fs.WriteStream;
27
- static readJSON(filePath: PathLike | number): Promise<any>;
27
+ static readJSON(...paths: string[]): Promise<any>;
28
28
  static writeJSON(filePath: PathLike | number, data: any): Promise<void>;
29
29
  static unlink(filePath: PathLike): Promise<void>;
30
30
  static watch(filename: PathLike, options?: any): fs.FSWatcher;
package/lib/makes/FS.js CHANGED
@@ -7,8 +7,8 @@ exports.FS = void 0;
7
7
  var fs = _interopRequireWildcard(require("fs"));
8
8
  var Path = _interopRequireWildcard(require("path"));
9
9
  var _readableStream = require("readable-stream");
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 FS {
13
13
  static async access(path) {
14
14
  return new Promise((resolve, reject) => {
@@ -185,15 +185,18 @@ class FS {
185
185
  static createWriteStream(path) {
186
186
  return fs.createWriteStream(path);
187
187
  }
188
- static async readJSON(filePath) {
189
- return FS.readFile(filePath).then(res => {
190
- try {
191
- const str = res.toString();
192
- return JSON.parse(str);
193
- } catch (ignore) {
194
- return {};
195
- }
188
+ static async readJSON(...paths) {
189
+ const res = await new Promise((resolve, reject) => {
190
+ const filePath = Path.join(...paths);
191
+ fs.readFile(filePath, (err, data) => {
192
+ if (err) {
193
+ reject(err);
194
+ return;
195
+ }
196
+ resolve(data);
197
+ });
196
198
  });
199
+ return JSON.parse(res.toString());
197
200
  }
198
201
  static async writeJSON(filePath, data) {
199
202
  const json = JSON.stringify(data, null, 4);
@@ -1,7 +1 @@
1
- export declare class Logger {
2
- static log(...data: any[]): void;
3
- static info(...data: any[]): void;
4
- static warning(...data: any[]): void;
5
- static error(...data: any[]): void;
6
- static _log(type: string, ...data: any[]): void;
7
- }
1
+ export { Logger } from "@wocker/core";
@@ -3,37 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Logger = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _format = _interopRequireDefault(require("date-fns/format"));
9
- var _env = require("../env");
10
- var _FS = require("./FS");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
14
- class Logger {
15
- static log(...data) {
16
- Logger._log("log", ...data);
6
+ Object.defineProperty(exports, "Logger", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _core.Logger;
17
10
  }
18
- static info(...data) {
19
- Logger._log("info", ...data);
20
- }
21
- static warning(...data) {
22
- Logger._log("warning", ...data);
23
- }
24
- static error(...data) {
25
- Logger._log("error", ...data);
26
- }
27
- static _log(type, ...data) {
28
- const time = (0, _format.default)(new Date(), "yyyy-MM-dd hh:mm:ss");
29
- const logPath = Path.join(_env.DATA_DIR, "ws.log");
30
- const logData = data.map(item => {
31
- return typeof item !== "string" ? JSON.stringify(item) : item;
32
- }).join(" ");
33
- if (!_FS.FS.existsSync(logPath)) {
34
- _FS.FS.writeFileSync(logPath, "");
35
- }
36
- _FS.FS.appendFileSync(logPath, `[${time}] ${type}: ${logData}\n`);
37
- }
38
- }
39
- exports.Logger = Logger;
11
+ });
12
+ var _core = require("@wocker/core");
@@ -8,8 +8,8 @@ var Path = _interopRequireWildcard(require("path"));
8
8
  var _env = require("../env");
9
9
  var _Controller = require("./Controller");
10
10
  var _FS = require("./FS");
11
- 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); }
12
- 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; }
13
13
  class Plugin extends _Controller.Controller {
14
14
  constructor(name) {
15
15
  super();
@@ -0,0 +1,16 @@
1
+ import { DI, AppConfigService, DockerService, Plugin, FSManager } from "@wocker/core";
2
+ import { Cli } from "@kearisp/cli";
3
+ type StartOptions = {
4
+ restart?: boolean;
5
+ };
6
+ declare class ElasticSearchPlugin extends Plugin {
7
+ protected containerName: string;
8
+ protected appConfigService: AppConfigService;
9
+ protected dockerService: DockerService;
10
+ protected fs: FSManager;
11
+ constructor(di: DI);
12
+ install(cli: Cli): void;
13
+ start(options: StartOptions): Promise<void>;
14
+ stop(): Promise<void>;
15
+ }
16
+ export { ElasticSearchPlugin };
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ElasticSearchPlugin = void 0;
7
+ var _core = require("@wocker/core");
8
+ class ElasticSearchPlugin extends _core.Plugin {
9
+ containerName = "elastic-search.workspace";
10
+ constructor(di) {
11
+ super();
12
+ this.appConfigService = di.resolveService(_core.AppConfigService);
13
+ this.dockerService = di.resolveService(_core.DockerService);
14
+ this.fs = new _core.FSManager(this.appConfigService.pluginsPath("elastic-search"), this.appConfigService.dataPath("plugins/elastic-search"));
15
+ }
16
+ install(cli) {
17
+ super.install(cli);
18
+ cli.command("elastica:start").option("restart", {
19
+ type: "boolean",
20
+ alias: "r",
21
+ description: "Restart service"
22
+ }).action(options => this.start(options));
23
+ cli.command("elastica:stop").action(() => this.stop());
24
+ }
25
+ async start(options) {
26
+ const {
27
+ restart
28
+ } = options;
29
+ await this.dockerService.pullImage("docker.elastic.co/elasticsearch/elasticsearch:7.5.2");
30
+ let container = await this.dockerService.getContainer(this.containerName);
31
+ if (restart && container) {
32
+ await this.dockerService.removeContainer(this.containerName);
33
+ container = null;
34
+ }
35
+ if (!container) {
36
+ await this.fs.mkdir("data", {
37
+ recursive: true
38
+ });
39
+ container = await this.dockerService.createContainer({
40
+ name: this.containerName,
41
+ image: "docker.elastic.co/elasticsearch/elasticsearch:7.5.2",
42
+ ulimits: {
43
+ memlock: {
44
+ hard: -1,
45
+ soft: -1
46
+ }
47
+ },
48
+ env: {
49
+ "node.name": "elasticsearch",
50
+ "cluster.name": "elasticsearch",
51
+ "cluster.initial_master_nodes": "elasticsearch",
52
+ "bootstrap.memory_lock": "false",
53
+ ES_JAVA_OPTS: "-Xms512m -Xmx512m"
54
+ },
55
+ volumes: [`${this.fs.path("data")}:/usr/share/elasticsearch/data`],
56
+ ports: ["9200:9200"]
57
+ });
58
+ }
59
+ const {
60
+ State: {
61
+ Status
62
+ }
63
+ } = await container.inspect();
64
+ if (Status === "created" || Status === "exited") {
65
+ await container.start();
66
+ }
67
+ }
68
+ async stop() {
69
+ await this.dockerService.removeContainer(this.containerName);
70
+ }
71
+ }
72
+ exports.ElasticSearchPlugin = ElasticSearchPlugin;
@@ -1,7 +1,6 @@
1
+ import { Project, DI, AppConfigService, AppEventsService, ProjectService, DockerService } 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
  name?: string;
7
6
  };
@@ -20,7 +19,8 @@ declare class LocaltunnelPlugin extends Plugin {
20
19
  protected appConfigService: AppConfigService;
21
20
  protected appEventsService: AppEventsService;
22
21
  protected projectService: ProjectService;
23
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
22
+ protected dockerService: DockerService;
23
+ constructor(di: DI);
24
24
  install(cli: Cli): void;
25
25
  getIp(): Promise<string>;
26
26
  onProjectStart(project: Project): Promise<void>;
@@ -4,16 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.LocaltunnelPlugin = void 0;
7
+ var _core = require("@wocker/core");
8
+ var _utils = require("@wocker/utils");
7
9
  var _axios = _interopRequireDefault(require("axios"));
8
10
  var _makes = require("../makes");
9
- var _utils = require("../utils");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  class LocaltunnelPlugin extends _makes.Plugin {
12
- constructor(appConfigService, appEventsService, projectService) {
13
+ constructor(di) {
13
14
  super("localtunnel");
14
- this.appConfigService = appConfigService;
15
- this.appEventsService = appEventsService;
16
- this.projectService = projectService;
15
+ this.appConfigService = di.resolveService(_core.AppConfigService);
16
+ this.appEventsService = di.resolveService(_core.AppEventsService);
17
+ this.projectService = di.resolveService(_core.ProjectService);
18
+ this.dockerService = di.resolveService(_core.DockerService);
17
19
  }
18
20
  install(cli) {
19
21
  super.install(cli);
@@ -67,7 +69,7 @@ class LocaltunnelPlugin extends _makes.Plugin {
67
69
  if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
68
70
  return;
69
71
  }
70
- let container = await _makes.Docker.getContainer(`localtunnel-${project.name}`);
72
+ let container = await this.dockerService.getContainer(`localtunnel-${project.name}`);
71
73
  if (container) {
72
74
  const {
73
75
  State: {
@@ -78,14 +80,14 @@ class LocaltunnelPlugin extends _makes.Plugin {
78
80
  console.info("Localtunnel is already running");
79
81
  return;
80
82
  } else {
81
- await _makes.Docker.removeContainer(`localtunnel-${project.name}`);
83
+ await this.dockerService.removeContainer(`localtunnel-${project.name}`);
82
84
  }
83
85
  }
84
86
  console.info("Localtunnel starting...");
85
- _makes.Logger.info(`Localtunnel start: ${project.name}`);
87
+ _core.Logger.info(`Localtunnel start: ${project.name}`);
86
88
  await this.build();
87
89
  const subdomain = project.getEnv("LOCALTUNNEL_SUBDOMAIN", project.name);
88
- container = await _makes.Docker.createContainer({
90
+ container = await this.dockerService.createContainer({
89
91
  name: `localtunnel-${project.name}`,
90
92
  image: "ws-localtunnel",
91
93
  // tty: true,
@@ -120,7 +122,7 @@ class LocaltunnelPlugin extends _makes.Plugin {
120
122
  stream.on("end", () => resolve(res));
121
123
  stream.on("error", reject);
122
124
  });
123
- _makes.Logger.info(`${project.name} localtunnel forwarding: ${link}`);
125
+ _core.Logger.info(`${project.name} localtunnel forwarding: ${link}`);
124
126
  const ip = await this.getIp();
125
127
  console.info(`IP: ${ip}`);
126
128
  console.info(`Forwarding: ${link}`);
@@ -154,12 +156,12 @@ class LocaltunnelPlugin extends _makes.Plugin {
154
156
  return;
155
157
  }
156
158
  console.info("Localtunnel stopping...");
157
- await _makes.Docker.removeContainer(`localtunnel-${project.name}`);
159
+ await this.dockerService.removeContainer(`localtunnel-${project.name}`);
158
160
  }
159
161
  async build() {
160
- const exists = await _makes.Docker.imageExists("ws-localtunnel");
162
+ const exists = await this.dockerService.imageExists("ws-localtunnel");
161
163
  if (!exists) {
162
- await _makes.Docker.imageBuild({
164
+ await this.dockerService.buildImage({
163
165
  tag: "ws-localtunnel",
164
166
  context: this.pluginPath(),
165
167
  src: "./Dockerfile"
@@ -168,7 +170,7 @@ class LocaltunnelPlugin extends _makes.Plugin {
168
170
  }
169
171
  async rebuild() {
170
172
  try {
171
- await _makes.Docker.imageRm("ws-localtunnel");
173
+ await this.dockerService.imageRm("ws-localtunnel");
172
174
  } catch (err) {
173
175
  console.info(err.message);
174
176
  }
@@ -255,7 +257,7 @@ class LocaltunnelPlugin extends _makes.Plugin {
255
257
  await this.projectService.cdProject(name);
256
258
  }
257
259
  const project = await this.projectService.get();
258
- const container = await _makes.Docker.getContainer(`localtunnel-${project.name}`);
260
+ const container = await this.dockerService.getContainer(`localtunnel-${project.name}`);
259
261
  const stream = await container.logs({
260
262
  follow: true,
261
263
  stderr: true,
@@ -1,8 +1,10 @@
1
+ import { DI, DockerService } from "@wocker/core";
1
2
  import { Cli } from "@kearisp/cli";
2
3
  import { Plugin } from "src/makes";
3
4
  declare class MaildevPlugin extends Plugin {
4
5
  protected containerName: string;
5
- constructor();
6
+ protected dockerService: DockerService;
7
+ constructor(di: DI);
6
8
  install(cli: Cli): void;
7
9
  start(): Promise<void>;
8
10
  stop(): Promise<void>;
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MaildevPlugin = void 0;
7
+ var _core = require("@wocker/core");
7
8
  var _makes = require("../makes");
8
9
  class MaildevPlugin extends _makes.Plugin {
9
10
  containerName = "maildev.workspace";
10
- constructor() {
11
+ constructor(di) {
11
12
  super("maildev");
13
+ this.dockerService = di.resolveService(_core.DockerService);
12
14
  }
13
15
  install(cli) {
14
16
  super.install(cli);
@@ -18,8 +20,8 @@ class MaildevPlugin extends _makes.Plugin {
18
20
  async start() {
19
21
  console.log("Maildev starting...");
20
22
  const imageName = "ws-maildev";
21
- if (!(await _makes.Docker.imageExists(imageName))) {
22
- await _makes.Docker.imageBuild({
23
+ if (!(await this.dockerService.imageExists(imageName))) {
24
+ await this.dockerService.buildImage({
23
25
  tag: "ws-maildev",
24
26
  buildArgs: {},
25
27
  labels: {},
@@ -27,7 +29,7 @@ class MaildevPlugin extends _makes.Plugin {
27
29
  src: "./Dockerfile"
28
30
  });
29
31
  }
30
- await _makes.Docker.containerRun({
32
+ let container = await this.dockerService.createContainer({
31
33
  name: this.containerName,
32
34
  restart: "always",
33
35
  env: {
@@ -36,10 +38,11 @@ class MaildevPlugin extends _makes.Plugin {
36
38
  ports: ["25:25"],
37
39
  image: imageName
38
40
  });
41
+ await container.start();
39
42
  }
40
43
  async stop() {
41
44
  console.log("Maildev stopping...");
42
- await _makes.Docker.removeContainer(this.containerName);
45
+ await this.dockerService.removeContainer(this.containerName);
43
46
  }
44
47
  }
45
48
  exports.MaildevPlugin = MaildevPlugin;
@@ -1,9 +1,11 @@
1
+ import { DI, DockerService } from "@wocker/core";
1
2
  import { Cli } from "@kearisp/cli";
2
3
  import { Plugin } from "src/makes";
3
4
  declare class MongodbPlugin extends Plugin {
4
- container: string;
5
- adminContainer: string;
6
- constructor();
5
+ protected container: string;
6
+ protected adminContainer: string;
7
+ protected dockerService: DockerService;
8
+ constructor(di: DI);
7
9
  install(cli: Cli): void;
8
10
  getDatabases(): Promise<string[]>;
9
11
  getDatabasesDumps(): Promise<string[]>;