@wocker/ws 1.0.7 → 1.0.8

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 (96) hide show
  1. package/bin/ws.js +1 -1
  2. package/lib/App.d.ts +1 -6
  3. package/lib/App.js +1 -27
  4. package/lib/AppModule.d.ts +6 -0
  5. package/lib/AppModule.js +97 -0
  6. package/lib/controllers/CompletionController.d.ts +6 -0
  7. package/lib/controllers/CompletionController.js +32 -0
  8. package/lib/controllers/ImageController.d.ts +5 -8
  9. package/lib/controllers/ImageController.js +27 -12
  10. package/lib/controllers/PluginController.d.ts +9 -13
  11. package/lib/controllers/PluginController.js +56 -18
  12. package/lib/controllers/PresetController.d.ts +9 -15
  13. package/lib/controllers/PresetController.js +41 -22
  14. package/lib/controllers/ProjectController.d.ts +27 -69
  15. package/lib/controllers/ProjectController.js +336 -261
  16. package/lib/controllers/ProxyController.d.ts +15 -25
  17. package/lib/controllers/ProxyController.js +142 -96
  18. package/lib/controllers/index.d.ts +1 -0
  19. package/lib/controllers/index.js +1 -0
  20. package/lib/index.d.ts +0 -1
  21. package/lib/index.js +0 -11
  22. package/lib/main.d.ts +3 -0
  23. package/lib/main.js +11 -0
  24. package/lib/makes/Logger.d.ts +2 -2
  25. package/lib/makes/Logger.js +19 -8
  26. package/lib/makes/Preset.d.ts +3 -4
  27. package/lib/makes/Preset.js +19 -8
  28. package/lib/makes/index.d.ts +0 -6
  29. package/lib/makes/index.js +0 -6
  30. package/lib/plugins/ElasticSearchPlugin.d.ts +5 -6
  31. package/lib/plugins/ElasticSearchPlugin.js +19 -8
  32. package/lib/plugins/LocaltunnelPlugin.d.ts +8 -8
  33. package/lib/plugins/LocaltunnelPlugin.js +25 -10
  34. package/lib/plugins/MaildevPlugin.d.ts +5 -6
  35. package/lib/plugins/MaildevPlugin.js +21 -8
  36. package/lib/plugins/MongodbPlugin.d.ts +5 -5
  37. package/lib/plugins/MongodbPlugin.js +26 -11
  38. package/lib/plugins/NgrokPlugin.d.ts +7 -6
  39. package/lib/plugins/NgrokPlugin.js +32 -17
  40. package/lib/plugins/PageKitePlugin.d.ts +10 -8
  41. package/lib/plugins/PageKitePlugin.js +36 -20
  42. package/lib/plugins/ProxmoxPlugin.d.ts +8 -5
  43. package/lib/plugins/ProxmoxPlugin.js +25 -9
  44. package/lib/plugins/RedisPlugin.d.ts +4 -6
  45. package/lib/plugins/RedisPlugin.js +19 -8
  46. package/lib/plugins/index.d.ts +0 -2
  47. package/lib/plugins/index.js +0 -2
  48. package/lib/services/AppConfigService.d.ts +3 -3
  49. package/lib/services/AppConfigService.js +16 -2
  50. package/lib/services/AppEventsService.d.ts +1 -2
  51. package/lib/services/AppEventsService.js +11 -2
  52. package/lib/services/DockerService.d.ts +9 -39
  53. package/lib/services/DockerService.js +122 -4
  54. package/lib/services/LogService.d.ts +3 -5
  55. package/lib/services/LogService.js +19 -4
  56. package/lib/services/PluginService.d.ts +4 -9
  57. package/lib/services/PluginService.js +18 -8
  58. package/lib/services/PresetService.d.ts +5 -5
  59. package/lib/services/PresetService.js +11 -2
  60. package/lib/services/ProjectService.d.ts +9 -6
  61. package/lib/services/ProjectService.js +62 -31
  62. package/lib/utils/get-config.d.ts +2 -2
  63. package/lib/utils/index.d.ts +0 -1
  64. package/lib/utils/index.js +0 -1
  65. package/lib/utils/set-config.d.ts +2 -2
  66. package/package.json +4 -4
  67. package/presets/node/config.json +1 -1
  68. package/presets/php-fpm/Dockerfile +1 -1
  69. package/lib/decorators/Inject.d.ts +0 -1
  70. package/lib/decorators/Inject.js +0 -8
  71. package/lib/decorators/Injectable.d.ts +0 -4
  72. package/lib/decorators/Injectable.js +0 -17
  73. package/lib/decorators/index.d.ts +0 -1
  74. package/lib/decorators/index.js +0 -17
  75. package/lib/makes/Controller.d.ts +0 -5
  76. package/lib/makes/Controller.js +0 -8
  77. package/lib/makes/DI.d.ts +0 -7
  78. package/lib/makes/DI.js +0 -27
  79. package/lib/makes/Docker.d.ts +0 -58
  80. package/lib/makes/Docker.js +0 -320
  81. package/lib/makes/Plugin.d.ts +0 -13
  82. package/lib/makes/Plugin.js +0 -61
  83. package/lib/makes/Project.d.ts +0 -45
  84. package/lib/makes/Project.js +0 -127
  85. package/lib/makes/Repository.d.ts +0 -11
  86. package/lib/makes/Repository.js +0 -22
  87. package/lib/plugins/PostgresPlugin.d.ts +0 -16
  88. package/lib/plugins/PostgresPlugin.js +0 -121
  89. package/lib/types/Config.d.ts +0 -12
  90. package/lib/types/Config.js +0 -2
  91. package/lib/types/EnvConfig.d.ts +0 -3
  92. package/lib/types/EnvConfig.js +0 -2
  93. package/lib/types/index.d.ts +0 -2
  94. package/lib/types/index.js +0 -18
  95. package/lib/utils/demuxOutput.d.ts +0 -2
  96. package/lib/utils/demuxOutput.js +0 -19
@@ -15,6 +15,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
18
24
  var __importStar = (this && this.__importStar) || function (mod) {
19
25
  if (mod && mod.__esModule) return mod;
20
26
  var result = {};
@@ -22,21 +28,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
28
  __setModuleDefault(result, mod);
23
29
  return result;
24
30
  };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  exports.ProxmoxPlugin = void 0;
36
+ const core_1 = require("@wocker/core");
27
37
  const Path = __importStar(require("path"));
28
- const makes_1 = require("../makes");
38
+ const services_1 = require("../services");
29
39
  const utils_1 = require("../utils");
30
- class ProxmoxPlugin extends makes_1.Plugin {
31
- constructor() {
32
- super("proxmox");
33
- this.configDir = Path.join(__dirname, "../../services/proxmox");
40
+ let ProxmoxPlugin = class ProxmoxPlugin {
41
+ constructor(appConfigService, dockerService) {
42
+ this.appConfigService = appConfigService;
43
+ this.dockerService = dockerService;
44
+ this.configDir = this.appConfigService.dataPath("plugins/proxmox");
34
45
  }
35
- install(cli) {
36
- super.install(cli);
46
+ pluginPath(...parts) {
47
+ return Path.join(this.appConfigService.pluginsPath("proxmox"), ...parts);
37
48
  }
38
49
  async up() {
39
- const container = await makes_1.Docker.getContainer("proxmox.workspace");
50
+ const container = await this.dockerService.getContainer("proxmox.workspace");
40
51
  if (container) {
41
52
  await this.down();
42
53
  }
@@ -63,5 +74,10 @@ class ProxmoxPlugin extends makes_1.Plugin {
63
74
  await (0, utils_1.exec)("docker image rm ws-proxmox").catch(() => {
64
75
  });
65
76
  }
66
- }
77
+ };
67
78
  exports.ProxmoxPlugin = ProxmoxPlugin;
79
+ exports.ProxmoxPlugin = ProxmoxPlugin = __decorate([
80
+ (0, core_1.Controller)(),
81
+ __metadata("design:paramtypes", [services_1.AppConfigService,
82
+ services_1.DockerService])
83
+ ], ProxmoxPlugin);
@@ -1,18 +1,16 @@
1
1
  import { FSManager } from "@wocker/core";
2
2
  import { Cli } from "@kearisp/cli";
3
- import { DI, Plugin } from "../makes";
4
3
  import { AppConfigService, DockerService } from "../services";
5
- declare class RedisPlugin extends Plugin {
4
+ export declare class RedisPlugin {
5
+ protected readonly appConfigService: AppConfigService;
6
+ protected readonly dockerService: DockerService;
6
7
  protected container: string;
7
8
  protected commander: string;
8
- protected appConfigService: AppConfigService;
9
- protected dockerService: DockerService;
10
9
  protected fs: FSManager;
11
- constructor(di: DI);
10
+ constructor(appConfigService: AppConfigService, dockerService: DockerService);
12
11
  install(cli: Cli): void;
13
12
  up(): Promise<void>;
14
13
  protected startCommander(): Promise<void>;
15
14
  down(): Promise<void>;
16
15
  protected stopCommander(): Promise<void>;
17
16
  }
18
- export { RedisPlugin };
@@ -1,20 +1,26 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.RedisPlugin = void 0;
4
13
  const core_1 = require("@wocker/core");
5
- const makes_1 = require("../makes");
6
14
  const services_1 = require("../services");
7
- class RedisPlugin extends makes_1.Plugin {
8
- constructor(di) {
9
- super("redis");
15
+ let RedisPlugin = class RedisPlugin {
16
+ constructor(appConfigService, dockerService) {
17
+ this.appConfigService = appConfigService;
18
+ this.dockerService = dockerService;
10
19
  this.container = "redis.workspace";
11
20
  this.commander = "redis-commander.workspace";
12
- this.appConfigService = di.resolveService(services_1.AppConfigService);
13
- this.dockerService = di.resolveService(services_1.DockerService);
14
21
  this.fs = new core_1.FSManager(this.appConfigService.pluginsPath("redis"), this.appConfigService.dataPath("plugins/redis"));
15
22
  }
16
23
  install(cli) {
17
- super.install(cli);
18
24
  cli.command("redis:start")
19
25
  .action(() => this.up());
20
26
  cli.command("redis:stop")
@@ -76,5 +82,10 @@ class RedisPlugin extends makes_1.Plugin {
76
82
  console.info("RedisCommander stopping...");
77
83
  await this.dockerService.removeContainer(this.commander);
78
84
  }
79
- }
85
+ };
80
86
  exports.RedisPlugin = RedisPlugin;
87
+ exports.RedisPlugin = RedisPlugin = __decorate([
88
+ (0, core_1.Controller)(),
89
+ __metadata("design:paramtypes", [services_1.AppConfigService,
90
+ services_1.DockerService])
91
+ ], RedisPlugin);
@@ -4,7 +4,5 @@ export * from "./MaildevPlugin";
4
4
  export * from "./MongodbPlugin";
5
5
  export * from "./NgrokPlugin";
6
6
  export * from "./PageKitePlugin";
7
- export * from "./PostgresPlugin";
8
- export * from "./PostgresPlugin";
9
7
  export * from "./ProxmoxPlugin";
10
8
  export * from "./RedisPlugin";
@@ -20,7 +20,5 @@ __exportStar(require("./MaildevPlugin"), exports);
20
20
  __exportStar(require("./MongodbPlugin"), exports);
21
21
  __exportStar(require("./NgrokPlugin"), exports);
22
22
  __exportStar(require("./PageKitePlugin"), exports);
23
- __exportStar(require("./PostgresPlugin"), exports);
24
- __exportStar(require("./PostgresPlugin"), exports);
25
23
  __exportStar(require("./ProxmoxPlugin"), exports);
26
24
  __exportStar(require("./RedisPlugin"), exports);
@@ -1,8 +1,8 @@
1
- import { Config, EnvConfig } from "../types";
1
+ import { AppConfig as Config, EnvConfig } from "@wocker/core";
2
2
  type TypeMap = {
3
3
  [type: string]: string;
4
4
  };
5
- declare class AppConfigService {
5
+ export declare class AppConfigService {
6
6
  protected pwd: string;
7
7
  protected mapTypes: TypeMap;
8
8
  constructor();
@@ -25,4 +25,4 @@ declare class AppConfigService {
25
25
  activatePlugin(name: string): Promise<void>;
26
26
  deactivatePlugin(name: string): Promise<void>;
27
27
  }
28
- export { AppConfigService };
28
+ export {};
@@ -15,6 +15,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
18
24
  var __importStar = (this && this.__importStar) || function (mod) {
19
25
  if (mod && mod.__esModule) return mod;
20
26
  var result = {};
@@ -22,12 +28,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
28
  __setModuleDefault(result, mod);
23
29
  return result;
24
30
  };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  exports.AppConfigService = void 0;
36
+ const core_1 = require("@wocker/core");
27
37
  const Path = __importStar(require("path"));
28
38
  const env_1 = require("../env");
29
39
  const makes_1 = require("../makes");
30
- class AppConfigService {
40
+ let AppConfigService = class AppConfigService {
31
41
  constructor() {
32
42
  this.mapTypes = {
33
43
  image: "Image",
@@ -163,5 +173,9 @@ class AppConfigService {
163
173
  ...rest
164
174
  });
165
175
  }
166
- }
176
+ };
167
177
  exports.AppConfigService = AppConfigService;
178
+ exports.AppConfigService = AppConfigService = __decorate([
179
+ (0, core_1.Injectable)("APP_CONFIG"),
180
+ __metadata("design:paramtypes", [])
181
+ ], AppConfigService);
@@ -1,5 +1,5 @@
1
1
  import { AppEventsService as CoreAppEventsService, AppEventHandle } from "@wocker/core";
2
- declare class AppEventsService extends CoreAppEventsService {
2
+ export declare class AppEventsService extends CoreAppEventsService {
3
3
  protected handles: ({
4
4
  [event: string]: AppEventHandle[];
5
5
  });
@@ -7,4 +7,3 @@ declare class AppEventsService extends CoreAppEventsService {
7
7
  off(event: string, handle: AppEventHandle): void;
8
8
  emit(event: string, ...args: any[]): Promise<void>;
9
9
  }
10
- export { AppEventsService };
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.AppEventsService = void 0;
4
10
  const core_1 = require("@wocker/core");
5
- class AppEventsService extends core_1.AppEventsService {
11
+ let AppEventsService = class AppEventsService extends core_1.AppEventsService {
6
12
  constructor() {
7
13
  super(...arguments);
8
14
  this.handles = {};
@@ -26,5 +32,8 @@ class AppEventsService extends core_1.AppEventsService {
26
32
  await handles[i](...args);
27
33
  }
28
34
  }
29
- }
35
+ };
30
36
  exports.AppEventsService = AppEventsService;
37
+ exports.AppEventsService = AppEventsService = __decorate([
38
+ (0, core_1.Injectable)("APP_EVENTS_SERVICE")
39
+ ], AppEventsService);
@@ -1,51 +1,21 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import Docker, { Container } from "dockerode";
3
- import { DI } from "../makes";
4
- declare namespace Params {
5
- type CreateContainer = {
6
- name: string;
7
- image: string;
8
- restart?: "always";
9
- projectId?: string;
10
- tty?: boolean;
11
- ulimits?: {
12
- [key: string]: {
13
- hard?: number;
14
- soft?: number;
15
- };
16
- };
17
- links?: string[];
18
- env?: {
19
- [key: string]: string;
20
- };
21
- networkMode?: string;
22
- extraHosts?: any;
23
- volumes?: string[];
24
- ports?: string[];
25
- cmd?: string[];
26
- };
27
- type BuildImage = {
28
- tag: string;
29
- buildArgs?: {
30
- [key: string]: string;
31
- };
32
- labels?: {
33
- [key: string]: string;
34
- };
35
- context: string;
36
- src: string;
37
- };
38
- }
39
- declare class DockerService {
4
+ import { DockerServiceParams as Params } from "@wocker/core";
5
+ import { LogService } from "./LogService";
6
+ export declare class DockerService {
7
+ protected readonly logService: LogService;
40
8
  protected docker: Docker;
41
- constructor(di: DI);
9
+ constructor(logService: LogService);
42
10
  createContainer(params: Params.CreateContainer): Promise<Container>;
43
11
  getContainer(name: string): Promise<Container | null>;
44
12
  removeContainer(name: string): Promise<void>;
45
13
  buildImage(params: Params.BuildImage): Promise<void>;
46
14
  imageExists(tag: string): Promise<boolean>;
47
15
  imageRm(tag: string): Promise<void>;
16
+ imageLs(options?: Params.ImageList): Promise<Docker.ImageInfo[]>;
48
17
  pullImage(tag: string): Promise<void>;
18
+ attach(name: string): Promise<void>;
49
19
  attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
20
+ exec(name: string, args?: string[], tty?: boolean): Promise<import("stream").Duplex>;
50
21
  }
51
- export { DockerService };
@@ -1,20 +1,32 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.DockerService = void 0;
7
16
  const dockerode_1 = __importDefault(require("dockerode"));
17
+ const core_1 = require("@wocker/core");
8
18
  const utils_1 = require("../utils");
9
19
  const makes_1 = require("../makes");
10
- class DockerService {
11
- constructor(di) {
20
+ const LogService_1 = require("./LogService");
21
+ let DockerService = class DockerService {
22
+ constructor(logService) {
23
+ this.logService = logService;
12
24
  this.docker = new dockerode_1.default({
13
25
  socketPath: "/var/run/docker.sock"
14
26
  });
15
27
  }
16
28
  async createContainer(params) {
17
- const { name, tty, image, projectId, restart, ulimits, extraHosts, networkMode, links = [], env = {}, volumes = [], ports = [], cmd = [] } = params;
29
+ const { name, user, entrypoint, tty, image, projectId, restart, ulimits, extraHosts, networkMode, links = [], env = {}, volumes = [], ports = [], cmd = [] } = params;
18
30
  const network = this.docker.getNetwork("workspace");
19
31
  try {
20
32
  await network.inspect();
@@ -29,6 +41,7 @@ class DockerService {
29
41
  await this.pullImage(image);
30
42
  return this.docker.createContainer({
31
43
  name,
44
+ User: user,
32
45
  Image: image,
33
46
  Hostname: name,
34
47
  Labels: {
@@ -39,6 +52,7 @@ class DockerService {
39
52
  AttachStderr: true,
40
53
  OpenStdin: true,
41
54
  StdinOnce: false,
55
+ Entrypoint: entrypoint,
42
56
  Tty: tty,
43
57
  Cmd: cmd,
44
58
  Env: Object.keys(env).map((key) => {
@@ -164,6 +178,31 @@ class DockerService {
164
178
  }
165
179
  await image.remove();
166
180
  }
181
+ async imageLs(options) {
182
+ const { tag, reference, labels } = options || {};
183
+ const filters = {};
184
+ if (reference) {
185
+ filters.reference = [
186
+ ...filters.reference || [],
187
+ reference
188
+ ];
189
+ }
190
+ if (tag) {
191
+ filters.reference = [
192
+ ...filters.reference || [],
193
+ tag
194
+ ];
195
+ }
196
+ if (labels) {
197
+ filters.label = [];
198
+ for (const i in labels) {
199
+ filters.label.push(`${i}=${labels[i]}`);
200
+ }
201
+ }
202
+ return this.docker.listImages({
203
+ filters: JSON.stringify(filters)
204
+ });
205
+ }
167
206
  async pullImage(tag) {
168
207
  const exists = await this.imageExists(tag);
169
208
  if (exists) {
@@ -172,6 +211,43 @@ class DockerService {
172
211
  const stream = await this.docker.pull(tag);
173
212
  await (0, utils_1.followProgress)(stream);
174
213
  }
214
+ async attach(name) {
215
+ const container = await this.getContainer(name);
216
+ const stream = await container.attach({
217
+ logs: true,
218
+ stream: true,
219
+ hijack: true,
220
+ stdin: true,
221
+ stdout: true,
222
+ stderr: true
223
+ });
224
+ process.stdin.resume();
225
+ process.stdin.setEncoding("utf8");
226
+ process.stdin.setRawMode(true);
227
+ process.stdin.pipe(stream);
228
+ process.stdin.on("data", (data) => {
229
+ if (data.toString() === "\u0003") {
230
+ process.stdin.setRawMode(false);
231
+ }
232
+ });
233
+ stream.setEncoding("utf8");
234
+ stream.pipe(process.stdout);
235
+ const [width, height] = process.stdout.getWindowSize();
236
+ await container.resize({
237
+ w: width,
238
+ h: height
239
+ });
240
+ stream.on("end", async () => {
241
+ process.exit();
242
+ });
243
+ process.stdout.on("resize", () => {
244
+ const [width, height] = process.stdout.getWindowSize();
245
+ container.resize({
246
+ w: width,
247
+ h: height
248
+ });
249
+ });
250
+ }
175
251
  async attachStream(stream) {
176
252
  process.stdin.resume();
177
253
  process.stdin.setEncoding("utf8");
@@ -196,5 +272,47 @@ class DockerService {
196
272
  stream.on("error", reject);
197
273
  });
198
274
  }
199
- }
275
+ async exec(name, args, tty = false) {
276
+ const container = await this.getContainer(name);
277
+ if (!container) {
278
+ return;
279
+ }
280
+ const exec = await container.exec({
281
+ AttachStdin: true,
282
+ AttachStdout: true,
283
+ AttachStderr: tty,
284
+ Tty: tty,
285
+ Cmd: args || []
286
+ });
287
+ const stream = await exec.start({
288
+ hijack: true,
289
+ stdin: tty,
290
+ Tty: tty
291
+ });
292
+ if (tty) {
293
+ stream.setEncoding("utf-8");
294
+ process.stdin.resume();
295
+ if (process.stdin.setRawMode) {
296
+ process.stdin.setRawMode(true);
297
+ }
298
+ process.stdin.setEncoding("utf-8");
299
+ process.stdin.pipe(stream);
300
+ stream.pipe(process.stdout);
301
+ stream.on("error", (err) => {
302
+ makes_1.Logger.error(err.message);
303
+ });
304
+ stream.on("end", async () => {
305
+ process.stdin.setRawMode(false);
306
+ });
307
+ stream.on("end", async () => {
308
+ process.exit();
309
+ });
310
+ }
311
+ return stream;
312
+ }
313
+ };
200
314
  exports.DockerService = DockerService;
315
+ exports.DockerService = DockerService = __decorate([
316
+ (0, core_1.Injectable)("DOCKER_SERVICE"),
317
+ __metadata("design:paramtypes", [LogService_1.LogService])
318
+ ], DockerService);
@@ -1,12 +1,10 @@
1
- import { DI } from "../makes";
2
1
  import { AppConfigService } from "./AppConfigService";
3
- declare class LogService {
4
- protected appConfigService: AppConfigService;
5
- constructor(di: DI);
2
+ export declare class LogService {
3
+ protected readonly appConfigService: AppConfigService;
4
+ constructor(appConfigService: AppConfigService);
6
5
  log(...data: any[]): void;
7
6
  info(...data: any[]): void;
8
7
  warn(...data: any[]): void;
9
8
  error(...data: any[]): void;
10
9
  protected _log(type: string, ...data: any[]): void;
11
10
  }
12
- export { LogService };
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.LogService = void 0;
16
+ const core_1 = require("@wocker/core");
7
17
  const format_1 = __importDefault(require("date-fns/format"));
8
18
  const makes_1 = require("../makes");
9
19
  const AppConfigService_1 = require("./AppConfigService");
10
- class LogService {
11
- constructor(di) {
12
- this.appConfigService = di.resolveService(AppConfigService_1.AppConfigService);
20
+ let LogService = class LogService {
21
+ constructor(appConfigService) {
22
+ this.appConfigService = appConfigService;
23
+ makes_1.Logger.install(this);
13
24
  }
14
25
  log(...data) {
15
26
  this._log("log", ...data);
@@ -34,5 +45,9 @@ class LogService {
34
45
  }
35
46
  makes_1.FS.appendFileSync(logPath, `[${time}] ${type}: ${logData}\n`);
36
47
  }
37
- }
48
+ };
38
49
  exports.LogService = LogService;
50
+ exports.LogService = LogService = __decorate([
51
+ (0, core_1.Injectable)("LOG_SERVICE"),
52
+ __metadata("design:paramtypes", [AppConfigService_1.AppConfigService])
53
+ ], LogService);
@@ -1,11 +1,6 @@
1
1
  import { Cli } from "@wocker/core";
2
- import { DI, Controller } from "../makes";
3
- declare class PluginService {
4
- protected di: DI;
5
- protected cli: Cli;
6
- constructor(di: DI);
7
- use(Constructor: {
8
- new (...params: any[]): Controller;
9
- }): void;
2
+ export declare class PluginService {
3
+ protected readonly cli: Cli;
4
+ constructor(cli: Cli);
5
+ use(): void;
10
6
  }
11
- export { PluginService };
@@ -1,15 +1,25 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.PluginService = void 0;
4
13
  const core_1 = require("@wocker/core");
5
- class PluginService {
6
- constructor(di) {
7
- this.di = di;
8
- this.cli = di.resolveService(core_1.Cli);
14
+ let PluginService = class PluginService {
15
+ constructor(cli) {
16
+ this.cli = cli;
9
17
  }
10
- use(Constructor) {
11
- const controller = new Constructor(this.di);
12
- controller.install(this.cli);
18
+ use() {
13
19
  }
14
- }
20
+ };
15
21
  exports.PluginService = PluginService;
22
+ exports.PluginService = PluginService = __decorate([
23
+ (0, core_1.Injectable)(),
24
+ __metadata("design:paramtypes", [core_1.Cli])
25
+ ], PluginService);
@@ -1,14 +1,14 @@
1
- import { EnvConfig } from "../types";
2
- import { DI, Preset } from "../makes";
1
+ import { EnvConfig } from "@wocker/core";
2
+ import { Preset } from "../makes";
3
3
  type SearchOptions = Partial<{
4
4
  name: string;
5
5
  }>;
6
- declare class PresetService {
7
- constructor(di: DI);
6
+ export declare class PresetService {
7
+ constructor();
8
8
  getImageName(preset: Preset, buildArgs?: EnvConfig): string;
9
9
  save(preset: Preset): Promise<void>;
10
10
  get(name: string): Promise<Preset>;
11
11
  search(options?: SearchOptions): Promise<Preset[]>;
12
12
  searchOne(options?: SearchOptions): Promise<Preset | null>;
13
13
  }
14
- export { PresetService, SearchOptions as PresetServiceSearchOptions };
14
+ export { SearchOptions as PresetServiceSearchOptions };
@@ -8,7 +8,9 @@ const md5_1 = __importDefault(require("md5"));
8
8
  const env_1 = require("../env");
9
9
  const makes_1 = require("../makes");
10
10
  class PresetService {
11
- constructor(di) { }
11
+ constructor() {
12
+ makes_1.Preset.install(this);
13
+ }
12
14
  getImageName(preset, buildArgs = {}) {
13
15
  const rawValues = [];
14
16
  const hashValues = [];
@@ -34,7 +36,14 @@ class PresetService {
34
36
  }
35
37
  async get(name) {
36
38
  const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
37
- return new makes_1.Preset({
39
+ return new class extends makes_1.Preset {
40
+ constructor(presetService, data) {
41
+ super(data);
42
+ this.presetService = presetService;
43
+ }
44
+ async save() {
45
+ }
46
+ }(this, {
38
47
  name,
39
48
  ...config
40
49
  });