@wocker/ws 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ws.js +1 -12
- package/lib/AppModule.js +6 -3
- package/lib/controllers/DebugController.d.ts +8 -0
- package/lib/controllers/DebugController.js +46 -0
- package/lib/controllers/ImageController.js +1 -1
- package/lib/controllers/PluginController.d.ts +2 -0
- package/lib/controllers/PluginController.js +42 -41
- package/lib/controllers/PresetController.d.ts +1 -0
- package/lib/controllers/PresetController.js +67 -6
- package/lib/controllers/ProjectController.d.ts +2 -3
- package/lib/controllers/ProjectController.js +58 -68
- package/lib/controllers/ProxyController.js +15 -6
- package/lib/controllers/index.d.ts +1 -0
- package/lib/controllers/index.js +1 -0
- package/lib/main.d.ts +1 -1
- package/lib/main.js +22 -2
- package/lib/makes/FS.d.ts +3 -5
- package/lib/makes/FS.js +3 -21
- package/lib/makes/Http.d.ts +18 -0
- package/lib/makes/Http.js +72 -0
- package/lib/makes/Preset.d.ts +2 -2
- package/lib/makes/index.d.ts +1 -0
- package/lib/makes/index.js +1 -0
- package/lib/plugins/index.d.ts +0 -2
- package/lib/plugins/index.js +0 -2
- package/lib/services/AppConfigService.d.ts +6 -16
- package/lib/services/AppConfigService.js +29 -113
- package/lib/services/DockerService.d.ts +2 -1
- package/lib/services/DockerService.js +31 -11
- package/lib/services/PluginService.d.ts +9 -2
- package/lib/services/PluginService.js +85 -3
- package/lib/services/PresetService.d.ts +1 -2
- package/lib/services/PresetService.js +19 -7
- package/lib/services/ProjectService.js +18 -13
- package/lib/utils/exec.d.ts +4 -1
- package/lib/utils/exec.js +16 -31
- package/lib/utils/followProgress.js +49 -45
- package/lib/utils/index.d.ts +0 -6
- package/lib/utils/index.js +0 -6
- package/lib/utils/spawn.d.ts +1 -1
- package/lib/utils/spawn.js +20 -12
- package/package.json +4 -6
- package/presets/php-apache/Dockerfile +1 -1
- package/presets/php-apache/config.json +2 -1
- package/lib/App.d.ts +0 -11
- package/lib/App.js +0 -81
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -22
- package/lib/plugins/NgrokPlugin.d.ts +0 -37
- package/lib/plugins/NgrokPlugin.js +0 -254
- package/lib/plugins/RedisPlugin.d.ts +0 -16
- package/lib/plugins/RedisPlugin.js +0 -91
- package/lib/utils/buildOptions.d.ts +0 -1
- package/lib/utils/buildOptions.js +0 -9
- package/lib/utils/fetch.d.ts +0 -5
- package/lib/utils/fetch.js +0 -52
- package/lib/utils/get-config.d.ts +0 -2
- package/lib/utils/get-config.js +0 -17
- package/lib/utils/image-build.d.ts +0 -13
- package/lib/utils/image-build.js +0 -46
- package/lib/utils/set-config.d.ts +0 -2
- package/lib/utils/set-config.js +0 -15
- package/lib/utils/tty.d.ts +0 -2
- package/lib/utils/tty.js +0 -6
- package/plugins/ngrok/Dockerfile +0 -2
|
@@ -1,25 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
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;
|
|
6
22
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
23
|
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
8
31
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
32
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
33
|
};
|
|
11
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
35
|
exports.PluginService = void 0;
|
|
13
36
|
const core_1 = require("@wocker/core");
|
|
37
|
+
const AppConfigService_1 = require("./AppConfigService");
|
|
38
|
+
const LogService_1 = require("./LogService");
|
|
39
|
+
const makes_1 = require("../makes");
|
|
40
|
+
const utils_1 = require("../utils");
|
|
14
41
|
let PluginService = class PluginService {
|
|
15
|
-
constructor(cli) {
|
|
42
|
+
constructor(appConfigService, logService, cli) {
|
|
43
|
+
this.appConfigService = appConfigService;
|
|
44
|
+
this.logService = logService;
|
|
16
45
|
this.cli = cli;
|
|
17
46
|
}
|
|
18
|
-
|
|
47
|
+
async checkPlugin(pluginName) {
|
|
48
|
+
try {
|
|
49
|
+
const { default: Plugin } = await Promise.resolve(`${pluginName}`).then(s => __importStar(require(s)));
|
|
50
|
+
const name = Reflect.getMetadata(core_1.MODULE_METADATA.NAME, Plugin);
|
|
51
|
+
if (!name) {
|
|
52
|
+
console.log("No name");
|
|
53
|
+
}
|
|
54
|
+
return !!name;
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
this.logService.error(err.message);
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
async import() {
|
|
62
|
+
}
|
|
63
|
+
async update() {
|
|
64
|
+
const config = await this.appConfigService.getConfig();
|
|
65
|
+
if (!config.plugins) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const name of new Set(config.plugins).values()) {
|
|
69
|
+
console.info(`Checking ${name}...`);
|
|
70
|
+
try {
|
|
71
|
+
const current = await this.getCurrentVersion(name);
|
|
72
|
+
const res = await makes_1.Http.get("https://registry.npmjs.org")
|
|
73
|
+
.send(name);
|
|
74
|
+
if (res.status !== 200) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const { "dist-tags": { latest } } = res.data;
|
|
78
|
+
this.logService.info(name, current, latest);
|
|
79
|
+
if (!current || current < latest) {
|
|
80
|
+
console.log(`Updating ${name}...`);
|
|
81
|
+
await (0, utils_1.spawn)("npm", ["i", "-g", name]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
this.logService.error(err.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
console.info("Done");
|
|
89
|
+
}
|
|
90
|
+
async getCurrentVersion(name) {
|
|
91
|
+
try {
|
|
92
|
+
const { dependencies: { [name]: { version } } } = JSON.parse(await (0, utils_1.exec)(`npm ls --json -g ${name}`));
|
|
93
|
+
return version;
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
this.logService.error(`Failed to get current version of ${name}`);
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
19
99
|
}
|
|
20
100
|
};
|
|
21
101
|
exports.PluginService = PluginService;
|
|
22
102
|
exports.PluginService = PluginService = __decorate([
|
|
23
103
|
(0, core_1.Injectable)(),
|
|
24
|
-
__metadata("design:paramtypes", [
|
|
104
|
+
__metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
|
|
105
|
+
LogService_1.LogService,
|
|
106
|
+
core_1.Cli])
|
|
25
107
|
], PluginService);
|
|
@@ -1,16 +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() {
|
|
12
|
-
makes_1.Preset.install(this);
|
|
13
|
-
}
|
|
20
|
+
let PresetService = class PresetService {
|
|
21
|
+
constructor() { }
|
|
14
22
|
getImageName(preset, buildArgs = {}) {
|
|
15
23
|
const rawValues = [];
|
|
16
24
|
const hashValues = [];
|
|
@@ -36,7 +44,7 @@ class PresetService {
|
|
|
36
44
|
}
|
|
37
45
|
async get(name) {
|
|
38
46
|
const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
|
|
39
|
-
return new class extends
|
|
47
|
+
return new class extends core_1.Preset {
|
|
40
48
|
constructor(presetService, data) {
|
|
41
49
|
super(data);
|
|
42
50
|
this.presetService = presetService;
|
|
@@ -57,7 +65,7 @@ class PresetService {
|
|
|
57
65
|
continue;
|
|
58
66
|
}
|
|
59
67
|
const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, dir, "config.json");
|
|
60
|
-
const preset = new
|
|
68
|
+
const preset = new core_1.Preset({
|
|
61
69
|
name: dir,
|
|
62
70
|
...config
|
|
63
71
|
});
|
|
@@ -69,5 +77,9 @@ class PresetService {
|
|
|
69
77
|
const [preset] = await this.search(options);
|
|
70
78
|
return preset || null;
|
|
71
79
|
}
|
|
72
|
-
}
|
|
80
|
+
};
|
|
73
81
|
exports.PresetService = PresetService;
|
|
82
|
+
exports.PresetService = PresetService = __decorate([
|
|
83
|
+
(0, core_1.Injectable)(),
|
|
84
|
+
__metadata("design:paramtypes", [])
|
|
85
|
+
], PresetService);
|
|
@@ -44,15 +44,15 @@ let ProjectService = class ProjectService {
|
|
|
44
44
|
this.dockerService = dockerService;
|
|
45
45
|
}
|
|
46
46
|
fromObject(data) {
|
|
47
|
+
const projectService = this;
|
|
47
48
|
return new class extends core_1.Project {
|
|
48
|
-
constructor(
|
|
49
|
+
constructor(data) {
|
|
49
50
|
super(data);
|
|
50
|
-
this.projectService = projectService;
|
|
51
51
|
}
|
|
52
52
|
async save() {
|
|
53
|
-
await
|
|
53
|
+
await projectService.save(this);
|
|
54
54
|
}
|
|
55
|
-
}(
|
|
55
|
+
}(data);
|
|
56
56
|
}
|
|
57
57
|
async getById(id) {
|
|
58
58
|
const data = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", id, "config.json"));
|
|
@@ -90,23 +90,25 @@ let ProjectService = class ProjectService {
|
|
|
90
90
|
if (images.length === 0) {
|
|
91
91
|
await this.dockerService.buildImage({
|
|
92
92
|
tag: project.imageName,
|
|
93
|
+
buildArgs: project.buildArgs,
|
|
93
94
|
context: this.appConfigService.getPWD(),
|
|
94
95
|
src: project.dockerfile
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
await this.appEventsService.emit("project:beforeStart", project);
|
|
99
99
|
let container = await this.dockerService.getContainer(project.containerName);
|
|
100
100
|
if (container && restart) {
|
|
101
101
|
container = null;
|
|
102
|
+
await this.appEventsService.emit("project:stop", project);
|
|
102
103
|
await this.dockerService.removeContainer(project.containerName);
|
|
103
104
|
}
|
|
104
105
|
if (!container) {
|
|
106
|
+
const config = await this.appConfigService.getConfig();
|
|
105
107
|
container = await this.dockerService.createContainer({
|
|
106
108
|
name: project.containerName,
|
|
107
109
|
image: project.imageName,
|
|
108
110
|
env: {
|
|
109
|
-
...
|
|
111
|
+
...config.env || {},
|
|
110
112
|
...project.env || {}
|
|
111
113
|
},
|
|
112
114
|
volumes: (project.volumes || []).map((volume) => {
|
|
@@ -118,10 +120,11 @@ let ProjectService = class ProjectService {
|
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
122
|
const { State: { Status } } = await container.inspect();
|
|
123
|
+
await this.appEventsService.emit("project:beforeStart", project);
|
|
121
124
|
if (Status === "created" || Status === "exited") {
|
|
122
125
|
await container.start();
|
|
123
|
-
await this.appEventsService.emit("project:start", project);
|
|
124
126
|
}
|
|
127
|
+
await this.appEventsService.emit("project:start", project);
|
|
125
128
|
}
|
|
126
129
|
async stop() {
|
|
127
130
|
const project = await this.get();
|
|
@@ -143,27 +146,29 @@ let ProjectService = class ProjectService {
|
|
|
143
146
|
project.id = project.name;
|
|
144
147
|
}
|
|
145
148
|
const projectDirPath = this.appConfigService.dataPath("projects", project.id);
|
|
149
|
+
const config = await this.appConfigService.getConfig();
|
|
146
150
|
const configPath = this.appConfigService.dataPath("projects", project.id, "config.json");
|
|
147
151
|
if (!makes_1.FS.existsSync(projectDirPath)) {
|
|
148
152
|
await makes_1.FS.mkdir(projectDirPath, {
|
|
149
153
|
recursive: true
|
|
150
154
|
});
|
|
151
155
|
}
|
|
152
|
-
|
|
156
|
+
config.setProject(project.id, project.path);
|
|
153
157
|
await makes_1.FS.writeJSON(configPath, project);
|
|
158
|
+
await config.save();
|
|
154
159
|
}
|
|
155
160
|
async search(params = {}) {
|
|
156
161
|
const { id, name, path } = params;
|
|
157
|
-
const
|
|
162
|
+
const config = await this.appConfigService.getConfig();
|
|
158
163
|
const projects = [];
|
|
159
|
-
for (const
|
|
160
|
-
if (id &&
|
|
164
|
+
for (const projectConfig of config.projects) {
|
|
165
|
+
if (id && projectConfig.id !== id) {
|
|
161
166
|
continue;
|
|
162
167
|
}
|
|
163
|
-
if (path &&
|
|
168
|
+
if (path && projectConfig.src !== path) {
|
|
164
169
|
continue;
|
|
165
170
|
}
|
|
166
|
-
const project = await this.getById(
|
|
171
|
+
const project = await this.getById(projectConfig.id);
|
|
167
172
|
if (name && project.name !== name) {
|
|
168
173
|
continue;
|
|
169
174
|
}
|
package/lib/utils/exec.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
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
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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);
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
export * from "./buildOptions";
|
|
2
1
|
export * from "./escapeRegExp";
|
|
3
2
|
export * from "./exec";
|
|
4
|
-
export * from "./fetch";
|
|
5
3
|
export * from "./followProgress";
|
|
6
4
|
export * from "./format-size-units";
|
|
7
|
-
export * from "./get-config";
|
|
8
5
|
export * from "./get-cursor-position";
|
|
9
|
-
export * from "./image-build";
|
|
10
6
|
export * from "./injectVariables";
|
|
11
7
|
export * from "./parse-table";
|
|
12
|
-
export * from "./set-config";
|
|
13
8
|
export * from "./spawn";
|
|
14
|
-
export * from "./tty";
|
|
15
9
|
export * from "./volumeFormat";
|
|
16
10
|
export * from "./volumeParse";
|
package/lib/utils/index.js
CHANGED
|
@@ -14,19 +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
17
|
__exportStar(require("./escapeRegExp"), exports);
|
|
19
18
|
__exportStar(require("./exec"), exports);
|
|
20
|
-
__exportStar(require("./fetch"), exports);
|
|
21
19
|
__exportStar(require("./followProgress"), exports);
|
|
22
20
|
__exportStar(require("./format-size-units"), exports);
|
|
23
|
-
__exportStar(require("./get-config"), exports);
|
|
24
21
|
__exportStar(require("./get-cursor-position"), exports);
|
|
25
|
-
__exportStar(require("./image-build"), exports);
|
|
26
22
|
__exportStar(require("./injectVariables"), exports);
|
|
27
23
|
__exportStar(require("./parse-table"), exports);
|
|
28
|
-
__exportStar(require("./set-config"), exports);
|
|
29
24
|
__exportStar(require("./spawn"), exports);
|
|
30
|
-
__exportStar(require("./tty"), exports);
|
|
31
25
|
__exportStar(require("./volumeFormat"), exports);
|
|
32
26
|
__exportStar(require("./volumeParse"), exports);
|
package/lib/utils/spawn.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const spawn: (command:
|
|
1
|
+
declare const spawn: (command: string, args: string[]) => Promise<void>;
|
|
2
2
|
export { spawn };
|
package/lib/utils/spawn.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Docker workspace for web projects",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@kearisp/cli": "^1.0.7",
|
|
29
|
-
"@wocker/core": "^1.0.
|
|
30
|
-
"@wocker/utils": "^1.0.
|
|
29
|
+
"@wocker/core": "^1.0.10",
|
|
30
|
+
"@wocker/utils": "^1.0.4",
|
|
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.
|
|
59
|
+
"typescript": "^5.4.4"
|
|
62
60
|
}
|
|
63
61
|
}
|
package/lib/App.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { AppConfigService } from "./services";
|
|
3
|
-
export declare class App {
|
|
4
|
-
protected cli: Cli;
|
|
5
|
-
protected appConfigService: AppConfigService;
|
|
6
|
-
constructor();
|
|
7
|
-
install(): void;
|
|
8
|
-
use(Constructor: any): void;
|
|
9
|
-
setDebug(status: string): Promise<string>;
|
|
10
|
-
run(): Promise<string>;
|
|
11
|
-
}
|