tmui-cli 1.2.4 → 1.2.5
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/cmdTool.js +229 -229
- package/bin/createTmui.js +382 -382
- package/bin/dirTool.js +152 -152
- package/bin/hooks.js +215 -215
- package/bin/net.js +145 -145
- package/bin/selectedDir.js +28 -28
- package/bin/tmui.js +27 -27
- package/package.json +50 -50
- package/webpack.config.js +16 -16
- package/website/index.html +20 -20
- package/website/js/app.js +996 -996
- package/website/js/chunk-vendors.js +13591 -13591
package/bin/hooks.js
CHANGED
|
@@ -1,215 +1,215 @@
|
|
|
1
|
-
const chalks = import("chalk")
|
|
2
|
-
|
|
3
|
-
const {createTmui,UpdateTmui} = require("./createTmui.js")
|
|
4
|
-
const {checkProject} = require("./dirTool.js")
|
|
5
|
-
const {selectedDir} = require("./selectedDir.js")
|
|
6
|
-
const osUtils = require("node-os-utils")
|
|
7
|
-
const {WebSocketServer} = require("ws")
|
|
8
|
-
const {execCmd, devRunApp, killChildAndGrandChildren, buildApp} = require("./cmdTool.js")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const wss = new WebSocketServer({ port: 6169 });
|
|
16
|
-
var client
|
|
17
|
-
var processList = [];
|
|
18
|
-
var runAppInfoList = [];
|
|
19
|
-
var wslist = [];
|
|
20
|
-
|
|
21
|
-
function uuid(len = 24, radix) {
|
|
22
|
-
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
23
|
-
var uuid = [], i;
|
|
24
|
-
radix = radix || chars.length;
|
|
25
|
-
if (len) {
|
|
26
|
-
// Compact form
|
|
27
|
-
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
|
|
28
|
-
} else {
|
|
29
|
-
// rfc4122, version 4 form
|
|
30
|
-
var r;
|
|
31
|
-
// rfc4122 requires these characters
|
|
32
|
-
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
33
|
-
uuid[14] = '4';
|
|
34
|
-
for (i = 0; i < 36; i++) {
|
|
35
|
-
if (!uuid[i]) {
|
|
36
|
-
r = 0 | Math.random() * 16;
|
|
37
|
-
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return uuid.join('');
|
|
46
|
-
}
|
|
47
|
-
function removeWs(id) {
|
|
48
|
-
const index = wslist.findIndex(function(el) {return el.uuid == id})
|
|
49
|
-
if (index > -1) {
|
|
50
|
-
wslist.splice(index, 1)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function send(arg) {
|
|
54
|
-
wslist.forEach(function(el) {
|
|
55
|
-
el.send(arg)
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
wss.on('connection', async function connection(ws) {
|
|
59
|
-
const chalk = (await chalks).default;
|
|
60
|
-
|
|
61
|
-
ws.uuid = uuid();
|
|
62
|
-
wslist.push(ws)
|
|
63
|
-
ws.on('error', console.error);
|
|
64
|
-
ws.on('message', function message(data) {
|
|
65
|
-
try {
|
|
66
|
-
|
|
67
|
-
let obj = JSON.parse(data)
|
|
68
|
-
if(obj.event!='getCpu'){
|
|
69
|
-
console.log(chalk.white(data))
|
|
70
|
-
}
|
|
71
|
-
// 执行命令
|
|
72
|
-
if (obj.event == 'cmd') {
|
|
73
|
-
execCmd(function (str) {
|
|
74
|
-
send(JSON.stringify({
|
|
75
|
-
event: 'info',
|
|
76
|
-
data: str
|
|
77
|
-
}))
|
|
78
|
-
}, function () {
|
|
79
|
-
send(JSON.stringify({
|
|
80
|
-
event: 'end',
|
|
81
|
-
data: ""
|
|
82
|
-
}))
|
|
83
|
-
}, obj.command)
|
|
84
|
-
// 选择文件目录。
|
|
85
|
-
} else if (obj.event == '18') {
|
|
86
|
-
|
|
87
|
-
selectedDir(function (str) {
|
|
88
|
-
send(JSON.stringify({
|
|
89
|
-
event: '18',
|
|
90
|
-
flag:'',
|
|
91
|
-
data: str
|
|
92
|
-
}))
|
|
93
|
-
}, function () {
|
|
94
|
-
send(JSON.stringify({
|
|
95
|
-
event: '18',
|
|
96
|
-
flag:'end',
|
|
97
|
-
data: ""
|
|
98
|
-
}))
|
|
99
|
-
}, obj.command)
|
|
100
|
-
// 查询目录项目的信息
|
|
101
|
-
} else if (obj.event == '17') {
|
|
102
|
-
let result = checkProject(obj.command)
|
|
103
|
-
let runfl = runAppInfoList.filter(function(el){ return el.id == result.id})
|
|
104
|
-
send(JSON.stringify({
|
|
105
|
-
event: '17',
|
|
106
|
-
data: result,
|
|
107
|
-
flag:'',
|
|
108
|
-
run: runfl
|
|
109
|
-
}))
|
|
110
|
-
send(JSON.stringify({
|
|
111
|
-
event: '17',
|
|
112
|
-
flag:'end',
|
|
113
|
-
data: ""
|
|
114
|
-
}))
|
|
115
|
-
/**运行项目dev:xxx */
|
|
116
|
-
} else if (obj.event == '1') {
|
|
117
|
-
|
|
118
|
-
const childrenProcess = devRunApp(wslist, obj.command)
|
|
119
|
-
if (childrenProcess) {
|
|
120
|
-
processList.push(childrenProcess)
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
/**关闭并退出运行的项目服务 */
|
|
124
|
-
} else if (obj.event == '2') {
|
|
125
|
-
try {
|
|
126
|
-
if (!obj.command) return;
|
|
127
|
-
// process.kill(Number(obj.command||0))
|
|
128
|
-
const pid = Number(obj.command || 0);
|
|
129
|
-
const index = processList.findIndex(function(el){ return el.pid == pid})
|
|
130
|
-
if (index > -1) {
|
|
131
|
-
// process.kill(sflit[0].pid)
|
|
132
|
-
killChildAndGrandChildren(processList[index].pid)
|
|
133
|
-
processList.splice(index, 1)
|
|
134
|
-
const index2 = runAppInfoList.findIndex(function(el){ return el.pid == pid})
|
|
135
|
-
runAppInfoList.splice(index2, 1)
|
|
136
|
-
}
|
|
137
|
-
} catch (error) {
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
/**编译应用build:xx */
|
|
141
|
-
} else if (obj.event == '3') {
|
|
142
|
-
const id = obj.command.data.id;
|
|
143
|
-
const childrenProcess = buildApp(wslist, obj.command, function() {
|
|
144
|
-
const index2 = runAppInfoList.findIndex(function(el){ return el.id == id})
|
|
145
|
-
console.log("编译结束")
|
|
146
|
-
if (index2 > -1) {
|
|
147
|
-
runAppInfoList.splice(index2, 1)
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
/**保存当前运行的用户信息。 */
|
|
151
|
-
} else if (obj.event == 'saveRunInfo') {
|
|
152
|
-
const index2 = runAppInfoList.findIndex(function(el){return el.id == obj.command.id})
|
|
153
|
-
if (index2 > -1) {
|
|
154
|
-
runAppInfoList.splice(index2, 1, obj.command)
|
|
155
|
-
} else {
|
|
156
|
-
runAppInfoList.push(obj.command)
|
|
157
|
-
}
|
|
158
|
-
/**获取系统使用率 */
|
|
159
|
-
} else if (obj.event == 'getCpu') {
|
|
160
|
-
|
|
161
|
-
Promise.all([osUtils.mem.info(),osUtils.cpu.usage()])
|
|
162
|
-
.then(function(arg){
|
|
163
|
-
send(JSON.stringify({
|
|
164
|
-
event: 'getCpu',
|
|
165
|
-
data: {
|
|
166
|
-
memUsage:arg[0].usedMemPercentage.toFixed(2),
|
|
167
|
-
cpuUsage:arg[1].toFixed(2)
|
|
168
|
-
}
|
|
169
|
-
}))
|
|
170
|
-
})
|
|
171
|
-
}else if(obj.event=='21'){
|
|
172
|
-
// npm view @dcloudio/uni-app versions --json
|
|
173
|
-
UpdateTmui(obj.command,function(str){
|
|
174
|
-
send(JSON.stringify({
|
|
175
|
-
event: 'info',
|
|
176
|
-
flag:'',
|
|
177
|
-
data: str
|
|
178
|
-
}))
|
|
179
|
-
},function(){
|
|
180
|
-
send(JSON.stringify({
|
|
181
|
-
event: '21',
|
|
182
|
-
flag:'end',
|
|
183
|
-
data: '完成'
|
|
184
|
-
}))
|
|
185
|
-
})
|
|
186
|
-
// 创建项目.
|
|
187
|
-
}else if(obj.event=='22'){
|
|
188
|
-
// npm view @dcloudio/uni-app versions --json
|
|
189
|
-
createTmui(obj.command,function(str){
|
|
190
|
-
send(JSON.stringify({
|
|
191
|
-
event: 'info',
|
|
192
|
-
flag:'',
|
|
193
|
-
data: str
|
|
194
|
-
}))
|
|
195
|
-
},function(prejectdir){
|
|
196
|
-
send(JSON.stringify({
|
|
197
|
-
event: '22',
|
|
198
|
-
flag:'end',
|
|
199
|
-
data: prejectdir
|
|
200
|
-
}))
|
|
201
|
-
})
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
} catch (error) {
|
|
206
|
-
console.log(chalk.red(data))
|
|
207
|
-
console.log(chalk.red(error))
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
ws.on('close', function() {
|
|
211
|
-
removeWs(ws.uuid)
|
|
212
|
-
})
|
|
213
|
-
send('something');
|
|
214
|
-
});
|
|
215
|
-
|
|
1
|
+
const chalks = import("chalk")
|
|
2
|
+
|
|
3
|
+
const {createTmui,UpdateTmui} = require("./createTmui.js")
|
|
4
|
+
const {checkProject} = require("./dirTool.js")
|
|
5
|
+
const {selectedDir} = require("./selectedDir.js")
|
|
6
|
+
const osUtils = require("node-os-utils")
|
|
7
|
+
const {WebSocketServer} = require("ws")
|
|
8
|
+
const {execCmd, devRunApp, killChildAndGrandChildren, buildApp} = require("./cmdTool.js")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const wss = new WebSocketServer({ port: 6169 });
|
|
16
|
+
var client
|
|
17
|
+
var processList = [];
|
|
18
|
+
var runAppInfoList = [];
|
|
19
|
+
var wslist = [];
|
|
20
|
+
|
|
21
|
+
function uuid(len = 24, radix) {
|
|
22
|
+
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
23
|
+
var uuid = [], i;
|
|
24
|
+
radix = radix || chars.length;
|
|
25
|
+
if (len) {
|
|
26
|
+
// Compact form
|
|
27
|
+
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
|
|
28
|
+
} else {
|
|
29
|
+
// rfc4122, version 4 form
|
|
30
|
+
var r;
|
|
31
|
+
// rfc4122 requires these characters
|
|
32
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
33
|
+
uuid[14] = '4';
|
|
34
|
+
for (i = 0; i < 36; i++) {
|
|
35
|
+
if (!uuid[i]) {
|
|
36
|
+
r = 0 | Math.random() * 16;
|
|
37
|
+
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return uuid.join('');
|
|
46
|
+
}
|
|
47
|
+
function removeWs(id) {
|
|
48
|
+
const index = wslist.findIndex(function(el) {return el.uuid == id})
|
|
49
|
+
if (index > -1) {
|
|
50
|
+
wslist.splice(index, 1)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function send(arg) {
|
|
54
|
+
wslist.forEach(function(el) {
|
|
55
|
+
el.send(arg)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
wss.on('connection', async function connection(ws) {
|
|
59
|
+
const chalk = (await chalks).default;
|
|
60
|
+
|
|
61
|
+
ws.uuid = uuid();
|
|
62
|
+
wslist.push(ws)
|
|
63
|
+
ws.on('error', console.error);
|
|
64
|
+
ws.on('message', function message(data) {
|
|
65
|
+
try {
|
|
66
|
+
|
|
67
|
+
let obj = JSON.parse(data)
|
|
68
|
+
if(obj.event!='getCpu'){
|
|
69
|
+
// console.log(chalk.white(data))
|
|
70
|
+
}
|
|
71
|
+
// 执行命令
|
|
72
|
+
if (obj.event == 'cmd') {
|
|
73
|
+
execCmd(function (str) {
|
|
74
|
+
send(JSON.stringify({
|
|
75
|
+
event: 'info',
|
|
76
|
+
data: str
|
|
77
|
+
}))
|
|
78
|
+
}, function () {
|
|
79
|
+
send(JSON.stringify({
|
|
80
|
+
event: 'end',
|
|
81
|
+
data: ""
|
|
82
|
+
}))
|
|
83
|
+
}, obj.command)
|
|
84
|
+
// 选择文件目录。
|
|
85
|
+
} else if (obj.event == '18') {
|
|
86
|
+
|
|
87
|
+
selectedDir(function (str) {
|
|
88
|
+
send(JSON.stringify({
|
|
89
|
+
event: '18',
|
|
90
|
+
flag:'',
|
|
91
|
+
data: str
|
|
92
|
+
}))
|
|
93
|
+
}, function () {
|
|
94
|
+
send(JSON.stringify({
|
|
95
|
+
event: '18',
|
|
96
|
+
flag:'end',
|
|
97
|
+
data: ""
|
|
98
|
+
}))
|
|
99
|
+
}, obj.command)
|
|
100
|
+
// 查询目录项目的信息
|
|
101
|
+
} else if (obj.event == '17') {
|
|
102
|
+
let result = checkProject(obj.command)
|
|
103
|
+
let runfl = runAppInfoList.filter(function(el){ return el.id == result.id})
|
|
104
|
+
send(JSON.stringify({
|
|
105
|
+
event: '17',
|
|
106
|
+
data: result,
|
|
107
|
+
flag:'',
|
|
108
|
+
run: runfl
|
|
109
|
+
}))
|
|
110
|
+
send(JSON.stringify({
|
|
111
|
+
event: '17',
|
|
112
|
+
flag:'end',
|
|
113
|
+
data: ""
|
|
114
|
+
}))
|
|
115
|
+
/**运行项目dev:xxx */
|
|
116
|
+
} else if (obj.event == '1') {
|
|
117
|
+
|
|
118
|
+
const childrenProcess = devRunApp(wslist, obj.command)
|
|
119
|
+
if (childrenProcess) {
|
|
120
|
+
processList.push(childrenProcess)
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
/**关闭并退出运行的项目服务 */
|
|
124
|
+
} else if (obj.event == '2') {
|
|
125
|
+
try {
|
|
126
|
+
if (!obj.command) return;
|
|
127
|
+
// process.kill(Number(obj.command||0))
|
|
128
|
+
const pid = Number(obj.command || 0);
|
|
129
|
+
const index = processList.findIndex(function(el){ return el.pid == pid})
|
|
130
|
+
if (index > -1) {
|
|
131
|
+
// process.kill(sflit[0].pid)
|
|
132
|
+
killChildAndGrandChildren(processList[index].pid)
|
|
133
|
+
processList.splice(index, 1)
|
|
134
|
+
const index2 = runAppInfoList.findIndex(function(el){ return el.pid == pid})
|
|
135
|
+
runAppInfoList.splice(index2, 1)
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
/**编译应用build:xx */
|
|
141
|
+
} else if (obj.event == '3') {
|
|
142
|
+
const id = obj.command.data.id;
|
|
143
|
+
const childrenProcess = buildApp(wslist, obj.command, function() {
|
|
144
|
+
const index2 = runAppInfoList.findIndex(function(el){ return el.id == id})
|
|
145
|
+
console.log("编译结束")
|
|
146
|
+
if (index2 > -1) {
|
|
147
|
+
runAppInfoList.splice(index2, 1)
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
/**保存当前运行的用户信息。 */
|
|
151
|
+
} else if (obj.event == 'saveRunInfo') {
|
|
152
|
+
const index2 = runAppInfoList.findIndex(function(el){return el.id == obj.command.id})
|
|
153
|
+
if (index2 > -1) {
|
|
154
|
+
runAppInfoList.splice(index2, 1, obj.command)
|
|
155
|
+
} else {
|
|
156
|
+
runAppInfoList.push(obj.command)
|
|
157
|
+
}
|
|
158
|
+
/**获取系统使用率 */
|
|
159
|
+
} else if (obj.event == 'getCpu') {
|
|
160
|
+
|
|
161
|
+
Promise.all([osUtils.mem.info(),osUtils.cpu.usage()])
|
|
162
|
+
.then(function(arg){
|
|
163
|
+
send(JSON.stringify({
|
|
164
|
+
event: 'getCpu',
|
|
165
|
+
data: {
|
|
166
|
+
memUsage:arg[0].usedMemPercentage.toFixed(2),
|
|
167
|
+
cpuUsage:arg[1].toFixed(2)
|
|
168
|
+
}
|
|
169
|
+
}))
|
|
170
|
+
})
|
|
171
|
+
}else if(obj.event=='21'){
|
|
172
|
+
// npm view @dcloudio/uni-app versions --json
|
|
173
|
+
UpdateTmui(obj.command,function(str){
|
|
174
|
+
send(JSON.stringify({
|
|
175
|
+
event: 'info',
|
|
176
|
+
flag:'',
|
|
177
|
+
data: str
|
|
178
|
+
}))
|
|
179
|
+
},function(){
|
|
180
|
+
send(JSON.stringify({
|
|
181
|
+
event: '21',
|
|
182
|
+
flag:'end',
|
|
183
|
+
data: '完成'
|
|
184
|
+
}))
|
|
185
|
+
})
|
|
186
|
+
// 创建项目.
|
|
187
|
+
}else if(obj.event=='22'){
|
|
188
|
+
// npm view @dcloudio/uni-app versions --json
|
|
189
|
+
createTmui(obj.command,function(str){
|
|
190
|
+
send(JSON.stringify({
|
|
191
|
+
event: 'info',
|
|
192
|
+
flag:'',
|
|
193
|
+
data: str
|
|
194
|
+
}))
|
|
195
|
+
},function(prejectdir){
|
|
196
|
+
send(JSON.stringify({
|
|
197
|
+
event: '22',
|
|
198
|
+
flag:'end',
|
|
199
|
+
data: prejectdir
|
|
200
|
+
}))
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.log(chalk.red(data))
|
|
207
|
+
console.log(chalk.red(error))
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
ws.on('close', function() {
|
|
211
|
+
removeWs(ws.uuid)
|
|
212
|
+
})
|
|
213
|
+
send('something');
|
|
214
|
+
});
|
|
215
|
+
|