tmui-cli 1.2.9 → 2.0.0
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 +18 -90
- package/dist/main.mjs +81 -0
- package/package.json +48 -50
- package/bin/cmdTool.js +0 -229
- package/bin/createTmui.js +0 -383
- package/bin/dirTool.js +0 -152
- package/bin/hooks.js +0 -215
- package/bin/net.js +0 -139
- package/bin/selectedDir.js +0 -28
- package/bin/tmui.js +0 -28
- package/dist/tmui.js +0 -1
- package/webpack.config.js +0 -17
- package/website/css/app.930a5dcc.css +0 -1
- package/website/css/chunk-vendors.4ad1cdb5.css +0 -2
- package/website/favicon.ico +0 -0
- package/website/index.html +0 -1
- package/website/js/app.4d09dd9c.js +0 -2
- package/website/js/app.4d09dd9c.js.map +0 -1
- package/website/js/chunk-vendors.6ab6ae16.js +0 -15
- package/website/js/chunk-vendors.6ab6ae16.js.map +0 -1
package/bin/createTmui.js
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const {execCmd} = require("./cmdTool.js")
|
|
4
|
-
const fs = require("fs")
|
|
5
|
-
const compressing = require("compressing")
|
|
6
|
-
const Fetch = import("node-fetch")
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const uniappDevListVer = [
|
|
10
|
-
"@dcloudio/uni-app",
|
|
11
|
-
"@dcloudio/uni-app-plus",
|
|
12
|
-
"@dcloudio/uni-components",
|
|
13
|
-
"@dcloudio/uni-h5",
|
|
14
|
-
"@dcloudio/uni-mp-alipay",
|
|
15
|
-
"@dcloudio/uni-mp-baidu",
|
|
16
|
-
"@dcloudio/uni-mp-kuaishou",
|
|
17
|
-
"@dcloudio/uni-mp-lark",
|
|
18
|
-
"@dcloudio/uni-mp-qq",
|
|
19
|
-
"@dcloudio/uni-mp-toutiao",
|
|
20
|
-
"@dcloudio/uni-mp-weixin",
|
|
21
|
-
"@dcloudio/uni-quickapp-webview",
|
|
22
|
-
"@dcloudio/uni-automator",
|
|
23
|
-
"@dcloudio/uni-cli-shared",
|
|
24
|
-
"@dcloudio/vite-plugin-uni"
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
//递归删除目录文件.
|
|
28
|
-
function delFile(fileUrl, flag) {
|
|
29
|
-
if (!fs.existsSync(fileUrl)) return;
|
|
30
|
-
// 当前文件为文件夹时
|
|
31
|
-
if (fs.statSync(fileUrl).isDirectory()) {
|
|
32
|
-
var files = fs.readdirSync(fileUrl);
|
|
33
|
-
var len = files.length,
|
|
34
|
-
removeNumber = 0;
|
|
35
|
-
if (len > 0) {
|
|
36
|
-
files.forEach(function (file) {
|
|
37
|
-
removeNumber++;
|
|
38
|
-
var stats = fs.statSync(fileUrl + '/' + file);
|
|
39
|
-
var url = fileUrl + '/' + file;
|
|
40
|
-
if (fs.statSync(url).isDirectory()) {
|
|
41
|
-
delFile(url, true);
|
|
42
|
-
} else {
|
|
43
|
-
fs.unlinkSync(url);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
if (len == removeNumber && flag) {
|
|
47
|
-
fs.rmdirSync(fileUrl);
|
|
48
|
-
}
|
|
49
|
-
} else if (len == 0 && flag) {
|
|
50
|
-
fs.rmdirSync(fileUrl);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
// 当前文件为文件时
|
|
54
|
-
fs.unlinkSync(fileUrl);
|
|
55
|
-
console.log('删除文件' + fileUrl + '成功');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
//读取项目的配置资料.
|
|
59
|
-
function readPackageJson(filepath) {
|
|
60
|
-
let str = fs.readFileSync(filepath).toString('utf-8');
|
|
61
|
-
let reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g;
|
|
62
|
-
str = str.replace(reg, function (word) {
|
|
63
|
-
// 去除注释后的文本
|
|
64
|
-
return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
|
|
65
|
-
});
|
|
66
|
-
const d = JSON.parse(str);
|
|
67
|
-
return d;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function writePackageJson(filepath, str) {
|
|
71
|
-
fs.writeFileSync(filepath, str, { encoding: 'utf-8' })
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 更新项目.
|
|
78
|
-
* @param {{path,type,uvue,tmui,uniappver}} arg
|
|
79
|
-
*/
|
|
80
|
-
async function UpdateTmui(arg, call, end) {
|
|
81
|
-
const fetch = (await Fetch).default;
|
|
82
|
-
|
|
83
|
-
let rootdir = path.normalize(arg.path)
|
|
84
|
-
call('检测目录...')
|
|
85
|
-
if (!fs.existsSync(rootdir)) {
|
|
86
|
-
call('项目目录有误...')
|
|
87
|
-
end()
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
process.chdir(arg.path);
|
|
92
|
-
|
|
93
|
-
let tmui32_hbx_dir = ''
|
|
94
|
-
let is32 = parseFloat(arg.tmui.replace('.', '')) >= 32 ? true : false;
|
|
95
|
-
|
|
96
|
-
if (arg.type == 'hbx') {
|
|
97
|
-
if (is32) {
|
|
98
|
-
let tmuidir = path.join(rootdir, 'uni_modules')
|
|
99
|
-
if (!fs.existsSync(tmuidir)) {
|
|
100
|
-
fs.mkdirSync(tmuidir)
|
|
101
|
-
}
|
|
102
|
-
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
103
|
-
if (!fs.existsSync(tmuidir)) {
|
|
104
|
-
fs.mkdirSync(tmuidir)
|
|
105
|
-
}
|
|
106
|
-
tmui32_hbx_dir = tmuidir
|
|
107
|
-
} else {
|
|
108
|
-
let tmuidir = path.join(rootdir, 'tmui')
|
|
109
|
-
if (!fs.existsSync(tmuidir)) {
|
|
110
|
-
fs.mkdirSync(tmuidir)
|
|
111
|
-
}
|
|
112
|
-
tmui32_hbx_dir = tmuidir
|
|
113
|
-
}
|
|
114
|
-
} else if (arg.type == 'cli') {
|
|
115
|
-
if (is32) {
|
|
116
|
-
let tmuidir = path.join(rootdir, 'src', 'uni_modules')
|
|
117
|
-
if (!fs.existsSync(tmuidir)) {
|
|
118
|
-
fs.mkdirSync(tmuidir)
|
|
119
|
-
}
|
|
120
|
-
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
121
|
-
if (!fs.existsSync(tmuidir)) {
|
|
122
|
-
fs.mkdirSync(tmuidir)
|
|
123
|
-
}
|
|
124
|
-
tmui32_hbx_dir = tmuidir
|
|
125
|
-
} else {
|
|
126
|
-
let tmuidir = path.join(rootdir, 'src', 'tmui')
|
|
127
|
-
if (!fs.existsSync(tmuidir)) {
|
|
128
|
-
fs.mkdirSync(tmuidir)
|
|
129
|
-
}
|
|
130
|
-
tmui32_hbx_dir = tmuidir
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
call('已创建/检测/清除...tmui目录...')
|
|
135
|
-
if (!fs.existsSync(tmui32_hbx_dir)) {
|
|
136
|
-
call('无法检测和创建目录,请检查权限...')
|
|
137
|
-
end()
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
//删除tmui目录.
|
|
141
|
-
delFile(tmui32_hbx_dir, true)
|
|
142
|
-
//再重新创建,确保目录被清空.
|
|
143
|
-
fs.mkdirSync(tmui32_hbx_dir)
|
|
144
|
-
call('下载tmui中,版本号为:' + arg.tmui)
|
|
145
|
-
|
|
146
|
-
// 下载tmui文件.
|
|
147
|
-
let donloadTmui = `https://cdn.tmui.design/public/static/tmui${arg.tmui}.zip`
|
|
148
|
-
let tmuizipdatabufrre = await fetch(donloadTmui);
|
|
149
|
-
let buffer = await tmuizipdatabufrre.arrayBuffer();
|
|
150
|
-
let tmuizipdir = path.join(rootdir, 'tmui.zip')
|
|
151
|
-
if (fs.existsSync(tmuizipdir)) {
|
|
152
|
-
fs.rmSync(tmuizipdir)
|
|
153
|
-
}
|
|
154
|
-
fs.writeFileSync(tmuizipdir, Buffer.from(buffer))
|
|
155
|
-
call(`tmui${arg.tmui}下载完成,正在解压处理中...`)
|
|
156
|
-
|
|
157
|
-
// 解压
|
|
158
|
-
let resutl = await compressing.zip.uncompress(tmuizipdir, tmui32_hbx_dir)
|
|
159
|
-
|
|
160
|
-
call(`tmui${arg.tmui}安装成功`)
|
|
161
|
-
call(`正在清理缓存文件...`)
|
|
162
|
-
if (fs.existsSync(tmuizipdir)) {
|
|
163
|
-
fs.rmSync(tmuizipdir)
|
|
164
|
-
}
|
|
165
|
-
call(`恭喜安装tmui成功!!!`)
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
if (arg.uniappver && arg.type == 'cli') {
|
|
169
|
-
call(`正在检查cli sdk 版本...`)
|
|
170
|
-
let packjsonDir = path.join(rootdir, 'package.json')
|
|
171
|
-
let initjson = readPackageJson(packjsonDir)
|
|
172
|
-
if (initjson['dependencies']['@dcloudio/uni-app'] != arg.uniappver) {
|
|
173
|
-
call(`检测到cli版本与你选中的不一样,正在设置你选中的版本号`)
|
|
174
|
-
uniappDevListVer.forEach( function(el) {
|
|
175
|
-
if (initjson['dependencies'][el]) {
|
|
176
|
-
initjson['dependencies'][el] = arg.uniappver
|
|
177
|
-
}
|
|
178
|
-
if (initjson['devDependencies'][el]) {
|
|
179
|
-
initjson['devDependencies'][el] = arg.uniappver
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
call(`更新版本号完成,正在重新安装依赖,这个过程可能比较缓慢,如果失败,请手动在项目目录执行npm install或者重试`)
|
|
183
|
-
|
|
184
|
-
writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
|
|
185
|
-
|
|
186
|
-
execCmd(function (datastr){
|
|
187
|
-
call(datastr)
|
|
188
|
-
}, function () {
|
|
189
|
-
end()
|
|
190
|
-
}, 'npm install --save --registry=https://registry.npmmirror.com/')
|
|
191
|
-
|
|
192
|
-
return;
|
|
193
|
-
} else {
|
|
194
|
-
call(`检测到cli版本与你选中的一样,跳过更新`)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
end()
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
//创建一个全新的项目.
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
* @param {{name,rootDir,type,ver,uniappver,uniappBuildType,machine}} arg
|
|
206
|
-
*/
|
|
207
|
-
async function createTmui(arg, call, end) {
|
|
208
|
-
const fetch = (await Fetch).default;
|
|
209
|
-
|
|
210
|
-
let rootdir = path.normalize(arg.rootDir)
|
|
211
|
-
call('检测目录...')
|
|
212
|
-
if (!fs.existsSync(rootdir)) {
|
|
213
|
-
call('目录有误...')
|
|
214
|
-
end()
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
rootdir = path.join(rootdir, arg.name);
|
|
218
|
-
if (!fs.existsSync(rootdir)) {
|
|
219
|
-
fs.mkdirSync(rootdir)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (arg.type == 'uniappx') {
|
|
223
|
-
call('暂不支持uniappx更新sdk及下载更新tmui库,请联系作者授权,当前仅是创建一个空项目.')
|
|
224
|
-
call('开始创建项目中...')
|
|
225
|
-
// 创建4x的空项目.
|
|
226
|
-
let donloadTmui = `https://cdn.tmui.design/tmui4.0/tmui4.0xhbxModel.zip`
|
|
227
|
-
let tmuizipdatabufrre = await fetch(donloadTmui);
|
|
228
|
-
let buffer = await tmuizipdatabufrre.arrayBuffer();
|
|
229
|
-
let tmuizipdir = path.join(rootdir, 'tmui.zip')
|
|
230
|
-
if (fs.existsSync(tmuizipdir)) {
|
|
231
|
-
fs.rmSync(tmuizipdir)
|
|
232
|
-
}
|
|
233
|
-
fs.writeFileSync(tmuizipdir, Buffer.from(buffer))
|
|
234
|
-
call(`正在解压处理中...`)
|
|
235
|
-
// 解压
|
|
236
|
-
let resutl = await compressing.zip.uncompress(tmuizipdir, rootdir)
|
|
237
|
-
|
|
238
|
-
call(`创建uniAppx tmui4.0x 项目成功`)
|
|
239
|
-
call(`正在清理缓存文件...`)
|
|
240
|
-
if (fs.existsSync(tmuizipdir)) {
|
|
241
|
-
fs.rmSync(tmuizipdir)
|
|
242
|
-
}
|
|
243
|
-
call(`恭喜成功!!!`)
|
|
244
|
-
end(rootdir)
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
process.chdir(rootdir)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
let is32 = parseFloat(arg.ver.replace('.', '')) >= 32 ? true : false;
|
|
252
|
-
let hbxDonwload = `https://cdn.tmui.design/public/static/${is32 ? 'tmuiHBX32' : 'tmuiHBX'}.zip`
|
|
253
|
-
let cliDonwload = `https://cdn.tmui.design/public/static/${is32 ? 'cli32' : 'cli'}.zip`
|
|
254
|
-
let creatRootdirZipMod = arg.type == 'uniapp' && arg.uniappBuildType == 'cli' ? cliDonwload : hbxDonwload
|
|
255
|
-
|
|
256
|
-
// 下载模板.
|
|
257
|
-
let tmuiModZipdatabufrre = await fetch(creatRootdirZipMod);
|
|
258
|
-
let tmuimodeBuffer = await tmuiModZipdatabufrre.arrayBuffer();
|
|
259
|
-
let tmuimodDir = path.join(rootdir, 'tmuimode.zip')
|
|
260
|
-
if (fs.existsSync(tmuimodDir)) {
|
|
261
|
-
fs.rmSync(tmuimodDir)
|
|
262
|
-
}
|
|
263
|
-
fs.writeFileSync(tmuimodDir, Buffer.from(tmuimodeBuffer))
|
|
264
|
-
call(`正在创建项目模板`)
|
|
265
|
-
// 解压
|
|
266
|
-
let resutl = await compressing.zip.uncompress(tmuimodDir, rootdir)
|
|
267
|
-
call(`tmui模板创建成功,正在下载tmuiUi库`)
|
|
268
|
-
if (fs.existsSync(tmuimodDir)) {
|
|
269
|
-
fs.rmSync(tmuimodDir)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
let tmui32_hbx_dir = ""
|
|
275
|
-
if (arg.uniappBuildType == 'hbx') {
|
|
276
|
-
if (is32) {
|
|
277
|
-
let tmuidir = path.join(rootdir, 'uni_modules')
|
|
278
|
-
if (!fs.existsSync(tmuidir)) {
|
|
279
|
-
fs.mkdirSync(tmuidir)
|
|
280
|
-
}
|
|
281
|
-
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
282
|
-
if (!fs.existsSync(tmuidir)) {
|
|
283
|
-
fs.mkdirSync(tmuidir)
|
|
284
|
-
}
|
|
285
|
-
tmui32_hbx_dir = tmuidir
|
|
286
|
-
} else {
|
|
287
|
-
let tmuidir = path.join(rootdir, 'tmui')
|
|
288
|
-
if (!fs.existsSync(tmuidir)) {
|
|
289
|
-
fs.mkdirSync(tmuidir)
|
|
290
|
-
}
|
|
291
|
-
tmui32_hbx_dir = tmuidir
|
|
292
|
-
}
|
|
293
|
-
} else if (arg.uniappBuildType == 'cli') {
|
|
294
|
-
if (is32) {
|
|
295
|
-
let tmuidir = path.join(rootdir, 'src', 'uni_modules')
|
|
296
|
-
if (!fs.existsSync(tmuidir)) {
|
|
297
|
-
fs.mkdirSync(tmuidir)
|
|
298
|
-
}
|
|
299
|
-
tmuidir = path.join(tmuidir, 'tm-ui')
|
|
300
|
-
if (!fs.existsSync(tmuidir)) {
|
|
301
|
-
fs.mkdirSync(tmuidir)
|
|
302
|
-
}
|
|
303
|
-
tmui32_hbx_dir = tmuidir
|
|
304
|
-
} else {
|
|
305
|
-
let tmuidir = path.join(rootdir, 'src', 'tmui')
|
|
306
|
-
if (!fs.existsSync(tmuidir)) {
|
|
307
|
-
fs.mkdirSync(tmuidir)
|
|
308
|
-
}
|
|
309
|
-
tmui32_hbx_dir = tmuidir
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
call('下载tmui中,版本号为:' + arg.ver)
|
|
317
|
-
|
|
318
|
-
// 下载tmui文件.
|
|
319
|
-
let donloadTmui = `https://cdn.tmui.design/public/static/tmui${arg.ver}.zip`
|
|
320
|
-
let tmuizipdatabufrre = await fetch(donloadTmui);
|
|
321
|
-
let buffer = await tmuizipdatabufrre.arrayBuffer();
|
|
322
|
-
let tmuizipdir = path.join(rootdir, 'tmui.zip')
|
|
323
|
-
if (fs.existsSync(tmuizipdir)) {
|
|
324
|
-
fs.rmSync(tmuizipdir)
|
|
325
|
-
}
|
|
326
|
-
fs.writeFileSync(tmuizipdir, Buffer.from(buffer))
|
|
327
|
-
call(`tmui${arg.ver}下载完成,正在解压处理中...`)
|
|
328
|
-
|
|
329
|
-
// 解压
|
|
330
|
-
let resutl2 = await compressing.zip.uncompress(tmuizipdir, tmui32_hbx_dir)
|
|
331
|
-
|
|
332
|
-
call(`tmui${arg.ver}安装成功`)
|
|
333
|
-
call(`正在清理缓存文件...`)
|
|
334
|
-
if (fs.existsSync(tmuizipdir)) {
|
|
335
|
-
fs.rmSync(tmuizipdir)
|
|
336
|
-
}
|
|
337
|
-
call(`恭喜安装tmui成功!!!`)
|
|
338
|
-
//
|
|
339
|
-
|
|
340
|
-
if (arg.uniappver && arg.uniappBuildType == 'cli') {
|
|
341
|
-
call(`正在检查cli sdk 版本...`)
|
|
342
|
-
let packjsonDir = path.join(rootdir, 'package.json')
|
|
343
|
-
let initjson = readPackageJson(packjsonDir)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
uniappDevListVer.forEach(function (el) {
|
|
347
|
-
if (initjson['dependencies'][el]) {
|
|
348
|
-
initjson['dependencies'][el] = arg.uniappver
|
|
349
|
-
}
|
|
350
|
-
if (initjson['devDependencies'][el]) {
|
|
351
|
-
initjson['devDependencies'][el] = arg.uniappver
|
|
352
|
-
}
|
|
353
|
-
})
|
|
354
|
-
call(`更新版本号完成,正在重新安装依赖,这个过程可能比较缓慢,如果失败,请手动在项目目录执行npm install或者重试`)
|
|
355
|
-
|
|
356
|
-
// 检查是不是mac m1芯片系列,最新的4.42+不需要了
|
|
357
|
-
if (arg.machine == 'arm') {
|
|
358
|
-
// initjson['dependencies']["@esbuild/darwin-x64"] = "^0.21.5"
|
|
359
|
-
// initjson['dependencies']["@rollup/rollup-darwin-x64"] = "^4.24.0"
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
|
|
363
|
-
|
|
364
|
-
execCmd(function (datastr) {
|
|
365
|
-
call(datastr)
|
|
366
|
-
}, function () {
|
|
367
|
-
end(rootdir)
|
|
368
|
-
}, 'npm install --save --registry=https://registry.npmmirror.com/')
|
|
369
|
-
|
|
370
|
-
return;
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
end(rootdir)
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
module.exports = {
|
|
380
|
-
createTmui,
|
|
381
|
-
UpdateTmui,
|
|
382
|
-
delFile
|
|
383
|
-
}
|
package/bin/dirTool.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
const path = require("path")
|
|
2
|
-
const fs = require("fs")
|
|
3
|
-
|
|
4
|
-
function getJsonFiles(jsonPath) {
|
|
5
|
-
let jsonFiles = [];
|
|
6
|
-
|
|
7
|
-
function findJsonFile(www) {
|
|
8
|
-
let files = fs.readdirSync(www);
|
|
9
|
-
files.forEach(function(item, index) {
|
|
10
|
-
let fPath = path.join(www, item);
|
|
11
|
-
let stat = fs.statSync(fPath);
|
|
12
|
-
if (stat.isDirectory() === true) {
|
|
13
|
-
findJsonFile(fPath);
|
|
14
|
-
}
|
|
15
|
-
if (stat.isFile() === true) {
|
|
16
|
-
jsonFiles.push(fPath);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
findJsonFile(jsonPath);
|
|
21
|
-
return jsonFiles;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getJsonDir(basePath = './') {
|
|
25
|
-
const dirPath = basePath;
|
|
26
|
-
const root = {
|
|
27
|
-
name: '',
|
|
28
|
-
type: 'dir',
|
|
29
|
-
parent: dirPath,
|
|
30
|
-
children: []
|
|
31
|
-
};
|
|
32
|
-
const files = fs.readdirSync(dirPath);
|
|
33
|
-
|
|
34
|
-
const tree = [];
|
|
35
|
-
for (let i = 0; i < files.length; i++) {
|
|
36
|
-
const filename = files[i];
|
|
37
|
-
const filePath = path.join(dirPath, filename);
|
|
38
|
-
const suffix = path.extname(filename)
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
if (filename.lastIndexOf('.tmp') == -1 && filename.lastIndexOf('.sys') == -1&&filename[0]!='.') {
|
|
42
|
-
const stats = fs.statSync(filePath);
|
|
43
|
-
if (stats.isFile()) {
|
|
44
|
-
const fileNode = {
|
|
45
|
-
name: filename,
|
|
46
|
-
type: 'file',
|
|
47
|
-
parent: dirPath,
|
|
48
|
-
suffix
|
|
49
|
-
};
|
|
50
|
-
tree.push(fileNode);
|
|
51
|
-
} else if (stats.isDirectory()) {
|
|
52
|
-
const dirNode = {
|
|
53
|
-
name: filename,
|
|
54
|
-
type: 'dir',
|
|
55
|
-
parent: dirPath,
|
|
56
|
-
suffix:'',
|
|
57
|
-
children: []
|
|
58
|
-
};
|
|
59
|
-
tree.push(dirNode);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} catch (error) {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
root.children = tree;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return root;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**读取项目信息根据提供的路径。 */
|
|
75
|
-
function checkProject(obj) {
|
|
76
|
-
|
|
77
|
-
// const {id,path,type} = obj;
|
|
78
|
-
let mainsetStrPath = "";
|
|
79
|
-
// 检查是否有tmui文件。和目录。
|
|
80
|
-
let tmuiDir = ""
|
|
81
|
-
//可运行的命令行。
|
|
82
|
-
let scriptsPackagePath = ""
|
|
83
|
-
let tmuix4dir = ""
|
|
84
|
-
if (obj.type == 'cli') {
|
|
85
|
-
mainsetStrPath = path.join(obj.path, 'src', 'manifest.json')
|
|
86
|
-
tmuiDir = path.join(obj.path, 'src', 'tmui', 'package.json')
|
|
87
|
-
if(!fs.existsSync(tmuiDir)){
|
|
88
|
-
tmuiDir = path.join(obj.path, 'src', 'uni_modules', 'tm-ui', 'package.json')
|
|
89
|
-
}
|
|
90
|
-
scriptsPackagePath = path.join(obj.path, 'package.json')
|
|
91
|
-
} else {
|
|
92
|
-
mainsetStrPath = path.join(obj.path, 'manifest.json')
|
|
93
|
-
tmuiDir = path.join(obj.path, 'tmui', 'package.json')
|
|
94
|
-
if(!fs.existsSync(tmuiDir)){
|
|
95
|
-
tmuiDir = path.join(obj.path, 'uni_modules', 'tm-ui', 'package.json')
|
|
96
|
-
}
|
|
97
|
-
tmuix4dir = path.join(obj.path, 'uni_modules','tmx-ui', 'package.json')
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let str = fs.readFileSync(mainsetStrPath).toString('utf-8');
|
|
101
|
-
|
|
102
|
-
let reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g;
|
|
103
|
-
|
|
104
|
-
str = str.replace(reg, function(word) {
|
|
105
|
-
// 去除注释后的文本
|
|
106
|
-
return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const d = JSON.parse(str);
|
|
110
|
-
// 是否是x项目
|
|
111
|
-
const isUniappx = d['uni-app-x']
|
|
112
|
-
let tmui = "";
|
|
113
|
-
if(isUniappx){
|
|
114
|
-
if (fs.existsSync(tmuix4dir)) {
|
|
115
|
-
let str2 = fs.readFileSync(tmuix4dir).toString('utf-8');
|
|
116
|
-
const p = JSON.parse(str2);
|
|
117
|
-
tmui = p.version
|
|
118
|
-
}
|
|
119
|
-
}else{
|
|
120
|
-
if (fs.existsSync(tmuiDir)) {
|
|
121
|
-
let str2 = fs.readFileSync(tmuiDir).toString('utf-8');
|
|
122
|
-
const p = JSON.parse(str2);
|
|
123
|
-
tmui = p.version
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// 读取运行的命令行。
|
|
129
|
-
let scripts = ""
|
|
130
|
-
if (fs.existsSync(scriptsPackagePath)) {
|
|
131
|
-
let str2 = fs.readFileSync(scriptsPackagePath).toString('utf-8');
|
|
132
|
-
const p = JSON.parse(str2);
|
|
133
|
-
scripts = p.scripts
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
name: d.name,
|
|
138
|
-
appid: d.appid,
|
|
139
|
-
versionName: d.versionName,
|
|
140
|
-
tmui: tmui,
|
|
141
|
-
unix:isUniappx,
|
|
142
|
-
id: obj.id,
|
|
143
|
-
scripts: scripts
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
module.exports = {
|
|
149
|
-
getJsonFiles,
|
|
150
|
-
getJsonDir,
|
|
151
|
-
checkProject
|
|
152
|
-
}
|