@wocker/ws 1.0.12 → 1.0.14

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
@@ -88,7 +88,8 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
88
88
  services_1.LogService,
89
89
  services_1.PluginService,
90
90
  services_1.PresetService,
91
- services_1.ProjectService
91
+ services_1.ProjectService,
92
+ services_1.ProxyService
92
93
  ],
93
94
  exports: [
94
95
  services_1.AppConfigService,
@@ -12,8 +12,15 @@ export declare class ProjectController {
12
12
  projectList(all: boolean): Promise<string>;
13
13
  start(name?: string, detach?: boolean, attach?: boolean, rebuild?: boolean, restart?: boolean): Promise<void>;
14
14
  stop(name: string): Promise<void>;
15
- run(name: string, script: string): Promise<void>;
16
- attach(name?: string): Promise<void>;
15
+ domains(name?: string): Promise<string>;
16
+ addDomain(name: string, addDomains: string[]): Promise<void>;
17
+ setDomains(name: string, domains: string[]): Promise<void>;
18
+ removeDomain(name: string, removeDomains: string[]): Promise<void>;
19
+ clearDomain(name?: string): Promise<void>;
20
+ ports(name?: string): Promise<string>;
21
+ addPort(hostPort: string, containerPort: string, name?: string): Promise<void>;
22
+ removePort(hostPort: string, containerPort: string, name?: string): Promise<void>;
23
+ clearPorts(name?: string): Promise<void>;
17
24
  configList(name?: string, global?: boolean): Promise<string>;
18
25
  configGet(name: string, global: boolean, keys: string[]): Promise<string>;
19
26
  configSet(name: string, global: boolean, variables: string[]): Promise<void>;
@@ -25,6 +32,8 @@ export declare class ProjectController {
25
32
  volumeList(name?: string): Promise<string>;
26
33
  volumeMount(name: string, volumes: string[]): Promise<void>;
27
34
  volumeUnmount(name: string, volumes: string[]): Promise<void>;
28
- logs(name: string, global: boolean, detach: boolean, follow: boolean): Promise<void>;
35
+ logs(name?: string, global?: boolean, detach?: boolean, follow?: boolean): Promise<void>;
29
36
  exec(name?: string, command?: string[]): Promise<void>;
37
+ run(name: string, script: string, args?: string[]): Promise<void>;
38
+ attach(name?: string): Promise<void>;
30
39
  }
@@ -90,6 +90,7 @@ let ProjectController = class ProjectController {
90
90
  message: "Project name:",
91
91
  default: project.name || Path.basename(project.path)
92
92
  });
93
+ project.addDomain(project.containerName);
93
94
  }
94
95
  if (type) {
95
96
  project.type = type;
@@ -160,10 +161,7 @@ let ProjectController = class ProjectController {
160
161
  await this.projectService.cdProject(name);
161
162
  }
162
163
  const project = await this.projectService.get();
163
- if (rebuild) {
164
- await this.projectService.rebuild(project);
165
- }
166
- await this.projectService.start(project, restart);
164
+ await this.projectService.start(project, rebuild, restart);
167
165
  if (detach) {
168
166
  console.info(chalk_1.default.yellow("Warning: Detach option is deprecated"));
169
167
  }
@@ -185,38 +183,96 @@ let ProjectController = class ProjectController {
185
183
  const project = await this.projectService.get();
186
184
  await this.projectService.stop(project);
187
185
  }
188
- async run(name, script) {
186
+ async domains(name) {
189
187
  if (name) {
190
188
  await this.projectService.cdProject(name);
191
189
  }
192
190
  const project = await this.projectService.get();
193
- if (!project.scripts || !project.scripts[script]) {
194
- throw new Error(`Script ${script} not found`);
191
+ const table = new cli_table3_1.default({
192
+ head: [chalk_1.default.yellow("Domain")]
193
+ });
194
+ for (const domain of project.domains) {
195
+ table.push([domain]);
195
196
  }
196
- const container = await this.dockerService.getContainer(`${project.name}.workspace`);
197
- if (!container) {
198
- throw new Error("The project is not started");
197
+ return table.toString();
198
+ }
199
+ async addDomain(name, addDomains) {
200
+ if (name) {
201
+ await this.projectService.cdProject(name);
199
202
  }
200
- const exec = await container.exec({
201
- Cmd: ["bash", "-i", "-c", project.scripts[script]],
202
- AttachStdin: true,
203
- AttachStdout: true,
204
- AttachStderr: true,
205
- Tty: process.stdin.isTTY
206
- });
207
- const stream = await exec.start({
208
- hijack: true,
209
- stdin: true,
210
- Tty: process.stdin.isTTY
203
+ const project = await this.projectService.get();
204
+ for (const domain of addDomains) {
205
+ project.addDomain(domain);
206
+ }
207
+ await project.save();
208
+ }
209
+ async setDomains(name, domains) {
210
+ if (name) {
211
+ await this.projectService.cdProject(name);
212
+ }
213
+ const project = await this.projectService.get();
214
+ project.clearDomains();
215
+ for (const domain of domains) {
216
+ project.addDomain(domain);
217
+ }
218
+ await project.save();
219
+ }
220
+ async removeDomain(name, removeDomains) {
221
+ if (name) {
222
+ await this.projectService.cdProject(name);
223
+ }
224
+ const project = await this.projectService.get();
225
+ for (const domain of removeDomains) {
226
+ project.removeDomain(domain);
227
+ }
228
+ await project.save();
229
+ }
230
+ async clearDomain(name) {
231
+ if (name) {
232
+ await this.projectService.cdProject(name);
233
+ }
234
+ const project = await this.projectService.get();
235
+ project.clearDomains();
236
+ await project.save();
237
+ }
238
+ async ports(name) {
239
+ if (name) {
240
+ await this.projectService.cdProject(name);
241
+ }
242
+ const project = await this.projectService.get();
243
+ const table = new cli_table3_1.default({
244
+ head: ["Ports"]
211
245
  });
212
- await this.dockerService.attachStream(stream);
246
+ for (const port of project.ports || []) {
247
+ table.push([port]);
248
+ }
249
+ return table.toString();
213
250
  }
214
- async attach(name) {
251
+ async addPort(hostPort, containerPort, name) {
215
252
  if (name) {
216
253
  await this.projectService.cdProject(name);
217
254
  }
218
255
  const project = await this.projectService.get();
219
- await this.dockerService.attach(project.containerName);
256
+ project.linkPort(parseInt(hostPort), parseInt(containerPort));
257
+ await project.save();
258
+ }
259
+ async removePort(hostPort, containerPort, name) {
260
+ if (name) {
261
+ await this.projectService.cdProject(name);
262
+ }
263
+ const project = await this.projectService.get();
264
+ project.unlinkPort(parseInt(hostPort), parseInt(containerPort));
265
+ await project.save();
266
+ }
267
+ async clearPorts(name) {
268
+ if (name) {
269
+ await this.projectService.cdProject(name);
270
+ }
271
+ const project = await this.projectService.get();
272
+ if (project.ports) {
273
+ delete project.ports;
274
+ await project.save();
275
+ }
220
276
  }
221
277
  async configList(name, global) {
222
278
  if (name) {
@@ -473,7 +529,11 @@ let ProjectController = class ProjectController {
473
529
  follow: true
474
530
  });
475
531
  stream.on("data", (data) => {
476
- process.stdout.write((0, utils_1.demuxOutput)(data));
532
+ try {
533
+ data = (0, utils_1.demuxOutput)(data);
534
+ }
535
+ catch (err) { }
536
+ process.stdout.write(data);
477
537
  });
478
538
  }
479
539
  else {
@@ -490,8 +550,40 @@ let ProjectController = class ProjectController {
490
550
  await this.projectService.cdProject(name);
491
551
  }
492
552
  const project = await this.projectService.get();
493
- const containerName = `${project.name}.workspace`;
494
- await this.dockerService.exec(containerName, command);
553
+ await this.dockerService.exec(project.containerName, command);
554
+ }
555
+ async run(name, script, args) {
556
+ if (name) {
557
+ await this.projectService.cdProject(name);
558
+ }
559
+ const project = await this.projectService.get();
560
+ if (!project.scripts || !project.scripts[script]) {
561
+ throw new Error(`Script ${script} not found`);
562
+ }
563
+ const container = await this.dockerService.getContainer(`${project.name}.workspace`);
564
+ if (!container) {
565
+ throw new Error("The project is not started");
566
+ }
567
+ const exec = await container.exec({
568
+ Cmd: ["bash", "-i", "-c", [project.scripts[script], ...args || []].join(" ")],
569
+ AttachStdin: true,
570
+ AttachStdout: true,
571
+ AttachStderr: true,
572
+ Tty: process.stdin.isTTY
573
+ });
574
+ const stream = await exec.start({
575
+ hijack: true,
576
+ stdin: true,
577
+ Tty: process.stdin.isTTY
578
+ });
579
+ await this.dockerService.attachStream(stream);
580
+ }
581
+ async attach(name) {
582
+ if (name) {
583
+ await this.projectService.cdProject(name);
584
+ }
585
+ const project = await this.projectService.get();
586
+ await this.dockerService.attach(project.containerName);
495
587
  }
496
588
  };
497
589
  exports.ProjectController = ProjectController;
@@ -512,7 +604,7 @@ __decorate([
512
604
  __param(0, (0, core_1.Option)("name", {
513
605
  type: "string",
514
606
  alias: "n",
515
- description: "Project name"
607
+ description: "The name of the project"
516
608
  })),
517
609
  __param(1, (0, core_1.Option)("type", {
518
610
  type: "string",
@@ -545,7 +637,7 @@ __decorate([
545
637
  __param(0, (0, core_1.Option)("name", {
546
638
  type: "string",
547
639
  alias: "n",
548
- description: "Project name",
640
+ description: "The name of the project",
549
641
  help: true
550
642
  })),
551
643
  __param(1, (0, core_1.Option)("detach", {
@@ -577,39 +669,121 @@ __decorate([
577
669
  __param(0, (0, core_1.Option)("name", {
578
670
  type: "string",
579
671
  alias: "n",
580
- description: "Project name"
672
+ description: "The name of the project"
581
673
  })),
582
674
  __metadata("design:type", Function),
583
675
  __metadata("design:paramtypes", [String]),
584
676
  __metadata("design:returntype", Promise)
585
677
  ], ProjectController.prototype, "stop", null);
586
678
  __decorate([
587
- (0, core_1.Command)("run <script>"),
679
+ (0, core_1.Command)("domains"),
680
+ __param(0, (0, core_1.Option)("name", {
681
+ type: "string",
682
+ alias: "n",
683
+ description: "The name of the project"
684
+ })),
685
+ __metadata("design:type", Function),
686
+ __metadata("design:paramtypes", [String]),
687
+ __metadata("design:returntype", Promise)
688
+ ], ProjectController.prototype, "domains", null);
689
+ __decorate([
690
+ (0, core_1.Command)("domain:add [...domains]"),
691
+ __param(0, (0, core_1.Option)("name", {
692
+ type: "string",
693
+ alias: "n",
694
+ description: "The name of the project"
695
+ })),
696
+ __metadata("design:type", Function),
697
+ __metadata("design:paramtypes", [String, Array]),
698
+ __metadata("design:returntype", Promise)
699
+ ], ProjectController.prototype, "addDomain", null);
700
+ __decorate([
701
+ (0, core_1.Command)("domain:set [...domains]"),
588
702
  __param(0, (0, core_1.Option)("name", {
589
703
  type: "string",
590
704
  alias: "n",
591
705
  description: "Project name"
592
706
  })),
593
707
  __metadata("design:type", Function),
594
- __metadata("design:paramtypes", [String, String]),
708
+ __metadata("design:paramtypes", [String, Array]),
709
+ __metadata("design:returntype", Promise)
710
+ ], ProjectController.prototype, "setDomains", null);
711
+ __decorate([
712
+ (0, core_1.Command)("domain:remove [...domains]"),
713
+ __param(0, (0, core_1.Option)("name", {
714
+ type: "string",
715
+ alias: "n",
716
+ description: "The name of the project"
717
+ })),
718
+ __metadata("design:type", Function),
719
+ __metadata("design:paramtypes", [String, Array]),
595
720
  __metadata("design:returntype", Promise)
596
- ], ProjectController.prototype, "run", null);
721
+ ], ProjectController.prototype, "removeDomain", null);
597
722
  __decorate([
598
- (0, core_1.Command)("attach"),
723
+ (0, core_1.Command)("domain:clear"),
599
724
  __param(0, (0, core_1.Option)("name", {
600
725
  type: "string",
601
- alias: "n"
726
+ alias: "n",
727
+ description: "The name of the project"
602
728
  })),
603
729
  __metadata("design:type", Function),
604
730
  __metadata("design:paramtypes", [String]),
605
731
  __metadata("design:returntype", Promise)
606
- ], ProjectController.prototype, "attach", null);
732
+ ], ProjectController.prototype, "clearDomain", null);
733
+ __decorate([
734
+ (0, core_1.Command)("ports"),
735
+ __param(0, (0, core_1.Option)("name", {
736
+ type: "string",
737
+ alias: "n",
738
+ description: "The name of the project"
739
+ })),
740
+ __metadata("design:type", Function),
741
+ __metadata("design:paramtypes", [String]),
742
+ __metadata("design:returntype", Promise)
743
+ ], ProjectController.prototype, "ports", null);
744
+ __decorate([
745
+ (0, core_1.Command)("port:add <host-port>:<container-port>"),
746
+ __param(0, (0, core_1.Param)("host-port")),
747
+ __param(1, (0, core_1.Param)("container-port")),
748
+ __param(2, (0, core_1.Option)("name", {
749
+ type: "string",
750
+ alias: "n",
751
+ description: "The name of the project"
752
+ })),
753
+ __metadata("design:type", Function),
754
+ __metadata("design:paramtypes", [String, String, String]),
755
+ __metadata("design:returntype", Promise)
756
+ ], ProjectController.prototype, "addPort", null);
757
+ __decorate([
758
+ (0, core_1.Command)("port:remove <host-port>:<container-port>"),
759
+ __param(0, (0, core_1.Param)("host-port")),
760
+ __param(1, (0, core_1.Param)("container-port")),
761
+ __param(2, (0, core_1.Option)("name", {
762
+ type: "string",
763
+ alias: "n",
764
+ description: "The name of the project"
765
+ })),
766
+ __metadata("design:type", Function),
767
+ __metadata("design:paramtypes", [String, String, String]),
768
+ __metadata("design:returntype", Promise)
769
+ ], ProjectController.prototype, "removePort", null);
770
+ __decorate([
771
+ (0, core_1.Command)("port:clear"),
772
+ __param(0, (0, core_1.Option)("name", {
773
+ type: "string",
774
+ alias: "n",
775
+ description: "The name of the project"
776
+ })),
777
+ __metadata("design:type", Function),
778
+ __metadata("design:paramtypes", [String]),
779
+ __metadata("design:returntype", Promise)
780
+ ], ProjectController.prototype, "clearPorts", null);
607
781
  __decorate([
608
782
  (0, core_1.Command)("config"),
609
783
  __param(0, (0, core_1.Option)("name", {
610
784
  type: "string",
611
785
  alias: "n",
612
- description: "Project name"
786
+ description: "The name of the project"
613
787
  })),
614
788
  __param(1, (0, core_1.Option)("global", {
615
789
  type: "boolean",
@@ -623,7 +797,8 @@ __decorate([
623
797
  (0, core_1.Command)("config:get [...key]"),
624
798
  __param(0, (0, core_1.Option)("name", {
625
799
  type: "string",
626
- alias: "n"
800
+ alias: "n",
801
+ description: "The name of the project"
627
802
  })),
628
803
  __param(1, (0, core_1.Option)("global", {
629
804
  type: "boolean",
@@ -638,7 +813,8 @@ __decorate([
638
813
  (0, core_1.Command)("config:set [...configs]"),
639
814
  __param(0, (0, core_1.Option)("name", {
640
815
  type: "string",
641
- alias: "n"
816
+ alias: "n",
817
+ description: "The name of the project"
642
818
  })),
643
819
  __param(1, (0, core_1.Option)("global", {
644
820
  type: "boolean",
@@ -652,7 +828,8 @@ __decorate([
652
828
  (0, core_1.Command)("config:unset [...configs]"),
653
829
  __param(0, (0, core_1.Option)("name", {
654
830
  type: "string",
655
- alias: "n"
831
+ alias: "n",
832
+ description: "The name of the project"
656
833
  })),
657
834
  __param(1, (0, core_1.Option)("global", {
658
835
  type: "boolean",
@@ -666,7 +843,8 @@ __decorate([
666
843
  (0, core_1.Command)("build-args"),
667
844
  __param(0, (0, core_1.Option)("name", {
668
845
  type: "string",
669
- alias: "n"
846
+ alias: "n",
847
+ description: "The name of the project"
670
848
  })),
671
849
  __metadata("design:type", Function),
672
850
  __metadata("design:paramtypes", [String]),
@@ -677,6 +855,7 @@ __decorate([
677
855
  __param(0, (0, core_1.Option)("name", {
678
856
  type: "string",
679
857
  alias: "n",
858
+ description: "The name of the project"
680
859
  })),
681
860
  __metadata("design:type", Function),
682
861
  __metadata("design:paramtypes", [String, Array]),
@@ -686,7 +865,8 @@ __decorate([
686
865
  (0, core_1.Command)("build-args:set [...buildArgs]"),
687
866
  __param(0, (0, core_1.Option)("name", {
688
867
  type: "string",
689
- alias: "n"
868
+ alias: "n",
869
+ description: "The name of the project"
690
870
  })),
691
871
  __metadata("design:type", Function),
692
872
  __metadata("design:paramtypes", [String, Array]),
@@ -696,7 +876,8 @@ __decorate([
696
876
  (0, core_1.Command)("build-args:unset [...buildArgs]"),
697
877
  __param(0, (0, core_1.Option)("name", {
698
878
  type: "string",
699
- alias: "n"
879
+ alias: "n",
880
+ description: "The name of the project"
700
881
  })),
701
882
  __metadata("design:type", Function),
702
883
  __metadata("design:paramtypes", [String, Array]),
@@ -706,7 +887,8 @@ __decorate([
706
887
  (0, core_1.Command)("volumes"),
707
888
  __param(0, (0, core_1.Option)("name", {
708
889
  type: "string",
709
- alias: "n"
890
+ alias: "n",
891
+ description: "The name of the project"
710
892
  })),
711
893
  __metadata("design:type", Function),
712
894
  __metadata("design:paramtypes", [String]),
@@ -716,7 +898,8 @@ __decorate([
716
898
  (0, core_1.Command)("volume:mount [...volumes]"),
717
899
  __param(0, (0, core_1.Option)("name", {
718
900
  type: "string",
719
- alias: "n"
901
+ alias: "n",
902
+ description: "The name of the project"
720
903
  })),
721
904
  __metadata("design:type", Function),
722
905
  __metadata("design:paramtypes", [String, Array]),
@@ -726,7 +909,8 @@ __decorate([
726
909
  (0, core_1.Command)("volume:unmount [...volumes]"),
727
910
  __param(0, (0, core_1.Option)("name", {
728
911
  type: "string",
729
- alias: "n"
912
+ alias: "n",
913
+ description: "The name of the project"
730
914
  })),
731
915
  __metadata("design:type", Function),
732
916
  __metadata("design:paramtypes", [String, Array]),
@@ -737,7 +921,7 @@ __decorate([
737
921
  __param(0, (0, core_1.Option)("name", {
738
922
  type: "string",
739
923
  alias: "n",
740
- description: "Project name"
924
+ description: "The name of the project"
741
925
  })),
742
926
  __param(1, (0, core_1.Option)("global", {
743
927
  type: "boolean",
@@ -760,12 +944,36 @@ __decorate([
760
944
  __param(0, (0, core_1.Option)("name", {
761
945
  type: "string",
762
946
  alias: "n",
763
- description: "Project name"
947
+ description: "The name of the project"
764
948
  })),
765
949
  __metadata("design:type", Function),
766
950
  __metadata("design:paramtypes", [String, Array]),
767
951
  __metadata("design:returntype", Promise)
768
952
  ], ProjectController.prototype, "exec", null);
953
+ __decorate([
954
+ (0, core_1.Command)("run <script> [...args]"),
955
+ __param(0, (0, core_1.Option)("name", {
956
+ type: "string",
957
+ alias: "n",
958
+ description: "The name of the project"
959
+ })),
960
+ __param(1, (0, core_1.Param)("script")),
961
+ __param(2, (0, core_1.Param)("args")),
962
+ __metadata("design:type", Function),
963
+ __metadata("design:paramtypes", [String, String, Array]),
964
+ __metadata("design:returntype", Promise)
965
+ ], ProjectController.prototype, "run", null);
966
+ __decorate([
967
+ (0, core_1.Command)("attach"),
968
+ __param(0, (0, core_1.Option)("name", {
969
+ type: "string",
970
+ alias: "n",
971
+ description: "The name of the project"
972
+ })),
973
+ __metadata("design:type", Function),
974
+ __metadata("design:paramtypes", [String]),
975
+ __metadata("design:returntype", Promise)
976
+ ], ProjectController.prototype, "attach", null);
769
977
  exports.ProjectController = ProjectController = __decorate([
770
978
  (0, core_1.Controller)(),
771
979
  __metadata("design:paramtypes", [services_1.AppConfigService,
@@ -1,24 +1,17 @@
1
1
  import { Project } from "@wocker/core";
2
- import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
2
+ import { AppConfigService, AppEventsService, ProjectService, ProxyService } from "../services";
3
3
  export declare class ProxyController {
4
4
  protected readonly appConfigService: AppConfigService;
5
5
  protected readonly appEventsService: AppEventsService;
6
6
  protected readonly projectService: ProjectService;
7
- protected readonly dockerService: DockerService;
7
+ protected readonly proxyService: ProxyService;
8
8
  protected containerName: string;
9
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
9
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, proxyService: ProxyService);
10
10
  onProjectStart(project: Project): Promise<void>;
11
11
  onProjectStop(project: Project): Promise<void>;
12
12
  getProjectNames(): Promise<string[]>;
13
- getDomains(name: string | undefined, selected: string[]): Promise<string[]>;
14
13
  init(httpPort: number, httpsPort: number): Promise<void>;
15
- start(): Promise<void>;
14
+ start(restart?: boolean): Promise<void>;
16
15
  stop(): Promise<void>;
17
- restart(): Promise<void>;
18
- domainList(name: string): Promise<string>;
19
- setDomains(name: string, domains: string[]): Promise<void>;
20
- addDomain(name: string, addDomains: string[]): Promise<void>;
21
- removeDomain(name: string, removeDomains: string[]): Promise<void>;
22
- clearDomains(name: string): Promise<void>;
23
16
  logs(): Promise<void>;
24
17
  }