tmui-cli 1.1.5 → 1.1.7
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 +19 -7
- package/bin/cmdTool.js +223 -0
- package/bin/createTmui.js +375 -0
- package/bin/dirTool.js +152 -0
- package/bin/hooks.js +58 -15
- package/bin/net.js +136 -0
- package/bin/selectedDir.js +28 -0
- package/bin/tmui.js +22 -243
- package/package.json +23 -62
- package/website/favicon.ico +0 -0
- package/website/index.html +20 -0
- package/website/js/app.js +997 -0
- package/website/js/chunk-vendors.js +13592 -0
- package/bin/cmd/cmdTool.js +0 -219
- package/bin/cmd/dirTool.js +0 -174
- package/bin/cmd/selectedDir.js +0 -27
- package/bin/donet.js +0 -50
- package/src/create.js +0 -176
- package/src/create4xhbx.js +0 -98
- package/src/createHbx.js +0 -142
- package/src/rcli.js +0 -136
- package/src/rhbx.js +0 -131
- package/src/router.js +0 -28
- package/src/theme.js +0 -8
- package/src/tmui2.js +0 -60
- package/src/util.js +0 -37
- package/src/viewTmuiVer.js +0 -24
package/README.md
CHANGED
|
@@ -7,13 +7,31 @@
|
|
|
7
7
|
### tmui-cli使用介绍
|
|
8
8
|
|
|
9
9
|
#### 全局安装
|
|
10
|
-
|
|
10
|
+
必须nodejs 18+以上版本才能使用
|
|
11
11
|
```npm
|
|
12
|
+
|
|
13
|
+
windows:
|
|
12
14
|
npm -g install tmui-cli
|
|
15
|
+
mac/liunx:
|
|
16
|
+
sudo pm -g install tmui-cli
|
|
17
|
+
|
|
13
18
|
安装成功后输入:tmui
|
|
14
19
|
即可查看所有可用命令
|
|
15
20
|
```
|
|
16
21
|
|
|
22
|
+
## 1.1.6及以上的使用方式
|
|
23
|
+
|
|
24
|
+
```npm
|
|
25
|
+
在命令行中输入:tmui
|
|
26
|
+
会打开默认浏览器,出现可视化安装界面,可以选择导入和管理你的项目.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
1.1.6及以上的界面如下:
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
## 1.1.5及以下的使用方式
|
|
34
|
+
|
|
17
35
|
#### 使用
|
|
18
36
|
请在项目文件的根目录下执行命令
|
|
19
37
|
输入 ```tmui```
|
|
@@ -83,9 +101,3 @@ npm -g install tmui-cli
|
|
|
83
101
|
|
|
84
102
|
----
|
|
85
103
|
|
|
86
|
-
### 3.0.4新功能特性快速了解
|
|
87
|
-
|
|
88
|
-

|
|
89
|
-

|
|
90
|
-
|
|
91
|
-

|
package/bin/cmdTool.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import {
|
|
4
|
+
spawn,
|
|
5
|
+
exec
|
|
6
|
+
} from "child_process"
|
|
7
|
+
import process from "process"
|
|
8
|
+
import codecs from "codecs"
|
|
9
|
+
import psTree from "ps-tree"
|
|
10
|
+
import iconv from "iconv-lite"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function detectEncoding(str) {
|
|
14
|
+
const buffer = Buffer.from(str);
|
|
15
|
+
if (buffer[0] < 128) {
|
|
16
|
+
return 'ascii';
|
|
17
|
+
} else if (buffer[0] < 224) {
|
|
18
|
+
return 'utf8';
|
|
19
|
+
} else if (buffer[0] < 240) {
|
|
20
|
+
return 'utf16le';
|
|
21
|
+
} else {
|
|
22
|
+
return 'utf32le';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function send(ws, arg) {
|
|
28
|
+
ws.forEach(el => {
|
|
29
|
+
el.send(arg)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function execCmd(cb, end, command) {
|
|
34
|
+
try {
|
|
35
|
+
// const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
|
|
36
|
+
const spawnObj = exec(command, {
|
|
37
|
+
encoding: 'binary'
|
|
38
|
+
})
|
|
39
|
+
// const spawnObj = spawn("npm.cmd",["run","dev:h5"],{detached:true})
|
|
40
|
+
|
|
41
|
+
spawnObj.stdout?.on('data', function(chunk) {
|
|
42
|
+
// Buffer.from(chunk,'binary').toString('utf-8')
|
|
43
|
+
// var str = iconv.decode(, 'cp936');
|
|
44
|
+
if (cb) {
|
|
45
|
+
let str = Buffer.from(chunk, 'binary').toString("utf8")
|
|
46
|
+
|
|
47
|
+
var codecsDecode = codecs(detectEncoding(chunk))
|
|
48
|
+
let strii = codecsDecode.decode(Buffer.from(chunk, 'binary')).toString('utf-8');
|
|
49
|
+
// 去除控制符
|
|
50
|
+
const cleanStr = strii.replace(
|
|
51
|
+
/[\u001B\u009B][[\]()#;?]*(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[A-PR-Za-z~])/g, '');
|
|
52
|
+
cb(cleanStr, spawnObj.pid || 0)
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
spawnObj.addListener('error', (err) => {
|
|
56
|
+
if (end) {
|
|
57
|
+
cb(err)
|
|
58
|
+
end('error')
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
spawnObj.on('close', function(code) {
|
|
62
|
+
// console.log('close code : ' + code);
|
|
63
|
+
if (end) {
|
|
64
|
+
end('end')
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
spawnObj.on('exit', (code) => {
|
|
68
|
+
// console.log('exit code : ' + code);
|
|
69
|
+
if (end) {
|
|
70
|
+
end('end')
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return spawnObj;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (end) {
|
|
77
|
+
cb(error)
|
|
78
|
+
end('end')
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// 杀死子进程及其所有子孙进程
|
|
84
|
+
export function killChildAndGrandChildren(pid) {
|
|
85
|
+
|
|
86
|
+
if (process.platform === 'win32') {
|
|
87
|
+
// 在 Windows 系统上执行的代码
|
|
88
|
+
const command = `taskkill /T /F /PID ${pid}`;
|
|
89
|
+
exec(command, (err, stdout, stderr) => {
|
|
90
|
+
if (err) {
|
|
91
|
+
console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
|
|
92
|
+
}
|
|
93
|
+
// console.log(`stdout: ${stdout}`);
|
|
94
|
+
// console.error(`stderr: ${stderr}`);
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
// 在 Linux/Unix/Mac 系统上执行的代码
|
|
98
|
+
psTree(pid, (err, children) => {
|
|
99
|
+
// 使用 kill 命令杀死所有子孙进程
|
|
100
|
+
console.log(5555)
|
|
101
|
+
exec(`kill -TERM ${pid} ${children.map(c => c.PID).join(' ')}`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function devRunApp(ws, obj) {
|
|
108
|
+
|
|
109
|
+
const nowcd = process.cwd();
|
|
110
|
+
process.chdir(path.normalize(obj.data.path));
|
|
111
|
+
|
|
112
|
+
const childreProcess = execCmd(function(msg, pid) {
|
|
113
|
+
send(ws, JSON.stringify({
|
|
114
|
+
event: 'info',
|
|
115
|
+
data: msg
|
|
116
|
+
}))
|
|
117
|
+
const reg_1 = /http:\/\/localhost(:\d+)?(\/[^\s]*)?/g;
|
|
118
|
+
const reg_2 = /http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?(\/[^\s]*)?/g;
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if (reg_1.test(msg)) {
|
|
122
|
+
send(ws, JSON.stringify({
|
|
123
|
+
event: '1',
|
|
124
|
+
data: {
|
|
125
|
+
id: obj.data.id,
|
|
126
|
+
msg: msg.match(reg_1)[0],
|
|
127
|
+
pid: pid
|
|
128
|
+
}
|
|
129
|
+
}))
|
|
130
|
+
}
|
|
131
|
+
if (reg_2.test(msg)) {
|
|
132
|
+
send(ws, JSON.stringify({
|
|
133
|
+
event: '1',
|
|
134
|
+
data: {
|
|
135
|
+
id: obj.data.id,
|
|
136
|
+
msg: msg.match(reg_2)[0],
|
|
137
|
+
pid: pid
|
|
138
|
+
}
|
|
139
|
+
}))
|
|
140
|
+
}
|
|
141
|
+
if (msg.indexOf('ready') > -1) {
|
|
142
|
+
send(ws, JSON.stringify({
|
|
143
|
+
event: 'ready',
|
|
144
|
+
data: {
|
|
145
|
+
id: obj.data.id,
|
|
146
|
+
pid: pid
|
|
147
|
+
},
|
|
148
|
+
}))
|
|
149
|
+
}
|
|
150
|
+
}, function(type) {
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if (type == 'end') {
|
|
154
|
+
send(ws, JSON.stringify({
|
|
155
|
+
event: 'end',
|
|
156
|
+
data: {
|
|
157
|
+
id: obj.data.id
|
|
158
|
+
},
|
|
159
|
+
}))
|
|
160
|
+
} else {
|
|
161
|
+
send(ws, JSON.stringify({
|
|
162
|
+
event: 'error',
|
|
163
|
+
data: {
|
|
164
|
+
id: obj.data.id
|
|
165
|
+
},
|
|
166
|
+
}))
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}, obj.command)
|
|
171
|
+
|
|
172
|
+
return childreProcess;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function buildApp(ws, obj, end) {
|
|
176
|
+
|
|
177
|
+
const nowcd = process.cwd();
|
|
178
|
+
process.chdir(path.normalize(obj.data.path));
|
|
179
|
+
|
|
180
|
+
const childreProcess = execCmd(function(msg, pid) {
|
|
181
|
+
send(ws, JSON.stringify({
|
|
182
|
+
event: 'info',
|
|
183
|
+
data: msg
|
|
184
|
+
}))
|
|
185
|
+
if (msg.indexOf('DONE') > -1) {
|
|
186
|
+
send(ws, JSON.stringify({
|
|
187
|
+
event: 'buildSucess',
|
|
188
|
+
data: {
|
|
189
|
+
id: obj.data.id,
|
|
190
|
+
pid: pid
|
|
191
|
+
},
|
|
192
|
+
}))
|
|
193
|
+
}
|
|
194
|
+
}, function(type) {
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if (type == 'end') {
|
|
198
|
+
send(ws, JSON.stringify({
|
|
199
|
+
event: 'end',
|
|
200
|
+
data: {
|
|
201
|
+
id: obj.data.id
|
|
202
|
+
},
|
|
203
|
+
}))
|
|
204
|
+
|
|
205
|
+
console.log('编译完成')
|
|
206
|
+
} else {
|
|
207
|
+
send(ws, JSON.stringify({
|
|
208
|
+
event: 'error',
|
|
209
|
+
data: {
|
|
210
|
+
id: obj.data.id
|
|
211
|
+
},
|
|
212
|
+
}))
|
|
213
|
+
}
|
|
214
|
+
if (end) {
|
|
215
|
+
end()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
}, obj.command)
|
|
219
|
+
|
|
220
|
+
return childreProcess;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import compressing from "compressing"
|
|
4
|
+
import { execCmd } from "./cmdTool.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const uniappDevListVer = [
|
|
8
|
+
"@dcloudio/uni-app",
|
|
9
|
+
"@dcloudio/uni-app-plus",
|
|
10
|
+
"@dcloudio/uni-components",
|
|
11
|
+
"@dcloudio/uni-h5",
|
|
12
|
+
"@dcloudio/uni-mp-alipay",
|
|
13
|
+
"@dcloudio/uni-mp-baidu",
|
|
14
|
+
"@dcloudio/uni-mp-kuaishou",
|
|
15
|
+
"@dcloudio/uni-mp-lark",
|
|
16
|
+
"@dcloudio/uni-mp-qq",
|
|
17
|
+
"@dcloudio/uni-mp-toutiao",
|
|
18
|
+
"@dcloudio/uni-mp-weixin",
|
|
19
|
+
"@dcloudio/uni-quickapp-webview",
|
|
20
|
+
"@dcloudio/uni-automator",
|
|
21
|
+
"@dcloudio/uni-cli-shared",
|
|
22
|
+
"@dcloudio/vite-plugin-uni"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
//递归删除目录文件.
|
|
26
|
+
function delFile(fileUrl, flag) {
|
|
27
|
+
if (!fs.existsSync(fileUrl)) return;
|
|
28
|
+
// 当前文件为文件夹时
|
|
29
|
+
if (fs.statSync(fileUrl).isDirectory()) {
|
|
30
|
+
var files = fs.readdirSync(fileUrl);
|
|
31
|
+
var len = files.length,
|
|
32
|
+
removeNumber = 0;
|
|
33
|
+
if (len > 0) {
|
|
34
|
+
files.forEach(function (file) {
|
|
35
|
+
removeNumber++;
|
|
36
|
+
var stats = fs.statSync(fileUrl + '/' + file);
|
|
37
|
+
var url = fileUrl + '/' + file;
|
|
38
|
+
if (fs.statSync(url).isDirectory()) {
|
|
39
|
+
delFile(url, true);
|
|
40
|
+
} else {
|
|
41
|
+
fs.unlinkSync(url);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (len == removeNumber && flag) {
|
|
45
|
+
fs.rmdirSync(fileUrl);
|
|
46
|
+
}
|
|
47
|
+
} else if (len == 0 && flag) {
|
|
48
|
+
fs.rmdirSync(fileUrl);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
// 当前文件为文件时
|
|
52
|
+
fs.unlinkSync(fileUrl);
|
|
53
|
+
console.log('删除文件' + fileUrl + '成功');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//读取项目的配置资料.
|
|
57
|
+
function readPackageJson(filepath) {
|
|
58
|
+
let str = fs.readFileSync(filepath).toString('utf-8');
|
|
59
|
+
let reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g;
|
|
60
|
+
str = str.replace(reg, function (word) {
|
|
61
|
+
// 去除注释后的文本
|
|
62
|
+
return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
|
|
63
|
+
});
|
|
64
|
+
const d = JSON.parse(str);
|
|
65
|
+
return d;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function writePackageJson(filepath, str) {
|
|
69
|
+
fs.writeFileSync(filepath, str, { encoding: 'utf-8' })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 更新项目.
|
|
76
|
+
* @param {{path,type,uvue,tmui,uniappver}} arg
|
|
77
|
+
* @param {(str)=>{}} call
|
|
78
|
+
* @param {()=>{}} end
|
|
79
|
+
*/
|
|
80
|
+
export async function UpdateTmui(arg, call, end) {
|
|
81
|
+
let rootdir = path.normalize(arg.path)
|
|
82
|
+
call('检测目录...')
|
|
83
|
+
if (!fs.existsSync(rootdir)) {
|
|
84
|
+
call('项目目录有误...')
|
|
85
|
+
end()
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
process.chdir(arg.path);
|
|
90
|
+
|
|
91
|
+
let tmui32_hbx_dir = ''
|
|
92
|
+
let is32 = parseFloat(arg.tmui.replace('.', '')) >= 32 ? true : false;
|
|
93
|
+
|
|
94
|
+
if (arg.type == 'hbx') {
|
|
95
|
+
if (is32) {
|
|
96
|
+
let tmuidir = path.join(rootdir, 'uni_modules')
|
|
97
|
+
if (!fs.existsSync(tmuidir)) {
|
|
98
|
+
fs.mkdirSync(tmuidir)
|
|
99
|
+
}
|
|
100
|
+
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
101
|
+
if (!fs.existsSync(tmuidir)) {
|
|
102
|
+
fs.mkdirSync(tmuidir)
|
|
103
|
+
}
|
|
104
|
+
tmui32_hbx_dir = tmuidir
|
|
105
|
+
} else {
|
|
106
|
+
let tmuidir = path.join(rootdir, 'tmui')
|
|
107
|
+
if (!fs.existsSync(tmuidir)) {
|
|
108
|
+
fs.mkdirSync(tmuidir)
|
|
109
|
+
}
|
|
110
|
+
tmui32_hbx_dir = tmuidir
|
|
111
|
+
}
|
|
112
|
+
} else if (arg.type == 'cli') {
|
|
113
|
+
if (is32) {
|
|
114
|
+
let tmuidir = path.join(rootdir, 'src', 'uni_modules')
|
|
115
|
+
if (!fs.existsSync(tmuidir)) {
|
|
116
|
+
fs.mkdirSync(tmuidir)
|
|
117
|
+
}
|
|
118
|
+
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
119
|
+
if (!fs.existsSync(tmuidir)) {
|
|
120
|
+
fs.mkdirSync(tmuidir)
|
|
121
|
+
}
|
|
122
|
+
tmui32_hbx_dir = tmuidir
|
|
123
|
+
} else {
|
|
124
|
+
let tmuidir = path.join(rootdir, 'src', 'tmui')
|
|
125
|
+
if (!fs.existsSync(tmuidir)) {
|
|
126
|
+
fs.mkdirSync(tmuidir)
|
|
127
|
+
}
|
|
128
|
+
tmui32_hbx_dir = tmuidir
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
call('已创建/检测/清除...tmui目录...')
|
|
133
|
+
if (!fs.existsSync(tmui32_hbx_dir)) {
|
|
134
|
+
call('无法检测和创建目录,请检查权限...')
|
|
135
|
+
end()
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
//删除tmui目录.
|
|
139
|
+
delFile(tmui32_hbx_dir, true)
|
|
140
|
+
//再重新创建,确保目录被清空.
|
|
141
|
+
fs.mkdirSync(tmui32_hbx_dir)
|
|
142
|
+
call('下载tmui中,版本号为:' + arg.tmui)
|
|
143
|
+
|
|
144
|
+
// 下载tmui文件.
|
|
145
|
+
let donloadTmui = `https://cdn.tmui.design/public/static/tmui${arg.tmui}.zip`
|
|
146
|
+
let tmuizipdatabufrre = await fetch(donloadTmui);
|
|
147
|
+
let buffer = await tmuizipdatabufrre.arrayBuffer();
|
|
148
|
+
let tmuizipdir = path.join(rootdir, 'tmui.zip')
|
|
149
|
+
if (fs.existsSync(tmuizipdir)) {
|
|
150
|
+
fs.rmSync(tmuizipdir)
|
|
151
|
+
}
|
|
152
|
+
fs.writeFileSync(tmuizipdir, Buffer.from(buffer))
|
|
153
|
+
call(`tmui${arg.tmui}下载完成,正在解压处理中...`)
|
|
154
|
+
|
|
155
|
+
// 解压
|
|
156
|
+
let resutl = await compressing.zip.uncompress(tmuizipdir, tmui32_hbx_dir)
|
|
157
|
+
|
|
158
|
+
call(`tmui${arg.tmui}安装成功`)
|
|
159
|
+
call(`正在清理缓存文件...`)
|
|
160
|
+
if (fs.existsSync(tmuizipdir)) {
|
|
161
|
+
fs.rmSync(tmuizipdir)
|
|
162
|
+
}
|
|
163
|
+
call(`恭喜安装tmui成功!!!`)
|
|
164
|
+
//
|
|
165
|
+
|
|
166
|
+
if (arg.uniappver && arg.type == 'cli') {
|
|
167
|
+
call(`正在检查cli sdk 版本...`)
|
|
168
|
+
let packjsonDir = path.join(rootdir, 'package.json')
|
|
169
|
+
let initjson = readPackageJson(packjsonDir)
|
|
170
|
+
if (initjson['dependencies']['@dcloudio/uni-app'] != arg.uniappver) {
|
|
171
|
+
call(`检测到cli版本与你选中的不一样,正在设置你选中的版本号`)
|
|
172
|
+
uniappDevListVer.forEach(el => {
|
|
173
|
+
if (initjson['dependencies'][el]) {
|
|
174
|
+
initjson['dependencies'][el] = arg.uniappver
|
|
175
|
+
}
|
|
176
|
+
if (initjson['devDependencies'][el]) {
|
|
177
|
+
initjson['devDependencies'][el] = arg.uniappver
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
call(`更新版本号完成,正在重新安装依赖,这个过程可能比较缓慢,如果失败,请手动在项目目录执行npm install或者重试`)
|
|
181
|
+
|
|
182
|
+
writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
|
|
183
|
+
|
|
184
|
+
execCmd((datastr) => {
|
|
185
|
+
call(datastr)
|
|
186
|
+
}, () => {
|
|
187
|
+
end()
|
|
188
|
+
}, 'npm install --save --registry=https://registry.npmmirror.com/')
|
|
189
|
+
|
|
190
|
+
return;
|
|
191
|
+
} else {
|
|
192
|
+
call(`检测到cli版本与你选中的一样,跳过更新`)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
end()
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//创建一个全新的项目.
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @param {{name,rootDir,type,ver,uniappver,uniappBuildType,machine}} arg
|
|
204
|
+
* @param {(str)=>{}} call
|
|
205
|
+
* @param {(str?:string)=>{}} end
|
|
206
|
+
*/
|
|
207
|
+
export async function createTmui(arg, call, end) {
|
|
208
|
+
let rootdir = path.normalize(arg.rootDir)
|
|
209
|
+
call('检测目录...')
|
|
210
|
+
if (!fs.existsSync(rootdir)) {
|
|
211
|
+
call('目录有误...')
|
|
212
|
+
end()
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
rootdir = path.join(rootdir, arg.name);
|
|
216
|
+
if (!fs.existsSync(rootdir)) {
|
|
217
|
+
fs.mkdirSync(rootdir)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (arg.type == 'uniappx') {
|
|
221
|
+
call('暂不支持uniappx更新sdk及下载更新tmui库,请联系作者授权,当前仅是创建一个空项目.')
|
|
222
|
+
call('开始创建项目中...')
|
|
223
|
+
// 创建4x的空项目.
|
|
224
|
+
let donloadTmui = `https://cdn.tmui.design/tmui4.0/tmui4.0xhbxModel.zip`
|
|
225
|
+
let tmuizipdatabufrre = await fetch(donloadTmui);
|
|
226
|
+
let buffer = await tmuizipdatabufrre.arrayBuffer();
|
|
227
|
+
let tmuizipdir = path.join(rootdir, 'tmui.zip')
|
|
228
|
+
if (fs.existsSync(tmuizipdir)) {
|
|
229
|
+
fs.rmSync(tmuizipdir)
|
|
230
|
+
}
|
|
231
|
+
fs.writeFileSync(tmuizipdir, Buffer.from(buffer))
|
|
232
|
+
call(`正在解压处理中...`)
|
|
233
|
+
// 解压
|
|
234
|
+
let resutl = await compressing.zip.uncompress(tmuizipdir, rootdir)
|
|
235
|
+
|
|
236
|
+
call(`创建uniAppx tmui4.0x 项目成功`)
|
|
237
|
+
call(`正在清理缓存文件...`)
|
|
238
|
+
if (fs.existsSync(tmuizipdir)) {
|
|
239
|
+
fs.rmSync(tmuizipdir)
|
|
240
|
+
}
|
|
241
|
+
call(`恭喜成功!!!`)
|
|
242
|
+
end(rootdir)
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
process.chdir(rootdir)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
let is32 = parseFloat(arg.ver.replace('.', '')) >= 32 ? true : false;
|
|
250
|
+
let hbxDonwload = `https://cdn.tmui.design/public/static/${is32 ? 'tmuiHBX32' : 'tmuiHBX'}.zip`
|
|
251
|
+
let cliDonwload = `https://cdn.tmui.design/public/static/${is32 ? 'cli32' : 'cli'}.zip`
|
|
252
|
+
let creatRootdirZipMod = arg.type == 'uniapp' && arg.uniappBuildType == 'cli' ? cliDonwload : hbxDonwload
|
|
253
|
+
|
|
254
|
+
// 下载模板.
|
|
255
|
+
let tmuiModZipdatabufrre = await fetch(creatRootdirZipMod);
|
|
256
|
+
let tmuimodeBuffer = await tmuiModZipdatabufrre.arrayBuffer();
|
|
257
|
+
let tmuimodDir = path.join(rootdir, 'tmuimode.zip')
|
|
258
|
+
if (fs.existsSync(tmuimodDir)) {
|
|
259
|
+
fs.rmSync(tmuimodDir)
|
|
260
|
+
}
|
|
261
|
+
fs.writeFileSync(tmuimodDir, Buffer.from(tmuimodeBuffer))
|
|
262
|
+
call(`正在创建项目模板`)
|
|
263
|
+
// 解压
|
|
264
|
+
let resutl = await compressing.zip.uncompress(tmuimodDir, rootdir)
|
|
265
|
+
call(`tmui模板创建成功,正在下载tmuiUi库`)
|
|
266
|
+
if (fs.existsSync(tmuimodDir)) {
|
|
267
|
+
fs.rmSync(tmuimodDir)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
let tmui32_hbx_dir = ""
|
|
273
|
+
if (arg.uniappBuildType == 'hbx') {
|
|
274
|
+
if (is32) {
|
|
275
|
+
let tmuidir = path.join(rootdir, 'uni_modules')
|
|
276
|
+
if (!fs.existsSync(tmuidir)) {
|
|
277
|
+
fs.mkdirSync(tmuidir)
|
|
278
|
+
}
|
|
279
|
+
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
280
|
+
if (!fs.existsSync(tmuidir)) {
|
|
281
|
+
fs.mkdirSync(tmuidir)
|
|
282
|
+
}
|
|
283
|
+
tmui32_hbx_dir = tmuidir
|
|
284
|
+
} else {
|
|
285
|
+
let tmuidir = path.join(rootdir, 'tmui')
|
|
286
|
+
if (!fs.existsSync(tmuidir)) {
|
|
287
|
+
fs.mkdirSync(tmuidir)
|
|
288
|
+
}
|
|
289
|
+
tmui32_hbx_dir = tmuidir
|
|
290
|
+
}
|
|
291
|
+
} else if (arg.uniappBuildType == 'cli') {
|
|
292
|
+
if (is32) {
|
|
293
|
+
let tmuidir = path.join(rootdir, 'src', 'uni_modules')
|
|
294
|
+
if (!fs.existsSync(tmuidir)) {
|
|
295
|
+
fs.mkdirSync(tmuidir)
|
|
296
|
+
}
|
|
297
|
+
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
298
|
+
if (!fs.existsSync(tmuidir)) {
|
|
299
|
+
fs.mkdirSync(tmuidir)
|
|
300
|
+
}
|
|
301
|
+
tmui32_hbx_dir = tmuidir
|
|
302
|
+
} else {
|
|
303
|
+
let tmuidir = path.join(rootdir, 'src', 'tmui')
|
|
304
|
+
if (!fs.existsSync(tmuidir)) {
|
|
305
|
+
fs.mkdirSync(tmuidir)
|
|
306
|
+
}
|
|
307
|
+
tmui32_hbx_dir = tmuidir
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
call('下载tmui中,版本号为:' + arg.ver)
|
|
315
|
+
|
|
316
|
+
// 下载tmui文件.
|
|
317
|
+
let donloadTmui = `https://cdn.tmui.design/public/static/tmui${arg.ver}.zip`
|
|
318
|
+
let tmuizipdatabufrre = await fetch(donloadTmui);
|
|
319
|
+
let buffer = await tmuizipdatabufrre.arrayBuffer();
|
|
320
|
+
let tmuizipdir = path.join(rootdir, 'tmui.zip')
|
|
321
|
+
if (fs.existsSync(tmuizipdir)) {
|
|
322
|
+
fs.rmSync(tmuizipdir)
|
|
323
|
+
}
|
|
324
|
+
fs.writeFileSync(tmuizipdir, Buffer.from(buffer))
|
|
325
|
+
call(`tmui${arg.ver}下载完成,正在解压处理中...`)
|
|
326
|
+
|
|
327
|
+
// 解压
|
|
328
|
+
let resutl2 = await compressing.zip.uncompress(tmuizipdir, tmui32_hbx_dir)
|
|
329
|
+
|
|
330
|
+
call(`tmui${arg.ver}安装成功`)
|
|
331
|
+
call(`正在清理缓存文件...`)
|
|
332
|
+
if (fs.existsSync(tmuizipdir)) {
|
|
333
|
+
fs.rmSync(tmuizipdir)
|
|
334
|
+
}
|
|
335
|
+
call(`恭喜安装tmui成功!!!`)
|
|
336
|
+
//
|
|
337
|
+
|
|
338
|
+
if (arg.uniappver && arg.uniappBuildType == 'cli') {
|
|
339
|
+
call(`正在检查cli sdk 版本...`)
|
|
340
|
+
let packjsonDir = path.join(rootdir, 'package.json')
|
|
341
|
+
let initjson = readPackageJson(packjsonDir)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
uniappDevListVer.forEach(el => {
|
|
345
|
+
if (initjson['dependencies'][el]) {
|
|
346
|
+
initjson['dependencies'][el] = arg.uniappver
|
|
347
|
+
}
|
|
348
|
+
if (initjson['devDependencies'][el]) {
|
|
349
|
+
initjson['devDependencies'][el] = arg.uniappver
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
call(`更新版本号完成,正在重新安装依赖,这个过程可能比较缓慢,如果失败,请手动在项目目录执行npm install或者重试`)
|
|
353
|
+
|
|
354
|
+
// 检查是不是mac m1芯片系列
|
|
355
|
+
if (arg.machine == 'arm') {
|
|
356
|
+
initjson['dependencies']["@esbuild/darwin-x64"] = "^0.21.5"
|
|
357
|
+
initjson['dependencies']["@rollup/rollup-darwin-x64"] = "^4.24.0"
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
|
|
361
|
+
|
|
362
|
+
execCmd((datastr) => {
|
|
363
|
+
call(datastr)
|
|
364
|
+
}, () => {
|
|
365
|
+
end(rootdir)
|
|
366
|
+
}, 'npm install --save --registry=https://registry.npmmirror.com/')
|
|
367
|
+
|
|
368
|
+
return;
|
|
369
|
+
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
end(rootdir)
|
|
374
|
+
|
|
375
|
+
}
|