@wocker/ws 1.0.18 → 1.0.19

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.
@@ -89,7 +89,8 @@ let PresetController = class PresetController {
89
89
  label: "Global usage",
90
90
  value: "global"
91
91
  }
92
- ]
92
+ ],
93
+ default: project.presetMode
93
94
  });
94
95
  const preset = await this.presetService.get(project.preset);
95
96
  if (!preset) {
@@ -187,9 +188,9 @@ let PresetController = class PresetController {
187
188
  }
188
189
  async eject(name) {
189
190
  if (name) {
190
- await this.projectService.cdProject(name);
191
+ this.projectService.cdProject(name);
191
192
  }
192
- const project = await this.projectService.get();
193
+ const project = this.projectService.get();
193
194
  const preset = await this.presetService.get(project.preset);
194
195
  if (!preset) {
195
196
  throw new Error("Preset not found");
@@ -1,12 +1,11 @@
1
1
  import { ProjectType } from "@wocker/core";
2
- import { AppConfigService, AppEventsService, ProjectService, DockerService, LogService } from "../services";
2
+ import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
3
3
  export declare class ProjectController {
4
4
  protected readonly appConfigService: AppConfigService;
5
5
  protected readonly appEventsService: AppEventsService;
6
6
  protected readonly projectService: ProjectService;
7
7
  protected readonly dockerService: DockerService;
8
- protected readonly logService: LogService;
9
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService, logService: LogService);
8
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
10
9
  protected getProjectNames(): Promise<string[]>;
11
10
  getScriptNames(): Promise<string[]>;
12
11
  init(name: string, type: ProjectType): Promise<void>;
@@ -36,8 +35,8 @@ export declare class ProjectController {
36
35
  extraHostList(name?: string): Promise<string>;
37
36
  addExtraHost(extraHost: string, extraDomain: string, name?: string): Promise<void>;
38
37
  removeExtraHost(extraHost: string, name?: string): Promise<void>;
39
- logs(name?: string, global?: boolean, detach?: boolean, follow?: boolean): Promise<void>;
38
+ attach(name?: string): Promise<void>;
40
39
  exec(name?: string, command?: string[]): Promise<void>;
41
40
  run(name: string, script: string, args?: string[]): Promise<void>;
42
- attach(name?: string): Promise<void>;
41
+ logs(name?: string, global?: boolean, detach?: boolean, follow?: boolean): Promise<void>;
43
42
  }
@@ -48,22 +48,21 @@ const async_mutex_1 = require("async-mutex");
48
48
  const makes_1 = require("../makes");
49
49
  const services_1 = require("../services");
50
50
  let ProjectController = class ProjectController {
51
- constructor(appConfigService, appEventsService, projectService, dockerService, logService) {
51
+ constructor(appConfigService, appEventsService, projectService, dockerService) {
52
52
  this.appConfigService = appConfigService;
53
53
  this.appEventsService = appEventsService;
54
54
  this.projectService = projectService;
55
55
  this.dockerService = dockerService;
56
- this.logService = logService;
57
56
  }
58
57
  async getProjectNames() {
59
- const projects = await this.projectService.search();
58
+ const projects = this.projectService.search();
60
59
  return projects.map((project) => {
61
60
  return project.name;
62
61
  });
63
62
  }
64
63
  async getScriptNames() {
65
64
  try {
66
- const project = await this.projectService.get();
65
+ const project = this.projectService.get();
67
66
  return Object.keys(project.scripts);
68
67
  }
69
68
  catch (err) {
@@ -71,7 +70,7 @@ let ProjectController = class ProjectController {
71
70
  }
72
71
  }
73
72
  async init(name, type) {
74
- let project = await this.projectService.searchOne({
73
+ let project = this.projectService.searchOne({
75
74
  path: this.appConfigService.pwd()
76
75
  });
77
76
  const fs = new core_1.FileSystem(this.appConfigService.pwd());
@@ -148,7 +147,7 @@ let ProjectController = class ProjectController {
148
147
  head: ["Name", "Type", "Status"],
149
148
  colAligns: ["left", "center", "center"]
150
149
  });
151
- const projects = await this.projectService.search({});
150
+ const projects = this.projectService.search({});
152
151
  for (const project of projects) {
153
152
  const container = await this.dockerService.getContainer(project.containerName);
154
153
  if (!container) {
@@ -163,36 +162,27 @@ let ProjectController = class ProjectController {
163
162
  return table.toString();
164
163
  }
165
164
  async start(name, detach, attach, rebuild, restart) {
166
- if (name) {
167
- await this.projectService.cdProject(name);
168
- }
169
- const project = await this.projectService.get();
165
+ const project = this.projectService.get(name);
170
166
  await this.projectService.start(project, restart, rebuild);
171
- if (detach) {
172
- console.info(chalk_1.default.yellow("Warning: Detach option is deprecated"));
173
- }
174
167
  if (attach) {
175
- const project = await this.projectService.get();
176
- const container = await this.dockerService.getContainer(project.containerName);
177
- await container.resize({
178
- w: process.stdout.columns,
179
- h: process.stdout.rows
180
- });
181
168
  await this.dockerService.attach(project.containerName);
182
169
  }
170
+ if (detach) {
171
+ console.info(chalk_1.default.yellow("Warning: Detach option is deprecated"));
172
+ }
183
173
  }
184
174
  async stop(name) {
185
175
  if (name) {
186
- await this.projectService.cdProject(name);
176
+ this.projectService.cdProject(name);
187
177
  }
188
- const project = await this.projectService.get();
178
+ const project = this.projectService.get();
189
179
  await this.projectService.stop(project);
190
180
  }
191
181
  async domains(name) {
192
182
  if (name) {
193
- await this.projectService.cdProject(name);
183
+ this.projectService.cdProject(name);
194
184
  }
195
- const project = await this.projectService.get();
185
+ const project = this.projectService.get();
196
186
  const table = new cli_table3_1.default({
197
187
  head: [chalk_1.default.yellow("Domain")]
198
188
  });
@@ -203,9 +193,9 @@ let ProjectController = class ProjectController {
203
193
  }
204
194
  async addDomain(name, addDomains) {
205
195
  if (name) {
206
- await this.projectService.cdProject(name);
196
+ this.projectService.cdProject(name);
207
197
  }
208
- const project = await this.projectService.get();
198
+ const project = this.projectService.get();
209
199
  for (const domain of addDomains) {
210
200
  project.addDomain(domain);
211
201
  }
@@ -213,9 +203,9 @@ let ProjectController = class ProjectController {
213
203
  }
214
204
  async setDomains(name, domains) {
215
205
  if (name) {
216
- await this.projectService.cdProject(name);
206
+ this.projectService.cdProject(name);
217
207
  }
218
- const project = await this.projectService.get();
208
+ const project = this.projectService.get();
219
209
  project.clearDomains();
220
210
  for (const domain of domains) {
221
211
  project.addDomain(domain);
@@ -224,9 +214,9 @@ let ProjectController = class ProjectController {
224
214
  }
225
215
  async removeDomain(name, removeDomains) {
226
216
  if (name) {
227
- await this.projectService.cdProject(name);
217
+ this.projectService.cdProject(name);
228
218
  }
229
- const project = await this.projectService.get();
219
+ const project = this.projectService.get();
230
220
  for (const domain of removeDomains) {
231
221
  project.removeDomain(domain);
232
222
  }
@@ -234,17 +224,17 @@ let ProjectController = class ProjectController {
234
224
  }
235
225
  async clearDomain(name) {
236
226
  if (name) {
237
- await this.projectService.cdProject(name);
227
+ this.projectService.cdProject(name);
238
228
  }
239
- const project = await this.projectService.get();
229
+ const project = this.projectService.get();
240
230
  project.clearDomains();
241
231
  await project.save();
242
232
  }
243
233
  async ports(name) {
244
234
  if (name) {
245
- await this.projectService.cdProject(name);
235
+ this.projectService.cdProject(name);
246
236
  }
247
- const project = await this.projectService.get();
237
+ const project = this.projectService.get();
248
238
  const table = new cli_table3_1.default({
249
239
  head: ["Ports"]
250
240
  });
@@ -255,25 +245,25 @@ let ProjectController = class ProjectController {
255
245
  }
256
246
  async addPort(hostPort, containerPort, name) {
257
247
  if (name) {
258
- await this.projectService.cdProject(name);
248
+ this.projectService.cdProject(name);
259
249
  }
260
- const project = await this.projectService.get();
250
+ const project = this.projectService.get();
261
251
  project.linkPort(parseInt(hostPort), parseInt(containerPort));
262
252
  await project.save();
263
253
  }
264
254
  async removePort(hostPort, containerPort, name) {
265
255
  if (name) {
266
- await this.projectService.cdProject(name);
256
+ this.projectService.cdProject(name);
267
257
  }
268
- const project = await this.projectService.get();
258
+ const project = this.projectService.get();
269
259
  project.unlinkPort(parseInt(hostPort), parseInt(containerPort));
270
260
  await project.save();
271
261
  }
272
262
  async clearPorts(name) {
273
263
  if (name) {
274
- await this.projectService.cdProject(name);
264
+ this.projectService.cdProject(name);
275
265
  }
276
- const project = await this.projectService.get();
266
+ const project = this.projectService.get();
277
267
  if (project.ports) {
278
268
  delete project.ports;
279
269
  await project.save();
@@ -281,11 +271,11 @@ let ProjectController = class ProjectController {
281
271
  }
282
272
  async configList(name, global) {
283
273
  if (name) {
284
- await this.projectService.cdProject(name);
274
+ this.projectService.cdProject(name);
285
275
  }
286
276
  let env;
287
277
  if (!global) {
288
- const project = await this.projectService.get();
278
+ const project = this.projectService.get();
289
279
  env = project.env || {};
290
280
  }
291
281
  else {
@@ -302,11 +292,11 @@ let ProjectController = class ProjectController {
302
292
  }
303
293
  async configGet(name, global, keys) {
304
294
  if (name) {
305
- await this.projectService.cdProject(name);
295
+ this.projectService.cdProject(name);
306
296
  }
307
297
  let config = global
308
298
  ? this.appConfigService.getConfig()
309
- : await this.projectService.get();
299
+ : this.projectService.get();
310
300
  const table = new cli_table3_1.default({
311
301
  head: ["KEY", "VALUE"]
312
302
  });
@@ -321,11 +311,11 @@ let ProjectController = class ProjectController {
321
311
  }
322
312
  async configSet(name, global, variables) {
323
313
  if (!global && name) {
324
- await this.projectService.cdProject(name);
314
+ this.projectService.cdProject(name);
325
315
  }
326
316
  const config = global
327
317
  ? this.appConfigService.getConfig()
328
- : await this.projectService.get();
318
+ : this.projectService.get();
329
319
  for (const variable of variables) {
330
320
  const [key, value] = variable.split("=");
331
321
  if (!value) {
@@ -336,7 +326,7 @@ let ProjectController = class ProjectController {
336
326
  }
337
327
  await config.save();
338
328
  if (!global) {
339
- const project = await this.projectService.get();
329
+ const project = this.projectService.get();
340
330
  const container = await this.dockerService.getContainer(project.containerName);
341
331
  if (container) {
342
332
  await this.projectService.start(project, true);
@@ -353,15 +343,15 @@ let ProjectController = class ProjectController {
353
343
  return;
354
344
  }
355
345
  if (name) {
356
- await this.projectService.cdProject(name);
346
+ this.projectService.cdProject(name);
357
347
  }
358
- const project = await this.projectService.get();
348
+ const project = this.projectService.get();
359
349
  for (const i in env) {
360
350
  project.unsetEnv(i);
361
351
  }
362
352
  await project.save();
363
353
  if (!global) {
364
- const project = await this.projectService.get();
354
+ const project = this.projectService.get();
365
355
  const container = await this.dockerService.getContainer(project.containerName);
366
356
  if (container) {
367
357
  await this.projectService.start(project, true);
@@ -370,9 +360,9 @@ let ProjectController = class ProjectController {
370
360
  }
371
361
  async buildArgsList(name) {
372
362
  if (name) {
373
- await this.projectService.cdProject(name);
363
+ this.projectService.cdProject(name);
374
364
  }
375
- const project = await this.projectService.get();
365
+ const project = this.projectService.get();
376
366
  const table = new cli_table3_1.default({
377
367
  head: ["KEY", "VALUE"]
378
368
  });
@@ -384,9 +374,9 @@ let ProjectController = class ProjectController {
384
374
  }
385
375
  async buildArgsGet(name, args) {
386
376
  if (name) {
387
- await this.projectService.cdProject(name);
377
+ this.projectService.cdProject(name);
388
378
  }
389
- const project = await this.projectService.get();
379
+ const project = this.projectService.get();
390
380
  const table = new cli_table3_1.default({
391
381
  head: ["KEY", "VALUE"]
392
382
  });
@@ -400,9 +390,9 @@ let ProjectController = class ProjectController {
400
390
  }
401
391
  async buildArgsSet(name, args) {
402
392
  if (name) {
403
- await this.projectService.cdProject(name);
393
+ this.projectService.cdProject(name);
404
394
  }
405
- const project = await this.projectService.get();
395
+ const project = this.projectService.get();
406
396
  const buildArgs = args.reduce((env, config) => {
407
397
  let [, key = "", value = ""] = config.split(/^([^=]+)=(.*)$/);
408
398
  key = key.trim();
@@ -422,9 +412,9 @@ let ProjectController = class ProjectController {
422
412
  }
423
413
  async buildArgsUnset(name, args) {
424
414
  if (name) {
425
- await this.projectService.cdProject(name);
415
+ this.projectService.cdProject(name);
426
416
  }
427
- const project = await this.projectService.get();
417
+ const project = this.projectService.get();
428
418
  const buildArgs = args.reduce((env, config) => {
429
419
  let [, key = "", value = ""] = config.split(/^([^=]+)(?:=(.*))?$/);
430
420
  key = key.trim();
@@ -444,9 +434,9 @@ let ProjectController = class ProjectController {
444
434
  }
445
435
  async volumeList(name) {
446
436
  if (name) {
447
- await this.projectService.cdProject(name);
437
+ this.projectService.cdProject(name);
448
438
  }
449
- const project = await this.projectService.get();
439
+ const project = this.projectService.get();
450
440
  const table = new cli_table3_1.default({
451
441
  head: ["Volume"]
452
442
  });
@@ -458,9 +448,9 @@ let ProjectController = class ProjectController {
458
448
  }
459
449
  async volumeMount(name, volumes) {
460
450
  if (name) {
461
- await this.projectService.cdProject(name);
451
+ this.projectService.cdProject(name);
462
452
  }
463
- const project = await this.projectService.get();
453
+ const project = this.projectService.get();
464
454
  if (Array.isArray(volumes) && volumes.length > 0) {
465
455
  project.volumeMount(...volumes);
466
456
  await project.save();
@@ -468,9 +458,9 @@ let ProjectController = class ProjectController {
468
458
  }
469
459
  async volumeUnmount(name, volumes) {
470
460
  if (name) {
471
- await this.projectService.cdProject(name);
461
+ this.projectService.cdProject(name);
472
462
  }
473
- const project = await this.projectService.get();
463
+ const project = this.projectService.get();
474
464
  if (Array.isArray(volumes) && volumes.length > 0) {
475
465
  project.volumeUnmount(...volumes);
476
466
  await project.save();
@@ -478,9 +468,9 @@ let ProjectController = class ProjectController {
478
468
  }
479
469
  async extraHostList(name) {
480
470
  if (name) {
481
- await this.projectService.cdProject(name);
471
+ this.projectService.cdProject(name);
482
472
  }
483
- const project = await this.projectService.get();
473
+ const project = this.projectService.get();
484
474
  if (!project.extraHosts) {
485
475
  return "No extra hosts found";
486
476
  }
@@ -496,20 +486,60 @@ let ProjectController = class ProjectController {
496
486
  }
497
487
  async addExtraHost(extraHost, extraDomain, name) {
498
488
  if (name) {
499
- await this.projectService.cdProject(name);
489
+ this.projectService.cdProject(name);
500
490
  }
501
- const project = await this.projectService.get();
491
+ const project = this.projectService.get();
502
492
  project.addExtraHost(extraHost, extraDomain);
503
493
  await project.save();
504
494
  }
505
495
  async removeExtraHost(extraHost, name) {
506
496
  if (name) {
507
- await this.projectService.cdProject(name);
497
+ this.projectService.cdProject(name);
508
498
  }
509
- const project = await this.projectService.get();
499
+ const project = this.projectService.get();
510
500
  project.removeExtraHost(extraHost);
511
501
  await project.save();
512
502
  }
503
+ async attach(name) {
504
+ if (name) {
505
+ this.projectService.cdProject(name);
506
+ }
507
+ const project = this.projectService.get();
508
+ await this.dockerService.attach(project.containerName);
509
+ }
510
+ async exec(name, command) {
511
+ if (name) {
512
+ this.projectService.cdProject(name);
513
+ }
514
+ const project = this.projectService.get();
515
+ await this.dockerService.exec(project.containerName, command, true);
516
+ }
517
+ async run(name, script, args) {
518
+ if (name) {
519
+ this.projectService.cdProject(name);
520
+ }
521
+ const project = this.projectService.get();
522
+ if (!project.scripts || !project.scripts[script]) {
523
+ throw new Error(`Script ${script} not found`);
524
+ }
525
+ const container = await this.dockerService.getContainer(project.containerName);
526
+ if (!container) {
527
+ throw new Error("The project is not started");
528
+ }
529
+ const exec = await container.exec({
530
+ AttachStdin: true,
531
+ AttachStdout: true,
532
+ AttachStderr: true,
533
+ Tty: process.stdin.isTTY,
534
+ Cmd: ["bash", "-i", "-c", [project.scripts[script], ...args || []].join(" ")]
535
+ });
536
+ const stream = await exec.start({
537
+ hijack: true,
538
+ stdin: true,
539
+ Tty: process.stdin.isTTY
540
+ });
541
+ await this.dockerService.attachStream(stream);
542
+ }
513
543
  async logs(name, global, detach, follow) {
514
544
  if (global) {
515
545
  const logFilepath = this.appConfigService.dataPath("ws.log");
@@ -562,30 +592,15 @@ let ProjectController = class ProjectController {
562
592
  return;
563
593
  }
564
594
  if (name) {
565
- await this.projectService.cdProject(name);
595
+ this.projectService.cdProject(name);
566
596
  }
567
- const project = await this.projectService.get();
597
+ const project = this.projectService.get();
568
598
  const container = await this.dockerService.getContainer(project.containerName);
569
599
  if (!container) {
570
600
  throw new Error("Project not started");
571
601
  }
572
602
  if (!detach) {
573
- const stream = await container.logs({
574
- stdout: true,
575
- stderr: true,
576
- follow: true
577
- });
578
- stream.on("data", (data) => {
579
- try {
580
- if (data instanceof Buffer) {
581
- data = (0, utils_1.demuxOutput)(data);
582
- }
583
- }
584
- catch (err) {
585
- this.logService.error(err.message, err);
586
- }
587
- process.stdout.write(data);
588
- });
603
+ await this.dockerService.logs(container);
589
604
  }
590
605
  else {
591
606
  let data = await container.logs({
@@ -593,57 +608,9 @@ let ProjectController = class ProjectController {
593
608
  stderr: true,
594
609
  follow: false
595
610
  });
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
611
  process.stdout.write(data);
605
612
  }
606
613
  }
607
- async exec(name, command) {
608
- if (name) {
609
- await this.projectService.cdProject(name);
610
- }
611
- const project = await this.projectService.get();
612
- await this.dockerService.exec(project.containerName, command);
613
- }
614
- async run(name, script, args) {
615
- if (name) {
616
- await this.projectService.cdProject(name);
617
- }
618
- const project = await this.projectService.get();
619
- if (!project.scripts || !project.scripts[script]) {
620
- throw new Error(`Script ${script} not found`);
621
- }
622
- const container = await this.dockerService.getContainer(project.containerName);
623
- if (!container) {
624
- throw new Error("The project is not started");
625
- }
626
- const exec = await container.exec({
627
- Cmd: ["bash", "-i", "-c", [project.scripts[script], ...args || []].join(" ")],
628
- AttachStdin: true,
629
- AttachStdout: true,
630
- AttachStderr: true,
631
- Tty: process.stdin.isTTY
632
- });
633
- const stream = await exec.start({
634
- hijack: true,
635
- stdin: true,
636
- Tty: process.stdin.isTTY
637
- });
638
- await this.dockerService.attachStream(stream);
639
- }
640
- async attach(name) {
641
- if (name) {
642
- await this.projectService.cdProject(name);
643
- }
644
- const project = await this.projectService.get();
645
- await this.dockerService.attach(project.containerName);
646
- }
647
614
  };
648
615
  exports.ProjectController = ProjectController;
649
616
  __decorate([
@@ -1019,29 +986,17 @@ __decorate([
1019
986
  __metadata("design:returntype", Promise)
1020
987
  ], ProjectController.prototype, "removeExtraHost", null);
1021
988
  __decorate([
1022
- (0, core_1.Command)("logs"),
989
+ (0, core_1.Command)("attach"),
990
+ (0, core_1.Description)("Attach local standard input, output, and error streams to a running container"),
1023
991
  __param(0, (0, core_1.Option)("name", {
1024
992
  type: "string",
1025
993
  alias: "n",
1026
994
  description: "The name of the project"
1027
995
  })),
1028
- __param(1, (0, core_1.Option)("global", {
1029
- type: "boolean",
1030
- alias: "g"
1031
- })),
1032
- __param(2, (0, core_1.Option)("detach", {
1033
- type: "boolean",
1034
- alias: "d",
1035
- description: "Detach"
1036
- })),
1037
- __param(3, (0, core_1.Option)("follow", {
1038
- type: "boolean",
1039
- alias: "f"
1040
- })),
1041
996
  __metadata("design:type", Function),
1042
- __metadata("design:paramtypes", [String, Boolean, Boolean, Boolean]),
997
+ __metadata("design:paramtypes", [String]),
1043
998
  __metadata("design:returntype", Promise)
1044
- ], ProjectController.prototype, "logs", null);
999
+ ], ProjectController.prototype, "attach", null);
1045
1000
  __decorate([
1046
1001
  (0, core_1.Command)("exec [...command]"),
1047
1002
  __param(0, (0, core_1.Option)("name", {
@@ -1067,22 +1022,33 @@ __decorate([
1067
1022
  __metadata("design:returntype", Promise)
1068
1023
  ], ProjectController.prototype, "run", null);
1069
1024
  __decorate([
1070
- (0, core_1.Command)("attach"),
1071
- (0, core_1.Description)("Attach local standard input, output, and error streams to a running container"),
1025
+ (0, core_1.Command)("logs"),
1072
1026
  __param(0, (0, core_1.Option)("name", {
1073
1027
  type: "string",
1074
1028
  alias: "n",
1075
1029
  description: "The name of the project"
1076
1030
  })),
1031
+ __param(1, (0, core_1.Option)("global", {
1032
+ type: "boolean",
1033
+ alias: "g"
1034
+ })),
1035
+ __param(2, (0, core_1.Option)("detach", {
1036
+ type: "boolean",
1037
+ alias: "d",
1038
+ description: "Detach"
1039
+ })),
1040
+ __param(3, (0, core_1.Option)("follow", {
1041
+ type: "boolean",
1042
+ alias: "f"
1043
+ })),
1077
1044
  __metadata("design:type", Function),
1078
- __metadata("design:paramtypes", [String]),
1045
+ __metadata("design:paramtypes", [String, Boolean, Boolean, Boolean]),
1079
1046
  __metadata("design:returntype", Promise)
1080
- ], ProjectController.prototype, "attach", null);
1047
+ ], ProjectController.prototype, "logs", null);
1081
1048
  exports.ProjectController = ProjectController = __decorate([
1082
1049
  (0, core_1.Controller)(),
1083
1050
  __metadata("design:paramtypes", [services_1.AppConfigService,
1084
1051
  services_1.AppEventsService,
1085
1052
  services_1.ProjectService,
1086
- services_1.DockerService,
1087
- services_1.LogService])
1053
+ services_1.DockerService])
1088
1054
  ], ProjectController);
@@ -9,7 +9,7 @@ export declare class ProxyController {
9
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
- getProjectNames(): Promise<string[]>;
12
+ getProjectNames(): string[];
13
13
  init(httpPort?: number, httpsPort?: number): Promise<void>;
14
14
  start(restart?: boolean): Promise<void>;
15
15
  stop(): Promise<void>;
@@ -43,12 +43,12 @@ let ProxyController = class ProxyController {
43
43
  }
44
44
  async onProjectStop(project) {
45
45
  }
46
- async getProjectNames() {
47
- const projects = await this.projectService.search();
46
+ getProjectNames() {
47
+ const projects = this.projectService.search();
48
48
  return projects.map((project) => project.name);
49
49
  }
50
50
  async init(httpPort, httpsPort) {
51
- const config = await this.appConfigService.getConfig();
51
+ const config = this.appConfigService.getConfig();
52
52
  if (httpPort === null || typeof httpPort === "undefined" || isNaN(httpPort)) {
53
53
  httpPort = await (0, utils_1.promptText)({
54
54
  required: true,
@@ -85,7 +85,7 @@ __decorate([
85
85
  (0, core_1.Completion)("name"),
86
86
  __metadata("design:type", Function),
87
87
  __metadata("design:paramtypes", []),
88
- __metadata("design:returntype", Promise)
88
+ __metadata("design:returntype", Array)
89
89
  ], ProxyController.prototype, "getProjectNames", null);
90
90
  __decorate([
91
91
  (0, core_1.Command)("proxy:init"),
package/lib/env.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const WOCKER_VERSION = "1.0.19";
1
2
  export declare const NODE_ENV: string;
2
3
  export declare const ROOT_DIR: string;
3
4
  export declare const PRESETS_DIR: string;
package/lib/env.js CHANGED
@@ -23,9 +23,10 @@ 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.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 = exports.WOCKER_VERSION = void 0;
27
27
  const OS = __importStar(require("os"));
28
28
  const Path = __importStar(require("path"));
29
+ exports.WOCKER_VERSION = "1.0.19";
29
30
  exports.NODE_ENV = process.env.NODE_ENV;
30
31
  exports.ROOT_DIR = Path.join(__dirname, "..");
31
32
  exports.PRESETS_DIR = Path.join(exports.ROOT_DIR, "presets");
@@ -1,11 +1,14 @@
1
- import { AppConfig, AppConfigService as CoreAppConfigService } from "@wocker/core";
1
+ import { AppConfig, AppConfigService as CoreAppConfigService, FileSystem } from "@wocker/core";
2
2
  type TypeMap = {
3
3
  [type: string]: string;
4
4
  };
5
5
  export declare class AppConfigService extends CoreAppConfigService {
6
6
  protected _pwd: string;
7
+ protected _fs?: FileSystem;
7
8
  protected readonly mapTypes: TypeMap;
8
9
  constructor();
10
+ get version(): string;
11
+ get fs(): FileSystem;
9
12
  pwd(...parts: string[]): string;
10
13
  setPWD(pwd: string): void;
11
14
  dataPath(...parts: string[]): string;
@@ -46,6 +46,15 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
46
46
  };
47
47
  this._pwd = (process.cwd() || process.env.PWD);
48
48
  }
49
+ get version() {
50
+ return env_1.WOCKER_VERSION;
51
+ }
52
+ get fs() {
53
+ if (!this._fs) {
54
+ this._fs = new core_1.FileSystem(env_1.DATA_DIR);
55
+ }
56
+ return this._fs;
57
+ }
49
58
  pwd(...parts) {
50
59
  return Path.join(this._pwd, ...parts);
51
60
  }
@@ -65,7 +74,7 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
65
74
  return this.mapTypes;
66
75
  }
67
76
  loadConfig() {
68
- const fs = new core_1.FileSystem(env_1.DATA_DIR);
77
+ const fs = this.fs;
69
78
  let data = {};
70
79
  if (fs.exists("wocker.config.js")) {
71
80
  try {
@@ -14,11 +14,11 @@ export declare class DockerService {
14
14
  removeContainer(name: string): Promise<void>;
15
15
  buildImage(params: Params.BuildImage): Promise<void>;
16
16
  imageExists(tag: string): Promise<boolean>;
17
- imageRm(tag: string): Promise<void>;
17
+ imageRm(tag: string, force?: boolean): Promise<void>;
18
18
  imageLs(options?: Params.ImageList): Promise<Docker.ImageInfo[]>;
19
19
  pullImage(tag: string): Promise<void>;
20
20
  attach(containerOrName: string | Container): Promise<NodeJS.ReadWriteStream>;
21
- logs(name: string): Promise<void>;
22
- attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
21
+ attachStream(stream: NodeJS.ReadWriteStream): Promise<NodeJS.ReadWriteStream>;
23
22
  exec(name: string, args?: string[], tty?: boolean): Promise<import("stream").Duplex>;
23
+ logs(containerOrName: string | Container): Promise<NodeJS.ReadableStream>;
24
24
  }
@@ -14,9 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.DockerService = void 0;
16
16
  const core_1 = require("@wocker/core");
17
- const utils_1 = require("@wocker/utils");
18
17
  const dockerode_1 = __importDefault(require("dockerode"));
19
- const utils_2 = require("../utils");
18
+ const utils_1 = require("../utils");
20
19
  const makes_1 = require("../makes");
21
20
  const LogService_1 = require("./LogService");
22
21
  let DockerService = class DockerService {
@@ -77,7 +76,7 @@ let DockerService = class DockerService {
77
76
  OpenStdin: true,
78
77
  StdinOnce: false,
79
78
  Entrypoint: entrypoint,
80
- Tty: tty,
79
+ Tty: true,
81
80
  Cmd: cmd,
82
81
  Env: Object.keys(env).map((key) => {
83
82
  const value = env[key];
@@ -183,7 +182,7 @@ let DockerService = class DockerService {
183
182
  }, {}),
184
183
  dockerfile: src
185
184
  });
186
- await (0, utils_2.followProgress)(stream);
185
+ await (0, utils_1.followProgress)(stream);
187
186
  }
188
187
  async imageExists(tag) {
189
188
  const image = this.docker.getImage(tag);
@@ -195,13 +194,15 @@ let DockerService = class DockerService {
195
194
  return false;
196
195
  }
197
196
  }
198
- async imageRm(tag) {
197
+ async imageRm(tag, force = false) {
199
198
  const image = this.docker.getImage(tag);
200
199
  const exists = await this.imageExists(tag);
201
200
  if (!exists) {
202
201
  return;
203
202
  }
204
- await image.remove();
203
+ await image.remove({
204
+ force
205
+ });
205
206
  }
206
207
  async imageLs(options) {
207
208
  const { tag, reference, labels } = options || {};
@@ -209,7 +210,7 @@ let DockerService = class DockerService {
209
210
  if (reference) {
210
211
  filters.reference = [
211
212
  ...filters.reference || [],
212
- reference
213
+ ...reference
213
214
  ];
214
215
  }
215
216
  if (tag) {
@@ -234,7 +235,7 @@ let DockerService = class DockerService {
234
235
  return;
235
236
  }
236
237
  const stream = await this.docker.pull(tag);
237
- await (0, utils_2.followProgress)(stream);
238
+ await (0, utils_1.followProgress)(stream);
238
239
  }
239
240
  async attach(containerOrName) {
240
241
  let container = typeof containerOrName === "string"
@@ -244,40 +245,15 @@ let DockerService = class DockerService {
244
245
  return;
245
246
  }
246
247
  const stream = await container.attach({
247
- logs: true,
248
248
  stream: true,
249
249
  hijack: true,
250
250
  stdin: true,
251
251
  stdout: true,
252
252
  stderr: true,
253
- detachKeys: "ctrl-c"
254
- });
255
- process.stdin.resume();
256
- process.stdin.setEncoding("utf8");
257
- process.stdin.setRawMode(true);
258
- process.stdin.pipe(stream);
259
- process.stdin.on("data", (data) => {
260
- if (data.toString() === "\u0003") {
261
- stream.end();
262
- setTimeout(() => {
263
- process.exit();
264
- }, 5000);
265
- }
266
- });
267
- stream.on("data", (data) => {
268
- if (data instanceof Buffer) {
269
- try {
270
- data = (0, utils_1.demuxOutput)(data);
271
- }
272
- catch (err) {
273
- this.logService.error(err.toString(), err.stack);
274
- }
275
- }
276
- process.stdout.write(data);
277
- });
278
- stream.on("end", async () => {
279
- process.exit();
253
+ logs: true,
254
+ detachKeys: "ctrl-d"
280
255
  });
256
+ await this.attachStream(stream);
281
257
  const handleResize = () => {
282
258
  const [width, height] = process.stdout.getWindowSize();
283
259
  container.resize({
@@ -289,43 +265,26 @@ let DockerService = class DockerService {
289
265
  handleResize();
290
266
  return stream;
291
267
  }
292
- async logs(name) {
293
- const container = await this.getContainer(name);
294
- if (!container) {
295
- return;
296
- }
297
- const stream = await container.logs({
298
- stdout: true,
299
- stderr: true,
300
- follow: true
301
- });
302
- stream.on("data", (data) => {
303
- process.stdout.write((0, utils_1.demuxOutput)(data));
304
- });
305
- }
306
268
  async attachStream(stream) {
307
- process.stdin.resume();
308
- process.stdin.setEncoding("utf8");
309
- process.stdin.pipe(stream);
310
269
  if (process.stdin.isTTY) {
311
270
  process.stdin.setRawMode(true);
312
271
  }
272
+ process.stdin.resume();
273
+ process.stdin.setEncoding("utf8");
274
+ process.stdin.pipe(stream);
313
275
  stream.setEncoding("utf8");
314
276
  stream.pipe(process.stdout);
315
- const end = () => {
277
+ const onEnd = () => {
316
278
  process.stdin.pause();
317
- process.stdin.unpipe(stream);
318
279
  if (process.stdin.isTTY) {
319
280
  process.stdin.setRawMode(false);
320
281
  }
282
+ process.stdin.unpipe(stream);
321
283
  stream.unpipe(process.stdout);
322
284
  };
323
- await new Promise((resolve, reject) => {
324
- stream.on("end", end);
325
- stream.on("error", end);
326
- stream.on("end", resolve);
327
- stream.on("error", reject);
328
- });
285
+ stream.on("end", onEnd);
286
+ stream.on("error", onEnd);
287
+ return stream;
329
288
  }
330
289
  async exec(name, args, tty = false) {
331
290
  const container = await this.getContainer(name);
@@ -365,6 +324,27 @@ let DockerService = class DockerService {
365
324
  }
366
325
  return stream;
367
326
  }
327
+ async logs(containerOrName) {
328
+ const container = typeof containerOrName === "string"
329
+ ? await this.getContainer(containerOrName)
330
+ : containerOrName;
331
+ if (!container) {
332
+ return;
333
+ }
334
+ const stream = await container.logs({
335
+ stdout: true,
336
+ stderr: true,
337
+ follow: true,
338
+ tail: 4
339
+ });
340
+ stream.on("data", (data) => {
341
+ process.stdout.write(data);
342
+ });
343
+ stream.on("error", (data) => {
344
+ process.stderr.write(data);
345
+ });
346
+ return stream;
347
+ }
368
348
  };
369
349
  exports.DockerService = DockerService;
370
350
  exports.DockerService = DockerService = __decorate([
@@ -10,13 +10,13 @@ declare class ProjectService {
10
10
  protected readonly dockerService: DockerService;
11
11
  constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, dockerService: DockerService);
12
12
  fromObject(data: Partial<ProjectProperties>): Project;
13
- get(): Promise<Project>;
14
- getById(id: string): Promise<Project>;
15
- cdProject(name: string): Promise<void>;
13
+ get(name?: string): Project;
14
+ getById(id: string): Project;
15
+ cdProject(name: string): void;
16
16
  start(project: Project, restart?: boolean, rebuild?: boolean): Promise<void>;
17
17
  stop(project: Project): Promise<void>;
18
18
  save(project: Project): Promise<void>;
19
- search(params?: Partial<SearchParams>): Promise<Project[]>;
20
- searchOne(params?: Partial<SearchParams>): Promise<Project | null>;
19
+ search(params?: Partial<SearchParams>): Project[];
20
+ searchOne(params?: Partial<SearchParams>): Project | null;
21
21
  }
22
22
  export { ProjectService };
@@ -11,7 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ProjectService = void 0;
13
13
  const core_1 = require("@wocker/core");
14
- const makes_1 = require("../makes");
15
14
  const services_1 = require("../services");
16
15
  let ProjectService = class ProjectService {
17
16
  constructor(appConfigService, appEventsService, dockerService) {
@@ -30,26 +29,31 @@ let ProjectService = class ProjectService {
30
29
  }
31
30
  }(data);
32
31
  }
33
- async get() {
34
- const project = await this.searchOne({
35
- path: this.appConfigService.pwd()
36
- });
32
+ get(name) {
33
+ const project = name
34
+ ? this.searchOne({ name })
35
+ : this.searchOne({
36
+ path: this.appConfigService.pwd()
37
+ });
37
38
  if (!project) {
38
39
  throw new Error("Project not found");
39
40
  }
41
+ if (name) {
42
+ this.appConfigService.setPWD(project.path);
43
+ }
40
44
  return project;
41
45
  }
42
- async getById(id) {
46
+ getById(id) {
43
47
  const config = this.appConfigService.getConfig();
44
48
  const projectData = config.getProject(id);
45
- const data = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", id, "config.json"));
49
+ const data = this.appConfigService.fs.readJSON("projects", id, "config.json");
46
50
  return this.fromObject({
47
51
  ...data,
48
52
  path: projectData.path || projectData.src
49
53
  });
50
54
  }
51
- async cdProject(name) {
52
- const project = await this.searchOne({
55
+ cdProject(name) {
56
+ const project = this.searchOne({
53
57
  name
54
58
  });
55
59
  if (!project) {
@@ -132,17 +136,16 @@ let ProjectService = class ProjectService {
132
136
  if (!project.id) {
133
137
  project.id = project.name;
134
138
  }
135
- const config = await this.appConfigService.getConfig();
136
- const fs = new core_1.FileSystem(this.appConfigService.dataPath("projects", project.id));
137
- if (!fs.exists()) {
138
- fs.mkdir("", { recursive: true });
139
+ const config = this.appConfigService.getConfig();
140
+ if (!this.appConfigService.fs.exists(`projects/${project.id}`)) {
141
+ this.appConfigService.fs.mkdir(`projects/${project.id}`, { recursive: true });
139
142
  }
140
143
  const { path, ...rest } = project.toJSON();
141
144
  config.addProject(project.id, project.name, path);
142
- await fs.writeJSON("config.json", rest);
145
+ this.appConfigService.fs.writeJSON(`projects/${project.id}/config.json`, rest);
143
146
  await config.save();
144
147
  }
145
- async search(params = {}) {
148
+ search(params = {}) {
146
149
  const { name, path } = params;
147
150
  const config = this.appConfigService.getConfig();
148
151
  const projects = [];
@@ -153,7 +156,7 @@ let ProjectService = class ProjectService {
153
156
  if (path && (projectConfig.path || projectConfig.src) !== path) {
154
157
  continue;
155
158
  }
156
- const project = await this.getById(projectConfig.id);
159
+ const project = this.getById(projectConfig.id);
157
160
  if (name && project.name !== name) {
158
161
  continue;
159
162
  }
@@ -161,8 +164,8 @@ let ProjectService = class ProjectService {
161
164
  }
162
165
  return projects;
163
166
  }
164
- async searchOne(params = {}) {
165
- const [project] = await this.search(params);
167
+ searchOne(params = {}) {
168
+ const [project] = this.search(params);
166
169
  return project || null;
167
170
  }
168
171
  };
@@ -20,7 +20,7 @@ let ProxyService = class ProxyService {
20
20
  this.appConfigService = appConfigService;
21
21
  this.dockerService = dockerService;
22
22
  this.containerName = "proxy.workspace";
23
- this.imageName = "nginxproxy/nginx-proxy";
23
+ this.imageName = "nginxproxy/nginx-proxy:latest";
24
24
  }
25
25
  async init(project) {
26
26
  const appPort = await (0, utils_1.promptText)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/ws",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Docker workspace for web projects",
6
6
  "license": "MIT",
@@ -21,11 +21,10 @@
21
21
  "prepare": "npm run build",
22
22
  "start": "npm run watch",
23
23
  "build": "tsc",
24
- "watch": "tsc -w",
25
- "lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
24
+ "watch": "tsc -w"
26
25
  },
27
26
  "dependencies": {
28
- "@wocker/core": "1.0.18",
27
+ "@wocker/core": "1.0.19",
29
28
  "@wocker/utils": "^1.0.7",
30
29
  "async-mutex": "^0.4.0",
31
30
  "axios": "^1.6.7",
@@ -50,12 +49,6 @@
50
49
  "@types/node": "^20.11.16",
51
50
  "@types/readable-stream": "^2.3.15",
52
51
  "@types/unzipper": "^0.10.10",
53
- "@typescript-eslint/eslint-plugin": "^6.5.0",
54
- "@typescript-eslint/parser": "^6.5.0",
55
- "eslint": "^8.48.0",
56
- "eslint-plugin-import": "^2.28.1",
57
- "eslint-plugin-node": "^11.1.0",
58
- "eslint-webpack-plugin": "^3.1.0",
59
- "typescript": "^5.5.4"
52
+ "typescript": "^5.6.3"
60
53
  }
61
54
  }