@wocker/ws 1.0.7 → 1.0.9

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 (118) hide show
  1. package/bin/ws.js +2 -13
  2. package/lib/AppModule.d.ts +6 -0
  3. package/lib/AppModule.js +100 -0
  4. package/lib/controllers/CompletionController.d.ts +6 -0
  5. package/lib/controllers/CompletionController.js +32 -0
  6. package/lib/controllers/DebugController.d.ts +7 -0
  7. package/lib/controllers/DebugController.js +44 -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 +11 -13
  11. package/lib/controllers/PluginController.js +93 -54
  12. package/lib/controllers/PresetController.d.ts +10 -15
  13. package/lib/controllers/PresetController.js +111 -27
  14. package/lib/controllers/ProjectController.d.ts +27 -70
  15. package/lib/controllers/ProjectController.js +357 -306
  16. package/lib/controllers/ProxyController.d.ts +15 -25
  17. package/lib/controllers/ProxyController.js +157 -102
  18. package/lib/controllers/index.d.ts +2 -0
  19. package/lib/controllers/index.js +2 -0
  20. package/lib/main.d.ts +3 -0
  21. package/lib/main.js +30 -0
  22. package/lib/makes/FS.d.ts +15 -5
  23. package/lib/makes/FS.js +42 -9
  24. package/lib/makes/Http.d.ts +18 -0
  25. package/lib/makes/{Plugin.js → Http.js} +45 -34
  26. package/lib/makes/Logger.d.ts +2 -2
  27. package/lib/makes/Logger.js +19 -8
  28. package/lib/makes/Preset.d.ts +5 -6
  29. package/lib/makes/Preset.js +19 -8
  30. package/lib/makes/index.d.ts +1 -6
  31. package/lib/makes/index.js +1 -6
  32. package/lib/plugins/ElasticSearchPlugin.d.ts +5 -6
  33. package/lib/plugins/ElasticSearchPlugin.js +19 -8
  34. package/lib/plugins/LocaltunnelPlugin.d.ts +8 -8
  35. package/lib/plugins/LocaltunnelPlugin.js +25 -10
  36. package/lib/plugins/MaildevPlugin.d.ts +5 -6
  37. package/lib/plugins/MaildevPlugin.js +21 -8
  38. package/lib/plugins/MongodbPlugin.d.ts +5 -5
  39. package/lib/plugins/MongodbPlugin.js +26 -11
  40. package/lib/plugins/NgrokPlugin.d.ts +7 -6
  41. package/lib/plugins/NgrokPlugin.js +32 -17
  42. package/lib/plugins/PageKitePlugin.d.ts +10 -8
  43. package/lib/plugins/PageKitePlugin.js +36 -20
  44. package/lib/plugins/ProxmoxPlugin.d.ts +8 -5
  45. package/lib/plugins/ProxmoxPlugin.js +25 -9
  46. package/lib/plugins/RedisPlugin.d.ts +4 -6
  47. package/lib/plugins/RedisPlugin.js +19 -8
  48. package/lib/plugins/index.d.ts +0 -2
  49. package/lib/plugins/index.js +0 -2
  50. package/lib/services/AppConfigService.d.ts +7 -17
  51. package/lib/services/AppConfigService.js +44 -114
  52. package/lib/services/AppEventsService.d.ts +1 -2
  53. package/lib/services/AppEventsService.js +11 -2
  54. package/lib/services/DockerService.d.ts +9 -39
  55. package/lib/services/DockerService.js +122 -4
  56. package/lib/services/LogService.d.ts +3 -5
  57. package/lib/services/LogService.js +19 -4
  58. package/lib/services/PluginService.d.ts +11 -9
  59. package/lib/services/PluginService.js +100 -8
  60. package/lib/services/PresetService.d.ts +4 -5
  61. package/lib/services/PresetService.js +26 -5
  62. package/lib/services/ProjectService.d.ts +9 -6
  63. package/lib/services/ProjectService.js +72 -37
  64. package/lib/utils/exec.d.ts +4 -1
  65. package/lib/utils/exec.js +16 -31
  66. package/lib/utils/followProgress.js +49 -45
  67. package/lib/utils/index.d.ts +0 -7
  68. package/lib/utils/index.js +0 -7
  69. package/lib/utils/spawn.d.ts +1 -1
  70. package/lib/utils/spawn.js +20 -12
  71. package/package.json +5 -7
  72. package/presets/node/config.json +1 -1
  73. package/presets/php-apache/Dockerfile +1 -1
  74. package/presets/php-apache/config.json +2 -1
  75. package/presets/php-fpm/Dockerfile +1 -1
  76. package/lib/App.d.ts +0 -16
  77. package/lib/App.js +0 -107
  78. package/lib/decorators/Inject.d.ts +0 -1
  79. package/lib/decorators/Inject.js +0 -8
  80. package/lib/decorators/Injectable.d.ts +0 -4
  81. package/lib/decorators/Injectable.js +0 -17
  82. package/lib/decorators/index.d.ts +0 -1
  83. package/lib/decorators/index.js +0 -17
  84. package/lib/index.d.ts +0 -6
  85. package/lib/index.js +0 -33
  86. package/lib/makes/Controller.d.ts +0 -5
  87. package/lib/makes/Controller.js +0 -8
  88. package/lib/makes/DI.d.ts +0 -7
  89. package/lib/makes/DI.js +0 -27
  90. package/lib/makes/Docker.d.ts +0 -58
  91. package/lib/makes/Docker.js +0 -320
  92. package/lib/makes/Plugin.d.ts +0 -13
  93. package/lib/makes/Project.d.ts +0 -45
  94. package/lib/makes/Project.js +0 -127
  95. package/lib/makes/Repository.d.ts +0 -11
  96. package/lib/makes/Repository.js +0 -22
  97. package/lib/plugins/PostgresPlugin.d.ts +0 -16
  98. package/lib/plugins/PostgresPlugin.js +0 -121
  99. package/lib/types/Config.d.ts +0 -12
  100. package/lib/types/Config.js +0 -2
  101. package/lib/types/EnvConfig.d.ts +0 -3
  102. package/lib/types/EnvConfig.js +0 -2
  103. package/lib/types/index.d.ts +0 -2
  104. package/lib/types/index.js +0 -18
  105. package/lib/utils/buildOptions.d.ts +0 -1
  106. package/lib/utils/buildOptions.js +0 -9
  107. package/lib/utils/demuxOutput.d.ts +0 -2
  108. package/lib/utils/demuxOutput.js +0 -19
  109. package/lib/utils/fetch.d.ts +0 -5
  110. package/lib/utils/fetch.js +0 -52
  111. package/lib/utils/get-config.d.ts +0 -2
  112. package/lib/utils/get-config.js +0 -17
  113. package/lib/utils/image-build.d.ts +0 -13
  114. package/lib/utils/image-build.js +0 -46
  115. package/lib/utils/set-config.d.ts +0 -2
  116. package/lib/utils/set-config.js +0 -15
  117. package/lib/utils/tty.d.ts +0 -2
  118. package/lib/utils/tty.js +0 -6
@@ -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,24 +28,32 @@ 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 extends core_1.AppConfigService {
31
41
  constructor() {
42
+ super();
32
43
  this.mapTypes = {
33
44
  image: "Image",
34
45
  dockerfile: "Dockerfile"
35
46
  };
36
47
  this.pwd = (process.cwd() || process.env.PWD);
37
48
  }
38
- dataPath(...args) {
39
- return Path.join(env_1.DATA_DIR, ...args);
49
+ dataPath(...parts) {
50
+ return Path.join(env_1.DATA_DIR, ...parts);
51
+ }
52
+ pluginsPath(...parts) {
53
+ return Path.join(env_1.PLUGINS_DIR, ...parts);
40
54
  }
41
- pluginsPath(...args) {
42
- return Path.join(env_1.PLUGINS_DIR, ...args);
55
+ presetPath(...parts) {
56
+ return Path.join(env_1.PRESETS_DIR, ...parts);
43
57
  }
44
58
  getPWD() {
45
59
  return this.pwd;
@@ -47,121 +61,37 @@ class AppConfigService {
47
61
  setPWD(pwd) {
48
62
  this.pwd = pwd;
49
63
  }
50
- async getAppConfig() {
51
- return makes_1.FS.readJSON(env_1.MAP_PATH);
52
- }
53
- async saveAppConfig(config) {
54
- await makes_1.FS.writeJSON(env_1.MAP_PATH, config);
55
- }
56
- async getMeta(name, defaultValue) {
57
- const config = await this.getAppConfig();
58
- const value = (config.meta || {})[name];
59
- if (!value) {
60
- return defaultValue;
61
- }
62
- return value;
63
- }
64
- async setMeta(name, value) {
65
- const config = await this.getAppConfig();
66
- if (!config.meta) {
67
- config.meta = {};
68
- }
69
- config.meta[name] = value ? value.toString() : undefined;
70
- await this.saveAppConfig(config);
71
- }
72
- async getAllEnvVariables() {
73
- const { env = {} } = await makes_1.FS.readJSON(env_1.MAP_PATH);
74
- return env;
75
- }
76
- async getEnvVariable(name, defaultValue) {
77
- const { [name]: value = defaultValue } = await this.getAllEnvVariables();
78
- if (value === null) {
79
- return defaultValue;
80
- }
81
- return value;
82
- }
83
- async setEnv(env) {
84
- const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
85
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
86
- ...config,
87
- env: {
88
- ...config.env || {},
89
- ...env
90
- }
91
- });
92
- }
93
- async setEnvVariable(name, value) {
94
- const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
95
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
96
- ...config,
97
- env: {
98
- ...config.env || {},
99
- [name]: value
100
- }
101
- });
102
- }
103
- async unsetEnv(...keys) {
104
- const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
105
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
106
- ...config,
107
- env: Object.keys(config.env || {}).reduce((res, key) => {
108
- if (!keys.includes(key)) {
109
- res[key] = config.env[key];
110
- }
111
- return res;
112
- }, {})
113
- });
114
- }
115
64
  getProjectTypes() {
116
65
  return this.mapTypes;
117
66
  }
118
67
  registerProjectType(name, title) {
119
68
  this.mapTypes[name] = title || name;
120
69
  }
121
- async setProjectConfig(id, path) {
122
- const { projects, ...rest } = await this.getAppConfig();
123
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
124
- ...rest,
125
- projects: [
126
- ...(projects || []).filter((project) => {
127
- return project.id !== id;
128
- }).filter((project) => {
129
- return project.src !== path;
130
- }),
131
- {
132
- id: id,
133
- src: path
70
+ async loadConfig() {
71
+ const data = makes_1.FS.existsSync(env_1.MAP_PATH)
72
+ ? await makes_1.FS.readJSON(env_1.MAP_PATH)
73
+ : {};
74
+ return new class extends core_1.Config {
75
+ constructor(data) {
76
+ super(data);
77
+ }
78
+ addPlugin(plugin) {
79
+ if (!this.plugins) {
80
+ this.plugins = [];
134
81
  }
135
- ]
136
- });
137
- }
138
- async activatePlugin(name) {
139
- const { default: Plugin } = await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
140
- if (!Plugin) {
141
- throw new Error("No plugin");
142
- }
143
- const { plugins = [], ...rest } = await this.getAppConfig();
144
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
145
- plugins: [
146
- ...plugins.filter((plugin) => {
147
- return plugin !== name;
148
- }),
149
- name
150
- ],
151
- ...rest
152
- });
153
- }
154
- async deactivatePlugin(name) {
155
- const { plugins = [], ...rest } = await this.getAppConfig();
156
- if (!plugins.includes(name)) {
157
- return;
158
- }
159
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
160
- plugins: plugins.filter((plugin) => {
161
- return plugin !== name;
162
- }),
163
- ...rest
164
- });
82
+ if (this.plugins.includes(plugin)) {
83
+ return;
84
+ }
85
+ this.plugins.push(plugin);
86
+ }
87
+ async save() {
88
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, this.toJson());
89
+ }
90
+ }(data);
165
91
  }
166
- }
92
+ };
167
93
  exports.AppConfigService = AppConfigService;
94
+ exports.AppConfigService = AppConfigService = __decorate([
95
+ (0, core_1.Injectable)("APP_CONFIG"),
96
+ __metadata("design:paramtypes", [])
97
+ ], 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,13 @@
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
+ import { AppConfigService } from "./AppConfigService";
3
+ import { LogService } from "./LogService";
4
+ export declare class PluginService {
5
+ protected readonly appConfigService: AppConfigService;
6
+ protected readonly logService: LogService;
7
+ protected readonly cli: Cli;
8
+ constructor(appConfigService: AppConfigService, logService: LogService, cli: Cli);
9
+ checkPlugin(pluginName: string): Promise<boolean>;
10
+ import(): Promise<void>;
11
+ update(): Promise<void>;
12
+ protected getCurrentVersion(name: string): Promise<string | null>;
10
13
  }
11
- export { PluginService };
@@ -1,15 +1,107 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
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
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
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
+ };
2
34
  Object.defineProperty(exports, "__esModule", { value: true });
3
35
  exports.PluginService = void 0;
4
36
  const core_1 = require("@wocker/core");
5
- class PluginService {
6
- constructor(di) {
7
- this.di = di;
8
- this.cli = di.resolveService(core_1.Cli);
37
+ const AppConfigService_1 = require("./AppConfigService");
38
+ const LogService_1 = require("./LogService");
39
+ const makes_1 = require("../makes");
40
+ const utils_1 = require("../utils");
41
+ let PluginService = class PluginService {
42
+ constructor(appConfigService, logService, cli) {
43
+ this.appConfigService = appConfigService;
44
+ this.logService = logService;
45
+ this.cli = cli;
46
+ }
47
+ async checkPlugin(pluginName) {
48
+ try {
49
+ const { default: Plugin } = await Promise.resolve(`${pluginName}`).then(s => __importStar(require(s)));
50
+ const name = Reflect.getMetadata(core_1.MODULE_METADATA.NAME, Plugin);
51
+ if (!name) {
52
+ console.log("No name");
53
+ }
54
+ return !!name;
55
+ }
56
+ catch (err) {
57
+ this.logService.error(err.message);
58
+ }
59
+ return false;
60
+ }
61
+ async import() {
62
+ }
63
+ async update() {
64
+ const config = await this.appConfigService.getConfig();
65
+ if (!config.plugins) {
66
+ return;
67
+ }
68
+ for (const name of new Set(config.plugins).values()) {
69
+ console.info(`Checking ${name}...`);
70
+ try {
71
+ const current = await this.getCurrentVersion(name);
72
+ const res = await makes_1.Http.get("https://registry.npmjs.org")
73
+ .send(name);
74
+ if (res.status !== 200) {
75
+ continue;
76
+ }
77
+ const { "dist-tags": { latest } } = res.data;
78
+ this.logService.info(name, current, latest);
79
+ if (!current || current < latest) {
80
+ console.log(`Updating ${name}...`);
81
+ await (0, utils_1.spawn)("npm", ["i", "-g", name]);
82
+ }
83
+ }
84
+ catch (err) {
85
+ this.logService.error(err.message);
86
+ }
87
+ }
88
+ console.info("Done");
9
89
  }
10
- use(Constructor) {
11
- const controller = new Constructor(this.di);
12
- controller.install(this.cli);
90
+ async getCurrentVersion(name) {
91
+ try {
92
+ const { dependencies: { [name]: { version } } } = JSON.parse(await (0, utils_1.exec)(`npm ls --json -g ${name}`));
93
+ return version;
94
+ }
95
+ catch (err) {
96
+ this.logService.error(`Failed to get current version of ${name}`);
97
+ }
98
+ return null;
13
99
  }
14
- }
100
+ };
15
101
  exports.PluginService = PluginService;
102
+ exports.PluginService = PluginService = __decorate([
103
+ (0, core_1.Injectable)(),
104
+ __metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
105
+ LogService_1.LogService,
106
+ core_1.Cli])
107
+ ], PluginService);