@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.
@@ -45,7 +45,6 @@ const cli_table3_1 = __importDefault(require("cli-table3"));
45
45
  const chalk_1 = __importDefault(require("chalk"));
46
46
  const Path = __importStar(require("path"));
47
47
  const async_mutex_1 = require("async-mutex");
48
- const env_1 = require("../env");
49
48
  const makes_1 = require("../makes");
50
49
  const services_1 = require("../services");
51
50
  let ProjectController = class ProjectController {
@@ -71,15 +70,17 @@ let ProjectController = class ProjectController {
71
70
  return [];
72
71
  }
73
72
  }
74
- async init(name, type, preset) {
73
+ async init(name, type) {
75
74
  let project = await this.projectService.searchOne({
76
- path: this.appConfigService.getPWD()
75
+ path: this.appConfigService.pwd()
77
76
  });
77
+ const fs = new core_1.FileSystem(this.appConfigService.pwd());
78
78
  if (!project) {
79
79
  project = this.projectService.fromObject({
80
- path: this.appConfigService.getPWD()
80
+ path: this.appConfigService.pwd()
81
81
  });
82
82
  }
83
+ project.path = this.appConfigService.pwd();
83
84
  if (name) {
84
85
  project.name = name;
85
86
  }
@@ -97,44 +98,49 @@ let ProjectController = class ProjectController {
97
98
  }
98
99
  const mapTypes = this.appConfigService.getProjectTypes();
99
100
  if (!type || !project.type || !mapTypes[project.type]) {
100
- project.type = await (0, utils_1.promptSelect)({
101
+ project.type = (await (0, utils_1.promptSelect)({
101
102
  message: "Project type:",
102
103
  options: mapTypes,
103
104
  default: project.type
104
- });
105
+ }));
105
106
  }
106
107
  switch (project.type) {
107
108
  case core_1.PROJECT_TYPE_DOCKERFILE: {
108
- const files = await makes_1.FS.readdirFiles(this.appConfigService.getPWD());
109
+ const files = await fs.readdirFiles();
109
110
  const dockerfiles = files.filter((fileName) => {
110
111
  if (new RegExp("^(.*)\\.dockerfile$").test(fileName)) {
111
112
  return true;
112
113
  }
113
114
  return new RegExp("^Dockerfile(\\..*)?").test(fileName);
114
115
  });
116
+ if (dockerfiles.length === 0) {
117
+ throw new Error("Dockerfiles not found");
118
+ }
115
119
  project.dockerfile = await (0, utils_1.promptSelect)({
120
+ message: "Dockerfile:",
116
121
  options: dockerfiles.map((dockerfile) => {
117
122
  return {
118
123
  value: dockerfile
119
124
  };
120
125
  }),
121
- message: "Dockerfile",
122
126
  default: project.dockerfile
123
127
  });
124
128
  break;
125
129
  }
126
130
  case core_1.PROJECT_TYPE_IMAGE: {
127
131
  project.imageName = await (0, utils_1.promptText)({
128
- message: "Image Name",
132
+ message: "Image name:",
133
+ required: true,
129
134
  default: project.imageName
130
135
  });
131
136
  break;
132
137
  }
133
- default:
138
+ case core_1.PROJECT_TYPE_PRESET:
134
139
  break;
140
+ default:
141
+ throw new Error("Invalid project type");
135
142
  }
136
143
  await this.appEventsService.emit("project:init", project);
137
- project.path = this.appConfigService.getPWD();
138
144
  await project.save();
139
145
  }
140
146
  async projectList(all) {
@@ -144,7 +150,7 @@ let ProjectController = class ProjectController {
144
150
  });
145
151
  const projects = await this.projectService.search({});
146
152
  for (const project of projects) {
147
- const container = await this.dockerService.getContainer(`${project.name}.workspace`);
153
+ const container = await this.dockerService.getContainer(project.containerName);
148
154
  if (!container) {
149
155
  if (all) {
150
156
  table.push([project.name, project.type, "-"]);
@@ -283,7 +289,7 @@ let ProjectController = class ProjectController {
283
289
  env = project.env || {};
284
290
  }
285
291
  else {
286
- const config = await this.appConfigService.getConfig();
292
+ const config = this.appConfigService.getConfig();
287
293
  env = config.env || {};
288
294
  }
289
295
  const table = new cli_table3_1.default({
@@ -299,7 +305,7 @@ let ProjectController = class ProjectController {
299
305
  await this.projectService.cdProject(name);
300
306
  }
301
307
  let config = global
302
- ? await this.appConfigService.getConfig()
308
+ ? this.appConfigService.getConfig()
303
309
  : await this.projectService.get();
304
310
  const table = new cli_table3_1.default({
305
311
  head: ["KEY", "VALUE"]
@@ -318,7 +324,7 @@ let ProjectController = class ProjectController {
318
324
  await this.projectService.cdProject(name);
319
325
  }
320
326
  const config = global
321
- ? await this.appConfigService.getConfig()
327
+ ? this.appConfigService.getConfig()
322
328
  : await this.projectService.get();
323
329
  for (const variable of variables) {
324
330
  const [key, value] = variable.split("=");
@@ -384,7 +390,6 @@ let ProjectController = class ProjectController {
384
390
  const table = new cli_table3_1.default({
385
391
  head: ["KEY", "VALUE"]
386
392
  });
387
- this.logService.info("...");
388
393
  for (const key of args) {
389
394
  if (project.buildArgs && typeof project.buildArgs[key] !== "undefined") {
390
395
  const value = project.buildArgs[key] || "";
@@ -399,8 +404,12 @@ let ProjectController = class ProjectController {
399
404
  }
400
405
  const project = await this.projectService.get();
401
406
  const buildArgs = args.reduce((env, config) => {
402
- const [key, value] = config.split("=");
403
- env[key.trim()] = value.trim();
407
+ let [, key = "", value = ""] = config.split(/^([^=]+)=(.*)$/);
408
+ key = key.trim();
409
+ value = value.trim();
410
+ if (key) {
411
+ env[key] = value;
412
+ }
404
413
  return env;
405
414
  }, {});
406
415
  for (const key in buildArgs) {
@@ -417,8 +426,10 @@ let ProjectController = class ProjectController {
417
426
  }
418
427
  const project = await this.projectService.get();
419
428
  const buildArgs = args.reduce((env, config) => {
420
- const [key, value] = config.split("=");
421
- env[key.trim()] = value.trim();
429
+ let [, key = "", value = ""] = config.split(/^([^=]+)(?:=(.*))?$/);
430
+ key = key.trim();
431
+ value = value.trim();
432
+ env[key] = value;
422
433
  return env;
423
434
  }, {});
424
435
  for (const key in buildArgs) {
@@ -465,9 +476,43 @@ let ProjectController = class ProjectController {
465
476
  await project.save();
466
477
  }
467
478
  }
479
+ async extraHostList(name) {
480
+ if (name) {
481
+ await this.projectService.cdProject(name);
482
+ }
483
+ const project = await this.projectService.get();
484
+ if (!project.extraHosts) {
485
+ return "No extra hosts found";
486
+ }
487
+ const table = new cli_table3_1.default({
488
+ head: ["Host", "Domain"]
489
+ });
490
+ for (const host in project.extraHosts) {
491
+ table.push([
492
+ host, project.extraHosts[host]
493
+ ]);
494
+ }
495
+ return table.toString();
496
+ }
497
+ async addExtraHost(extraHost, extraDomain, name) {
498
+ if (name) {
499
+ await this.projectService.cdProject(name);
500
+ }
501
+ const project = await this.projectService.get();
502
+ project.addExtraHost(extraHost, extraDomain);
503
+ await project.save();
504
+ }
505
+ async removeExtraHost(extraHost, name) {
506
+ if (name) {
507
+ await this.projectService.cdProject(name);
508
+ }
509
+ const project = await this.projectService.get();
510
+ project.removeExtraHost(extraHost);
511
+ await project.save();
512
+ }
468
513
  async logs(name, global, detach, follow) {
469
514
  if (global) {
470
- const logFilepath = Path.join(env_1.DATA_DIR, "ws.log");
515
+ const logFilepath = this.appConfigService.dataPath("ws.log");
471
516
  const prepareLog = (str) => {
472
517
  return str.replace(/^\[.*]\s([^:]+):\s.*$/gm, (substring, type) => {
473
518
  switch (type) {
@@ -520,7 +565,10 @@ let ProjectController = class ProjectController {
520
565
  await this.projectService.cdProject(name);
521
566
  }
522
567
  const project = await this.projectService.get();
523
- const container = await this.dockerService.getContainer(`${project.name}.workspace`);
568
+ const container = await this.dockerService.getContainer(project.containerName);
569
+ if (!container) {
570
+ throw new Error("Project not started");
571
+ }
524
572
  if (!detach) {
525
573
  const stream = await container.logs({
526
574
  stdout: true,
@@ -529,19 +577,31 @@ let ProjectController = class ProjectController {
529
577
  });
530
578
  stream.on("data", (data) => {
531
579
  try {
532
- data = (0, utils_1.demuxOutput)(data);
580
+ if (data instanceof Buffer) {
581
+ data = (0, utils_1.demuxOutput)(data);
582
+ }
583
+ }
584
+ catch (err) {
585
+ this.logService.error(err.message, err);
533
586
  }
534
- catch (err) { }
535
587
  process.stdout.write(data);
536
588
  });
537
589
  }
538
590
  else {
539
- const buffer = await container.logs({
591
+ let data = await container.logs({
540
592
  stdout: true,
541
593
  stderr: true,
542
594
  follow: false
543
595
  });
544
- process.stdout.write((0, utils_1.demuxOutput)(buffer));
596
+ try {
597
+ if (data instanceof Buffer) {
598
+ data = (0, utils_1.demuxOutput)(data);
599
+ }
600
+ }
601
+ catch (err) {
602
+ this.logService.error(err.message, err);
603
+ }
604
+ process.stdout.write(data);
545
605
  }
546
606
  }
547
607
  async exec(name, command) {
@@ -559,7 +619,7 @@ let ProjectController = class ProjectController {
559
619
  if (!project.scripts || !project.scripts[script]) {
560
620
  throw new Error(`Script ${script} not found`);
561
621
  }
562
- const container = await this.dockerService.getContainer(`${project.name}.workspace`);
622
+ const container = await this.dockerService.getContainer(project.containerName);
563
623
  if (!container) {
564
624
  throw new Error("The project is not started");
565
625
  }
@@ -600,6 +660,7 @@ __decorate([
600
660
  ], ProjectController.prototype, "getScriptNames", null);
601
661
  __decorate([
602
662
  (0, core_1.Command)("init"),
663
+ (0, core_1.Description)("Project initialisation"),
603
664
  __param(0, (0, core_1.Option)("name", {
604
665
  type: "string",
605
666
  alias: "n",
@@ -610,17 +671,13 @@ __decorate([
610
671
  alias: "t",
611
672
  description: "Project type"
612
673
  })),
613
- __param(2, (0, core_1.Option)("preset", {
614
- type: "string",
615
- alias: "p",
616
- description: "Preset"
617
- })),
618
674
  __metadata("design:type", Function),
619
- __metadata("design:paramtypes", [String, String, String]),
675
+ __metadata("design:paramtypes", [String, String]),
620
676
  __metadata("design:returntype", Promise)
621
677
  ], ProjectController.prototype, "init", null);
622
678
  __decorate([
623
679
  (0, core_1.Command)("ps"),
680
+ (0, core_1.Description)("Projects list"),
624
681
  __param(0, (0, core_1.Option)("all", {
625
682
  type: "boolean",
626
683
  alias: "a",
@@ -665,6 +722,7 @@ __decorate([
665
722
  ], ProjectController.prototype, "start", null);
666
723
  __decorate([
667
724
  (0, core_1.Command)("stop"),
725
+ (0, core_1.Description)("Stopping project"),
668
726
  __param(0, (0, core_1.Option)("name", {
669
727
  type: "string",
670
728
  alias: "n",
@@ -676,6 +734,7 @@ __decorate([
676
734
  ], ProjectController.prototype, "stop", null);
677
735
  __decorate([
678
736
  (0, core_1.Command)("domains"),
737
+ (0, core_1.Description)("Project domain list"),
679
738
  __param(0, (0, core_1.Option)("name", {
680
739
  type: "string",
681
740
  alias: "n",
@@ -687,6 +746,7 @@ __decorate([
687
746
  ], ProjectController.prototype, "domains", null);
688
747
  __decorate([
689
748
  (0, core_1.Command)("domain:add [...domains]"),
749
+ (0, core_1.Description)("Adding project domain"),
690
750
  __param(0, (0, core_1.Option)("name", {
691
751
  type: "string",
692
752
  alias: "n",
@@ -698,6 +758,7 @@ __decorate([
698
758
  ], ProjectController.prototype, "addDomain", null);
699
759
  __decorate([
700
760
  (0, core_1.Command)("domain:set [...domains]"),
761
+ (0, core_1.Description)("Setting project domains"),
701
762
  __param(0, (0, core_1.Option)("name", {
702
763
  type: "string",
703
764
  alias: "n",
@@ -709,6 +770,7 @@ __decorate([
709
770
  ], ProjectController.prototype, "setDomains", null);
710
771
  __decorate([
711
772
  (0, core_1.Command)("domain:remove [...domains]"),
773
+ (0, core_1.Description)("Removing project domain"),
712
774
  __param(0, (0, core_1.Option)("name", {
713
775
  type: "string",
714
776
  alias: "n",
@@ -720,6 +782,7 @@ __decorate([
720
782
  ], ProjectController.prototype, "removeDomain", null);
721
783
  __decorate([
722
784
  (0, core_1.Command)("domain:clear"),
785
+ (0, core_1.Description)("Clearing project domain"),
723
786
  __param(0, (0, core_1.Option)("name", {
724
787
  type: "string",
725
788
  alias: "n",
@@ -916,6 +979,45 @@ __decorate([
916
979
  __metadata("design:paramtypes", [String, Array]),
917
980
  __metadata("design:returntype", Promise)
918
981
  ], ProjectController.prototype, "volumeUnmount", null);
982
+ __decorate([
983
+ (0, core_1.Command)("extra-hosts"),
984
+ (0, core_1.Description)("List of extra hosts"),
985
+ __param(0, (0, core_1.Option)("name", {
986
+ type: "string",
987
+ alias: "n",
988
+ description: "The name of the project"
989
+ })),
990
+ __metadata("design:type", Function),
991
+ __metadata("design:paramtypes", [String]),
992
+ __metadata("design:returntype", Promise)
993
+ ], ProjectController.prototype, "extraHostList", null);
994
+ __decorate([
995
+ (0, core_1.Command)("extra-host:add <extraHost>:<extraDomain>"),
996
+ (0, core_1.Description)("Adding extra host"),
997
+ __param(0, (0, core_1.Param)("extraHost")),
998
+ __param(1, (0, core_1.Param)("extraDomain")),
999
+ __param(2, (0, core_1.Option)("name", {
1000
+ type: "string",
1001
+ alias: "n",
1002
+ description: "The name of the project"
1003
+ })),
1004
+ __metadata("design:type", Function),
1005
+ __metadata("design:paramtypes", [String, String, String]),
1006
+ __metadata("design:returntype", Promise)
1007
+ ], ProjectController.prototype, "addExtraHost", null);
1008
+ __decorate([
1009
+ (0, core_1.Command)("extra-host:remove <extraHost>"),
1010
+ (0, core_1.Description)("Removing extra host"),
1011
+ __param(0, (0, core_1.Param)("extraHost")),
1012
+ __param(1, (0, core_1.Option)("name", {
1013
+ type: "string",
1014
+ alias: "n",
1015
+ description: "The name of the project"
1016
+ })),
1017
+ __metadata("design:type", Function),
1018
+ __metadata("design:paramtypes", [String, String]),
1019
+ __metadata("design:returntype", Promise)
1020
+ ], ProjectController.prototype, "removeExtraHost", null);
919
1021
  __decorate([
920
1022
  (0, core_1.Command)("logs"),
921
1023
  __param(0, (0, core_1.Option)("name", {
@@ -929,7 +1031,8 @@ __decorate([
929
1031
  })),
930
1032
  __param(2, (0, core_1.Option)("detach", {
931
1033
  type: "boolean",
932
- alias: "d"
1034
+ alias: "d",
1035
+ description: "Detach"
933
1036
  })),
934
1037
  __param(3, (0, core_1.Option)("follow", {
935
1038
  type: "boolean",
@@ -965,6 +1068,7 @@ __decorate([
965
1068
  ], ProjectController.prototype, "run", null);
966
1069
  __decorate([
967
1070
  (0, core_1.Command)("attach"),
1071
+ (0, core_1.Description)("Attach local standard input, output, and error streams to a running container"),
968
1072
  __param(0, (0, core_1.Option)("name", {
969
1073
  type: "string",
970
1074
  alias: "n",
package/lib/env.d.ts CHANGED
@@ -4,5 +4,4 @@ export declare const PRESETS_DIR: string;
4
4
  export declare const SERVICES_DIR: string;
5
5
  export declare const PLUGINS_DIR: string;
6
6
  export declare const DATA_DIR: string;
7
- export declare const MAP_PATH: string;
8
7
  export declare const VIRTUAL_HOST_KEY = "VIRTUAL_HOST";
package/lib/env.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.VIRTUAL_HOST_KEY = exports.MAP_PATH = exports.DATA_DIR = exports.PLUGINS_DIR = exports.SERVICES_DIR = exports.PRESETS_DIR = exports.ROOT_DIR = exports.NODE_ENV = void 0;
26
+ exports.VIRTUAL_HOST_KEY = exports.DATA_DIR = exports.PLUGINS_DIR = exports.SERVICES_DIR = exports.PRESETS_DIR = exports.ROOT_DIR = exports.NODE_ENV = void 0;
27
27
  const OS = __importStar(require("os"));
28
28
  const Path = __importStar(require("path"));
29
29
  exports.NODE_ENV = process.env.NODE_ENV;
@@ -32,5 +32,4 @@ exports.PRESETS_DIR = Path.join(exports.ROOT_DIR, "presets");
32
32
  exports.SERVICES_DIR = Path.join(exports.ROOT_DIR, "services");
33
33
  exports.PLUGINS_DIR = Path.join(exports.ROOT_DIR, "plugins");
34
34
  exports.DATA_DIR = process.env.WS_DIR || Path.join(OS.homedir(), ".workspace");
35
- exports.MAP_PATH = Path.join(exports.DATA_DIR, "data.json");
36
35
  exports.VIRTUAL_HOST_KEY = "VIRTUAL_HOST";
package/lib/main.js CHANGED
@@ -22,9 +22,9 @@ exports.app = {
22
22
  }
23
23
  catch (err) {
24
24
  console.error(chalk_1.default.red(err.message));
25
- const { debug } = await config.getConfig();
25
+ const { debug } = config.getConfig();
26
26
  if (debug) {
27
- logger.error(err.stack || err.message);
27
+ logger.error(err.stack || err.toString());
28
28
  }
29
29
  }
30
30
  }
@@ -1,18 +1,17 @@
1
- import { Config, AppConfigService as CoreAppConfigService } from "@wocker/core";
1
+ import { AppConfig, AppConfigService as CoreAppConfigService } from "@wocker/core";
2
2
  type TypeMap = {
3
3
  [type: string]: string;
4
4
  };
5
5
  export declare class AppConfigService extends CoreAppConfigService {
6
- protected pwd: string;
7
- protected mapTypes: TypeMap;
6
+ protected _pwd: string;
7
+ protected readonly mapTypes: TypeMap;
8
8
  constructor();
9
+ setPWD(pwd: string): void;
10
+ pwd(...parts: string[]): string;
9
11
  dataPath(...parts: string[]): string;
10
12
  pluginsPath(...parts: string[]): string;
11
13
  presetPath(...parts: string[]): string;
12
- getPWD(): string;
13
- setPWD(pwd: string): void;
14
14
  getProjectTypes(): TypeMap;
15
- registerProjectType(name: string, title?: string): void;
16
- protected loadConfig(): Promise<Config>;
15
+ protected loadConfig(): AppConfig;
17
16
  }
18
17
  export {};
@@ -36,15 +36,21 @@ exports.AppConfigService = void 0;
36
36
  const core_1 = require("@wocker/core");
37
37
  const Path = __importStar(require("path"));
38
38
  const env_1 = require("../env");
39
- const makes_1 = require("../makes");
40
39
  let AppConfigService = class AppConfigService extends core_1.AppConfigService {
41
40
  constructor() {
42
41
  super();
43
42
  this.mapTypes = {
44
- image: "Image",
45
- dockerfile: "Dockerfile"
43
+ [core_1.PROJECT_TYPE_IMAGE]: "Image",
44
+ [core_1.PROJECT_TYPE_DOCKERFILE]: "Dockerfile",
45
+ [core_1.PROJECT_TYPE_PRESET]: "Preset"
46
46
  };
47
- this.pwd = (process.cwd() || process.env.PWD);
47
+ this._pwd = (process.cwd() || process.env.PWD);
48
+ }
49
+ setPWD(pwd) {
50
+ this._pwd = pwd;
51
+ }
52
+ pwd(...parts) {
53
+ return Path.join(this._pwd, ...parts);
48
54
  }
49
55
  dataPath(...parts) {
50
56
  return Path.join(env_1.DATA_DIR, ...parts);
@@ -55,37 +61,57 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
55
61
  presetPath(...parts) {
56
62
  return Path.join(env_1.PRESETS_DIR, ...parts);
57
63
  }
58
- getPWD() {
59
- return this.pwd;
60
- }
61
- setPWD(pwd) {
62
- this.pwd = pwd;
63
- }
64
64
  getProjectTypes() {
65
65
  return this.mapTypes;
66
66
  }
67
- registerProjectType(name, title) {
68
- this.mapTypes[name] = title || name;
69
- }
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 {
67
+ loadConfig() {
68
+ const fs = new core_1.FileSystem(env_1.DATA_DIR);
69
+ let data = {};
70
+ if (fs.exists("wocker.config.js")) {
71
+ try {
72
+ const { config } = require(fs.path("wocker.config.js"));
73
+ data = config;
74
+ }
75
+ catch (err) {
76
+ if (fs.exists("wocker.config.json")) {
77
+ let json = fs.readJSON("wocker.config.json");
78
+ if (typeof json === "string") {
79
+ json = JSON.parse(json);
80
+ }
81
+ data = json;
82
+ }
83
+ }
84
+ }
85
+ else if (fs.exists("wocker.config.json")) {
86
+ data = fs.readJSON("wocker.config.json");
87
+ }
88
+ else if (fs.exists("wocker.json")) {
89
+ let json = fs.readJSON("wocker.json");
90
+ if (typeof json === "string") {
91
+ json = JSON.parse(json);
92
+ }
93
+ data = json;
94
+ }
95
+ else if (fs.exists("data.json")) {
96
+ data = fs.readJSON("data.json");
97
+ }
98
+ return new class extends core_1.AppConfig {
75
99
  constructor(data) {
76
100
  super(data);
77
101
  }
78
- addPlugin(plugin) {
79
- if (!this.plugins) {
80
- this.plugins = [];
102
+ async save() {
103
+ if (!fs.exists()) {
104
+ fs.mkdir("");
81
105
  }
82
- if (this.plugins.includes(plugin)) {
83
- return;
106
+ const json = JSON.stringify(this.toJson(), null, 4);
107
+ await fs.writeFile("wocker.config.js", `// Wocker config\nexports.config = ${json};`);
108
+ await fs.writeFile("wocker.config.json", json);
109
+ if (fs.exists("data.json")) {
110
+ await fs.rm("data.json");
111
+ }
112
+ if (fs.exists("wocker.json")) {
113
+ await fs.rm("wocker.json");
84
114
  }
85
- this.plugins.push(plugin);
86
- }
87
- async save() {
88
- await makes_1.FS.writeJSON(env_1.MAP_PATH, this.toJson());
89
115
  }
90
116
  }(data);
91
117
  }
@@ -214,15 +214,11 @@ let DockerService = class DockerService {
214
214
  await (0, utils_2.followProgress)(stream);
215
215
  }
216
216
  async attach(containerOrName) {
217
- let container;
218
- if (typeof containerOrName === "string") {
219
- container = await this.getContainer(containerOrName);
220
- }
221
- else {
222
- if (!containerOrName) {
223
- return;
224
- }
225
- container = containerOrName;
217
+ let container = typeof containerOrName === "string"
218
+ ? await this.getContainer(containerOrName)
219
+ : containerOrName;
220
+ if (!container) {
221
+ return;
226
222
  }
227
223
  const stream = await container.attach({
228
224
  logs: true,
@@ -239,10 +235,21 @@ let DockerService = class DockerService {
239
235
  process.stdin.pipe(stream);
240
236
  process.stdin.on("data", (data) => {
241
237
  if (data.toString() === "\u0003") {
242
- process.stdin.setRawMode(false);
238
+ stream.end();
239
+ setTimeout(() => {
240
+ process.exit();
241
+ }, 5000);
243
242
  }
244
243
  });
245
244
  stream.on("data", (data) => {
245
+ if (data instanceof Buffer) {
246
+ try {
247
+ data = (0, utils_1.demuxOutput)(data);
248
+ }
249
+ catch (err) {
250
+ this.logService.error(err.toString(), err.stack);
251
+ }
252
+ }
246
253
  process.stdout.write(data);
247
254
  });
248
255
  stream.on("end", async () => {
@@ -1,7 +1,9 @@
1
+ import { LogService as CoreLogService } from "@wocker/core";
1
2
  import { AppConfigService } from "./AppConfigService";
2
- export declare class LogService {
3
+ export declare class LogService extends CoreLogService {
3
4
  protected readonly appConfigService: AppConfigService;
4
5
  constructor(appConfigService: AppConfigService);
6
+ debug(...data: any[]): void;
5
7
  log(...data: any[]): void;
6
8
  info(...data: any[]): void;
7
9
  warn(...data: any[]): void;
@@ -17,11 +17,15 @@ const core_1 = require("@wocker/core");
17
17
  const format_1 = __importDefault(require("date-fns/format"));
18
18
  const makes_1 = require("../makes");
19
19
  const AppConfigService_1 = require("./AppConfigService");
20
- let LogService = class LogService {
20
+ let LogService = class LogService extends core_1.LogService {
21
21
  constructor(appConfigService) {
22
+ super();
22
23
  this.appConfigService = appConfigService;
23
24
  makes_1.Logger.install(this);
24
25
  }
26
+ debug(...data) {
27
+ this._log("debug", ...data);
28
+ }
25
29
  log(...data) {
26
30
  this._log("log", ...data);
27
31
  }
@@ -35,6 +39,10 @@ let LogService = class LogService {
35
39
  this._log("error", ...data);
36
40
  }
37
41
  _log(type, ...data) {
42
+ const config = this.appConfigService.getConfig();
43
+ if (type === "debug" && !config.debug) {
44
+ return;
45
+ }
38
46
  const time = (0, format_1.default)(new Date(), "yyyy-MM-dd hh:mm:ss");
39
47
  const logPath = this.appConfigService.dataPath("ws.log");
40
48
  const logData = data.map((item) => {
@@ -0,0 +1,5 @@
1
+ import { PackageInfo } from "../types";
2
+ export declare class NpmService {
3
+ getPackageInfo(name: string): Promise<PackageInfo>;
4
+ install(name: string, version?: string): Promise<void>;
5
+ }