tmui-cli 1.1.2 → 1.1.4
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/README.md +5 -4
- package/bin/cmd/cmdTool.js +219 -0
- package/bin/cmd/dirTool.js +174 -0
- package/bin/cmd/selectedDir.js +27 -0
- package/bin/donet.js +50 -0
- package/bin/hooks.js +170 -0
- package/bin/tmui.js +109 -22
- package/package.json +70 -52
- package/src/create.js +23 -6
- package/src/create4xhbx.js +98 -0
- package/src/createHbx.js +18 -4
- package/src/rcli.js +19 -2
- package/src/rhbx.js +16 -19
package/README.md
CHANGED
|
@@ -21,10 +21,11 @@ npm -g install tmui-cli
|
|
|
21
21
|
|
|
22
22
|
#### 命令解释
|
|
23
23
|
|
|
24
|
-
0. tmui
|
|
25
|
-
1. tmui
|
|
26
|
-
2. tmui
|
|
27
|
-
3. tmui
|
|
24
|
+
0. tmui 4x 创建uniappx 平台的hbx tmui4.0x项目
|
|
25
|
+
1. tmui cli 创建uniapp 平台的cli初始项目,内部已经包含了tmui最新框架(自动更新)
|
|
26
|
+
2. tmui hbx 创建uniapp 平台的HBX初始项目,内部已经包含了tmui最新框架(自动更新)
|
|
27
|
+
3. tmui rcli 为【已有】uniapp 平台的cli项目,更新和下载tmui最新框架(自动更新)
|
|
28
|
+
4. tmui rhbx 为【已有】uniapp 平台的HBX项目,更新和下载tmui最新框架(自动更新)
|
|
28
29
|
4. tmui use 为保姆级引导式下载安装上述功能项目。
|
|
29
30
|
|
|
30
31
|
#### 注意事项
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { spawn, exec } = require('child_process');
|
|
4
|
+
const process = require('process');
|
|
5
|
+
var codecs = require('codecs')
|
|
6
|
+
const psTree = require('ps-tree');
|
|
7
|
+
var iconv = require('iconv-lite');
|
|
8
|
+
|
|
9
|
+
function detectEncoding(str) {
|
|
10
|
+
const buffer = Buffer.from(str);
|
|
11
|
+
if (buffer[0] < 128) {
|
|
12
|
+
return 'ascii';
|
|
13
|
+
} else if (buffer[0] < 224) {
|
|
14
|
+
return 'utf8';
|
|
15
|
+
} else if (buffer[0] < 240) {
|
|
16
|
+
return 'utf16le';
|
|
17
|
+
} else {
|
|
18
|
+
return 'utf32le';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function send(ws,arg){
|
|
24
|
+
ws.forEach(el=>{
|
|
25
|
+
el.send(arg)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function execCmd(cb, end, command) {
|
|
30
|
+
try {
|
|
31
|
+
// const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
|
|
32
|
+
const spawnObj = exec(command, { encoding: 'binary' })
|
|
33
|
+
// const spawnObj = spawn("npm.cmd",["run","dev:h5"],{detached:true})
|
|
34
|
+
|
|
35
|
+
spawnObj.stdout?.on('data', function (chunk) {
|
|
36
|
+
// Buffer.from(chunk,'binary').toString('utf-8')
|
|
37
|
+
// var str = iconv.decode(, 'cp936');
|
|
38
|
+
if (cb) {
|
|
39
|
+
let str = Buffer.from(chunk, 'binary').toString("utf8")
|
|
40
|
+
|
|
41
|
+
var codecsDecode = codecs(detectEncoding(chunk))
|
|
42
|
+
let strii = codecsDecode.decode(Buffer.from(chunk,'binary')).toString('utf-8');
|
|
43
|
+
// 去除控制符
|
|
44
|
+
const cleanStr = strii.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[A-PR-Za-z~])/g, '');
|
|
45
|
+
cb(cleanStr,spawnObj.pid||0)
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
spawnObj.addListener('error', (err) => {
|
|
49
|
+
if (end) {
|
|
50
|
+
cb(err)
|
|
51
|
+
end('error')
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
spawnObj.on('close', function (code) {
|
|
55
|
+
// console.log('close code : ' + code);
|
|
56
|
+
if (end) {
|
|
57
|
+
end('end')
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
spawnObj.on('exit', (code) => {
|
|
61
|
+
// console.log('exit code : ' + code);
|
|
62
|
+
if (end) {
|
|
63
|
+
end('end')
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return spawnObj;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (end) {
|
|
70
|
+
cb(error)
|
|
71
|
+
end('end')
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// 杀死子进程及其所有子孙进程
|
|
77
|
+
function killChildAndGrandChildren(pid) {
|
|
78
|
+
|
|
79
|
+
if (process.platform === 'win32') {
|
|
80
|
+
// 在 Windows 系统上执行的代码
|
|
81
|
+
const command = `taskkill /T /F /PID ${pid}`;
|
|
82
|
+
exec(command, (err, stdout, stderr) => {
|
|
83
|
+
if (err) {
|
|
84
|
+
console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
|
|
85
|
+
}
|
|
86
|
+
// console.log(`stdout: ${stdout}`);
|
|
87
|
+
// console.error(`stderr: ${stderr}`);
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
// 在 Linux/Unix/Mac 系统上执行的代码
|
|
91
|
+
psTree(pid, (err, children) => {
|
|
92
|
+
// 使用 kill 命令杀死所有子孙进程
|
|
93
|
+
console.log(5555)
|
|
94
|
+
exec(`kill -TERM ${pid} ${children.map(c => c.PID).join(' ')}`);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
function devRunApp(ws, obj) {
|
|
100
|
+
|
|
101
|
+
const nowcd = process.cwd();
|
|
102
|
+
process.chdir(path.normalize(obj.data.path));
|
|
103
|
+
|
|
104
|
+
const childreProcess = execCmd(function (msg,pid) {
|
|
105
|
+
send(ws,JSON.stringify({
|
|
106
|
+
event: 'info',
|
|
107
|
+
data: msg
|
|
108
|
+
}))
|
|
109
|
+
const reg_1 = /http:\/\/localhost(:\d+)?(\/[^\s]*)?/g;
|
|
110
|
+
const reg_2 = /http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?(\/[^\s]*)?/g;
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if(reg_1.test(msg)){
|
|
114
|
+
send(ws,JSON.stringify({
|
|
115
|
+
event: '1',
|
|
116
|
+
data: {
|
|
117
|
+
id:obj.data.id,
|
|
118
|
+
msg:msg.match(reg_1)[0],
|
|
119
|
+
pid:pid
|
|
120
|
+
}
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
123
|
+
if(reg_2.test(msg)){
|
|
124
|
+
send(ws,JSON.stringify({
|
|
125
|
+
event: '1',
|
|
126
|
+
data: {
|
|
127
|
+
id:obj.data.id,
|
|
128
|
+
msg:msg.match(reg_2)[0],
|
|
129
|
+
pid:pid
|
|
130
|
+
}
|
|
131
|
+
}))
|
|
132
|
+
}
|
|
133
|
+
if(msg.indexOf('ready')>-1){
|
|
134
|
+
send(ws,JSON.stringify({
|
|
135
|
+
event: 'ready',
|
|
136
|
+
data: {
|
|
137
|
+
id:obj.data.id,
|
|
138
|
+
pid:pid
|
|
139
|
+
},
|
|
140
|
+
}))
|
|
141
|
+
}
|
|
142
|
+
}, function (type) {
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if(type=='end'){
|
|
146
|
+
send(ws,JSON.stringify({
|
|
147
|
+
event: 'end',
|
|
148
|
+
data: {
|
|
149
|
+
id:obj.data.id
|
|
150
|
+
},
|
|
151
|
+
}))
|
|
152
|
+
}else{
|
|
153
|
+
send(ws,JSON.stringify({
|
|
154
|
+
event: 'error',
|
|
155
|
+
data: {
|
|
156
|
+
id:obj.data.id
|
|
157
|
+
},
|
|
158
|
+
}))
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
}, obj.command)
|
|
163
|
+
|
|
164
|
+
return childreProcess;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function buildApp(ws, obj,end) {
|
|
168
|
+
|
|
169
|
+
const nowcd = process.cwd();
|
|
170
|
+
process.chdir(path.normalize(obj.data.path));
|
|
171
|
+
|
|
172
|
+
const childreProcess = execCmd(function (msg,pid) {
|
|
173
|
+
send(ws,JSON.stringify({
|
|
174
|
+
event: 'info',
|
|
175
|
+
data: msg
|
|
176
|
+
}))
|
|
177
|
+
if(msg.indexOf('DONE')>-1){
|
|
178
|
+
send(ws,JSON.stringify({
|
|
179
|
+
event: 'buildSucess',
|
|
180
|
+
data: {
|
|
181
|
+
id:obj.data.id,
|
|
182
|
+
pid:pid
|
|
183
|
+
},
|
|
184
|
+
}))
|
|
185
|
+
}
|
|
186
|
+
}, function (type) {
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
if(type=='end'){
|
|
190
|
+
send(ws,JSON.stringify({
|
|
191
|
+
event: 'end',
|
|
192
|
+
data: {
|
|
193
|
+
id:obj.data.id
|
|
194
|
+
},
|
|
195
|
+
}))
|
|
196
|
+
|
|
197
|
+
console.log('编译完成')
|
|
198
|
+
}else{
|
|
199
|
+
send(ws,JSON.stringify({
|
|
200
|
+
event: 'error',
|
|
201
|
+
data: {
|
|
202
|
+
id:obj.data.id
|
|
203
|
+
},
|
|
204
|
+
}))
|
|
205
|
+
}
|
|
206
|
+
if(end){
|
|
207
|
+
end()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
}, obj.command)
|
|
211
|
+
|
|
212
|
+
return childreProcess;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
exports.execCmd = execCmd;
|
|
217
|
+
exports.devRunApp = devRunApp;
|
|
218
|
+
exports.killChildAndGrandChildren = killChildAndGrandChildren;
|
|
219
|
+
exports.buildApp = buildApp;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const process = require('process');
|
|
5
|
+
const { spawn, exec } = require('child_process');
|
|
6
|
+
|
|
7
|
+
function getJsonFiles(jsonPath) {
|
|
8
|
+
let jsonFiles = [];
|
|
9
|
+
function findJsonFile(www) {
|
|
10
|
+
let files = fs.readdirSync(www);
|
|
11
|
+
files.forEach(function (item, index) {
|
|
12
|
+
let fPath = path.join(www, item);
|
|
13
|
+
let stat = fs.statSync(fPath);
|
|
14
|
+
if (stat.isDirectory() === true) {
|
|
15
|
+
findJsonFile(fPath);
|
|
16
|
+
}
|
|
17
|
+
if (stat.isFile() === true) {
|
|
18
|
+
jsonFiles.push(fPath);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
findJsonFile(jsonPath);
|
|
23
|
+
return jsonFiles;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getJsonDir(basePath = './') {
|
|
27
|
+
const dirPath = basePath;
|
|
28
|
+
const root = { name: '', type: 'dir', parent: dirPath, children: [] };
|
|
29
|
+
const files = fs.readdirSync(dirPath);
|
|
30
|
+
|
|
31
|
+
const tree = [];
|
|
32
|
+
for (let i = 0; i < files.length; i++) {
|
|
33
|
+
const filename = files[i];
|
|
34
|
+
const filePath = path.join(dirPath, filename);
|
|
35
|
+
try {
|
|
36
|
+
if (filename.lastIndexOf('.tmp') == -1 && filename.lastIndexOf('.sys') == -1) {
|
|
37
|
+
const stats = fs.statSync(filePath);
|
|
38
|
+
if (stats.isFile()) {
|
|
39
|
+
const fileNode = { name: filename, type: 'file', parent: dirPath };
|
|
40
|
+
tree.push(fileNode);
|
|
41
|
+
} else if (stats.isDirectory()) {
|
|
42
|
+
const dirNode = { name: filename, type: 'dir', parent: dirPath, children: [] };
|
|
43
|
+
tree.push(dirNode);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
root.children = tree;
|
|
52
|
+
|
|
53
|
+
return root;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**读取项目信息根据提供的路径。 */
|
|
57
|
+
function checkProject(obj) {
|
|
58
|
+
// const {id,path,type} = obj;
|
|
59
|
+
let mainsetStrPath = "";
|
|
60
|
+
// 检查是否有tmui文件。和目录。
|
|
61
|
+
let tmuiDir = ""
|
|
62
|
+
//可运行的命令行。
|
|
63
|
+
let scriptsPackagePath = ""
|
|
64
|
+
if (obj.type == 'cli') {
|
|
65
|
+
mainsetStrPath = path.join(obj.path, 'src', 'manifest.json')
|
|
66
|
+
tmuiDir = path.join(obj.path, 'src', 'tmui', 'package.json')
|
|
67
|
+
scriptsPackagePath = path.join(obj.path, 'package.json')
|
|
68
|
+
} else {
|
|
69
|
+
mainsetStrPath = path.join(obj.path, 'manifest.json')
|
|
70
|
+
tmuiDir = path.join(obj.path, 'tmui', 'package.json')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let str = fs.readFileSync(mainsetStrPath).toString('utf-8');
|
|
74
|
+
|
|
75
|
+
reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g;
|
|
76
|
+
|
|
77
|
+
str = str.replace(reg, function (word) {
|
|
78
|
+
// 去除注释后的文本
|
|
79
|
+
return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const d = JSON.parse(str);
|
|
83
|
+
let tmui = "";
|
|
84
|
+
if (fs.existsSync(tmuiDir)) {
|
|
85
|
+
let str2 = fs.readFileSync(tmuiDir).toString('utf-8');
|
|
86
|
+
const p = JSON.parse(str2);
|
|
87
|
+
tmui = p.version
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 读取运行的命令行。
|
|
91
|
+
let scripts = ""
|
|
92
|
+
if (fs.existsSync(scriptsPackagePath)) {
|
|
93
|
+
let str2 = fs.readFileSync(scriptsPackagePath).toString('utf-8');
|
|
94
|
+
const p = JSON.parse(str2);
|
|
95
|
+
scripts = p.scripts
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
name: d.name,
|
|
100
|
+
appid: d.appid,
|
|
101
|
+
versionName: d.versionName,
|
|
102
|
+
tmui: tmui,
|
|
103
|
+
id: obj.id,
|
|
104
|
+
scripts: scripts
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**获取系统磁盘。 */
|
|
108
|
+
function getDirver(callbck) {
|
|
109
|
+
if (process.platform === 'win32') {
|
|
110
|
+
// 执行 wmic 命令
|
|
111
|
+
const cmd = spawn('wmic', ['logicaldisk', 'get', 'name']);
|
|
112
|
+
// 监听命令输出流
|
|
113
|
+
cmd.stdout.on('data', data => {
|
|
114
|
+
// 解析命令输出结果
|
|
115
|
+
const disks = data.toString()
|
|
116
|
+
.split('\r\r\n') // 分割为行
|
|
117
|
+
.slice(1) // 跳过标题行
|
|
118
|
+
.map(line => line.trim()) // 去除行首尾空格
|
|
119
|
+
.filter(name => /^[A-Za-z]:$/.test(name)); // 过滤掉非磁盘名称
|
|
120
|
+
const pdist = disks.map(el=>el+"\\")
|
|
121
|
+
|
|
122
|
+
if(callbck){
|
|
123
|
+
callbck(pdist)
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// 监听命令错误流
|
|
128
|
+
cmd.stderr.on('data', data => {
|
|
129
|
+
// console.error(`执行 wmic 命令出错:${data}`);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// 监听命令退出事件
|
|
133
|
+
cmd.on('exit', code => {
|
|
134
|
+
// console.log(`wmic 命令退出,返回码:${code}`);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
} else {
|
|
139
|
+
// 在 Linux/Unix/Mac 系统上执行的代码
|
|
140
|
+
// 获取系统中的所有磁盘名称
|
|
141
|
+
fs.readFile('/proc/mounts', 'utf8', (err, data) => {
|
|
142
|
+
if (err) {
|
|
143
|
+
console.error(`获取磁盘信息失败:${err}`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const lines = data.split('\n');
|
|
147
|
+
const disks = [];
|
|
148
|
+
for (const line of lines) {
|
|
149
|
+
const parts = line.split(' ');
|
|
150
|
+
const mountpoint = parts[1];
|
|
151
|
+
|
|
152
|
+
if (mountpoint.startsWith('/dev/')) {
|
|
153
|
+
const disk = parts[0];
|
|
154
|
+
disks.push(disk);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
console.log(`系统中的所有磁盘:${disks}`);
|
|
159
|
+
if (callbck) {
|
|
160
|
+
callbck(disks)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
exports.getJsonFiles = getJsonFiles;
|
|
171
|
+
exports.getJsonDir = getJsonDir;
|
|
172
|
+
exports.checkProject = checkProject;
|
|
173
|
+
exports.getDirver = getDirver;
|
|
174
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const globalDirectories = require('global-dirs');
|
|
4
|
+
const { getJsonDir } = require("./dirTool");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async function selectedDir(cb, end, pathStr) {
|
|
9
|
+
try {
|
|
10
|
+
let dirpath = globalDirectories.npm.prefix
|
|
11
|
+
if(pathStr){
|
|
12
|
+
dirpath = path.normalize(pathStr);
|
|
13
|
+
}
|
|
14
|
+
let str = getJsonDir(dirpath);
|
|
15
|
+
cb(str)
|
|
16
|
+
end('end')
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.log(error,'---')
|
|
19
|
+
if (end) {
|
|
20
|
+
cb(error)
|
|
21
|
+
end('end')
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.selectedDir = selectedDir;
|
package/bin/donet.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const {spawn} = require('child_process');
|
|
4
|
+
var iconv = require('iconv-lite');
|
|
5
|
+
var BufferHelper = require('bufferhelper');
|
|
6
|
+
const app = express();
|
|
7
|
+
const {getJsonFiles} = require("./cmd/dirTool")
|
|
8
|
+
const open = require('open');
|
|
9
|
+
|
|
10
|
+
app.post("/api/dirlist",(req,res)=>{
|
|
11
|
+
res.setHeader("Access-Control-Allow-Headers","*")
|
|
12
|
+
res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
|
|
13
|
+
res.setHeader("Access-Control-Allow-Headers","DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization")
|
|
14
|
+
|
|
15
|
+
const ls = getJsonFiles( __dirname )
|
|
16
|
+
res.json(ls)
|
|
17
|
+
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
app.post("/api/cmd",(req,res)=>{
|
|
21
|
+
res.setHeader("Access-Control-Allow-Headers","*")
|
|
22
|
+
res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
|
|
23
|
+
res.setHeader("Access-Control-Allow-Headers","DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
res.json(["响应中..."])
|
|
27
|
+
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
app.listen(6170)
|
|
33
|
+
// open('http://localhost:6170')
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
package/bin/hooks.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
|
|
2
|
+
const ws = require('ws')
|
|
3
|
+
const wss = new ws.WebSocketServer({ port: 6169 });
|
|
4
|
+
const { execCmd, devRunApp, killChildAndGrandChildren, buildApp } = require("./cmd/cmdTool");
|
|
5
|
+
const { selectedDir } = require('./cmd/selectedDir');
|
|
6
|
+
const { checkProject, getDirver } = require('./cmd/dirTool');
|
|
7
|
+
const osUtils = require('node-os-utils');
|
|
8
|
+
|
|
9
|
+
var client
|
|
10
|
+
var processList = [];
|
|
11
|
+
var runAppInfoList = [];
|
|
12
|
+
var wslist = [];
|
|
13
|
+
console.log(getDirver())
|
|
14
|
+
function uuid(len = 24, radix) {
|
|
15
|
+
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
16
|
+
var uuid = [], i;
|
|
17
|
+
radix = radix || chars.length;
|
|
18
|
+
if (len) {
|
|
19
|
+
// Compact form
|
|
20
|
+
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
|
|
21
|
+
} else {
|
|
22
|
+
// rfc4122, version 4 form
|
|
23
|
+
var r;
|
|
24
|
+
// rfc4122 requires these characters
|
|
25
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
26
|
+
uuid[14] = '4';
|
|
27
|
+
for (i = 0; i < 36; i++) {
|
|
28
|
+
if (!uuid[i]) {
|
|
29
|
+
r = 0 | Math.random() * 16;
|
|
30
|
+
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return uuid.join('');
|
|
39
|
+
}
|
|
40
|
+
function removeWs(id) {
|
|
41
|
+
const index = wslist.findIndex(el => el.uuid == id)
|
|
42
|
+
if (index > -1) {
|
|
43
|
+
wslist.splice(index, 1)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function send(arg) {
|
|
47
|
+
wslist.forEach(el => {
|
|
48
|
+
el.send(arg)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
wss.on('connection', function connection(ws) {
|
|
52
|
+
|
|
53
|
+
ws.uuid = uuid();
|
|
54
|
+
wslist.push(ws)
|
|
55
|
+
ws.on('error', console.error);
|
|
56
|
+
ws.on('message', function message(data) {
|
|
57
|
+
try {
|
|
58
|
+
let obj = JSON.parse(data)
|
|
59
|
+
// 执行命令
|
|
60
|
+
if (obj.event == 'cmd') {
|
|
61
|
+
execCmd(function (str) {
|
|
62
|
+
send(JSON.stringify({
|
|
63
|
+
event: 'info',
|
|
64
|
+
data: str
|
|
65
|
+
}))
|
|
66
|
+
}, function () {
|
|
67
|
+
send(JSON.stringify({
|
|
68
|
+
event: 'end',
|
|
69
|
+
data: ""
|
|
70
|
+
}))
|
|
71
|
+
}, obj.command)
|
|
72
|
+
// 选择文件目录。
|
|
73
|
+
} else if (obj.event == '18') {
|
|
74
|
+
selectedDir(function (str) {
|
|
75
|
+
send(JSON.stringify({
|
|
76
|
+
event: '18',
|
|
77
|
+
data: str
|
|
78
|
+
}))
|
|
79
|
+
}, function () {
|
|
80
|
+
send(JSON.stringify({
|
|
81
|
+
event: 'end',
|
|
82
|
+
data: ""
|
|
83
|
+
}))
|
|
84
|
+
}, obj.command)
|
|
85
|
+
// 查询目录项目的信息
|
|
86
|
+
} else if (obj.event == '17') {
|
|
87
|
+
let result = checkProject(obj.command)
|
|
88
|
+
let runfl = runAppInfoList.filter(el => el.id == result.id)
|
|
89
|
+
send(JSON.stringify({
|
|
90
|
+
event: '17',
|
|
91
|
+
data: result,
|
|
92
|
+
run: runfl
|
|
93
|
+
}))
|
|
94
|
+
send(JSON.stringify({
|
|
95
|
+
event: 'end',
|
|
96
|
+
data: ""
|
|
97
|
+
}))
|
|
98
|
+
/**运行项目dev:xxx */
|
|
99
|
+
} else if (obj.event == '1') {
|
|
100
|
+
|
|
101
|
+
const childrenProcess = devRunApp(wslist, obj.command)
|
|
102
|
+
if (childrenProcess) {
|
|
103
|
+
processList.push(childrenProcess)
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
/**关闭并退出运行的项目服务 */
|
|
107
|
+
} else if (obj.event == '2') {
|
|
108
|
+
try {
|
|
109
|
+
if (!obj.command) return;
|
|
110
|
+
// process.kill(Number(obj.command||0))
|
|
111
|
+
const pid = Number(obj.command || 0);
|
|
112
|
+
const index = processList.findIndex(el => el.pid == pid)
|
|
113
|
+
if (index > -1) {
|
|
114
|
+
// process.kill(sflit[0].pid)
|
|
115
|
+
killChildAndGrandChildren(processList[index].pid)
|
|
116
|
+
processList.splice(index, 1)
|
|
117
|
+
const index2 = runAppInfoList.findIndex(el => el.pid == pid)
|
|
118
|
+
runAppInfoList.splice(index2, 1)
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
/**编译应用build:xx */
|
|
124
|
+
} else if (obj.event == '3') {
|
|
125
|
+
const id = obj.command.data.id;
|
|
126
|
+
const childrenProcess = buildApp(wslist, obj.command, () => {
|
|
127
|
+
const index2 = runAppInfoList.findIndex(el => el.id == id)
|
|
128
|
+
console.log("编译结束")
|
|
129
|
+
if (index2 > -1) {
|
|
130
|
+
runAppInfoList.splice(index2, 1)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
/**保存当前运行的用户信息。 */
|
|
134
|
+
} else if (obj.event == 'saveRunInfo') {
|
|
135
|
+
const index2 = runAppInfoList.findIndex(el => el.id == obj.command.id)
|
|
136
|
+
if (index2 > -1) {
|
|
137
|
+
runAppInfoList.splice(index2, 1, obj.command)
|
|
138
|
+
} else {
|
|
139
|
+
runAppInfoList.push(obj.command)
|
|
140
|
+
}
|
|
141
|
+
/**获取系统使用率 */
|
|
142
|
+
} else if (obj.event == 'getCpu') {
|
|
143
|
+
|
|
144
|
+
Promise.all([osUtils.mem.info(),osUtils.cpu.usage()])
|
|
145
|
+
.then(arg=>{
|
|
146
|
+
send(JSON.stringify({
|
|
147
|
+
event: 'getCpu',
|
|
148
|
+
data: {
|
|
149
|
+
memUsage:arg[0].usedMemPercentage.toFixed(2),
|
|
150
|
+
cpuUsage:arg[1].toFixed(2)
|
|
151
|
+
}
|
|
152
|
+
}))
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
} catch (error) {
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
ws.on('close', () => {
|
|
164
|
+
removeWs(ws.uuid)
|
|
165
|
+
})
|
|
166
|
+
send('something');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
package/bin/tmui.js
CHANGED
|
@@ -5,53 +5,121 @@ const chalk = import("chalk")
|
|
|
5
5
|
const { Command } = require('commander');
|
|
6
6
|
const program = new Command();
|
|
7
7
|
const create = require("../src/create")
|
|
8
|
+
const create4xhbx = require("../src/create4xhbx")
|
|
8
9
|
const createHbx = require("../src/createHbx")
|
|
9
10
|
const rhbx = require("../src/rhbx")
|
|
10
11
|
const rcli = require("../src/rcli")
|
|
11
12
|
const viewTmuiVer = require("../src/viewTmuiVer")
|
|
12
13
|
const tm2 = require("../src/tmui2")
|
|
13
|
-
const inquirer = import(
|
|
14
|
-
const
|
|
14
|
+
const inquirer = import("inquirer")
|
|
15
|
+
const fetch = import("node-fetch")
|
|
15
16
|
var clear = require('clear');
|
|
16
17
|
var figlet = require('figlet');
|
|
18
|
+
// require('./donet')
|
|
19
|
+
// require('./hooks')
|
|
20
|
+
const ft = import("node-fetch")
|
|
17
21
|
clear()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// async function main(){
|
|
26
|
+
// const Chalk = await (await chalk).default
|
|
27
|
+
// const Inquirer = await (await inquirer).default
|
|
28
|
+
// const Fetch = await (await fetch).default
|
|
29
|
+
// figlet('TMUI3.1.0',figletSucess)
|
|
30
|
+
// function figletSucess(err,d){
|
|
31
|
+
// console.log(Chalk.green(d))
|
|
32
|
+
// console.log(Chalk.white('请注意浏览器打开状态,如果打开失败'))
|
|
33
|
+
// console.log(Chalk.white('请访问:http://localhost:6170'))
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// }
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
// main()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
18
51
|
chalk.then(v=>{
|
|
19
52
|
const ck = new v.Chalk();
|
|
20
53
|
|
|
21
|
-
figlet('
|
|
54
|
+
figlet('TMUI4.0x CLI', function(err, data) {
|
|
22
55
|
if (err) {
|
|
23
56
|
console.log('Something went wrong...');
|
|
24
57
|
console.dir(err);
|
|
25
58
|
return;
|
|
26
59
|
}
|
|
27
|
-
console.log(ck.white(`---------------------------------------------------`))
|
|
28
60
|
console.log(ck.green(data))
|
|
29
|
-
console.log(ck.green(
|
|
61
|
+
console.log(ck.green(`tmui2.0文档地址:https://jx2d.cn`))
|
|
62
|
+
console.log(ck.blue(`tmui3.0文档地址:https://tmui.design`))
|
|
63
|
+
console.log(ck.yellow(`tmui4.0x文档地址:https://xui.tmui.design`))
|
|
30
64
|
console.log(ck.white(`---------------------------------------------------`))
|
|
31
65
|
console.log(ck.white(`命令使用方式为:tmui xxx命令 比如:tmui use`))
|
|
32
66
|
console.log(ck.white(`---------------------------------------------------`))
|
|
67
|
+
|
|
68
|
+
|
|
33
69
|
inquirer.then(ivk=>{
|
|
70
|
+
const { prompt,Separator} = ivk.default;
|
|
71
|
+
|
|
72
|
+
function createTest(type,name){
|
|
73
|
+
if(type=="rcli"){
|
|
74
|
+
rcli.run(type,name,null,'npm','')
|
|
75
|
+
}else if(type=="rhbx"){
|
|
76
|
+
createHbx.run(type,name,null,'npm','')
|
|
77
|
+
}
|
|
78
|
+
prompt([{
|
|
79
|
+
type: 'input',
|
|
80
|
+
name: 'filename',
|
|
81
|
+
message: '在当前路径下创建项目,请输入项目名称:',
|
|
82
|
+
}, ])
|
|
83
|
+
.then(answers2 => {
|
|
84
|
+
if(type=="cli"){
|
|
85
|
+
create.run(type,name,null,'npm',answers2.filename)
|
|
86
|
+
}else if(type=="rcli"){
|
|
87
|
+
rcli.run(type,name,null,'npm',answers2.filename)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}
|
|
34
91
|
program
|
|
35
92
|
.version(require('../package').version)
|
|
93
|
+
program.command('4x')
|
|
94
|
+
.description('创建uniapp的tmui4.0x hbx项目')
|
|
95
|
+
.action(function(type, name){
|
|
96
|
+
create4xhbx.run(type,name,null,null)
|
|
97
|
+
})
|
|
36
98
|
program.command('cli')
|
|
37
99
|
.description('创建uniapp的cli项目包含tmui3.0[推荐]')
|
|
38
100
|
.action(function(type, name){
|
|
39
|
-
|
|
101
|
+
createTest('cli',name)
|
|
40
102
|
})
|
|
41
103
|
program.command('hbx')
|
|
42
104
|
.description('创建uniapp的hbx项目包含tmui3.0[不推荐]')
|
|
43
105
|
.action(function(type, name){
|
|
44
|
-
createHbx.run(type,name)
|
|
106
|
+
// createHbx.run(type,name)
|
|
107
|
+
createTest('hbx',name)
|
|
108
|
+
|
|
45
109
|
})
|
|
46
110
|
program.command('rcli')
|
|
47
111
|
.description('为cli项目下载/更新tmui3.0')
|
|
48
112
|
.action(function(type, name){
|
|
49
|
-
rcli.run(type,name)
|
|
113
|
+
// rcli.run(type,name)
|
|
114
|
+
createTest('rcli',name)
|
|
115
|
+
|
|
116
|
+
|
|
50
117
|
})
|
|
51
118
|
program.command('rhbx')
|
|
52
119
|
.description('为hbx项目下载/更新tmui3.0')
|
|
53
120
|
.action(function(type, name){
|
|
54
|
-
rhbx.run(type,name)
|
|
121
|
+
// rhbx.run(type,name)
|
|
122
|
+
createTest('rhbx',name)
|
|
55
123
|
})
|
|
56
124
|
program.command('ver')
|
|
57
125
|
.description('查看tmui可用版本号')
|
|
@@ -61,15 +129,15 @@ chalk.then(v=>{
|
|
|
61
129
|
program.command('use')
|
|
62
130
|
.description('引导式安装tmui3.0项目[自定义安装]')
|
|
63
131
|
.action(function(type, name){
|
|
64
|
-
const { prompt,Separator} = ivk.default;
|
|
65
132
|
prompt([
|
|
66
133
|
{
|
|
67
134
|
type: 'list',
|
|
68
135
|
name: 'tmuiVerName',
|
|
69
|
-
message: '请选择你的uniApp项目的vue
|
|
136
|
+
message: '请选择你的uniApp项目的vue版本/项目类型',
|
|
70
137
|
choices: [
|
|
71
138
|
'vue2',
|
|
72
|
-
'vue3'
|
|
139
|
+
'vue3',
|
|
140
|
+
'tmui4.0x'
|
|
73
141
|
],
|
|
74
142
|
}
|
|
75
143
|
])
|
|
@@ -124,20 +192,40 @@ chalk.then(v=>{
|
|
|
124
192
|
console.log(ck.red("请正确输入版本号"))
|
|
125
193
|
return;
|
|
126
194
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
195
|
+
prompt([{
|
|
196
|
+
type: 'input',
|
|
197
|
+
name: 'filename',
|
|
198
|
+
message: '在当前路径下创建项目,请输入项目名称:',
|
|
199
|
+
}, ])
|
|
200
|
+
.then(answers2 => {
|
|
201
|
+
|
|
202
|
+
if(ms=="cli"){
|
|
203
|
+
create.run(null,null,ver,packname,answers2.filename)
|
|
204
|
+
}else if(ms=="rcli"){
|
|
205
|
+
rcli.run(null,null,ver,packname,answers2.filename)
|
|
206
|
+
}else if(ms=="hbx"){
|
|
207
|
+
createHbx.run(null,null,ver,packname,answers2.filename)
|
|
208
|
+
}else if(ms=="rhbx"){
|
|
209
|
+
rhbx.run(null,null,ver,packname,answers2.filename)
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
|
|
136
214
|
})
|
|
137
215
|
})
|
|
138
216
|
|
|
139
217
|
})
|
|
140
218
|
|
|
219
|
+
}else if(answers.tmuiVerName=='tmui4.0x'){
|
|
220
|
+
|
|
221
|
+
prompt([{
|
|
222
|
+
type: 'input',
|
|
223
|
+
name: 'filename',
|
|
224
|
+
message: '在当前路径下创建项目,请输入项目名称:',
|
|
225
|
+
}, ])
|
|
226
|
+
.then(answers2 => {
|
|
227
|
+
create4xhbx.run(null,null,null,answers2.filename)
|
|
228
|
+
})
|
|
141
229
|
}
|
|
142
230
|
});
|
|
143
231
|
|
|
@@ -153,4 +241,3 @@ chalk.then(v=>{
|
|
|
153
241
|
|
|
154
242
|
})
|
|
155
243
|
|
|
156
|
-
|
package/package.json
CHANGED
|
@@ -1,52 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_from": "tmui-cli",
|
|
3
|
-
"_inBundle": false,
|
|
4
|
-
"_integrity": "sha512-mnddgPs3eUjTuxQGv6hxlc0b98d53YXtjd0tvrlzWvrAnf0IS0qQMo4bZHi+ImwOEYqbNLX9jhd9pq1cVb9tjw==",
|
|
5
|
-
"_location": "/tmui-cli",
|
|
6
|
-
"_phantomChildren": {},
|
|
7
|
-
"_requested": {
|
|
8
|
-
"type": "tag",
|
|
9
|
-
"registry": true,
|
|
10
|
-
"raw": "tmui-cli",
|
|
11
|
-
"name": "tmui-cli",
|
|
12
|
-
"escapedName": "tmui-cli",
|
|
13
|
-
"rawSpec": "",
|
|
14
|
-
"saveSpec": null,
|
|
15
|
-
"fetchSpec": "latest"
|
|
16
|
-
},
|
|
17
|
-
"_requiredBy": [
|
|
18
|
-
"#USER"
|
|
19
|
-
],
|
|
20
|
-
"_resolved": "https://registry.npmjs.org/tmui-cli/-/tmui-cli-1.0.3.tgz",
|
|
21
|
-
"_shasum": "162803da7d6cc696e3f4a908b223a15f0b33d245",
|
|
22
|
-
"_spec": "tmui-cli",
|
|
23
|
-
"_where": "C:\\Users\\zsylp",
|
|
24
|
-
"author": {
|
|
25
|
-
"name": "tmzdy tmui"
|
|
26
|
-
},
|
|
27
|
-
"bin": {
|
|
28
|
-
"tmui": "bin/tmui.js"
|
|
29
|
-
},
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"chalk": "^5.0.1",
|
|
33
|
-
"clear": "^0.1.0",
|
|
34
|
-
"clui": "^0.3.6",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
1
|
+
{
|
|
2
|
+
"_from": "tmui-cli",
|
|
3
|
+
"_inBundle": false,
|
|
4
|
+
"_integrity": "sha512-mnddgPs3eUjTuxQGv6hxlc0b98d53YXtjd0tvrlzWvrAnf0IS0qQMo4bZHi+ImwOEYqbNLX9jhd9pq1cVb9tjw==",
|
|
5
|
+
"_location": "/tmui-cli",
|
|
6
|
+
"_phantomChildren": {},
|
|
7
|
+
"_requested": {
|
|
8
|
+
"type": "tag",
|
|
9
|
+
"registry": true,
|
|
10
|
+
"raw": "tmui-cli",
|
|
11
|
+
"name": "tmui-cli",
|
|
12
|
+
"escapedName": "tmui-cli",
|
|
13
|
+
"rawSpec": "",
|
|
14
|
+
"saveSpec": null,
|
|
15
|
+
"fetchSpec": "latest"
|
|
16
|
+
},
|
|
17
|
+
"_requiredBy": [
|
|
18
|
+
"#USER"
|
|
19
|
+
],
|
|
20
|
+
"_resolved": "https://registry.npmjs.org/tmui-cli/-/tmui-cli-1.0.3.tgz",
|
|
21
|
+
"_shasum": "162803da7d6cc696e3f4a908b223a15f0b33d245",
|
|
22
|
+
"_spec": "tmui-cli",
|
|
23
|
+
"_where": "C:\\Users\\zsylp",
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "tmzdy tmui"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"tmui": "bin/tmui.js"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"bufferhelper": "^0.2.1",
|
|
32
|
+
"chalk": "^5.0.1",
|
|
33
|
+
"clear": "^0.1.0",
|
|
34
|
+
"clui": "^0.3.6",
|
|
35
|
+
"codecs": "^3.0.0",
|
|
36
|
+
"commander": "^9.4.0",
|
|
37
|
+
"compressing": "^1.6.2",
|
|
38
|
+
"echarts": "^5.5.1",
|
|
39
|
+
"express": "^4.18.2",
|
|
40
|
+
"figlet": "^1.5.2",
|
|
41
|
+
"global-dirs": "^3.0.1",
|
|
42
|
+
"iconv-lite": "^0.6.3",
|
|
43
|
+
"inquirer": "^9.1.4",
|
|
44
|
+
"node-fetch": "^3.2.10",
|
|
45
|
+
"node-os-utils": "^1.3.7",
|
|
46
|
+
"open": "^8.4.2",
|
|
47
|
+
"ps-tree": "^1.2.0",
|
|
48
|
+
"ws": "^8.13.0"
|
|
49
|
+
},
|
|
50
|
+
"deprecated": false,
|
|
51
|
+
"description": "tmui3.0,tmui4.0x,tmui2.0",
|
|
52
|
+
"keywords": [
|
|
53
|
+
"tmui",
|
|
54
|
+
"tm-vuetify",
|
|
55
|
+
"tmui4",
|
|
56
|
+
"tmui4.0x",
|
|
57
|
+
"tmui2.0",
|
|
58
|
+
"uts",
|
|
59
|
+
"uvue",
|
|
60
|
+
"uniappx",
|
|
61
|
+
"uniapp"
|
|
62
|
+
],
|
|
63
|
+
"license": "ISC",
|
|
64
|
+
"main": "./bin/tmui.js",
|
|
65
|
+
"name": "tmui-cli",
|
|
66
|
+
"scripts": {
|
|
67
|
+
"run": "node ./bin/tmui.js"
|
|
68
|
+
},
|
|
69
|
+
"version": "1.1.4"
|
|
70
|
+
}
|
package/src/create.js
CHANGED
|
@@ -10,11 +10,11 @@ var CLI = require('clui'),
|
|
|
10
10
|
Spinner = CLI.Spinner;
|
|
11
11
|
var countdown = new Spinner('请等待... ', ['/','\\','/','\\']);
|
|
12
12
|
const delFile = require("./util").default.delFile
|
|
13
|
-
exports.run = function(type, name,vr,packname="npm") {
|
|
13
|
+
exports.run = function(type, name,vr,packname="npm",filename="") {
|
|
14
14
|
chalk.then(v=>{
|
|
15
15
|
const ck = new v.Chalk();
|
|
16
|
-
const nowPath = path.resolve('./');
|
|
17
|
-
|
|
16
|
+
const nowPath = path.join(path.resolve('./'),filename);
|
|
17
|
+
var vrNumber = 0
|
|
18
18
|
countdown.message(ck.bgBlue('不 要 关闭窗体,正在创建中....'))
|
|
19
19
|
let userInputVer = "";
|
|
20
20
|
if(vr!=null){
|
|
@@ -33,9 +33,17 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
33
33
|
userInputVer = typeof userInputVer=='undefined'?"":userInputVer
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
vrNumber = parseInt(userInputVer.replace(/\./g,''))
|
|
37
|
+
if(isNaN(vrNumber)){
|
|
38
|
+
console.log(ck.red("没有输入版本号"))
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
countdown.start()
|
|
37
42
|
// 检查是否有router目录?
|
|
38
43
|
// fs.existsSync(path.join(nowPath,'router','index.ts'))
|
|
44
|
+
if(!fs.existsSync(nowPath)){
|
|
45
|
+
fs.mkdirSync(nowPath);
|
|
46
|
+
}
|
|
39
47
|
ft.then((fah)=>{
|
|
40
48
|
const fetch = fah.default
|
|
41
49
|
fetch('https://cdn.tmui.design/tmuiVer.txt').then(async (res)=>{
|
|
@@ -53,7 +61,7 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
53
61
|
|
|
54
62
|
|
|
55
63
|
countdown.message(ck.green('正在使用版本号:'+ver))
|
|
56
|
-
fetch(`https://cdn.tmui.design/public/static
|
|
64
|
+
fetch(`https://cdn.tmui.design/public/static/${vrNumber>=320?'cli32':'cli'}.zip`).then(async (rf)=>{
|
|
57
65
|
let d = await rf.buffer()
|
|
58
66
|
fs.writeFile(path.join(nowPath,'cli.zip'),d,(err)=>{
|
|
59
67
|
if(err){
|
|
@@ -65,6 +73,13 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
65
73
|
.then(revalue=>{
|
|
66
74
|
//创建tmui目录
|
|
67
75
|
let tmuipath = path.join(nowPath,'src','tmui');
|
|
76
|
+
if(vrNumber>=320){
|
|
77
|
+
tmuipath = path.join(nowPath,'src','uni_modules');
|
|
78
|
+
if(!fs.existsSync(tmuipath)){
|
|
79
|
+
fs.mkdirSync(tmuipath);
|
|
80
|
+
}
|
|
81
|
+
tmuipath = path.join(nowPath,'src','uni_modules','tm-ui');
|
|
82
|
+
}
|
|
68
83
|
if(!fs.existsSync(tmuipath)){
|
|
69
84
|
fs.mkdirSync(tmuipath);
|
|
70
85
|
}else{
|
|
@@ -74,6 +89,7 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
74
89
|
let donloadTmui = `https://cdn.tmui.design/public/static/tmui${ver}.zip`
|
|
75
90
|
fetch(donloadTmui).then(async (tmuires)=>{
|
|
76
91
|
fs.writeFileSync(path.join(nowPath,'tmui.zip'),await tmuires.buffer())
|
|
92
|
+
|
|
77
93
|
compressing.zip.uncompress(path.join(nowPath,'tmui.zip'),tmuipath)
|
|
78
94
|
.then(comtmui=>{
|
|
79
95
|
countdown.message(ck.green('非常nice,安装成功,正在清理'))
|
|
@@ -104,8 +120,9 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
104
120
|
console.log(ck.green(`---------------------------------------------------`))
|
|
105
121
|
console.log(ck.green(`---------------------------------------------------`))
|
|
106
122
|
console.log(ck.green('安装成功请执行uni cli命令,编译一个H5项目试:'))
|
|
107
|
-
console.log(ck.green(
|
|
108
|
-
console.log(ck.green('
|
|
123
|
+
console.log(ck.green(`请切换到你的项目目录: cd ${filename}`))
|
|
124
|
+
console.log(ck.green('再执行: '+packname+' run dev:h5'))
|
|
125
|
+
|
|
109
126
|
})
|
|
110
127
|
|
|
111
128
|
})
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const chalk = import("chalk")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const {
|
|
4
|
+
Command
|
|
5
|
+
} = require('commander');
|
|
6
|
+
const fs = require("fs")
|
|
7
|
+
const ft = import("node-fetch")
|
|
8
|
+
const compressing = require("compressing")
|
|
9
|
+
const chilPro = require("child_process")
|
|
10
|
+
var clear = require('clear');
|
|
11
|
+
var figlet = require('figlet');
|
|
12
|
+
const program = new Command();
|
|
13
|
+
const inquirer = import("inquirer")
|
|
14
|
+
var CLI = require('clui'),
|
|
15
|
+
Spinner = CLI.Spinner;
|
|
16
|
+
const delFile = require("./util").default.delFile
|
|
17
|
+
|
|
18
|
+
// https://cdn.tmui.design/tmui4.0/tmui4.0xhbxModel.zip
|
|
19
|
+
exports.run = function(type, name, vr, packname,filename) {
|
|
20
|
+
chalk.then(v => {
|
|
21
|
+
clear()
|
|
22
|
+
const ck = new v.Chalk();
|
|
23
|
+
const nowPath = path.resolve('./');
|
|
24
|
+
console.log(ck.white('不 要 关闭窗体,正在创建中....'))
|
|
25
|
+
|
|
26
|
+
inquirer.then(ivk => {
|
|
27
|
+
function build(fname){
|
|
28
|
+
let filemul = path.join(nowPath, fname)
|
|
29
|
+
console.log(ck.green(`正在当前目录${filemul}创建项目`))
|
|
30
|
+
fetch(`https://cdn.tmui.design/tmui4.0/tmui4.0xhbxModel.zip`).then(async (rf) => {
|
|
31
|
+
if(!fs.existsSync(filemul)){
|
|
32
|
+
fs.mkdirSync(filemul)
|
|
33
|
+
}
|
|
34
|
+
let d = await rf.arrayBuffer()
|
|
35
|
+
|
|
36
|
+
fs.writeFile(path.join(filemul, 'tmui4.0xhbxModel.zip'), Buffer.from(d), (err) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
console.log(ck.bgRed(err))
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
compressing.zip.uncompress(path.join(filemul, 'tmui4.0xhbxModel.zip'), path.join(
|
|
42
|
+
filemul))
|
|
43
|
+
.then(revalue => {
|
|
44
|
+
console.log(ck.green( '非常nice,安装成功,正在清理'))
|
|
45
|
+
if (fs.existsSync(path.join(
|
|
46
|
+
filemul,
|
|
47
|
+
'tmui4.0xhbxModel.zip'))) {
|
|
48
|
+
fs.unlinkSync(path.join(
|
|
49
|
+
filemul,
|
|
50
|
+
'tmui4.0xhbxModel.zip'))
|
|
51
|
+
}
|
|
52
|
+
figlet('TMUI4.0x OK!!', function(err, data) {
|
|
53
|
+
if (err) {
|
|
54
|
+
console.log('Something went wrong...');
|
|
55
|
+
console.dir(err);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
console.log(ck.bgGreen(data))
|
|
59
|
+
console.log(ck.green(`---------------------------------------------------`))
|
|
60
|
+
console.log(ck.green(`---------------------------------------------------`))
|
|
61
|
+
console.log(ck.green('请使用hbx4.21+以上版本导入项目目录并运行'))
|
|
62
|
+
console.log(ck.yellow('想要运行成功:您还需要导入tmui4.0x组件库及插件库,请联系作者购买授权并下载'))
|
|
63
|
+
console.log(ck.blue('市场购买地址:https://ext.dcloud.net.cn/plugin?id=16369'))
|
|
64
|
+
console.log(ck.green('文档地址:https://xui.tmui.design/'))
|
|
65
|
+
console.log(ck.yellow('线上WEB、H5预览:https://xui.tmui.design/h5'))
|
|
66
|
+
console.log(ck.yellow('安卓安装:https://gitee.com/LYTB/tmui4.0/releases/download/1.07/%20tmui4.0for%20unix%201.0.7.apk'))
|
|
67
|
+
console.log(ck.white('敬请期待4.0x的鸿蒙,小程序版本!!!'))
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
}).catch(errs => {
|
|
71
|
+
console.log(ck.bgRed(errs))
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
}).catch(e => {
|
|
75
|
+
console.log(ck.bgRed(e))
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
if(packname==null){
|
|
79
|
+
const {
|
|
80
|
+
prompt,
|
|
81
|
+
Separator
|
|
82
|
+
} = ivk.default;
|
|
83
|
+
prompt([{
|
|
84
|
+
type: 'input',
|
|
85
|
+
name: 'filename',
|
|
86
|
+
message: '在当前路径下创建项目,请输入项目名称:',
|
|
87
|
+
}, ])
|
|
88
|
+
.then(answers => {
|
|
89
|
+
build(answers.filename)
|
|
90
|
+
});
|
|
91
|
+
}else{
|
|
92
|
+
build(packname)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
})
|
|
98
|
+
}
|
package/src/createHbx.js
CHANGED
|
@@ -10,11 +10,12 @@ var CLI = require('clui'),
|
|
|
10
10
|
Spinner = CLI.Spinner;
|
|
11
11
|
const delFile = require("./util").default.delFile
|
|
12
12
|
var countdown = new Spinner('请等待... ', ['/','\\','/','\\']);
|
|
13
|
-
exports.run = function(type, name,vr,packname="npm") {
|
|
13
|
+
exports.run = function(type, name,vr,packname="npm",filename) {
|
|
14
14
|
chalk.then(v=>{
|
|
15
15
|
clear()
|
|
16
16
|
const ck = new v.Chalk();
|
|
17
|
-
const nowPath = path.resolve('./');
|
|
17
|
+
const nowPath = path.join(path.resolve('./'),filename);
|
|
18
|
+
var vrNumber = 0
|
|
18
19
|
console.log(ck.bgBlue('不 要 关闭窗体,正在创建中....'))
|
|
19
20
|
let userInputVer = "";
|
|
20
21
|
if(vr!=null){
|
|
@@ -33,7 +34,13 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
33
34
|
userInputVer = typeof userInputVer=='undefined'?"":userInputVer
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
vrNumber = parseInt(userInputVer.replace(/\./g,''))
|
|
38
|
+
if(isNaN(vrNumber)){
|
|
39
|
+
console.log(ck.red("没有输入版本号"))
|
|
40
|
+
}
|
|
41
|
+
if(!fs.existsSync(nowPath)){
|
|
42
|
+
fs.mkdirSync(nowPath);
|
|
43
|
+
}
|
|
37
44
|
ft.then((fah)=>{
|
|
38
45
|
const fetch = fah.default
|
|
39
46
|
|
|
@@ -63,11 +70,19 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
63
70
|
.then(revalue=>{
|
|
64
71
|
//创建tmui目录
|
|
65
72
|
let tmuipath = path.join(nowPath,'tmui');
|
|
73
|
+
if(vrNumber>=320){
|
|
74
|
+
tmuipath = path.join(nowPath,'uni_modules');
|
|
75
|
+
if(!fs.existsSync(tmuipath)){
|
|
76
|
+
fs.mkdirSync(tmuipath);
|
|
77
|
+
}
|
|
78
|
+
tmuipath = path.join(nowPath,'uni_modules','tm-ui');
|
|
79
|
+
}
|
|
66
80
|
if(!fs.existsSync(tmuipath)){
|
|
67
81
|
fs.mkdirSync(tmuipath);
|
|
68
82
|
}else{
|
|
69
83
|
delFile(tmuipath)
|
|
70
84
|
}
|
|
85
|
+
|
|
71
86
|
countdown.start()
|
|
72
87
|
//下载tmui
|
|
73
88
|
let donloadTmui = `https://cdn.tmui.design/public/static/tmui${ver}.zip`
|
|
@@ -99,7 +114,6 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
99
114
|
}
|
|
100
115
|
console.log(ck.bgGreen(data))
|
|
101
116
|
console.log(ck.green(`---------------------------------------------------`))
|
|
102
|
-
console.log(ck.red(`截止3.5.4 hbx版本号,运行到浏览器会报错,其它平台没问题。这是uni的bug。但cli模式不会有问题。`))
|
|
103
117
|
console.log(ck.bgGreen('安装成功,请使用hbx导入项目,运行本项目。'))
|
|
104
118
|
})
|
|
105
119
|
|
package/src/rcli.js
CHANGED
|
@@ -10,10 +10,11 @@ var CLI = require('clui'),
|
|
|
10
10
|
Spinner = CLI.Spinner;
|
|
11
11
|
var countdown = new Spinner('请等待... ', ['/','\\','/','\\']);
|
|
12
12
|
const delFile = require("./util").default.delFile
|
|
13
|
-
exports.run = function(type, name,vr,packname="npm") {
|
|
13
|
+
exports.run = function(type, name,vr,packname="npm",filename="") {
|
|
14
14
|
chalk.then(v=>{
|
|
15
15
|
const ck = new v.Chalk();
|
|
16
|
-
const nowPath = path.resolve('./');
|
|
16
|
+
const nowPath = path.join(path.resolve('./'),filename);
|
|
17
|
+
var vrNumber = 0
|
|
17
18
|
console.log(ck.bgBlue('不 要 关闭窗体,正在创建中....'))
|
|
18
19
|
let userInputVer = "";
|
|
19
20
|
if(vr!=null){
|
|
@@ -32,6 +33,13 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
32
33
|
userInputVer = typeof userInputVer=='undefined'?"":userInputVer
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
vrNumber = parseInt(userInputVer.replace(/\./g,''))
|
|
37
|
+
if(isNaN(vrNumber)){
|
|
38
|
+
console.log(ck.red("没有输入版本号"))
|
|
39
|
+
}
|
|
40
|
+
if(!fs.existsSync(nowPath)){
|
|
41
|
+
fs.mkdirSync(nowPath);
|
|
42
|
+
}
|
|
35
43
|
ft.then((fah)=>{
|
|
36
44
|
const fetch = fah.default
|
|
37
45
|
|
|
@@ -56,7 +64,16 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
56
64
|
console.log(ck.bgRed('非cli项目,请使用rhbx项目'))
|
|
57
65
|
return
|
|
58
66
|
}
|
|
67
|
+
//创建tmui目录
|
|
59
68
|
let tmuipath = path.join(nowPath,'src','tmui');
|
|
69
|
+
if(vrNumber>=320){
|
|
70
|
+
tmuipath = path.join(nowPath,'src','uni_modules');
|
|
71
|
+
if(!fs.existsSync(tmuipath)){
|
|
72
|
+
fs.mkdirSync(tmuipath);
|
|
73
|
+
}
|
|
74
|
+
tmuipath = path.join(nowPath,'src','uni_modules','tm-ui');
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
if(!fs.existsSync(tmuipath)){
|
|
61
78
|
fs.mkdirSync(tmuipath);
|
|
62
79
|
}else{
|
package/src/rhbx.js
CHANGED
|
@@ -11,11 +11,12 @@ Spinner = CLI.Spinner;
|
|
|
11
11
|
const delFile = require("./util").default.delFile
|
|
12
12
|
|
|
13
13
|
var countdown = new Spinner('请等待... ', ['/','\\','/','\\']);
|
|
14
|
-
exports.run = function(type, name,vr,packname="npm") {
|
|
14
|
+
exports.run = function(type, name,vr,packname="npm",filename) {
|
|
15
15
|
chalk.then(v=>{
|
|
16
16
|
clear()
|
|
17
17
|
const ck = new v.Chalk();
|
|
18
|
-
const nowPath = path.resolve('./');
|
|
18
|
+
const nowPath = path.join(path.resolve('./'),filename);
|
|
19
|
+
var vrNumber = 0
|
|
19
20
|
console.log(ck.bgBlue('不 要 关闭窗体,正在创建中....'))
|
|
20
21
|
let userInputVer = "";
|
|
21
22
|
if(vr!=null){
|
|
@@ -35,28 +36,25 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
let txt = require('./router').txt;
|
|
43
|
-
fs.writeFileSync(path.join(nowPath,'router','index.ts'),txt)
|
|
39
|
+
vrNumber = parseInt(userInputVer.replace(/\./g,''))
|
|
40
|
+
if(isNaN(vrNumber)){
|
|
41
|
+
console.log(ck.red("没有输入版本号"))
|
|
44
42
|
}
|
|
45
|
-
if(!fs.existsSync(
|
|
46
|
-
|
|
47
|
-
fs.mkdirSync(path.join(nowPath,'theme'));
|
|
48
|
-
}
|
|
49
|
-
let txt = require('./theme').txt;
|
|
50
|
-
fs.writeFileSync(path.join(nowPath,'theme','index.ts'),txt)
|
|
43
|
+
if(!fs.existsSync(nowPath)){
|
|
44
|
+
fs.mkdirSync(nowPath);
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// 检查是否有router目录?
|
|
55
|
-
// fs.existsSync(path.join(nowPath,'router','index.ts'))
|
|
46
|
+
|
|
56
47
|
ft.then((fah)=>{
|
|
57
48
|
const fetch = fah.default
|
|
58
49
|
//创建tmui目录
|
|
59
50
|
let tmuipath = path.join(nowPath,'tmui');
|
|
51
|
+
if(vrNumber>=320){
|
|
52
|
+
tmuipath = path.join(nowPath,'uni_modules');
|
|
53
|
+
if(!fs.existsSync(tmuipath)){
|
|
54
|
+
fs.mkdirSync(tmuipath);
|
|
55
|
+
}
|
|
56
|
+
tmuipath = path.join(nowPath,'uni_modules','tm-ui');
|
|
57
|
+
}
|
|
60
58
|
if(!fs.existsSync(tmuipath)){
|
|
61
59
|
fs.mkdirSync(tmuipath);
|
|
62
60
|
}else{
|
|
@@ -111,7 +109,6 @@ exports.run = function(type, name,vr,packname="npm") {
|
|
|
111
109
|
}
|
|
112
110
|
console.log(ck.bgGreen(data))
|
|
113
111
|
console.log(ck.green(`---------------------------------------------------`))
|
|
114
|
-
console.log(ck.red(`截止3.5.4 hbx版本号,运行到浏览器会报错,其它平台没问题。这是uni的bug。但cli模式不会有问题。`))
|
|
115
112
|
console.log(ck.bgGreen('安装成功,请使用hbx导入项目,运行本项目。'))
|
|
116
113
|
})
|
|
117
114
|
|