@wocker/ws 1.0.15 → 1.0.17

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.
package/lib/AppModule.js CHANGED
@@ -38,10 +38,9 @@ let AppModule = AppModule_1 = class AppModule {
38
38
  async load(container) {
39
39
  const appConfigService = container.getModule(AppModule_1).get(services_1.AppConfigService);
40
40
  const logService = container.getModule(AppModule_1).get(services_1.LogService);
41
- const pluginService = container.getModule(AppModule_1).get(services_1.PluginService);
42
- const config = await appConfigService.getConfig();
41
+ const config = appConfigService.getConfig();
43
42
  const imports = [];
44
- for (const plugin of config.plugins) {
43
+ for (const plugin of config.plugins || []) {
45
44
  try {
46
45
  const { default: Plugin } = await Promise.resolve(`${plugin}`).then(s => __importStar(require(s)));
47
46
  if (!Plugin) {
@@ -71,6 +70,7 @@ let AppModule = AppModule_1 = class AppModule {
71
70
  };
72
71
  exports.AppModule = AppModule;
73
72
  exports.AppModule = AppModule = AppModule_1 = __decorate([
73
+ (0, core_1.Global)(),
74
74
  (0, core_1.Module)({
75
75
  controllers: [
76
76
  controllers_1.CompletionController,
@@ -86,6 +86,7 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
86
86
  services_1.AppEventsService,
87
87
  services_1.DockerService,
88
88
  services_1.LogService,
89
+ services_1.NpmService,
89
90
  services_1.PluginService,
90
91
  services_1.PresetService,
91
92
  services_1.ProjectService,
@@ -95,7 +96,9 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
95
96
  services_1.AppConfigService,
96
97
  services_1.AppEventsService,
97
98
  services_1.DockerService,
98
- services_1.LogService
99
+ services_1.LogService,
100
+ services_1.ProjectService,
101
+ services_1.ProxyService
99
102
  ]
100
103
  })
101
104
  ], AppModule);
@@ -4,5 +4,8 @@ export declare class DebugController {
4
4
  protected readonly logService: LogService;
5
5
  constructor(appConfigService: AppConfigService, logService: LogService);
6
6
  debug(status: string): Promise<void>;
7
+ setLog(level: string): Promise<void>;
8
+ testLog(level: string, args: string[]): Promise<void>;
7
9
  debugCompletion(): Promise<string[]>;
10
+ getLevels(): string[];
8
11
  }
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.DebugController = void 0;
13
16
  const core_1 = require("@wocker/core");
@@ -18,27 +21,66 @@ let DebugController = class DebugController {
18
21
  this.logService = logService;
19
22
  }
20
23
  async debug(status) {
21
- const config = await this.appConfigService.getConfig();
24
+ const config = this.appConfigService.getConfig();
22
25
  config.debug = status === "on";
23
26
  await config.save();
24
27
  }
28
+ async setLog(level) {
29
+ const validLevels = this.getLevels();
30
+ if (!validLevels.includes(level)) {
31
+ throw new Error(`Invalid log level: ${level}. Valid options are ${validLevels.join(', ')}`);
32
+ }
33
+ const config = this.appConfigService.getConfig();
34
+ config.logLevel = level;
35
+ await config.save();
36
+ }
37
+ async testLog(level, args) {
38
+ this.logService._log(level, ...args);
39
+ }
25
40
  async debugCompletion() {
26
41
  return ["on", "off"];
27
42
  }
43
+ getLevels() {
44
+ return ["debug", "info", "warn", "error"];
45
+ }
28
46
  };
29
47
  exports.DebugController = DebugController;
30
48
  __decorate([
49
+ (0, core_1.Command)("debug:<status>"),
31
50
  (0, core_1.Command)("debug <status>"),
51
+ __param(0, (0, core_1.Param)("status")),
32
52
  __metadata("design:type", Function),
33
53
  __metadata("design:paramtypes", [String]),
34
54
  __metadata("design:returntype", Promise)
35
55
  ], DebugController.prototype, "debug", null);
56
+ __decorate([
57
+ (0, core_1.Description)("Set the log level (options: debug, log, info, warn, error)"),
58
+ (0, core_1.Command)("loglevel <level>"),
59
+ __param(0, (0, core_1.Param)("level")),
60
+ __metadata("design:type", Function),
61
+ __metadata("design:paramtypes", [String]),
62
+ __metadata("design:returntype", Promise)
63
+ ], DebugController.prototype, "setLog", null);
64
+ __decorate([
65
+ (0, core_1.Command)("log:<level> [...args]"),
66
+ __param(0, (0, core_1.Param)("level")),
67
+ __param(1, (0, core_1.Param)("args")),
68
+ __metadata("design:type", Function),
69
+ __metadata("design:paramtypes", [String, Array]),
70
+ __metadata("design:returntype", Promise)
71
+ ], DebugController.prototype, "testLog", null);
36
72
  __decorate([
37
73
  (0, core_1.Completion)("status"),
38
74
  __metadata("design:type", Function),
39
75
  __metadata("design:paramtypes", []),
40
76
  __metadata("design:returntype", Promise)
41
77
  ], DebugController.prototype, "debugCompletion", null);
78
+ __decorate([
79
+ (0, core_1.Completion)("level"),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", []),
82
+ __metadata("design:returntype", Array)
83
+ ], DebugController.prototype, "getLevels", null);
42
84
  exports.DebugController = DebugController = __decorate([
43
85
  (0, core_1.Controller)(),
44
86
  __metadata("design:paramtypes", [services_1.AppConfigService,
@@ -1,12 +1,13 @@
1
- import { AppConfigService, PluginService, LogService } from "../services";
1
+ import { AppConfigService, PluginService, LogService, NpmService } from "../services";
2
2
  export declare class PluginController {
3
3
  protected readonly appConfigService: AppConfigService;
4
4
  protected readonly pluginService: PluginService;
5
+ protected readonly npmService: NpmService;
5
6
  protected readonly logService: LogService;
6
- constructor(appConfigService: AppConfigService, pluginService: PluginService, logService: LogService);
7
+ constructor(appConfigService: AppConfigService, pluginService: PluginService, npmService: NpmService, logService: LogService);
7
8
  list(): Promise<string>;
8
- add(addName: string): Promise<void>;
9
+ add(addName: string, dev?: boolean): Promise<void>;
9
10
  remove(removeName: string): Promise<void>;
10
11
  update(): Promise<void>;
11
- getInstalledPlugins(): Promise<string[]>;
12
+ getInstalledPlugins(): string[];
12
13
  }
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
11
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
16
  };
@@ -17,30 +20,31 @@ const core_1 = require("@wocker/core");
17
20
  const chalk_1 = __importDefault(require("chalk"));
18
21
  const cli_table3_1 = __importDefault(require("cli-table3"));
19
22
  const services_1 = require("../services");
20
- const utils_1 = require("../utils");
21
- const Http_1 = require("../makes/Http");
22
23
  let PluginController = class PluginController {
23
- constructor(appConfigService, pluginService, logService) {
24
+ constructor(appConfigService, pluginService, npmService, logService) {
24
25
  this.appConfigService = appConfigService;
25
26
  this.pluginService = pluginService;
27
+ this.npmService = npmService;
26
28
  this.logService = logService;
27
29
  }
28
30
  async list() {
29
- const config = await this.appConfigService.getConfig();
31
+ const config = this.appConfigService.getConfig();
30
32
  const table = new cli_table3_1.default({
31
33
  head: ["Name"],
32
34
  colWidths: [30]
33
35
  });
36
+ if (!config.plugins) {
37
+ return chalk_1.default.gray("No plugins installed");
38
+ }
34
39
  for (const name of config.plugins) {
35
40
  table.push([name]);
36
41
  }
37
42
  return table.toString() + "\n";
38
43
  }
39
- async add(addName) {
44
+ async add(addName, dev) {
40
45
  const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(addName) || [];
41
46
  const fullName = `${prefix}${name}${suffix}`;
42
- this.logService.info(`Installing plugin... ${fullName}`);
43
- const config = await this.appConfigService.getConfig();
47
+ const config = this.appConfigService.getConfig();
44
48
  try {
45
49
  if (await this.pluginService.checkPlugin(fullName)) {
46
50
  config.addPlugin(fullName);
@@ -48,14 +52,8 @@ let PluginController = class PluginController {
48
52
  console.info(`Plugin ${fullName} activated`);
49
53
  return;
50
54
  }
51
- const res = await Http_1.Http.get("https://registry.npmjs.org")
52
- .send(fullName);
53
- if (res.status !== 200) {
54
- console.error(chalk_1.default.red(`Plugin ${fullName} not found`));
55
- return;
56
- }
57
- console.info(`Installing ${fullName}`);
58
- await (0, utils_1.exec)(`npm install -g ${fullName}`);
55
+ const packageInfo = await this.npmService.getPackageInfo(fullName);
56
+ await this.npmService.install(fullName, packageInfo["dist-tags"].dev && dev ? "dev" : "latest");
59
57
  if (await this.pluginService.checkPlugin(fullName)) {
60
58
  config.addPlugin(fullName);
61
59
  await config.save();
@@ -70,7 +68,7 @@ let PluginController = class PluginController {
70
68
  async remove(removeName) {
71
69
  const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(removeName) || [];
72
70
  const fullName = `${prefix}${name}${suffix}`;
73
- const config = await this.appConfigService.getConfig();
71
+ const config = this.appConfigService.getConfig();
74
72
  config.removePlugin(fullName);
75
73
  await config.save();
76
74
  console.info(`Plugin ${fullName} deactivated`);
@@ -78,22 +76,31 @@ let PluginController = class PluginController {
78
76
  async update() {
79
77
  await this.pluginService.update();
80
78
  }
81
- async getInstalledPlugins() {
82
- const config = await this.appConfigService.getConfig();
79
+ getInstalledPlugins() {
80
+ const config = this.appConfigService.getConfig();
83
81
  return config.plugins || [];
84
82
  }
85
83
  };
86
84
  exports.PluginController = PluginController;
87
85
  __decorate([
88
86
  (0, core_1.Command)("plugins"),
87
+ (0, core_1.Description)("Plugins list"),
89
88
  __metadata("design:type", Function),
90
89
  __metadata("design:paramtypes", []),
91
90
  __metadata("design:returntype", Promise)
92
91
  ], PluginController.prototype, "list", null);
93
92
  __decorate([
94
93
  (0, core_1.Command)("plugin:add <name>"),
94
+ (0, core_1.Command)("plugin:install <name>"),
95
+ (0, core_1.Description)("Install a plugin"),
96
+ __param(0, (0, core_1.Param)("name")),
97
+ __param(1, (0, core_1.Option)("dev", {
98
+ type: "boolean",
99
+ alias: "d",
100
+ description: "Use dev version of plugin"
101
+ })),
95
102
  __metadata("design:type", Function),
96
- __metadata("design:paramtypes", [String]),
103
+ __metadata("design:paramtypes", [String, Boolean]),
97
104
  __metadata("design:returntype", Promise)
98
105
  ], PluginController.prototype, "add", null);
99
106
  __decorate([
@@ -113,11 +120,12 @@ __decorate([
113
120
  (0, core_1.Completion)("name", "plugin:remove <name>"),
114
121
  __metadata("design:type", Function),
115
122
  __metadata("design:paramtypes", []),
116
- __metadata("design:returntype", Promise)
123
+ __metadata("design:returntype", Array)
117
124
  ], PluginController.prototype, "getInstalledPlugins", null);
118
125
  exports.PluginController = PluginController = __decorate([
119
126
  (0, core_1.Controller)(),
120
127
  __metadata("design:paramtypes", [services_1.AppConfigService,
121
128
  services_1.PluginService,
129
+ services_1.NpmService,
122
130
  services_1.LogService])
123
131
  ], PluginController);
@@ -11,6 +11,8 @@ export declare class PresetController {
11
11
  protected onInit(project: Project): Promise<void>;
12
12
  protected onRebuild(project: Project): Promise<void>;
13
13
  protected onBeforeStart(project: Project): Promise<void>;
14
+ init(): Promise<void>;
15
+ deinit(): Promise<void>;
14
16
  add(name: string): Promise<void>;
15
17
  delete(name: string, confirm?: boolean): Promise<void>;
16
18
  eject(name?: string): Promise<void>;
@@ -50,7 +50,6 @@ let PresetController = class PresetController {
50
50
  this.projectService = projectService;
51
51
  this.presetService = presetService;
52
52
  this.dockerService = dockerService;
53
- this.appConfigService.registerProjectType("preset", "Preset");
54
53
  this.appEventsService.on("project:init", (project) => this.onInit(project));
55
54
  this.appEventsService.on("project:beforeStart", (project) => this.onBeforeStart(project));
56
55
  this.appEventsService.on("project:rebuild", (project) => this.onRebuild(project));
@@ -62,7 +61,7 @@ let PresetController = class PresetController {
62
61
  });
63
62
  }
64
63
  async onInit(project) {
65
- if (project.type !== "preset") {
64
+ if (project.type !== core_1.PROJECT_TYPE_PRESET) {
66
65
  return;
67
66
  }
68
67
  const presets = await this.presetService.search();
@@ -79,6 +78,19 @@ let PresetController = class PresetController {
79
78
  }),
80
79
  default: project.preset
81
80
  });
81
+ project.presetMode = await (0, utils_1.promptSelect)({
82
+ message: "Preset mode:",
83
+ options: [
84
+ {
85
+ label: "For project only",
86
+ value: "project"
87
+ },
88
+ {
89
+ label: "Global usage",
90
+ value: "global"
91
+ }
92
+ ]
93
+ });
82
94
  const preset = await this.presetService.get(project.preset);
83
95
  if (!preset) {
84
96
  throw new Error("Preset not found");
@@ -95,15 +107,16 @@ let PresetController = class PresetController {
95
107
  ...project.buildArgs || {},
96
108
  ...project.env || {}
97
109
  });
98
- const { destination, options } = (0, utils_3.volumeParse)(volume);
110
+ const { source, destination, options } = (0, utils_3.volumeParse)(volume);
99
111
  let projectVolume = project.getVolumeByDestination(destination);
100
- const source = await (0, utils_1.promptText)({
101
- message: "Volume",
112
+ const newSource = await (0, utils_1.promptText)({
113
+ message: "Volume:",
114
+ required: true,
102
115
  suffix: `:${destination}`,
103
- default: projectVolume ? (0, utils_3.volumeParse)(projectVolume).source : "./"
116
+ default: projectVolume ? (0, utils_3.volumeParse)(projectVolume).source : source
104
117
  });
105
118
  projectVolume = (0, utils_3.volumeFormat)({
106
- source,
119
+ source: newSource,
107
120
  destination,
108
121
  options
109
122
  });
@@ -111,7 +124,7 @@ let PresetController = class PresetController {
111
124
  }
112
125
  }
113
126
  if (preset.dockerfile) {
114
- project.imageName = this.presetService.getImageName(preset, project.buildArgs);
127
+ project.imageName = this.presetService.getImageNameForProject(project, preset);
115
128
  }
116
129
  }
117
130
  async onRebuild(project) {
@@ -122,7 +135,7 @@ let PresetController = class PresetController {
122
135
  if (!preset) {
123
136
  throw new Error(`Preset ${project.preset} not found`);
124
137
  }
125
- const imageName = this.presetService.getImageName(preset, project.buildArgs || {});
138
+ const imageName = this.presetService.getImageNameForProject(project, preset);
126
139
  const exists = await this.dockerService.imageExists(imageName);
127
140
  if (exists) {
128
141
  console.info(`Removing image: ${imageName}`);
@@ -135,7 +148,7 @@ let PresetController = class PresetController {
135
148
  }
136
149
  const preset = await this.presetService.get(project.preset);
137
150
  if (preset.dockerfile) {
138
- project.imageName = this.presetService.getImageName(preset, project.buildArgs);
151
+ project.imageName = this.presetService.getImageNameForProject(project, preset);
139
152
  if (!await this.dockerService.imageExists(project.imageName)) {
140
153
  await this.dockerService.buildImage({
141
154
  tag: project.imageName,
@@ -149,6 +162,12 @@ let PresetController = class PresetController {
149
162
  }
150
163
  }
151
164
  }
165
+ async init() {
166
+ await this.presetService.init();
167
+ }
168
+ async deinit() {
169
+ await this.presetService.deinit();
170
+ }
152
171
  async add(name) {
153
172
  await this.presetService.addPreset(name);
154
173
  }
@@ -182,7 +201,7 @@ let PresetController = class PresetController {
182
201
  if (!confirm) {
183
202
  return;
184
203
  }
185
- const copier = new core_1.FSManager(this.appConfigService.presetPath(preset.name), this.appConfigService.getPWD());
204
+ const copier = new core_1.FSManager(this.appConfigService.presetPath(preset.name), this.appConfigService.pwd());
186
205
  if (preset.dockerfile) {
187
206
  if (!copier.destination.exists(preset.dockerfile)) {
188
207
  await copier.copy(preset.dockerfile);
@@ -222,6 +241,9 @@ let PresetController = class PresetController {
222
241
  buildArgs = await (0, utils_1.promptGroup)(preset.buildArgsOptions);
223
242
  }
224
243
  const imageName = this.presetService.getImageName(preset, buildArgs);
244
+ if (rebuild) {
245
+ await this.dockerService.imageRm(imageName);
246
+ }
225
247
  await this.dockerService.buildImage({
226
248
  tag: imageName,
227
249
  labels: {
@@ -234,6 +256,18 @@ let PresetController = class PresetController {
234
256
  }
235
257
  };
236
258
  exports.PresetController = PresetController;
259
+ __decorate([
260
+ (0, core_1.Command)("preset:init"),
261
+ __metadata("design:type", Function),
262
+ __metadata("design:paramtypes", []),
263
+ __metadata("design:returntype", Promise)
264
+ ], PresetController.prototype, "init", null);
265
+ __decorate([
266
+ (0, core_1.Command)("preset:deinit"),
267
+ __metadata("design:type", Function),
268
+ __metadata("design:paramtypes", []),
269
+ __metadata("design:returntype", Promise)
270
+ ], PresetController.prototype, "deinit", null);
237
271
  __decorate([
238
272
  (0, core_1.Command)("preset:add <preset>"),
239
273
  __param(0, (0, core_1.Param)("preset")),
@@ -1,3 +1,4 @@
1
+ import { ProjectType } from "@wocker/core";
1
2
  import { AppConfigService, AppEventsService, ProjectService, DockerService, LogService } from "../services";
2
3
  export declare class ProjectController {
3
4
  protected readonly appConfigService: AppConfigService;
@@ -8,7 +9,7 @@ export declare class ProjectController {
8
9
  constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService, logService: LogService);
9
10
  protected getProjectNames(): Promise<string[]>;
10
11
  getScriptNames(): Promise<string[]>;
11
- init(name: string, type: string, preset: string): Promise<void>;
12
+ init(name: string, type: ProjectType): Promise<void>;
12
13
  projectList(all: boolean): Promise<string>;
13
14
  start(name?: string, detach?: boolean, attach?: boolean, rebuild?: boolean, restart?: boolean): Promise<void>;
14
15
  stop(name: string): Promise<void>;
@@ -32,6 +33,9 @@ export declare class ProjectController {
32
33
  volumeList(name?: string): Promise<string>;
33
34
  volumeMount(name: string, volumes: string[]): Promise<void>;
34
35
  volumeUnmount(name: string, volumes: string[]): Promise<void>;
36
+ extraHostList(name?: string): Promise<string>;
37
+ addExtraHost(extraHost: string, extraDomain: string, name?: string): Promise<void>;
38
+ removeExtraHost(extraHost: string, name?: string): Promise<void>;
35
39
  logs(name?: string, global?: boolean, detach?: boolean, follow?: boolean): Promise<void>;
36
40
  exec(name?: string, command?: string[]): Promise<void>;
37
41
  run(name: string, script: string, args?: string[]): Promise<void>;