@wocker/ws 1.0.8 → 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 (55) hide show
  1. package/bin/ws.js +1 -12
  2. package/lib/AppModule.js +6 -3
  3. package/lib/controllers/DebugController.d.ts +7 -0
  4. package/lib/controllers/DebugController.js +44 -0
  5. package/lib/controllers/PluginController.d.ts +2 -0
  6. package/lib/controllers/PluginController.js +42 -41
  7. package/lib/controllers/PresetController.d.ts +1 -0
  8. package/lib/controllers/PresetController.js +71 -6
  9. package/lib/controllers/ProjectController.d.ts +2 -3
  10. package/lib/controllers/ProjectController.js +36 -60
  11. package/lib/controllers/ProxyController.js +15 -6
  12. package/lib/controllers/index.d.ts +1 -0
  13. package/lib/controllers/index.js +1 -0
  14. package/lib/main.d.ts +1 -1
  15. package/lib/main.js +21 -2
  16. package/lib/makes/FS.d.ts +15 -5
  17. package/lib/makes/FS.js +42 -9
  18. package/lib/makes/Http.d.ts +18 -0
  19. package/lib/makes/Http.js +72 -0
  20. package/lib/makes/Preset.d.ts +2 -2
  21. package/lib/makes/index.d.ts +1 -0
  22. package/lib/makes/index.js +1 -0
  23. package/lib/services/AppConfigService.d.ts +6 -16
  24. package/lib/services/AppConfigService.js +29 -113
  25. package/lib/services/PluginService.d.ts +9 -2
  26. package/lib/services/PluginService.js +85 -3
  27. package/lib/services/PresetService.d.ts +1 -2
  28. package/lib/services/PresetService.js +19 -7
  29. package/lib/services/ProjectService.js +15 -11
  30. package/lib/utils/exec.d.ts +4 -1
  31. package/lib/utils/exec.js +16 -31
  32. package/lib/utils/followProgress.js +49 -45
  33. package/lib/utils/index.d.ts +0 -6
  34. package/lib/utils/index.js +0 -6
  35. package/lib/utils/spawn.d.ts +1 -1
  36. package/lib/utils/spawn.js +20 -12
  37. package/package.json +3 -5
  38. package/presets/php-apache/Dockerfile +1 -1
  39. package/presets/php-apache/config.json +2 -1
  40. package/lib/App.d.ts +0 -11
  41. package/lib/App.js +0 -81
  42. package/lib/index.d.ts +0 -5
  43. package/lib/index.js +0 -22
  44. package/lib/utils/buildOptions.d.ts +0 -1
  45. package/lib/utils/buildOptions.js +0 -9
  46. package/lib/utils/fetch.d.ts +0 -5
  47. package/lib/utils/fetch.js +0 -52
  48. package/lib/utils/get-config.d.ts +0 -2
  49. package/lib/utils/get-config.js +0 -17
  50. package/lib/utils/image-build.d.ts +0 -13
  51. package/lib/utils/image-build.js +0 -46
  52. package/lib/utils/set-config.d.ts +0 -2
  53. package/lib/utils/set-config.js +0 -15
  54. package/lib/utils/tty.d.ts +0 -2
  55. package/lib/utils/tty.js +0 -6
package/bin/ws.js CHANGED
@@ -1,17 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const chalk = require("chalk");
4
3
  const {app} = require("../lib/main.js");
5
4
 
6
5
 
7
- app.run(process.argv).then((res) => {
8
- if(!res) {
9
- return;
10
- }
11
-
12
- process.stdout.write(res);
13
- }).catch((err) => {
14
- console.error(chalk.red(err.message));
15
-
16
- // throw err;
17
- });
6
+ app.run(process.argv);
package/lib/AppModule.js CHANGED
@@ -38,10 +38,10 @@ 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 config = await appConfigService.getAppConfig();
42
- const { plugins } = config;
41
+ const pluginService = container.getModule(AppModule_1).get(services_1.PluginService);
42
+ const config = await appConfigService.getConfig();
43
43
  const imports = [];
44
- for (const plugin of plugins) {
44
+ for (const plugin of config.plugins) {
45
45
  try {
46
46
  const { default: Plugin } = await Promise.resolve(`${plugin}`).then(s => __importStar(require(s)));
47
47
  if (!Plugin) {
@@ -59,6 +59,8 @@ let AppModule = AppModule_1 = class AppModule {
59
59
  }
60
60
  catch (err) {
61
61
  logService.error(err.message);
62
+ config.removePlugin(plugin);
63
+ await config.save();
62
64
  throw err;
63
65
  }
64
66
  }
@@ -72,6 +74,7 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
72
74
  (0, core_1.Module)({
73
75
  controllers: [
74
76
  controllers_1.CompletionController,
77
+ controllers_1.DebugController,
75
78
  controllers_1.ImageController,
76
79
  controllers_1.PluginController,
77
80
  controllers_1.PresetController,
@@ -0,0 +1,7 @@
1
+ import { AppConfigService } from "../services";
2
+ export declare class DebugController {
3
+ protected readonly appConfigService: AppConfigService;
4
+ constructor(appConfigService: AppConfigService);
5
+ debug(status: string): Promise<void>;
6
+ debugCompletion(): Promise<string[]>;
7
+ }
@@ -0,0 +1,44 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DebugController = void 0;
13
+ const core_1 = require("@wocker/core");
14
+ const services_1 = require("../services");
15
+ let DebugController = class DebugController {
16
+ constructor(appConfigService) {
17
+ this.appConfigService = appConfigService;
18
+ }
19
+ async debug(status) {
20
+ const config = await this.appConfigService.getConfig();
21
+ config.debug = status === "on";
22
+ await config.save();
23
+ }
24
+ async debugCompletion() {
25
+ return ["on", "off"];
26
+ }
27
+ };
28
+ exports.DebugController = DebugController;
29
+ __decorate([
30
+ (0, core_1.Command)("debug <status>"),
31
+ __metadata("design:type", Function),
32
+ __metadata("design:paramtypes", [String]),
33
+ __metadata("design:returntype", Promise)
34
+ ], DebugController.prototype, "debug", null);
35
+ __decorate([
36
+ (0, core_1.Completion)("status"),
37
+ __metadata("design:type", Function),
38
+ __metadata("design:paramtypes", []),
39
+ __metadata("design:returntype", Promise)
40
+ ], DebugController.prototype, "debugCompletion", null);
41
+ exports.DebugController = DebugController = __decorate([
42
+ (0, core_1.Controller)(),
43
+ __metadata("design:paramtypes", [services_1.AppConfigService])
44
+ ], DebugController);
@@ -7,4 +7,6 @@ export declare class PluginController {
7
7
  list(): Promise<string>;
8
8
  add(addName: string): Promise<void>;
9
9
  remove(removeName: string): Promise<void>;
10
+ update(): Promise<void>;
11
+ getInstalledPlugins(): Promise<string[]>;
10
12
  }
@@ -1,33 +1,10 @@
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
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
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;
22
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
7
  };
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
8
  var __metadata = (this && this.__metadata) || function (k, v) {
32
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
10
  };
@@ -37,12 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  exports.PluginController = void 0;
39
16
  const core_1 = require("@wocker/core");
40
- const axios_1 = __importDefault(require("axios"));
41
17
  const chalk_1 = __importDefault(require("chalk"));
42
18
  const cli_table3_1 = __importDefault(require("cli-table3"));
43
19
  const services_1 = require("../services");
44
20
  const utils_1 = require("../utils");
45
- const console = __importStar(require("console"));
21
+ const Http_1 = require("../makes/Http");
46
22
  let PluginController = class PluginController {
47
23
  constructor(appConfigService, pluginService, logService) {
48
24
  this.appConfigService = appConfigService;
@@ -50,12 +26,12 @@ let PluginController = class PluginController {
50
26
  this.logService = logService;
51
27
  }
52
28
  async list() {
53
- const { plugins } = await this.appConfigService.getAppConfig();
29
+ const config = await this.appConfigService.getConfig();
54
30
  const table = new cli_table3_1.default({
55
31
  head: ["Name"],
56
32
  colWidths: [30]
57
33
  });
58
- for (const name of plugins) {
34
+ for (const name of config.plugins) {
59
35
  table.push([name]);
60
36
  }
61
37
  return table.toString() + "\n";
@@ -63,26 +39,29 @@ let PluginController = class PluginController {
63
39
  async add(addName) {
64
40
  const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(addName) || [];
65
41
  const fullName = `${prefix}${name}${suffix}`;
42
+ this.logService.info(`Installing plugin... ${fullName}`);
43
+ const config = await this.appConfigService.getConfig();
66
44
  try {
67
- const { default: Plugin } = await Promise.resolve(`${fullName}`).then(s => __importStar(require(s)));
68
- await this.appConfigService.activatePlugin(fullName);
69
- console.info(`Plugin ${fullName} activated`);
70
- return;
71
- }
72
- catch (err) {
73
- this.logService.error(err.message);
74
- }
75
- try {
76
- const res = await axios_1.default.get(`https://registry.npmjs.org/${encodeURIComponent(fullName)}`, {
77
- validateStatus: () => true
78
- });
45
+ if (await this.pluginService.checkPlugin(fullName)) {
46
+ config.addPlugin(fullName);
47
+ await config.save();
48
+ console.info(`Plugin ${fullName} activated`);
49
+ return;
50
+ }
51
+ const res = await Http_1.Http.get("https://registry.npmjs.org")
52
+ .send(fullName);
79
53
  if (res.status !== 200) {
80
54
  console.error(chalk_1.default.red(`Plugin ${fullName} not found`));
81
55
  return;
82
56
  }
83
57
  console.info(`Installing ${fullName}`);
84
58
  await (0, utils_1.exec)(`npm install -g ${fullName}`);
85
- await this.appConfigService.activatePlugin(fullName);
59
+ if (await this.pluginService.checkPlugin(fullName)) {
60
+ config.addPlugin(fullName);
61
+ await config.save();
62
+ console.info(`Plugin ${fullName} activated`);
63
+ return;
64
+ }
86
65
  }
87
66
  catch (err) {
88
67
  this.logService.error(err.message);
@@ -91,9 +70,18 @@ let PluginController = class PluginController {
91
70
  async remove(removeName) {
92
71
  const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(removeName) || [];
93
72
  const fullName = `${prefix}${name}${suffix}`;
94
- await this.appConfigService.deactivatePlugin(fullName);
73
+ const config = await this.appConfigService.getConfig();
74
+ config.removePlugin(fullName);
75
+ await config.save();
95
76
  console.info(`Plugin ${fullName} deactivated`);
96
77
  }
78
+ async update() {
79
+ await this.pluginService.update();
80
+ }
81
+ async getInstalledPlugins() {
82
+ const config = await this.appConfigService.getConfig();
83
+ return config.plugins || [];
84
+ }
97
85
  };
98
86
  exports.PluginController = PluginController;
99
87
  __decorate([
@@ -114,6 +102,19 @@ __decorate([
114
102
  __metadata("design:paramtypes", [String]),
115
103
  __metadata("design:returntype", Promise)
116
104
  ], PluginController.prototype, "remove", null);
105
+ __decorate([
106
+ (0, core_1.Command)("plugin:update [name]"),
107
+ __metadata("design:type", Function),
108
+ __metadata("design:paramtypes", []),
109
+ __metadata("design:returntype", Promise)
110
+ ], PluginController.prototype, "update", null);
111
+ __decorate([
112
+ (0, core_1.Completion)("name", "plugin:update [name]"),
113
+ (0, core_1.Completion)("name", "plugin:remove <name>"),
114
+ __metadata("design:type", Function),
115
+ __metadata("design:paramtypes", []),
116
+ __metadata("design:returntype", Promise)
117
+ ], PluginController.prototype, "getInstalledPlugins", null);
117
118
  exports.PluginController = PluginController = __decorate([
118
119
  (0, core_1.Controller)(),
119
120
  __metadata("design:paramtypes", [services_1.AppConfigService,
@@ -11,5 +11,6 @@ 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
+ eject(name?: string): Promise<void>;
14
15
  build(rebuild: boolean, presetName: string): Promise<void>;
15
16
  }
@@ -38,9 +38,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.PresetController = void 0;
39
39
  const core_1 = require("@wocker/core");
40
40
  const utils_1 = require("@wocker/utils");
41
+ const utils_2 = require("@wocker/utils");
41
42
  const Path = __importStar(require("path"));
42
43
  const env_1 = require("../env");
43
- const utils_2 = require("../utils");
44
+ const utils_3 = require("../utils");
45
+ const makes_1 = require("../makes");
44
46
  const services_1 = require("../services");
45
47
  let PresetController = class PresetController {
46
48
  constructor(appConfigService, appEventsService, projectService, presetService, dockerService) {
@@ -90,18 +92,18 @@ let PresetController = class PresetController {
90
92
  }
91
93
  if (preset.volumeOptions) {
92
94
  for (let volume of preset.volumeOptions) {
93
- volume = (0, utils_2.injectVariables)(volume, {
95
+ volume = (0, utils_3.injectVariables)(volume, {
94
96
  ...project.buildArgs || {},
95
97
  ...project.env || {}
96
98
  });
97
- const { destination, options } = (0, utils_2.volumeParse)(volume);
99
+ const { destination, options } = (0, utils_3.volumeParse)(volume);
98
100
  let projectVolume = project.getVolumeByDestination(destination);
99
101
  const source = await (0, utils_1.promptText)({
100
102
  message: "Volume",
101
103
  suffix: `:${destination}`,
102
- default: projectVolume ? (0, utils_2.volumeParse)(projectVolume).source : "./"
104
+ default: projectVolume ? (0, utils_3.volumeParse)(projectVolume).source : "./"
103
105
  });
104
- projectVolume = (0, utils_2.volumeFormat)({
106
+ projectVolume = (0, utils_3.volumeFormat)({
105
107
  source,
106
108
  destination,
107
109
  options
@@ -110,7 +112,7 @@ let PresetController = class PresetController {
110
112
  }
111
113
  }
112
114
  if (preset.dockerfile) {
113
- project.imageName = preset.getImageName(project.buildArgs);
115
+ project.imageName = this.presetService.getImageName(preset, project.buildArgs);
114
116
  }
115
117
  }
116
118
  async onRebuild(project) {
@@ -148,6 +150,58 @@ let PresetController = class PresetController {
148
150
  }
149
151
  }
150
152
  }
153
+ async eject(name) {
154
+ if (name) {
155
+ await this.projectService.cdProject(name);
156
+ }
157
+ const project = await this.projectService.get();
158
+ const preset = await this.presetService.get(project.preset);
159
+ if (!preset) {
160
+ throw new Error("Preset not found");
161
+ }
162
+ const confirm = await (0, utils_2.promptConfirm)({
163
+ message: "Confirm eject",
164
+ default: false
165
+ });
166
+ if (!confirm) {
167
+ return;
168
+ }
169
+ const source = new makes_1.FS(this.appConfigService.presetPath(preset.name));
170
+ const destination = new makes_1.FS(this.appConfigService.getPWD());
171
+ const fs = new core_1.FSManager(this.appConfigService.presetPath(preset.name), this.appConfigService.getPWD());
172
+ if (preset.dockerfile) {
173
+ if (!destination.exists(preset.dockerfile)) {
174
+ await fs.copy(preset.dockerfile);
175
+ }
176
+ project.type = "dockerfile";
177
+ project.dockerfile = preset.dockerfile;
178
+ }
179
+ const files = await source.readdirFiles("", {
180
+ recursive: true
181
+ });
182
+ for (const path of files) {
183
+ const stat = source.stat(path);
184
+ if (stat.isFile() && path === "config.json") {
185
+ continue;
186
+ }
187
+ if (stat.isFile() && path === preset.dockerfile) {
188
+ continue;
189
+ }
190
+ if (destination.exists(path)) {
191
+ continue;
192
+ }
193
+ const dir = Path.dirname(path);
194
+ if (!destination.exists(dir)) {
195
+ destination.mkdir(dir, {
196
+ recursive: true
197
+ });
198
+ }
199
+ await fs.copy(path);
200
+ }
201
+ delete project.preset;
202
+ delete project.imageName;
203
+ await project.save();
204
+ }
151
205
  async build(rebuild, presetName) {
152
206
  const preset = await this.presetService.get(presetName);
153
207
  let buildArgs = {};
@@ -167,6 +221,17 @@ let PresetController = class PresetController {
167
221
  }
168
222
  };
169
223
  exports.PresetController = PresetController;
224
+ __decorate([
225
+ (0, core_1.Command)("preset:eject"),
226
+ __param(0, (0, core_1.Option)("name", {
227
+ type: "string",
228
+ alias: "n",
229
+ description: "Project name"
230
+ })),
231
+ __metadata("design:type", Function),
232
+ __metadata("design:paramtypes", [String]),
233
+ __metadata("design:returntype", Promise)
234
+ ], PresetController.prototype, "eject", null);
170
235
  __decorate([
171
236
  (0, core_1.Command)("preset:build <preset>"),
172
237
  __param(0, (0, core_1.Option)("rebuild", {
@@ -7,7 +7,6 @@ export declare class ProjectController {
7
7
  protected readonly logService: LogService;
8
8
  constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService, logService: LogService);
9
9
  protected getProjectNames(): Promise<string[]>;
10
- protected getScripts(): Promise<string[]>;
11
10
  init(name: string, type: string, preset: string): Promise<void>;
12
11
  projectList(all: boolean): Promise<string>;
13
12
  start(name?: string, detach?: boolean, rebuild?: boolean, restart?: boolean): Promise<void>;
@@ -15,8 +14,8 @@ export declare class ProjectController {
15
14
  run(name: string, script: string): Promise<void>;
16
15
  attach(name?: string): Promise<void>;
17
16
  configList(name?: string, global?: boolean): Promise<string>;
18
- configGet(name: string, global: boolean, key: string): Promise<string>;
19
- configSet(name: string, global: boolean, configs: string[]): Promise<void>;
17
+ configGet(name: string, global: boolean, keys: string[]): Promise<string>;
18
+ configSet(name: string, global: boolean, variables: string[]): Promise<void>;
20
19
  configUnset(name: string, global: boolean, configs: string[]): Promise<void>;
21
20
  buildArgsList(name?: string): Promise<string>;
22
21
  buildArgsGet(name: string, args: string[]): Promise<string>;
@@ -48,7 +48,6 @@ const async_mutex_1 = require("async-mutex");
48
48
  const env_1 = require("../env");
49
49
  const makes_1 = require("../makes");
50
50
  const services_1 = require("../services");
51
- const utils_2 = require("../utils");
52
51
  let ProjectController = class ProjectController {
53
52
  constructor(appConfigService, appEventsService, projectService, dockerService, logService) {
54
53
  this.appConfigService = appConfigService;
@@ -63,22 +62,14 @@ let ProjectController = class ProjectController {
63
62
  return project.name;
64
63
  });
65
64
  }
66
- async getScripts() {
67
- this.logService.warn(">_<");
68
- try {
69
- const project = await this.projectService.get();
70
- return Object.keys(project.scripts || {});
71
- }
72
- catch (ignore) {
73
- return [];
74
- }
75
- }
76
65
  async init(name, type, preset) {
77
66
  let project = await this.projectService.searchOne({
78
67
  path: this.appConfigService.getPWD()
79
68
  });
80
69
  if (!project) {
81
- project = this.projectService.fromObject({});
70
+ project = this.projectService.fromObject({
71
+ path: this.appConfigService.getPWD()
72
+ });
82
73
  }
83
74
  if (name) {
84
75
  project.name = name;
@@ -87,8 +78,8 @@ let ProjectController = class ProjectController {
87
78
  project.name = await (0, utils_1.promptText)({
88
79
  type: "string",
89
80
  required: true,
90
- message: "Project name",
91
- default: project.name
81
+ message: "Project name:",
82
+ default: project.name || Path.basename(project.path)
92
83
  });
93
84
  }
94
85
  if (type) {
@@ -97,7 +88,7 @@ let ProjectController = class ProjectController {
97
88
  const mapTypes = this.appConfigService.getProjectTypes();
98
89
  if (!type || !project.type || !mapTypes[project.type]) {
99
90
  project.type = await (0, utils_1.promptSelect)({
100
- message: "Project type",
91
+ message: "Project type:",
101
92
  options: mapTypes,
102
93
  default: project.type
103
94
  });
@@ -134,7 +125,7 @@ let ProjectController = class ProjectController {
134
125
  }
135
126
  await this.appEventsService.emit("project:init", project);
136
127
  project.path = this.appConfigService.getPWD();
137
- await this.projectService.save(project);
128
+ await project.save();
138
129
  }
139
130
  async projectList(all) {
140
131
  const table = new cli_table3_1.default({
@@ -219,13 +210,13 @@ let ProjectController = class ProjectController {
219
210
  if (name) {
220
211
  await this.projectService.cdProject(name);
221
212
  }
222
- let env = {};
213
+ let env;
223
214
  if (!global) {
224
215
  const project = await this.projectService.get();
225
216
  env = project.env || {};
226
217
  }
227
218
  else {
228
- const config = await (0, utils_2.getConfig)();
219
+ const config = await this.appConfigService.getConfig();
229
220
  env = config.env || {};
230
221
  }
231
222
  const table = new cli_table3_1.default({
@@ -236,50 +227,41 @@ let ProjectController = class ProjectController {
236
227
  }
237
228
  return table.toString() + "\n";
238
229
  }
239
- async configGet(name, global, key) {
230
+ async configGet(name, global, keys) {
240
231
  if (name) {
241
232
  await this.projectService.cdProject(name);
242
233
  }
243
- let value = "";
244
- if (global) {
245
- const config = await (0, utils_2.getConfig)();
246
- value = config[key] || "";
247
- }
248
- else {
249
- const project = await this.projectService.get();
250
- value = project.getEnv(key);
251
- }
234
+ let config = global
235
+ ? await this.appConfigService.getConfig()
236
+ : await this.projectService.get();
252
237
  const table = new cli_table3_1.default({
253
238
  head: ["KEY", "VALUE"]
254
239
  });
255
- table.push([key, value]);
240
+ for (const key of keys) {
241
+ const value = config.getEnv(key, "");
242
+ if (!value) {
243
+ continue;
244
+ }
245
+ table.push([key, value]);
246
+ }
256
247
  return table.toString() + "\n";
257
248
  }
258
- async configSet(name, global, configs) {
259
- const env = configs.reduce((env, config) => {
260
- const [key, value] = config.split("=");
261
- env[key.trim()] = value.trim();
262
- return env;
263
- }, {});
264
- if (global) {
265
- const config = await (0, utils_2.getConfig)();
266
- await (0, utils_2.setConfig)({
267
- ...config,
268
- env: {
269
- ...config.env || {},
270
- ...env
271
- }
272
- });
273
- return;
274
- }
275
- if (name) {
249
+ async configSet(name, global, variables) {
250
+ if (!global && name) {
276
251
  await this.projectService.cdProject(name);
277
252
  }
278
- const project = await this.projectService.get();
279
- for (const i in env) {
280
- project.setEnv(i, env[i]);
253
+ const config = global
254
+ ? await this.appConfigService.getConfig()
255
+ : await this.projectService.get();
256
+ for (const variable of variables) {
257
+ const [key, value] = variable.split("=");
258
+ if (!value) {
259
+ console.info(chalk_1.default.yellow(`No value for "${key}"`));
260
+ continue;
261
+ }
262
+ config.setEnv(key.trim(), value.trim());
281
263
  }
282
- await project.save();
264
+ await config.save();
283
265
  }
284
266
  async configUnset(name, global, configs) {
285
267
  const env = configs.reduce((env, config) => {
@@ -489,12 +471,6 @@ __decorate([
489
471
  __metadata("design:paramtypes", []),
490
472
  __metadata("design:returntype", Promise)
491
473
  ], ProjectController.prototype, "getProjectNames", null);
492
- __decorate([
493
- (0, core_1.Completion)("script"),
494
- __metadata("design:type", Function),
495
- __metadata("design:paramtypes", []),
496
- __metadata("design:returntype", Promise)
497
- ], ProjectController.prototype, "getScripts", null);
498
474
  __decorate([
499
475
  (0, core_1.Command)("init"),
500
476
  __param(0, (0, core_1.Option)("name", {
@@ -598,17 +574,17 @@ __decorate([
598
574
  __metadata("design:returntype", Promise)
599
575
  ], ProjectController.prototype, "configList", null);
600
576
  __decorate([
601
- (0, core_1.Command)("config:get <key>"),
577
+ (0, core_1.Command)("config:get [...key]"),
602
578
  __param(0, (0, core_1.Option)("name", {
603
579
  type: "string",
604
580
  alias: "n"
605
581
  })),
606
582
  __param(1, (0, core_1.Option)("global", {
607
583
  type: "boolean",
608
- alias: "b"
584
+ alias: "g"
609
585
  })),
610
586
  __metadata("design:type", Function),
611
- __metadata("design:paramtypes", [String, Boolean, String]),
587
+ __metadata("design:paramtypes", [String, Boolean, Array]),
612
588
  __metadata("design:returntype", Promise)
613
589
  ], ProjectController.prototype, "configGet", null);
614
590
  __decorate([
@@ -54,30 +54,33 @@ let ProxyController = class ProxyController {
54
54
  });
55
55
  }
56
56
  async init(httpPort, httpsPort) {
57
+ const config = await this.appConfigService.getConfig();
57
58
  if (typeof httpPort === "undefined" || isNaN(httpPort)) {
58
59
  httpPort = await (0, utils_1.promptText)({
59
60
  required: true,
60
61
  message: "Http port:",
61
62
  type: "int",
62
- default: await this.appConfigService.getEnvVariable("PROXY_HTTP_PORT", "80")
63
+ default: config.getMeta("PROXY_HTTP_PORT", "80")
63
64
  });
64
65
  }
65
- await this.appConfigService.setEnvVariable("PROXY_HTTP_PORT", httpPort);
66
+ config.setMeta("PROXY_HTTP_PORT", httpPort.toString());
66
67
  if (typeof httpsPort === "undefined" || isNaN(httpsPort)) {
67
68
  httpsPort = await (0, utils_1.promptText)({
68
69
  required: true,
69
70
  message: "Https port:",
70
71
  type: "int",
71
- default: await this.appConfigService.getEnvVariable("PROXY_HTTPS_PORT", "443")
72
+ default: config.getMeta("PROXY_HTTPS_PORT", "443")
72
73
  });
73
74
  }
74
- await this.appConfigService.setEnvVariable("PROXY_HTTPS_PORT", httpsPort);
75
+ config.setMeta("PROXY_HTTPS_PORT", httpsPort.toString());
76
+ await config.save();
75
77
  }
76
78
  async start() {
77
79
  console.info("Proxy starting...");
80
+ const config = await this.appConfigService.getConfig();
78
81
  await this.dockerService.pullImage("nginxproxy/nginx-proxy");
79
- const httpPort = await this.appConfigService.getEnvVariable("PROXY_HTTP_PORT", "80");
80
- const httpsPort = await this.appConfigService.getEnvVariable("PROXY_HTTPS_PORT", "443");
82
+ const httpPort = config.getMeta("PROXY_HTTP_PORT", "80");
83
+ const httpsPort = config.getMeta("PROXY_HTTPS_PORT", "443");
81
84
  let container = await this.dockerService.getContainer(this.containerName);
82
85
  if (!container) {
83
86
  const certsDir = this.appConfigService.dataPath("certs");
@@ -217,6 +220,12 @@ __decorate([
217
220
  __metadata("design:paramtypes", []),
218
221
  __metadata("design:returntype", Promise)
219
222
  ], ProxyController.prototype, "getProjectNames", null);
223
+ __decorate([
224
+ (0, core_1.Command)("domains"),
225
+ __metadata("design:type", Function),
226
+ __metadata("design:paramtypes", [String, Array]),
227
+ __metadata("design:returntype", Promise)
228
+ ], ProxyController.prototype, "getDomains", null);
220
229
  __decorate([
221
230
  (0, core_1.Command)("proxy:init"),
222
231
  __param(0, (0, core_1.Option)("http-port", {
@@ -1,4 +1,5 @@
1
1
  export * from "./CompletionController";
2
+ export * from "./DebugController";
2
3
  export * from "./ImageController";
3
4
  export * from "./PluginController";
4
5
  export * from "./PresetController";
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./CompletionController"), exports);
18
+ __exportStar(require("./DebugController"), exports);
18
19
  __exportStar(require("./ImageController"), exports);
19
20
  __exportStar(require("./PluginController"), exports);
20
21
  __exportStar(require("./PresetController"), exports);
package/lib/main.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export declare const app: {
2
- run(args: string[]): Promise<any>;
2
+ run(args: string[]): Promise<void>;
3
3
  };