verteilen-core 1.2.3 → 1.2.6
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/dist/index.d.ts +3 -0
- package/dist/jest.config.d.ts +2 -0
- package/dist/src/client/analysis.d.ts +35 -0
- package/dist/src/client/analysis.js +318 -319
- package/dist/src/client/client.d.ts +25 -0
- package/dist/src/client/client.js +162 -168
- package/dist/src/client/cluster.d.ts +1 -0
- package/dist/src/client/cluster.js +1 -2
- package/dist/src/client/database.d.ts +13 -0
- package/dist/src/client/database.js +28 -27
- package/dist/src/client/execute.d.ts +24 -0
- package/dist/src/client/execute.js +61 -51
- package/dist/src/client/http.d.ts +7 -0
- package/dist/src/client/http.js +29 -26
- package/dist/src/client/javascript.d.ts +47 -0
- package/dist/src/client/javascript.js +110 -136
- package/dist/src/client/job_database.d.ts +10 -0
- package/dist/src/client/job_database.js +27 -29
- package/dist/src/client/job_execute.d.ts +20 -0
- package/dist/src/client/job_execute.js +148 -146
- package/dist/src/client/os.d.ts +29 -0
- package/dist/src/client/os.js +131 -136
- package/dist/src/client/resource.d.ts +7 -0
- package/dist/src/client/resource.js +93 -104
- package/dist/src/client/shell.d.ts +16 -0
- package/dist/src/client/shell.js +102 -98
- package/dist/src/computed.d.ts +13 -0
- package/dist/src/interface/base.d.ts +70 -0
- package/dist/src/interface/bus.d.ts +90 -0
- package/dist/src/interface/enum.d.ts +143 -0
- package/dist/src/interface/enum.js +5 -5
- package/dist/src/interface/execute.d.ts +20 -0
- package/dist/src/interface/record.d.ts +93 -0
- package/dist/src/interface/server.d.ts +76 -0
- package/dist/src/interface/struct.d.ts +182 -0
- package/dist/src/interface/table.d.ts +20 -0
- package/dist/src/interface/ui.d.ts +29 -0
- package/dist/src/interface.d.ts +29 -0
- package/dist/src/plugins/i18n.d.ts +1666 -0
- package/dist/src/script/console_manager.d.ts +18 -0
- package/dist/src/script/console_manager.js +97 -91
- package/dist/src/script/console_server_manager.d.ts +13 -0
- package/dist/src/script/console_server_manager.js +29 -26
- package/dist/src/script/execute/base.d.ts +45 -0
- package/dist/src/script/execute/base.js +165 -162
- package/dist/src/script/execute/feedback.d.ts +12 -0
- package/dist/src/script/execute/feedback.js +162 -171
- package/dist/src/script/execute/interface.d.ts +8 -0
- package/dist/src/script/execute/region_job.d.ts +5 -0
- package/dist/src/script/execute/region_job.js +1 -0
- package/dist/src/script/execute/region_project.d.ts +10 -0
- package/dist/src/script/execute/region_project.js +4 -0
- package/dist/src/script/execute/region_subtask.d.ts +5 -0
- package/dist/src/script/execute/region_subtask.js +1 -0
- package/dist/src/script/execute/region_task.d.ts +10 -0
- package/dist/src/script/execute/region_task.js +4 -0
- package/dist/src/script/execute/runner.d.ts +14 -0
- package/dist/src/script/execute/runner.js +129 -139
- package/dist/src/script/execute/util_parser.d.ts +14 -0
- package/dist/src/script/execute/util_parser.js +119 -121
- package/dist/src/script/execute_manager.d.ts +25 -0
- package/dist/src/script/execute_manager.js +266 -278
- package/dist/src/script/socket_manager.d.ts +31 -0
- package/dist/src/script/socket_manager.js +196 -193
- package/dist/src/script/webhook_manager.d.ts +3 -0
- package/dist/src/script/webhook_server_manager.d.ts +13 -0
- package/dist/src/script/webhook_server_manager.js +79 -86
- package/dist/src/server/detail.d.ts +72 -0
- package/dist/src/server/detail.js +401 -378
- package/dist/src/server/io.d.ts +46 -0
- package/dist/src/server/io.js +42 -51
- package/dist/src/server/plugin.d.ts +18 -0
- package/dist/src/server/plugin.js +45 -54
- package/dist/src/server/server.d.ts +27 -0
- package/dist/src/server/server.js +38 -36
- package/dist/src/server.d.ts +4 -0
- package/dist/src/util/console_handle.d.ts +20 -0
- package/dist/src/util/console_handle.js +214 -218
- package/dist/src/util/log_handle.d.ts +23 -0
- package/dist/src/util/log_handle.js +158 -164
- package/dist/test/TEST.d.ts +1 -0
- package/dist/test/TEST.js +37 -54
- package/dist/test/client/execute.test.d.ts +1 -0
- package/dist/test/client/execute.test.js +6 -15
- package/dist/test/client/javascript.test.d.ts +1 -0
- package/dist/test/client/javascript.test.js +21 -30
- package/dist/test/client/server.test.d.ts +1 -0
- package/dist/test/client/task.test.d.ts +1 -0
- package/dist/test/client/task.test.js +1 -1
- package/dist/test/script/parser.test.d.ts +1 -0
- package/dist/test/script/socket.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/interface/enum.ts +1 -1
- package/tsconfig.json +5 -3
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ClientJobExecute = void 0;
|
|
13
4
|
const interface_1 = require("../interface");
|
|
@@ -16,144 +7,18 @@ const javascript_1 = require("./javascript");
|
|
|
16
7
|
const job_database_1 = require("./job_database");
|
|
17
8
|
const os_1 = require("./os");
|
|
18
9
|
class ClientJobExecute {
|
|
10
|
+
database;
|
|
11
|
+
libraries;
|
|
12
|
+
tag;
|
|
13
|
+
runtime;
|
|
14
|
+
messager;
|
|
15
|
+
messager_log;
|
|
16
|
+
javascript;
|
|
17
|
+
os;
|
|
18
|
+
para;
|
|
19
|
+
job;
|
|
20
|
+
plugin;
|
|
19
21
|
constructor(_messager, _messager_log, _job, _source, _plugin) {
|
|
20
|
-
this.execute = () => {
|
|
21
|
-
this.messager_log(`[Execute] ${this.job.uuid} ${this.job.category == interface_1.JobCategory.Execution ? i18n_1.i18n.global.t(interface_1.JobTypeText[this.job.type]) : i18n_1.i18n.global.t(interface_1.JobType2Text[this.job.type])}`, this.tag, this.runtime);
|
|
22
|
-
const child = this.job.category == interface_1.JobCategory.Execution ? this.execute_job_exe() : this.execute_job_con();
|
|
23
|
-
return child;
|
|
24
|
-
};
|
|
25
|
-
this.stop_all = () => {
|
|
26
|
-
this.os.stopall();
|
|
27
|
-
};
|
|
28
|
-
this.execute_job_exe = () => {
|
|
29
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
switch (this.job.type) {
|
|
31
|
-
case interface_1.JobType.COPY_FILE:
|
|
32
|
-
{
|
|
33
|
-
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
34
|
-
this.os.file_copy(data);
|
|
35
|
-
resolve(`Copy file successfully, ${data.from}, ${data.to}`);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case interface_1.JobType.COPY_DIR:
|
|
39
|
-
{
|
|
40
|
-
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
41
|
-
this.os.dir_copy(data);
|
|
42
|
-
resolve(`Copy dir successfully, ${data.from}, ${data.to}`);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case interface_1.JobType.DELETE_FILE:
|
|
46
|
-
{
|
|
47
|
-
const data = { path: this.job.string_args[0] };
|
|
48
|
-
this.os.file_delete(data);
|
|
49
|
-
resolve(`Delete file successfully, ${data.path}`);
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case interface_1.JobType.DELETE_DIR:
|
|
53
|
-
{
|
|
54
|
-
const data = { path: this.job.string_args[0] };
|
|
55
|
-
this.os.dir_delete(data);
|
|
56
|
-
resolve(`Delete folder successfully, ${data.path}`);
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case interface_1.JobType.CREATE_DIR:
|
|
60
|
-
{
|
|
61
|
-
const data = { path: this.job.string_args[0] };
|
|
62
|
-
this.os.dir_create(data);
|
|
63
|
-
resolve(`Create dir successfully, ${data.path}`);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case interface_1.JobType.CREATE_FILE:
|
|
67
|
-
{
|
|
68
|
-
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
69
|
-
this.os.file_write(data);
|
|
70
|
-
resolve(`Create file successfully, ${data.from} ${data.to}`);
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case interface_1.JobType.RENAME:
|
|
74
|
-
{
|
|
75
|
-
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
76
|
-
this.os.rename(data);
|
|
77
|
-
resolve(`Rename successfully, ${data.from} ${data.to}`);
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case interface_1.JobType.JAVASCRIPT:
|
|
81
|
-
{
|
|
82
|
-
yield this.javascript.JavascriptExecuteWithLib(this.job.script, this.job.string_args).then(() => {
|
|
83
|
-
resolve(`Execute Javascript successfully`);
|
|
84
|
-
}).catch(k => {
|
|
85
|
-
reject(k);
|
|
86
|
-
});
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case interface_1.JobType.COMMAND:
|
|
90
|
-
{
|
|
91
|
-
this.os.command(this.job.string_args[1], this.job.string_args[2], this.job.string_args[0]).then(m => {
|
|
92
|
-
resolve(m);
|
|
93
|
-
}).catch(err => {
|
|
94
|
-
reject(err);
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case interface_1.JobType.LIB_COMMAND:
|
|
99
|
-
{
|
|
100
|
-
const target = this.plugin.plugins.find(x => x.name == this.job.string_args[0]);
|
|
101
|
-
if (target == undefined) {
|
|
102
|
-
reject("Cannot find plugin " + this.job.string_args[0]);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const archTarget = target.contents.find(x => x.arch == process.arch && x.platform == process.platform);
|
|
106
|
-
if (archTarget == undefined) {
|
|
107
|
-
reject({
|
|
108
|
-
code: 1,
|
|
109
|
-
message: "Cannot find plugin match arch " + this.job.string_args[0] + " " + process.arch
|
|
110
|
-
});
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
this.os.lib_command(archTarget.filename, this.job.string_args[1]).then(m => {
|
|
114
|
-
resolve(m);
|
|
115
|
-
}).catch(err => {
|
|
116
|
-
reject(err);
|
|
117
|
-
});
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}));
|
|
122
|
-
};
|
|
123
|
-
this.execute_job_con = () => {
|
|
124
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
switch (this.job.type) {
|
|
126
|
-
case interface_1.JobType2.CHECK_PATH:
|
|
127
|
-
{
|
|
128
|
-
const data = { path: this.job.string_args[0] };
|
|
129
|
-
if (this.os.fs_exist(data)) {
|
|
130
|
-
resolve(`Path exist ${data.path}`);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
reject({
|
|
134
|
-
code: 2,
|
|
135
|
-
message: `Path not exist ${data.path}`
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case interface_1.JobType2.JAVASCRIPT:
|
|
141
|
-
{
|
|
142
|
-
const r = yield this.javascript.JavascriptExecuteWithLib(this.job.script, this.job.string_args);
|
|
143
|
-
if (r != undefined && r == 0) {
|
|
144
|
-
resolve(`Execute Javascript successfully`);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
reject({
|
|
148
|
-
code: 3,
|
|
149
|
-
message: `Execute Javascript failed`
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}));
|
|
156
|
-
};
|
|
157
22
|
this.messager = _messager;
|
|
158
23
|
this.messager_log = _messager_log;
|
|
159
24
|
this.tag = _job.uuid;
|
|
@@ -167,5 +32,142 @@ class ClientJobExecute {
|
|
|
167
32
|
this.libraries = process.env.libraries != undefined ? JSON.parse(process.env.libraries) : undefined;
|
|
168
33
|
javascript_1.ClientJavascript.Init(_messager, _messager_log, this.os, this.para, () => this.libraries, () => this.database, () => this.job);
|
|
169
34
|
}
|
|
35
|
+
execute = () => {
|
|
36
|
+
this.messager_log(`[Execute] ${this.job.uuid} ${this.job.category == interface_1.JobCategory.Execution ? i18n_1.i18n.global.t(interface_1.JobTypeText[this.job.type]) : i18n_1.i18n.global.t(interface_1.JobType2Text[this.job.type])}`, this.tag, this.runtime);
|
|
37
|
+
const child = this.job.category == interface_1.JobCategory.Execution ? this.execute_job_exe() : this.execute_job_con();
|
|
38
|
+
return child;
|
|
39
|
+
};
|
|
40
|
+
stop_all = () => {
|
|
41
|
+
this.os.stopall();
|
|
42
|
+
};
|
|
43
|
+
execute_job_exe = () => {
|
|
44
|
+
return new Promise(async (resolve, reject) => {
|
|
45
|
+
switch (this.job.type) {
|
|
46
|
+
case interface_1.JobType.COPY_FILE:
|
|
47
|
+
{
|
|
48
|
+
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
49
|
+
this.os.file_copy(data);
|
|
50
|
+
resolve(`Copy file successfully, ${data.from}, ${data.to}`);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case interface_1.JobType.COPY_DIR:
|
|
54
|
+
{
|
|
55
|
+
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
56
|
+
this.os.dir_copy(data);
|
|
57
|
+
resolve(`Copy dir successfully, ${data.from}, ${data.to}`);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case interface_1.JobType.DELETE_FILE:
|
|
61
|
+
{
|
|
62
|
+
const data = { path: this.job.string_args[0] };
|
|
63
|
+
this.os.file_delete(data);
|
|
64
|
+
resolve(`Delete file successfully, ${data.path}`);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case interface_1.JobType.DELETE_DIR:
|
|
68
|
+
{
|
|
69
|
+
const data = { path: this.job.string_args[0] };
|
|
70
|
+
this.os.dir_delete(data);
|
|
71
|
+
resolve(`Delete folder successfully, ${data.path}`);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case interface_1.JobType.CREATE_DIR:
|
|
75
|
+
{
|
|
76
|
+
const data = { path: this.job.string_args[0] };
|
|
77
|
+
this.os.dir_create(data);
|
|
78
|
+
resolve(`Create dir successfully, ${data.path}`);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case interface_1.JobType.CREATE_FILE:
|
|
82
|
+
{
|
|
83
|
+
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
84
|
+
this.os.file_write(data);
|
|
85
|
+
resolve(`Create file successfully, ${data.from} ${data.to}`);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case interface_1.JobType.RENAME:
|
|
89
|
+
{
|
|
90
|
+
const data = { from: this.job.string_args[0], to: this.job.string_args[1] };
|
|
91
|
+
this.os.rename(data);
|
|
92
|
+
resolve(`Rename successfully, ${data.from} ${data.to}`);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case interface_1.JobType.JAVASCRIPT:
|
|
96
|
+
{
|
|
97
|
+
await this.javascript.JavascriptExecuteWithLib(this.job.script, this.job.string_args).then(() => {
|
|
98
|
+
resolve(`Execute Javascript successfully`);
|
|
99
|
+
}).catch(k => {
|
|
100
|
+
reject(k);
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case interface_1.JobType.COMMAND:
|
|
105
|
+
{
|
|
106
|
+
this.os.command(this.job.string_args[1], this.job.string_args[2], this.job.string_args[0]).then(m => {
|
|
107
|
+
resolve(m);
|
|
108
|
+
}).catch(err => {
|
|
109
|
+
reject(err);
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case interface_1.JobType.LIB_COMMAND:
|
|
114
|
+
{
|
|
115
|
+
const target = this.plugin.plugins.find(x => x.name == this.job.string_args[0]);
|
|
116
|
+
if (target == undefined) {
|
|
117
|
+
reject("Cannot find plugin " + this.job.string_args[0]);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const archTarget = target.contents.find(x => x.arch == process.arch && x.platform == process.platform);
|
|
121
|
+
if (archTarget == undefined) {
|
|
122
|
+
reject({
|
|
123
|
+
code: 1,
|
|
124
|
+
message: "Cannot find plugin match arch " + this.job.string_args[0] + " " + process.arch
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.os.lib_command(archTarget.filename, this.job.string_args[1]).then(m => {
|
|
129
|
+
resolve(m);
|
|
130
|
+
}).catch(err => {
|
|
131
|
+
reject(err);
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
execute_job_con = () => {
|
|
139
|
+
return new Promise(async (resolve, reject) => {
|
|
140
|
+
switch (this.job.type) {
|
|
141
|
+
case interface_1.JobType2.CHECK_PATH:
|
|
142
|
+
{
|
|
143
|
+
const data = { path: this.job.string_args[0] };
|
|
144
|
+
if (this.os.fs_exist(data)) {
|
|
145
|
+
resolve(`Path exist ${data.path}`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
reject({
|
|
149
|
+
code: 2,
|
|
150
|
+
message: `Path not exist ${data.path}`
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
case interface_1.JobType2.JAVASCRIPT:
|
|
156
|
+
{
|
|
157
|
+
const r = await this.javascript.JavascriptExecuteWithLib(this.job.script, this.job.string_args);
|
|
158
|
+
if (r != undefined && r == 0) {
|
|
159
|
+
resolve(`Execute Javascript successfully`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
reject({
|
|
163
|
+
code: 3,
|
|
164
|
+
message: `Execute Javascript failed`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
};
|
|
170
172
|
}
|
|
171
173
|
exports.ClientJobExecute = ClientJobExecute;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Messager, Messager_log, OnePath, TwoPath } from "../interface";
|
|
2
|
+
type getstring = () => string;
|
|
3
|
+
export declare class ClientOS {
|
|
4
|
+
private messager;
|
|
5
|
+
private messager_log;
|
|
6
|
+
private tag;
|
|
7
|
+
private runtime;
|
|
8
|
+
private children;
|
|
9
|
+
constructor(_tag: getstring, _runtime: getstring, _messager: Messager, _messager_log: Messager_log);
|
|
10
|
+
file_copy: (data: TwoPath) => void;
|
|
11
|
+
dir_copy: (data: TwoPath) => void;
|
|
12
|
+
file_delete: (data: OnePath) => void;
|
|
13
|
+
dir_delete: (data: OnePath) => void;
|
|
14
|
+
rename: (data: TwoPath) => void;
|
|
15
|
+
fs_exist: (data: OnePath) => boolean;
|
|
16
|
+
fs_dir_exist: (data: OnePath) => boolean;
|
|
17
|
+
fs_file_exist: (data: OnePath) => boolean;
|
|
18
|
+
dir_files: (data: OnePath) => Array<string>;
|
|
19
|
+
dir_dirs: (data: OnePath) => Array<string>;
|
|
20
|
+
dir_create: (data: OnePath) => void;
|
|
21
|
+
file_write: (data: TwoPath) => void;
|
|
22
|
+
file_read: (data: OnePath) => string;
|
|
23
|
+
stopall: () => void;
|
|
24
|
+
lib_command: (command: string, args: string) => Promise<string>;
|
|
25
|
+
command: (command: string, args: string, cwd?: string) => Promise<string>;
|
|
26
|
+
command_sync: (command: string, args: string, cwd?: string) => Promise<string>;
|
|
27
|
+
command_exec: (command: string, args: string, cwd?: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
package/dist/src/client/os.js
CHANGED
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
37
|
};
|
|
@@ -53,135 +44,105 @@ const path = __importStar(require("path"));
|
|
|
53
44
|
const os = __importStar(require("os"));
|
|
54
45
|
const interface_1 = require("../interface");
|
|
55
46
|
class ClientOS {
|
|
47
|
+
messager;
|
|
48
|
+
messager_log;
|
|
49
|
+
tag;
|
|
50
|
+
runtime;
|
|
51
|
+
children = [];
|
|
56
52
|
constructor(_tag, _runtime, _messager, _messager_log) {
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const cc = process.platform == "win32" ? command : "./" + command;
|
|
126
|
-
return this.command(cc, args, path.join(os.homedir(), interface_1.DATA_FOLDER, "exe"));
|
|
127
|
-
});
|
|
128
|
-
this.command = (command, args, cwd) => __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
this.messager_log(`[OS Action] Command cwd: ${cwd}`, this.tag());
|
|
130
|
-
this.messager_log(`[OS Action] Command command: ${command}`, this.tag());
|
|
131
|
-
this.messager_log(`[OS Action] Command args: ${args}`, this.tag());
|
|
132
|
-
return new Promise((resolve, reject) => {
|
|
133
|
-
const child = (0, child_process_1.spawn)(command, args.split(' '), {
|
|
134
|
-
cwd: cwd,
|
|
135
|
-
shell: true,
|
|
136
|
-
stdio: ['pipe', 'pipe', 'pipe']
|
|
137
|
-
});
|
|
138
|
-
child.stdin.setDefaultEncoding('utf8');
|
|
139
|
-
child.on('spawn', () => {
|
|
140
|
-
this.children.push(child);
|
|
141
|
-
this.messager_log(`[Command] Spawn process`, this.tag());
|
|
142
|
-
});
|
|
143
|
-
child.on('error', (err) => {
|
|
144
|
-
this.messager_log(`[Command] Error: ${err}`, this.tag());
|
|
145
|
-
reject(`Error ${err}`);
|
|
146
|
-
});
|
|
147
|
-
child.on('exit', (code, signal) => {
|
|
148
|
-
this.messager_log(`[Command] Process Exit: ${code}`, this.tag());
|
|
149
|
-
});
|
|
150
|
-
child.on('message', (message, sendHandle) => {
|
|
151
|
-
this.messager_log(`[Command] : ${message.toString()}`, this.tag());
|
|
152
|
-
});
|
|
153
|
-
child.on('close', (code, signal) => {
|
|
154
|
-
this.messager_log(`[Command] Process Close: ${code}`, this.tag());
|
|
155
|
-
const index = this.children.findIndex(x => x.pid == child.pid);
|
|
156
|
-
if (index != -1)
|
|
157
|
-
this.children.splice(index, 1);
|
|
158
|
-
resolve(`Successfully ${code}`);
|
|
159
|
-
});
|
|
160
|
-
child.stdout.setEncoding('utf8');
|
|
161
|
-
child.stdout.on('data', (chunk) => {
|
|
162
|
-
this.messager_log(`[Command Info] : ${chunk.toString()}`, this.tag());
|
|
163
|
-
});
|
|
164
|
-
child.stderr.setEncoding('utf8');
|
|
165
|
-
child.stderr.on('data', (chunk) => {
|
|
166
|
-
this.messager_log(`[Command Error] : ${chunk.toString()}`, this.tag());
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
this.command_sync = (command, args, cwd) => __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
return this.command(command, args, cwd);
|
|
53
|
+
this.tag = _tag;
|
|
54
|
+
this.runtime = _runtime;
|
|
55
|
+
this.messager = _messager;
|
|
56
|
+
this.messager_log = _messager_log;
|
|
57
|
+
}
|
|
58
|
+
file_copy = (data) => {
|
|
59
|
+
this.messager(`[OS Action] File copy, ${data.from} => ${data.to}`, this.tag());
|
|
60
|
+
fs.copyFileSync(data.from, data.to);
|
|
61
|
+
};
|
|
62
|
+
dir_copy = (data) => {
|
|
63
|
+
this.messager(`[OS Action] Folder copy, ${data.from} => ${data.to}`, this.tag());
|
|
64
|
+
fs.cpSync(data.from, data.to, { recursive: true, force: true });
|
|
65
|
+
};
|
|
66
|
+
file_delete = (data) => {
|
|
67
|
+
this.messager(`[OS Action] File delete, ${data.path}`, this.tag());
|
|
68
|
+
fs.rmSync(data.path);
|
|
69
|
+
};
|
|
70
|
+
dir_delete = (data) => {
|
|
71
|
+
this.messager(`[OS Action] Folder delete, ${data.path}`, this.tag());
|
|
72
|
+
fs.rmSync(data.path, { recursive: true, force: true });
|
|
73
|
+
};
|
|
74
|
+
rename = (data) => {
|
|
75
|
+
this.messager(`[OS Action] File or dir rename, ${data.from} => ${data.to}`, this.tag());
|
|
76
|
+
fs.renameSync(data.from, data.to);
|
|
77
|
+
};
|
|
78
|
+
fs_exist = (data) => {
|
|
79
|
+
const v = fs.existsSync(data.path);
|
|
80
|
+
this.messager(`[OS Action] Check path exists, ${data.path}`, this.tag());
|
|
81
|
+
return v;
|
|
82
|
+
};
|
|
83
|
+
fs_dir_exist = (data) => {
|
|
84
|
+
const p = this.fs_exist(data);
|
|
85
|
+
if (!p)
|
|
86
|
+
return false;
|
|
87
|
+
const stat = fs.statSync(data.path);
|
|
88
|
+
return stat.isDirectory();
|
|
89
|
+
};
|
|
90
|
+
fs_file_exist = (data) => {
|
|
91
|
+
const p = this.fs_exist(data);
|
|
92
|
+
if (!p)
|
|
93
|
+
return false;
|
|
94
|
+
const stat = fs.statSync(data.path);
|
|
95
|
+
return stat.isFile();
|
|
96
|
+
};
|
|
97
|
+
dir_files = (data) => {
|
|
98
|
+
const r = fs.readdirSync(data.path, { withFileTypes: true }).filter(x => x.isFile()).map(x => x.name);
|
|
99
|
+
return r;
|
|
100
|
+
};
|
|
101
|
+
dir_dirs = (data) => {
|
|
102
|
+
const r = fs.readdirSync(data.path, { withFileTypes: true }).filter(x => x.isDirectory()).map(x => x.name);
|
|
103
|
+
return r;
|
|
104
|
+
};
|
|
105
|
+
dir_create = (data) => {
|
|
106
|
+
this.messager(`[OS Action] Create folder, ${data.path}`, this.tag());
|
|
107
|
+
fs.mkdirSync(data.path, { recursive: true });
|
|
108
|
+
};
|
|
109
|
+
file_write = (data) => {
|
|
110
|
+
this.messager(`[OS Action] Create file, ${data.from}`, this.tag());
|
|
111
|
+
fs.writeFileSync(data.from, data.to);
|
|
112
|
+
};
|
|
113
|
+
file_read = (data) => {
|
|
114
|
+
return fs.readFileSync(data.path).toString();
|
|
115
|
+
};
|
|
116
|
+
stopall = () => {
|
|
117
|
+
this.children.forEach(x => {
|
|
118
|
+
x.stdin.write('q');
|
|
119
|
+
x.stdin.end();
|
|
120
|
+
(0, tree_kill_1.default)(x.pid, 'SIGKILL');
|
|
172
121
|
});
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
122
|
+
this.children = [];
|
|
123
|
+
};
|
|
124
|
+
lib_command = async (command, args) => {
|
|
125
|
+
const cc = process.platform == "win32" ? command : "./" + command;
|
|
126
|
+
return this.command(cc, args, path.join(os.homedir(), interface_1.DATA_FOLDER, "exe"));
|
|
127
|
+
};
|
|
128
|
+
command = async (command, args, cwd) => {
|
|
129
|
+
this.messager_log(`[OS Action] Command cwd: ${cwd}`, this.tag());
|
|
130
|
+
this.messager_log(`[OS Action] Command command: ${command}`, this.tag());
|
|
131
|
+
this.messager_log(`[OS Action] Command args: ${args}`, this.tag());
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const child = (0, child_process_1.spawn)(command, args.split(' '), {
|
|
134
|
+
cwd: cwd,
|
|
135
|
+
shell: true,
|
|
136
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
179
137
|
});
|
|
138
|
+
child.stdin.setDefaultEncoding('utf8');
|
|
180
139
|
child.on('spawn', () => {
|
|
140
|
+
this.children.push(child);
|
|
181
141
|
this.messager_log(`[Command] Spawn process`, this.tag());
|
|
182
142
|
});
|
|
183
143
|
child.on('error', (err) => {
|
|
184
144
|
this.messager_log(`[Command] Error: ${err}`, this.tag());
|
|
145
|
+
reject(`Error ${err}`);
|
|
185
146
|
});
|
|
186
147
|
child.on('exit', (code, signal) => {
|
|
187
148
|
this.messager_log(`[Command] Process Exit: ${code}`, this.tag());
|
|
@@ -191,12 +152,46 @@ class ClientOS {
|
|
|
191
152
|
});
|
|
192
153
|
child.on('close', (code, signal) => {
|
|
193
154
|
this.messager_log(`[Command] Process Close: ${code}`, this.tag());
|
|
155
|
+
const index = this.children.findIndex(x => x.pid == child.pid);
|
|
156
|
+
if (index != -1)
|
|
157
|
+
this.children.splice(index, 1);
|
|
158
|
+
resolve(`Successfully ${code}`);
|
|
194
159
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
160
|
+
child.stdout.setEncoding('utf8');
|
|
161
|
+
child.stdout.on('data', (chunk) => {
|
|
162
|
+
this.messager_log(`[Command Info] : ${chunk.toString()}`, this.tag());
|
|
163
|
+
});
|
|
164
|
+
child.stderr.setEncoding('utf8');
|
|
165
|
+
child.stderr.on('data', (chunk) => {
|
|
166
|
+
this.messager_log(`[Command Error] : ${chunk.toString()}`, this.tag());
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
command_sync = async (command, args, cwd) => {
|
|
171
|
+
return this.command(command, args, cwd);
|
|
172
|
+
};
|
|
173
|
+
command_exec = (command, args, cwd) => {
|
|
174
|
+
this.messager_log(`[OS Action] Command cwd: ${cwd}`, this.tag());
|
|
175
|
+
this.messager_log(`[OS Action] Command command: ${command}`, this.tag());
|
|
176
|
+
this.messager_log(`[OS Action] Command args: ${args}`, this.tag());
|
|
177
|
+
const child = (0, child_process_1.exec)(`${command} ${args}`, {
|
|
178
|
+
cwd: cwd
|
|
179
|
+
});
|
|
180
|
+
child.on('spawn', () => {
|
|
181
|
+
this.messager_log(`[Command] Spawn process`, this.tag());
|
|
182
|
+
});
|
|
183
|
+
child.on('error', (err) => {
|
|
184
|
+
this.messager_log(`[Command] Error: ${err}`, this.tag());
|
|
185
|
+
});
|
|
186
|
+
child.on('exit', (code, signal) => {
|
|
187
|
+
this.messager_log(`[Command] Process Exit: ${code}`, this.tag());
|
|
188
|
+
});
|
|
189
|
+
child.on('message', (message, sendHandle) => {
|
|
190
|
+
this.messager_log(`[Command] : ${message.toString()}`, this.tag());
|
|
191
|
+
});
|
|
192
|
+
child.on('close', (code, signal) => {
|
|
193
|
+
this.messager_log(`[Command] Process Close: ${code}`, this.tag());
|
|
194
|
+
});
|
|
195
|
+
};
|
|
201
196
|
}
|
|
202
197
|
exports.ClientOS = ClientOS;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ResourceType } from "../interface";
|
|
2
|
+
import { SystemLoad } from "../interface/struct";
|
|
3
|
+
export declare class ClientResource {
|
|
4
|
+
is_query: boolean;
|
|
5
|
+
Query: (src?: SystemLoad | undefined, type?: ResourceType) => Promise<SystemLoad>;
|
|
6
|
+
private create_new;
|
|
7
|
+
}
|