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/cmdTool.js
CHANGED
|
@@ -1,229 +1,229 @@
|
|
|
1
|
-
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const fs = require("fs")
|
|
4
|
-
const {spawn,exec} = require("child_process")
|
|
5
|
-
const process = require("process")
|
|
6
|
-
const codecs = require("codecs")
|
|
7
|
-
const psTree = require("ps-tree")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function detectEncoding(str) {
|
|
13
|
-
const buffer = Buffer.from(str);
|
|
14
|
-
if (buffer[0] < 128) {
|
|
15
|
-
return 'ascii';
|
|
16
|
-
} else if (buffer[0] < 224) {
|
|
17
|
-
return 'utf8';
|
|
18
|
-
} else if (buffer[0] < 240) {
|
|
19
|
-
return 'utf16le';
|
|
20
|
-
} else {
|
|
21
|
-
return 'utf32le';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function send(ws, arg) {
|
|
27
|
-
ws.forEach(function(el){
|
|
28
|
-
el.send(arg)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function execCmd(cb, end, command) {
|
|
33
|
-
try {
|
|
34
|
-
// const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
|
|
35
|
-
const spawnObj = exec(command, {
|
|
36
|
-
encoding: 'binary'
|
|
37
|
-
})
|
|
38
|
-
// const spawnObj = spawn("npm.cmd",["run","dev:h5"],{detached:true})
|
|
39
|
-
|
|
40
|
-
spawnObj.stdout?.on('data', function(chunk) {
|
|
41
|
-
// Buffer.from(chunk,'binary').toString('utf-8')
|
|
42
|
-
// var str = iconv.decode(, 'cp936');
|
|
43
|
-
if (cb) {
|
|
44
|
-
let str = Buffer.from(chunk, 'binary').toString("utf8")
|
|
45
|
-
|
|
46
|
-
var codecsDecode = codecs(detectEncoding(chunk))
|
|
47
|
-
let strii = codecsDecode.decode(Buffer.from(chunk, 'binary')).toString('utf-8');
|
|
48
|
-
// 去除控制符
|
|
49
|
-
const cleanStr = strii.replace(
|
|
50
|
-
/[\u001B\u009B][[\]()#;?]*(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[A-PR-Za-z~])/g, '');
|
|
51
|
-
cb(cleanStr, spawnObj.pid || 0)
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
spawnObj.addListener('error', function(err) {
|
|
55
|
-
if (end) {
|
|
56
|
-
cb(err)
|
|
57
|
-
end('error')
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
spawnObj.on('close', function(code) {
|
|
61
|
-
// console.log('close code : ' + code);
|
|
62
|
-
if (end) {
|
|
63
|
-
end('end')
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
spawnObj.on('exit', function(code){
|
|
67
|
-
// console.log('exit code : ' + code);
|
|
68
|
-
if (end) {
|
|
69
|
-
end('end')
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return spawnObj;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (end) {
|
|
76
|
-
cb(error)
|
|
77
|
-
end('end')
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// 杀死子进程及其所有子孙进程
|
|
83
|
-
function killChildAndGrandChildren(pid) {
|
|
84
|
-
|
|
85
|
-
if (process.platform === 'win32') {
|
|
86
|
-
// 在 Windows 系统上执行的代码
|
|
87
|
-
const command = `taskkill /T /F /PID ${pid}`;
|
|
88
|
-
exec(command, function(err, stdout, stderr){
|
|
89
|
-
if (err) {
|
|
90
|
-
console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
|
|
91
|
-
}
|
|
92
|
-
// console.log(`stdout: ${stdout}`);
|
|
93
|
-
// console.error(`stderr: ${stderr}`);
|
|
94
|
-
});
|
|
95
|
-
} else {
|
|
96
|
-
// 在 Linux/Unix/Mac 系统上执行的代码
|
|
97
|
-
psTree(pid, function(err, children){
|
|
98
|
-
// 使用 kill 命令杀死所有子孙进程
|
|
99
|
-
console.log(5555)
|
|
100
|
-
exec(`kill -TERM ${pid} ${children.map(function(c) {return c.PID}).join(' ')}`);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function devRunApp(ws, obj) {
|
|
107
|
-
|
|
108
|
-
const nowcd = process.cwd();
|
|
109
|
-
process.chdir(path.normalize(obj.data.path));
|
|
110
|
-
|
|
111
|
-
const childreProcess = execCmd(function(msg, pid) {
|
|
112
|
-
send(ws, JSON.stringify({
|
|
113
|
-
event: 'info',
|
|
114
|
-
data: msg
|
|
115
|
-
}))
|
|
116
|
-
const reg_1 = /http:\/\/localhost(:\d+)?(\/[^\s]*)?/g;
|
|
117
|
-
const reg_2 = /http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?(\/[^\s]*)?/g;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (reg_1.test(msg)) {
|
|
121
|
-
send(ws, JSON.stringify({
|
|
122
|
-
event: '1',
|
|
123
|
-
data: {
|
|
124
|
-
id: obj.data.id,
|
|
125
|
-
msg: msg.match(reg_1)[0],
|
|
126
|
-
pid: pid
|
|
127
|
-
}
|
|
128
|
-
}))
|
|
129
|
-
}
|
|
130
|
-
if (reg_2.test(msg)) {
|
|
131
|
-
send(ws, JSON.stringify({
|
|
132
|
-
event: '1',
|
|
133
|
-
data: {
|
|
134
|
-
id: obj.data.id,
|
|
135
|
-
msg: msg.match(reg_2)[0],
|
|
136
|
-
pid: pid
|
|
137
|
-
}
|
|
138
|
-
}))
|
|
139
|
-
}
|
|
140
|
-
if (msg.indexOf('ready') > -1) {
|
|
141
|
-
send(ws, JSON.stringify({
|
|
142
|
-
event: 'ready',
|
|
143
|
-
data: {
|
|
144
|
-
id: obj.data.id,
|
|
145
|
-
pid: pid
|
|
146
|
-
},
|
|
147
|
-
}))
|
|
148
|
-
}
|
|
149
|
-
}, function(type) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (type == 'end') {
|
|
153
|
-
send(ws, JSON.stringify({
|
|
154
|
-
event: 'end',
|
|
155
|
-
data: {
|
|
156
|
-
id: obj.data.id
|
|
157
|
-
},
|
|
158
|
-
}))
|
|
159
|
-
} else {
|
|
160
|
-
send(ws, JSON.stringify({
|
|
161
|
-
event: 'error',
|
|
162
|
-
data: {
|
|
163
|
-
id: obj.data.id
|
|
164
|
-
},
|
|
165
|
-
}))
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}, obj.command)
|
|
170
|
-
|
|
171
|
-
return childreProcess;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function buildApp(ws, obj, end) {
|
|
175
|
-
|
|
176
|
-
const nowcd = process.cwd();
|
|
177
|
-
process.chdir(path.normalize(obj.data.path));
|
|
178
|
-
|
|
179
|
-
const childreProcess = execCmd(function(msg, pid) {
|
|
180
|
-
send(ws, JSON.stringify({
|
|
181
|
-
event: 'info',
|
|
182
|
-
data: msg
|
|
183
|
-
}))
|
|
184
|
-
if (msg.indexOf('DONE') > -1) {
|
|
185
|
-
send(ws, JSON.stringify({
|
|
186
|
-
event: 'buildSucess',
|
|
187
|
-
data: {
|
|
188
|
-
id: obj.data.id,
|
|
189
|
-
pid: pid
|
|
190
|
-
},
|
|
191
|
-
}))
|
|
192
|
-
}
|
|
193
|
-
}, function(type) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (type == 'end') {
|
|
197
|
-
send(ws, JSON.stringify({
|
|
198
|
-
event: 'end',
|
|
199
|
-
data: {
|
|
200
|
-
id: obj.data.id
|
|
201
|
-
},
|
|
202
|
-
}))
|
|
203
|
-
|
|
204
|
-
console.log('编译完成')
|
|
205
|
-
} else {
|
|
206
|
-
send(ws, JSON.stringify({
|
|
207
|
-
event: 'error',
|
|
208
|
-
data: {
|
|
209
|
-
id: obj.data.id
|
|
210
|
-
},
|
|
211
|
-
}))
|
|
212
|
-
}
|
|
213
|
-
if (end) {
|
|
214
|
-
end()
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
}, obj.command)
|
|
218
|
-
|
|
219
|
-
return childreProcess;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
module.exports = {
|
|
223
|
-
execCmd,
|
|
224
|
-
killChildAndGrandChildren,
|
|
225
|
-
devRunApp,
|
|
226
|
-
buildApp
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const {spawn,exec} = require("child_process")
|
|
5
|
+
const process = require("process")
|
|
6
|
+
const codecs = require("codecs")
|
|
7
|
+
const psTree = require("ps-tree")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
function detectEncoding(str) {
|
|
13
|
+
const buffer = Buffer.from(str);
|
|
14
|
+
if (buffer[0] < 128) {
|
|
15
|
+
return 'ascii';
|
|
16
|
+
} else if (buffer[0] < 224) {
|
|
17
|
+
return 'utf8';
|
|
18
|
+
} else if (buffer[0] < 240) {
|
|
19
|
+
return 'utf16le';
|
|
20
|
+
} else {
|
|
21
|
+
return 'utf32le';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function send(ws, arg) {
|
|
27
|
+
ws.forEach(function(el){
|
|
28
|
+
el.send(arg)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function execCmd(cb, end, command) {
|
|
33
|
+
try {
|
|
34
|
+
// const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
|
|
35
|
+
const spawnObj = exec(command, {
|
|
36
|
+
encoding: 'binary'
|
|
37
|
+
})
|
|
38
|
+
// const spawnObj = spawn("npm.cmd",["run","dev:h5"],{detached:true})
|
|
39
|
+
|
|
40
|
+
spawnObj.stdout?.on('data', function(chunk) {
|
|
41
|
+
// Buffer.from(chunk,'binary').toString('utf-8')
|
|
42
|
+
// var str = iconv.decode(, 'cp936');
|
|
43
|
+
if (cb) {
|
|
44
|
+
let str = Buffer.from(chunk, 'binary').toString("utf8")
|
|
45
|
+
|
|
46
|
+
var codecsDecode = codecs(detectEncoding(chunk))
|
|
47
|
+
let strii = codecsDecode.decode(Buffer.from(chunk, 'binary')).toString('utf-8');
|
|
48
|
+
// 去除控制符
|
|
49
|
+
const cleanStr = strii.replace(
|
|
50
|
+
/[\u001B\u009B][[\]()#;?]*(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[A-PR-Za-z~])/g, '');
|
|
51
|
+
cb(cleanStr, spawnObj.pid || 0)
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
spawnObj.addListener('error', function(err) {
|
|
55
|
+
if (end) {
|
|
56
|
+
cb(err)
|
|
57
|
+
end('error')
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
spawnObj.on('close', function(code) {
|
|
61
|
+
// console.log('close code : ' + code);
|
|
62
|
+
if (end) {
|
|
63
|
+
end('end')
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
spawnObj.on('exit', function(code){
|
|
67
|
+
// console.log('exit code : ' + code);
|
|
68
|
+
if (end) {
|
|
69
|
+
end('end')
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return spawnObj;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (end) {
|
|
76
|
+
cb(error)
|
|
77
|
+
end('end')
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// 杀死子进程及其所有子孙进程
|
|
83
|
+
function killChildAndGrandChildren(pid) {
|
|
84
|
+
|
|
85
|
+
if (process.platform === 'win32') {
|
|
86
|
+
// 在 Windows 系统上执行的代码
|
|
87
|
+
const command = `taskkill /T /F /PID ${pid}`;
|
|
88
|
+
exec(command, function(err, stdout, stderr){
|
|
89
|
+
if (err) {
|
|
90
|
+
console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
|
|
91
|
+
}
|
|
92
|
+
// console.log(`stdout: ${stdout}`);
|
|
93
|
+
// console.error(`stderr: ${stderr}`);
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
// 在 Linux/Unix/Mac 系统上执行的代码
|
|
97
|
+
psTree(pid, function(err, children){
|
|
98
|
+
// 使用 kill 命令杀死所有子孙进程
|
|
99
|
+
console.log(5555)
|
|
100
|
+
exec(`kill -TERM ${pid} ${children.map(function(c) {return c.PID}).join(' ')}`);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function devRunApp(ws, obj) {
|
|
107
|
+
|
|
108
|
+
const nowcd = process.cwd();
|
|
109
|
+
process.chdir(path.normalize(obj.data.path));
|
|
110
|
+
|
|
111
|
+
const childreProcess = execCmd(function(msg, pid) {
|
|
112
|
+
send(ws, JSON.stringify({
|
|
113
|
+
event: 'info',
|
|
114
|
+
data: msg
|
|
115
|
+
}))
|
|
116
|
+
const reg_1 = /http:\/\/localhost(:\d+)?(\/[^\s]*)?/g;
|
|
117
|
+
const reg_2 = /http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?(\/[^\s]*)?/g;
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if (reg_1.test(msg)) {
|
|
121
|
+
send(ws, JSON.stringify({
|
|
122
|
+
event: '1',
|
|
123
|
+
data: {
|
|
124
|
+
id: obj.data.id,
|
|
125
|
+
msg: msg.match(reg_1)[0],
|
|
126
|
+
pid: pid
|
|
127
|
+
}
|
|
128
|
+
}))
|
|
129
|
+
}
|
|
130
|
+
if (reg_2.test(msg)) {
|
|
131
|
+
send(ws, JSON.stringify({
|
|
132
|
+
event: '1',
|
|
133
|
+
data: {
|
|
134
|
+
id: obj.data.id,
|
|
135
|
+
msg: msg.match(reg_2)[0],
|
|
136
|
+
pid: pid
|
|
137
|
+
}
|
|
138
|
+
}))
|
|
139
|
+
}
|
|
140
|
+
if (msg.indexOf('ready') > -1) {
|
|
141
|
+
send(ws, JSON.stringify({
|
|
142
|
+
event: 'ready',
|
|
143
|
+
data: {
|
|
144
|
+
id: obj.data.id,
|
|
145
|
+
pid: pid
|
|
146
|
+
},
|
|
147
|
+
}))
|
|
148
|
+
}
|
|
149
|
+
}, function(type) {
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if (type == 'end') {
|
|
153
|
+
send(ws, JSON.stringify({
|
|
154
|
+
event: 'end',
|
|
155
|
+
data: {
|
|
156
|
+
id: obj.data.id
|
|
157
|
+
},
|
|
158
|
+
}))
|
|
159
|
+
} else {
|
|
160
|
+
send(ws, JSON.stringify({
|
|
161
|
+
event: 'error',
|
|
162
|
+
data: {
|
|
163
|
+
id: obj.data.id
|
|
164
|
+
},
|
|
165
|
+
}))
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
}, obj.command)
|
|
170
|
+
|
|
171
|
+
return childreProcess;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function buildApp(ws, obj, end) {
|
|
175
|
+
|
|
176
|
+
const nowcd = process.cwd();
|
|
177
|
+
process.chdir(path.normalize(obj.data.path));
|
|
178
|
+
|
|
179
|
+
const childreProcess = execCmd(function(msg, pid) {
|
|
180
|
+
send(ws, JSON.stringify({
|
|
181
|
+
event: 'info',
|
|
182
|
+
data: msg
|
|
183
|
+
}))
|
|
184
|
+
if (msg.indexOf('DONE') > -1) {
|
|
185
|
+
send(ws, JSON.stringify({
|
|
186
|
+
event: 'buildSucess',
|
|
187
|
+
data: {
|
|
188
|
+
id: obj.data.id,
|
|
189
|
+
pid: pid
|
|
190
|
+
},
|
|
191
|
+
}))
|
|
192
|
+
}
|
|
193
|
+
}, function(type) {
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if (type == 'end') {
|
|
197
|
+
send(ws, JSON.stringify({
|
|
198
|
+
event: 'end',
|
|
199
|
+
data: {
|
|
200
|
+
id: obj.data.id
|
|
201
|
+
},
|
|
202
|
+
}))
|
|
203
|
+
|
|
204
|
+
console.log('编译完成')
|
|
205
|
+
} else {
|
|
206
|
+
send(ws, JSON.stringify({
|
|
207
|
+
event: 'error',
|
|
208
|
+
data: {
|
|
209
|
+
id: obj.data.id
|
|
210
|
+
},
|
|
211
|
+
}))
|
|
212
|
+
}
|
|
213
|
+
if (end) {
|
|
214
|
+
end()
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
}, obj.command)
|
|
218
|
+
|
|
219
|
+
return childreProcess;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
module.exports = {
|
|
223
|
+
execCmd,
|
|
224
|
+
killChildAndGrandChildren,
|
|
225
|
+
devRunApp,
|
|
226
|
+
buildApp
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|