@wocker/ws 1.0.7 → 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 (118) hide show
  1. package/bin/ws.js +2 -13
  2. package/lib/AppModule.d.ts +6 -0
  3. package/lib/AppModule.js +100 -0
  4. package/lib/controllers/CompletionController.d.ts +6 -0
  5. package/lib/controllers/CompletionController.js +32 -0
  6. package/lib/controllers/DebugController.d.ts +7 -0
  7. package/lib/controllers/DebugController.js +44 -0
  8. package/lib/controllers/ImageController.d.ts +5 -8
  9. package/lib/controllers/ImageController.js +27 -12
  10. package/lib/controllers/PluginController.d.ts +11 -13
  11. package/lib/controllers/PluginController.js +93 -54
  12. package/lib/controllers/PresetController.d.ts +10 -15
  13. package/lib/controllers/PresetController.js +111 -27
  14. package/lib/controllers/ProjectController.d.ts +27 -70
  15. package/lib/controllers/ProjectController.js +357 -306
  16. package/lib/controllers/ProxyController.d.ts +15 -25
  17. package/lib/controllers/ProxyController.js +157 -102
  18. package/lib/controllers/index.d.ts +2 -0
  19. package/lib/controllers/index.js +2 -0
  20. package/lib/main.d.ts +3 -0
  21. package/lib/main.js +30 -0
  22. package/lib/makes/FS.d.ts +15 -5
  23. package/lib/makes/FS.js +42 -9
  24. package/lib/makes/Http.d.ts +18 -0
  25. package/lib/makes/{Plugin.js → Http.js} +45 -34
  26. package/lib/makes/Logger.d.ts +2 -2
  27. package/lib/makes/Logger.js +19 -8
  28. package/lib/makes/Preset.d.ts +5 -6
  29. package/lib/makes/Preset.js +19 -8
  30. package/lib/makes/index.d.ts +1 -6
  31. package/lib/makes/index.js +1 -6
  32. package/lib/plugins/ElasticSearchPlugin.d.ts +5 -6
  33. package/lib/plugins/ElasticSearchPlugin.js +19 -8
  34. package/lib/plugins/LocaltunnelPlugin.d.ts +8 -8
  35. package/lib/plugins/LocaltunnelPlugin.js +25 -10
  36. package/lib/plugins/MaildevPlugin.d.ts +5 -6
  37. package/lib/plugins/MaildevPlugin.js +21 -8
  38. package/lib/plugins/MongodbPlugin.d.ts +5 -5
  39. package/lib/plugins/MongodbPlugin.js +26 -11
  40. package/lib/plugins/NgrokPlugin.d.ts +7 -6
  41. package/lib/plugins/NgrokPlugin.js +32 -17
  42. package/lib/plugins/PageKitePlugin.d.ts +10 -8
  43. package/lib/plugins/PageKitePlugin.js +36 -20
  44. package/lib/plugins/ProxmoxPlugin.d.ts +8 -5
  45. package/lib/plugins/ProxmoxPlugin.js +25 -9
  46. package/lib/plugins/RedisPlugin.d.ts +4 -6
  47. package/lib/plugins/RedisPlugin.js +19 -8
  48. package/lib/plugins/index.d.ts +0 -2
  49. package/lib/plugins/index.js +0 -2
  50. package/lib/services/AppConfigService.d.ts +7 -17
  51. package/lib/services/AppConfigService.js +44 -114
  52. package/lib/services/AppEventsService.d.ts +1 -2
  53. package/lib/services/AppEventsService.js +11 -2
  54. package/lib/services/DockerService.d.ts +9 -39
  55. package/lib/services/DockerService.js +122 -4
  56. package/lib/services/LogService.d.ts +3 -5
  57. package/lib/services/LogService.js +19 -4
  58. package/lib/services/PluginService.d.ts +11 -9
  59. package/lib/services/PluginService.js +100 -8
  60. package/lib/services/PresetService.d.ts +4 -5
  61. package/lib/services/PresetService.js +26 -5
  62. package/lib/services/ProjectService.d.ts +9 -6
  63. package/lib/services/ProjectService.js +72 -37
  64. package/lib/utils/exec.d.ts +4 -1
  65. package/lib/utils/exec.js +16 -31
  66. package/lib/utils/followProgress.js +49 -45
  67. package/lib/utils/index.d.ts +0 -7
  68. package/lib/utils/index.js +0 -7
  69. package/lib/utils/spawn.d.ts +1 -1
  70. package/lib/utils/spawn.js +20 -12
  71. package/package.json +5 -7
  72. package/presets/node/config.json +1 -1
  73. package/presets/php-apache/Dockerfile +1 -1
  74. package/presets/php-apache/config.json +2 -1
  75. package/presets/php-fpm/Dockerfile +1 -1
  76. package/lib/App.d.ts +0 -16
  77. package/lib/App.js +0 -107
  78. package/lib/decorators/Inject.d.ts +0 -1
  79. package/lib/decorators/Inject.js +0 -8
  80. package/lib/decorators/Injectable.d.ts +0 -4
  81. package/lib/decorators/Injectable.js +0 -17
  82. package/lib/decorators/index.d.ts +0 -1
  83. package/lib/decorators/index.js +0 -17
  84. package/lib/index.d.ts +0 -6
  85. package/lib/index.js +0 -33
  86. package/lib/makes/Controller.d.ts +0 -5
  87. package/lib/makes/Controller.js +0 -8
  88. package/lib/makes/DI.d.ts +0 -7
  89. package/lib/makes/DI.js +0 -27
  90. package/lib/makes/Docker.d.ts +0 -58
  91. package/lib/makes/Docker.js +0 -320
  92. package/lib/makes/Plugin.d.ts +0 -13
  93. package/lib/makes/Project.d.ts +0 -45
  94. package/lib/makes/Project.js +0 -127
  95. package/lib/makes/Repository.d.ts +0 -11
  96. package/lib/makes/Repository.js +0 -22
  97. package/lib/plugins/PostgresPlugin.d.ts +0 -16
  98. package/lib/plugins/PostgresPlugin.js +0 -121
  99. package/lib/types/Config.d.ts +0 -12
  100. package/lib/types/Config.js +0 -2
  101. package/lib/types/EnvConfig.d.ts +0 -3
  102. package/lib/types/EnvConfig.js +0 -2
  103. package/lib/types/index.d.ts +0 -2
  104. package/lib/types/index.js +0 -18
  105. package/lib/utils/buildOptions.d.ts +0 -1
  106. package/lib/utils/buildOptions.js +0 -9
  107. package/lib/utils/demuxOutput.d.ts +0 -2
  108. package/lib/utils/demuxOutput.js +0 -19
  109. package/lib/utils/fetch.d.ts +0 -5
  110. package/lib/utils/fetch.js +0 -52
  111. package/lib/utils/get-config.d.ts +0 -2
  112. package/lib/utils/get-config.js +0 -17
  113. package/lib/utils/image-build.d.ts +0 -13
  114. package/lib/utils/image-build.js +0 -46
  115. package/lib/utils/set-config.d.ts +0 -2
  116. package/lib/utils/set-config.js +0 -15
  117. package/lib/utils/tty.d.ts +0 -2
  118. package/lib/utils/tty.js +0 -6
@@ -1,14 +1,13 @@
1
- import { EnvConfig } from "../types";
2
- import { DI, Preset } from "../makes";
1
+ import { EnvConfig, Preset } from "@wocker/core";
3
2
  type SearchOptions = Partial<{
4
3
  name: string;
5
4
  }>;
6
- declare class PresetService {
7
- constructor(di: DI);
5
+ export declare class PresetService {
6
+ constructor();
8
7
  getImageName(preset: Preset, buildArgs?: EnvConfig): string;
9
8
  save(preset: Preset): Promise<void>;
10
9
  get(name: string): Promise<Preset>;
11
10
  search(options?: SearchOptions): Promise<Preset[]>;
12
11
  searchOne(options?: SearchOptions): Promise<Preset | null>;
13
12
  }
14
- export { PresetService, SearchOptions as PresetServiceSearchOptions };
13
+ export { SearchOptions as PresetServiceSearchOptions };
@@ -1,14 +1,24 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.PresetService = void 0;
16
+ const core_1 = require("@wocker/core");
7
17
  const md5_1 = __importDefault(require("md5"));
8
18
  const env_1 = require("../env");
9
19
  const makes_1 = require("../makes");
10
- class PresetService {
11
- constructor(di) { }
20
+ let PresetService = class PresetService {
21
+ constructor() { }
12
22
  getImageName(preset, buildArgs = {}) {
13
23
  const rawValues = [];
14
24
  const hashValues = [];
@@ -34,7 +44,14 @@ class PresetService {
34
44
  }
35
45
  async get(name) {
36
46
  const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
37
- return new makes_1.Preset({
47
+ return new class extends core_1.Preset {
48
+ constructor(presetService, data) {
49
+ super(data);
50
+ this.presetService = presetService;
51
+ }
52
+ async save() {
53
+ }
54
+ }(this, {
38
55
  name,
39
56
  ...config
40
57
  });
@@ -48,7 +65,7 @@ class PresetService {
48
65
  continue;
49
66
  }
50
67
  const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, dir, "config.json");
51
- const preset = new makes_1.Preset({
68
+ const preset = new core_1.Preset({
52
69
  name: dir,
53
70
  ...config
54
71
  });
@@ -60,5 +77,9 @@ class PresetService {
60
77
  const [preset] = await this.search(options);
61
78
  return preset || null;
62
79
  }
63
- }
80
+ };
64
81
  exports.PresetService = PresetService;
82
+ exports.PresetService = PresetService = __decorate([
83
+ (0, core_1.Injectable)(),
84
+ __metadata("design:paramtypes", [])
85
+ ], PresetService);
@@ -1,4 +1,4 @@
1
- import { DI, Project } from "../makes";
1
+ import { Project, PickProperties } from "@wocker/core";
2
2
  import { DockerService, AppConfigService, AppEventsService } from "../services";
3
3
  type SearchParams = Partial<{
4
4
  id: string;
@@ -6,16 +6,19 @@ type SearchParams = Partial<{
6
6
  path: string;
7
7
  }>;
8
8
  declare class ProjectService {
9
- protected appConfigService: AppConfigService;
10
- protected appEventsService: AppEventsService;
11
- protected dockerService: DockerService;
12
- constructor(di: DI);
9
+ protected readonly appConfigService: AppConfigService;
10
+ protected readonly appEventsService: AppEventsService;
11
+ protected readonly dockerService: DockerService;
12
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, dockerService: DockerService);
13
+ fromObject(data: Partial<PickProperties<Project>>): Project;
14
+ getById(id: string): Promise<Project>;
13
15
  cdProject(name: string): Promise<void>;
14
16
  get(): Promise<Project>;
15
17
  getContainer(): Promise<import("dockerode").Container>;
16
- start(): Promise<void>;
18
+ start(restart?: boolean): Promise<void>;
17
19
  stop(): Promise<void>;
18
20
  save(project: Project): Promise<void>;
19
21
  search(params?: Partial<SearchParams>): Promise<Project[]>;
22
+ searchOne(params?: Partial<SearchParams>): Promise<Project | null>;
20
23
  }
21
24
  export { ProjectService };
@@ -15,6 +15,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
18
24
  var __importStar = (this && this.__importStar) || function (mod) {
19
25
  if (mod && mod.__esModule) return mod;
20
26
  var result = {};
@@ -22,19 +28,38 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
28
  __setModuleDefault(result, mod);
23
29
  return result;
24
30
  };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  exports.ProjectService = void 0;
36
+ const core_1 = require("@wocker/core");
27
37
  const Path = __importStar(require("path"));
28
38
  const makes_1 = require("../makes");
29
39
  const services_1 = require("../services");
30
- class ProjectService {
31
- constructor(di) {
32
- this.appConfigService = di.resolveService(services_1.AppConfigService);
33
- this.appEventsService = di.resolveService(services_1.AppEventsService);
34
- this.dockerService = di.resolveService(services_1.DockerService);
40
+ let ProjectService = class ProjectService {
41
+ constructor(appConfigService, appEventsService, dockerService) {
42
+ this.appConfigService = appConfigService;
43
+ this.appEventsService = appEventsService;
44
+ this.dockerService = dockerService;
45
+ }
46
+ fromObject(data) {
47
+ const projectService = this;
48
+ return new class extends core_1.Project {
49
+ constructor(data) {
50
+ super(data);
51
+ }
52
+ async save() {
53
+ await projectService.save(this);
54
+ }
55
+ }(data);
56
+ }
57
+ async getById(id) {
58
+ const data = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", id, "config.json"));
59
+ return this.fromObject(data);
35
60
  }
36
61
  async cdProject(name) {
37
- const project = await makes_1.Project.searchOne({
62
+ const project = await this.searchOne({
38
63
  name
39
64
  });
40
65
  if (!project) {
@@ -43,7 +68,7 @@ class ProjectService {
43
68
  this.appConfigService.setPWD(project.path);
44
69
  }
45
70
  async get() {
46
- const project = await makes_1.Project.searchOne({
71
+ const project = await this.searchOne({
47
72
  path: this.appConfigService.getPWD()
48
73
  });
49
74
  if (!project) {
@@ -55,16 +80,17 @@ class ProjectService {
55
80
  const project = await this.get();
56
81
  return this.dockerService.getContainer(project.containerName);
57
82
  }
58
- async start() {
83
+ async start(restart) {
59
84
  const project = await this.get();
60
85
  if (project.type === "dockerfile") {
61
86
  project.imageName = `project-${project.name}:develop`;
62
- const images = await makes_1.Docker.imageLs({
87
+ const images = await this.dockerService.imageLs({
63
88
  tag: project.imageName
64
89
  });
65
90
  if (images.length === 0) {
66
- await makes_1.Docker.imageBuild2({
91
+ await this.dockerService.buildImage({
67
92
  tag: project.imageName,
93
+ buildArgs: project.buildArgs,
68
94
  context: this.appConfigService.getPWD(),
69
95
  src: project.dockerfile
70
96
  });
@@ -72,12 +98,17 @@ class ProjectService {
72
98
  }
73
99
  await this.appEventsService.emit("project:beforeStart", project);
74
100
  let container = await this.dockerService.getContainer(project.containerName);
101
+ if (container && restart) {
102
+ container = null;
103
+ await this.dockerService.removeContainer(project.containerName);
104
+ }
75
105
  if (!container) {
76
- container = await makes_1.Docker.createContainer({
106
+ const config = await this.appConfigService.getConfig();
107
+ container = await this.dockerService.createContainer({
77
108
  name: project.containerName,
78
109
  image: project.imageName,
79
110
  env: {
80
- ...await this.appConfigService.getAllEnvVariables(),
111
+ ...config.env || {},
81
112
  ...project.env || {}
82
113
  },
83
114
  volumes: (project.volumes || []).map((volume) => {
@@ -88,24 +119,20 @@ class ProjectService {
88
119
  ports: project.ports || []
89
120
  });
90
121
  }
91
- else {
92
- process.stdout.write("Container already exists\n");
93
- }
94
- if (container) {
95
- const { State: { Status } } = await container.inspect();
96
- if (Status === "created" || Status === "exited") {
97
- await container.start();
98
- await this.appEventsService.emit("project:start", project);
99
- }
122
+ const { State: { Status } } = await container.inspect();
123
+ if (Status === "created" || Status === "exited") {
124
+ await container.start();
125
+ await this.appEventsService.emit("project:start", project);
100
126
  }
101
127
  }
102
128
  async stop() {
103
129
  const project = await this.get();
104
- const container = await makes_1.Docker.getContainer(project.containerName);
105
- if (container) {
106
- await this.appEventsService.emit("project:stop", project);
107
- await makes_1.Docker.removeContainer(`${project.name}.workspace`);
130
+ const container = await this.dockerService.getContainer(project.containerName);
131
+ if (!container) {
132
+ return;
108
133
  }
134
+ await this.appEventsService.emit("project:stop", project);
135
+ await this.dockerService.removeContainer(project.containerName);
109
136
  }
110
137
  async save(project) {
111
138
  if (!project.name) {
@@ -118,37 +145,45 @@ class ProjectService {
118
145
  project.id = project.name;
119
146
  }
120
147
  const projectDirPath = this.appConfigService.dataPath("projects", project.id);
148
+ const config = await this.appConfigService.getConfig();
121
149
  const configPath = this.appConfigService.dataPath("projects", project.id, "config.json");
122
150
  if (!makes_1.FS.existsSync(projectDirPath)) {
123
151
  await makes_1.FS.mkdir(projectDirPath, {
124
152
  recursive: true
125
153
  });
126
154
  }
127
- await this.appConfigService.setProjectConfig(project.id, project.path);
155
+ config.setProject(project.id, project.path);
128
156
  await makes_1.FS.writeJSON(configPath, project);
157
+ await config.save();
129
158
  }
130
159
  async search(params = {}) {
131
160
  const { id, name, path } = params;
132
- const { projects: configs } = await this.appConfigService.getAppConfig();
161
+ const config = await this.appConfigService.getConfig();
133
162
  const projects = [];
134
- for (const config of configs) {
135
- if (id && config.id !== id) {
163
+ for (const projectConfig of config.projects) {
164
+ if (id && projectConfig.id !== id) {
136
165
  continue;
137
166
  }
138
- if (path && config.src !== path) {
167
+ if (path && projectConfig.src !== path) {
139
168
  continue;
140
169
  }
141
- const projectData = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", config.id, "config.json"));
142
- if (name && projectData.name !== name) {
170
+ const project = await this.getById(projectConfig.id);
171
+ if (name && project.name !== name) {
143
172
  continue;
144
173
  }
145
- const project = makes_1.Project.fromObject({
146
- id: config.id,
147
- ...projectData
148
- });
149
174
  projects.push(project);
150
175
  }
151
176
  return projects;
152
177
  }
153
- }
178
+ async searchOne(params = {}) {
179
+ const [project] = await this.search(params);
180
+ return project || null;
181
+ }
182
+ };
154
183
  exports.ProjectService = ProjectService;
184
+ exports.ProjectService = ProjectService = __decorate([
185
+ (0, core_1.Injectable)("PROJECT_SERVICE"),
186
+ __metadata("design:paramtypes", [services_1.AppConfigService,
187
+ services_1.AppEventsService,
188
+ services_1.DockerService])
189
+ ], ProjectService);
@@ -1,2 +1,5 @@
1
- declare const exec: (command: string) => Promise<unknown>;
1
+ /// <reference types="node" />
2
+ import { ExecOptions } from "child_process";
3
+ type Options = Omit<ExecOptions, "maxBuffer">;
4
+ declare const exec: (command: string, options?: Options) => Promise<string>;
2
5
  export { exec };
package/lib/utils/exec.js CHANGED
@@ -1,41 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.exec = void 0;
7
4
  const child_process_1 = require("child_process");
8
- const chalk_1 = __importDefault(require("chalk"));
9
- const makes_1 = require("../makes");
10
- const exec = async (command) => {
11
- makes_1.Logger.info(` > ${command.trim().replace(/\s+/g, " ")}`);
5
+ const exec = async (command, options) => {
6
+ const worker = (0, child_process_1.exec)(command, {
7
+ ...options || {},
8
+ maxBuffer: Infinity
9
+ });
12
10
  return new Promise((resolve, reject) => {
13
- const worker = (0, child_process_1.exec)(command, {
14
- maxBuffer: Infinity
15
- }, (err, stdout, stderr) => {
16
- if (err) {
17
- return reject(err);
18
- }
19
- return resolve({
20
- stdout,
21
- stderr
22
- });
23
- });
24
- if (worker.stdout) {
25
- worker.stdout.on("data", (data) => {
26
- process.stdout.write(data);
27
- });
28
- }
29
- if (worker.stderr) {
30
- worker.stderr.on("data", (data) => {
31
- process.stderr.write(data);
32
- });
33
- }
34
- worker.on("close", (code) => {
35
- makes_1.Logger.info("close", chalk_1.default.red(code));
11
+ let data = "";
12
+ worker.stdout.on("data", (chunk) => {
13
+ data += chunk.toString();
36
14
  });
37
15
  worker.on("exit", (code) => {
38
- makes_1.Logger.info("exit", chalk_1.default.red(code));
16
+ if (code !== 0) {
17
+ reject(new Error(`Process exited with code ${code}`));
18
+ return;
19
+ }
20
+ resolve(data.replace(/\n$/, ""));
21
+ });
22
+ worker.on("error", (err) => {
23
+ reject(err);
39
24
  });
40
25
  });
41
26
  };
@@ -8,51 +8,6 @@ const followProgress = async (stream) => {
8
8
  const lineStream = new LineConvertStream_1.LineConvertStream(stream);
9
9
  let line = 0;
10
10
  const mapLines = {};
11
- lineStream.on("data", (chunk) => {
12
- const data = JSON.parse(chunk.toString());
13
- const { stream, id, status, progressDetail: { current, total } = {}, aux } = data;
14
- if (stream) {
15
- process.stdout.write(`${stream}`);
16
- line += stream.split("\n").length - 1;
17
- }
18
- else if (id) {
19
- if (typeof mapLines[id] === "undefined") {
20
- mapLines[id] = line;
21
- }
22
- const targetLine = typeof mapLines[id] !== "undefined" ? mapLines[id] : line;
23
- const dy = line - targetLine;
24
- if (dy > 0) {
25
- process.stdout.write("\x1b[s");
26
- process.stdout.write(`\x1b[${dy}A`);
27
- }
28
- process.stdout.write("\x1b[2K");
29
- let str = `${id}: ${status}\n`;
30
- if (status === "Downloading") {
31
- const width = process.stdout.columns;
32
- const sizeWidth = 19, totalWidth = width - id.length - status.length - sizeWidth - 7, currentWidth = Math.floor(totalWidth * (current / total)), formatSize = `${(0, format_size_units_1.formatSizeUnits)(current)}/${(0, format_size_units_1.formatSizeUnits)(total)}`;
33
- str = `${id}: ${status} [${"█".repeat(currentWidth)}${"░".repeat(totalWidth - currentWidth)}] ${formatSize}\n`;
34
- }
35
- process.stdout.write(str);
36
- if (dy > 0) {
37
- process.stdout.write("\x1b[u");
38
- }
39
- else {
40
- line++;
41
- }
42
- }
43
- else if (status) {
44
- process.stdout.write(`${status}\n`);
45
- line += Math.ceil(status.length / process.stdout.columns);
46
- }
47
- else if (aux) {
48
- const str = `auxID: ${aux.ID}`;
49
- process.stdout.write(`${str}\n`);
50
- line += Math.ceil(str.length / process.stdout.columns);
51
- }
52
- else {
53
- makes_1.Logger.warn("followProgress: unexpected data", data);
54
- }
55
- });
56
11
  return new Promise((resolve, reject) => {
57
12
  let isEnded = false;
58
13
  const handleEnd = () => {
@@ -61,6 +16,55 @@ const followProgress = async (stream) => {
61
16
  }
62
17
  isEnded = true;
63
18
  };
19
+ lineStream.on("data", (chunk) => {
20
+ const data = JSON.parse(chunk.toString());
21
+ const { stream, id, status, progressDetail: { current, total } = {}, aux, error, errorDetail } = data;
22
+ if (stream) {
23
+ process.stdout.write(`${stream}`);
24
+ line += stream.split("\n").length - 1;
25
+ }
26
+ else if (id) {
27
+ if (typeof mapLines[id] === "undefined") {
28
+ mapLines[id] = line;
29
+ }
30
+ const targetLine = typeof mapLines[id] !== "undefined" ? mapLines[id] : line;
31
+ const dy = line - targetLine;
32
+ if (dy > 0) {
33
+ process.stdout.write("\x1b[s");
34
+ process.stdout.write(`\x1b[${dy}A`);
35
+ }
36
+ process.stdout.write("\x1b[2K");
37
+ let str = `${id}: ${status}\n`;
38
+ if (status === "Downloading") {
39
+ const width = process.stdout.columns;
40
+ const sizeWidth = 19, totalWidth = width - id.length - status.length - sizeWidth - 7, currentWidth = Math.floor(totalWidth * (current / total)), formatSize = `${(0, format_size_units_1.formatSizeUnits)(current)}/${(0, format_size_units_1.formatSizeUnits)(total)}`;
41
+ str = `${id}: ${status} [${"█".repeat(currentWidth)}${"░".repeat(totalWidth - currentWidth)}] ${formatSize}\n`;
42
+ }
43
+ process.stdout.write(str);
44
+ if (dy > 0) {
45
+ process.stdout.write("\x1b[u");
46
+ }
47
+ else {
48
+ line++;
49
+ }
50
+ }
51
+ else if (status) {
52
+ process.stdout.write(`${status}\n`);
53
+ line += Math.ceil(status.length / process.stdout.columns);
54
+ }
55
+ else if (aux) {
56
+ const str = `auxID: ${aux.ID}`;
57
+ process.stdout.write(`${str}\n`);
58
+ line += Math.ceil(str.length / process.stdout.columns);
59
+ }
60
+ else if (error) {
61
+ reject(new Error(error));
62
+ }
63
+ else {
64
+ makes_1.Logger.warn("followProgress: unexpected data", data);
65
+ reject(new Error(`(followProgress) unexpected data: ${JSON.stringify(data)}`));
66
+ }
67
+ });
64
68
  lineStream.on("end", handleEnd);
65
69
  lineStream.on("close", handleEnd);
66
70
  lineStream.on("error", reject);
@@ -1,17 +1,10 @@
1
- export * from "./buildOptions";
2
- export * from "./demuxOutput";
3
1
  export * from "./escapeRegExp";
4
2
  export * from "./exec";
5
- export * from "./fetch";
6
3
  export * from "./followProgress";
7
4
  export * from "./format-size-units";
8
- export * from "./get-config";
9
5
  export * from "./get-cursor-position";
10
- export * from "./image-build";
11
6
  export * from "./injectVariables";
12
7
  export * from "./parse-table";
13
- export * from "./set-config";
14
8
  export * from "./spawn";
15
- export * from "./tty";
16
9
  export * from "./volumeFormat";
17
10
  export * from "./volumeParse";
@@ -14,20 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./buildOptions"), exports);
18
- __exportStar(require("./demuxOutput"), exports);
19
17
  __exportStar(require("./escapeRegExp"), exports);
20
18
  __exportStar(require("./exec"), exports);
21
- __exportStar(require("./fetch"), exports);
22
19
  __exportStar(require("./followProgress"), exports);
23
20
  __exportStar(require("./format-size-units"), exports);
24
- __exportStar(require("./get-config"), exports);
25
21
  __exportStar(require("./get-cursor-position"), exports);
26
- __exportStar(require("./image-build"), exports);
27
22
  __exportStar(require("./injectVariables"), exports);
28
23
  __exportStar(require("./parse-table"), exports);
29
- __exportStar(require("./set-config"), exports);
30
24
  __exportStar(require("./spawn"), exports);
31
- __exportStar(require("./tty"), exports);
32
25
  __exportStar(require("./volumeFormat"), exports);
33
26
  __exportStar(require("./volumeParse"), exports);
@@ -1,2 +1,2 @@
1
- declare const spawn: (command: any) => Promise<void>;
1
+ declare const spawn: (command: string, args: string[]) => Promise<void>;
2
2
  export { spawn };
@@ -2,20 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.spawn = void 0;
4
4
  const child_process_1 = require("child_process");
5
- const spawn = async (command) => {
6
- return new Promise((resolve) => {
7
- let [prog, ...options] = command.split(/\s+/);
8
- let worker = (0, child_process_1.spawn)(prog, options);
9
- worker.stdout.on("data", (data) => {
10
- console.log(`stdout: ${data}`);
11
- });
12
- worker.stderr.on("data", (data) => {
13
- console.error(`stderr: ${data}`);
14
- });
15
- worker.on("close", (code) => {
16
- console.log(`child process exited with code ${code}`);
5
+ const spawn = async (command, args) => {
6
+ const abortController = new AbortController();
7
+ const child = (0, child_process_1.spawn)(command, args, {
8
+ signal: abortController.signal,
9
+ stdio: "inherit"
10
+ });
11
+ await new Promise((resolve, reject) => {
12
+ let withError = false;
13
+ child.on("close", (code) => {
14
+ if (withError) {
15
+ return;
16
+ }
17
+ if (code !== 0) {
18
+ reject(new Error(`Process exited with code ${code}`));
19
+ return;
20
+ }
17
21
  resolve(undefined);
18
22
  });
23
+ child.on("error", (err) => {
24
+ withError = true;
25
+ reject(err);
26
+ });
19
27
  });
20
28
  };
21
29
  exports.spawn = spawn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/ws",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Docker workspace for web projects",
6
6
  "license": "MIT",
@@ -25,9 +25,9 @@
25
25
  "lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
26
26
  },
27
27
  "dependencies": {
28
- "@kearisp/cli": "^1.0.6",
29
- "@wocker/core": "^1.0.4",
30
- "@wocker/utils": "^1.0.2",
28
+ "@kearisp/cli": "^1.0.7",
29
+ "@wocker/core": "^1.0.9",
30
+ "@wocker/utils": "^1.0.3",
31
31
  "async-mutex": "^0.4.0",
32
32
  "axios": "^1.6.7",
33
33
  "chalk": "^2.4.2",
@@ -36,7 +36,6 @@
36
36
  "date-fns": "^2.29.3",
37
37
  "dockerode": "^4.0.2",
38
38
  "fs": "^0.0.1-security",
39
- "inquirer": "^7.0.0",
40
39
  "md5": "^2.3.0",
41
40
  "os": "^0.1.2",
42
41
  "path": "^0.12.7",
@@ -45,7 +44,6 @@
45
44
  },
46
45
  "devDependencies": {
47
46
  "@types/dockerode": "3.3.23",
48
- "@types/inquirer": "^7.0.0",
49
47
  "@types/jest": "^29.5.12",
50
48
  "@types/lodash": "^4.14.161",
51
49
  "@types/md5": "^2.3.2",
@@ -58,6 +56,6 @@
58
56
  "eslint-plugin-import": "^2.28.1",
59
57
  "eslint-plugin-node": "^11.1.0",
60
58
  "eslint-webpack-plugin": "^3.1.0",
61
- "typescript": "^5.4.2"
59
+ "typescript": "^5.4.4"
62
60
  }
63
61
  }
@@ -33,7 +33,7 @@
33
33
  ]
34
34
  }
35
35
  },
36
- "volumes": [
36
+ "volumeOptions": [
37
37
  "./:/usr/app"
38
38
  ]
39
39
  }
@@ -131,7 +131,7 @@ ARG XDEBUG_ENABLE=false
131
131
  RUN if [ "$XDEBUG_ENABLE" = "true" ]; then \
132
132
  pecl install xdebug && \
133
133
  docker-php-ext-enable xdebug; \
134
- fi \
134
+ fi
135
135
 
136
136
  # Gettext
137
137
  ARG GETTEXT_ENABLE=false
@@ -37,7 +37,8 @@
37
37
  },
38
38
  "COMPOSER_ENABLE": {
39
39
  "message": "Install composer?",
40
- "type": "boolean"
40
+ "type": "boolean",
41
+ "default": false
41
42
  },
42
43
  "NODE_VERSION": {
43
44
  "type": "select",
@@ -164,7 +164,7 @@ ARG NGINX_DOCUMENT_ROOT=/var/www
164
164
  WORKDIR $WORKDIR
165
165
 
166
166
  ADD etc/nginx/sites-available/default.conf /tmp/default.conf.txt
167
- RUN envsubst '\${NGINX_DOCUMENT_ROOT}' < /tmp/default.conf.txt > /etc/nginx/sites-available/default.conf
167
+ RUN envsubst '\${NGINX_DOCUMENT_ROOT}' < /tmp/default.conf.txt > /etc/nginx/sites-available/default
168
168
 
169
169
  EXPOSE 80
170
170
  EXPOSE 9000