-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
Copy pathutils.js
113 lines (107 loc) · 2.64 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const fs = require('fs')
const path = require('path')
const colors = require('picocolors')
const priority = {
uts: 100,
'uni-uts-v1': 99,
'uni-shared': 98,
'uni-i18n': 90,
'uni-app': 90,
'uni-cli-shared': 80,
'uni-stat': 75,
'uni-push': 75,
'uni-components': 75,
'uni-mp-vue': 75,
'uni-mp-alipay': 70,
'uni-mp-baidu': 70,
'uni-mp-kuaishou': 70,
'uni-mp-qq': 70,
'uni-mp-lark': 70,
'uni-mp-toutiao': 70,
'uni-mp-weixin': 70,
'uni-quickapp-webview': 70,
'uni-h5-vite': 50,
'uni-h5': 40,
'uni-mp-compiler': 40,
'uni-mp-vite': 35,
'uni-app-vue': 35,
'uni-nvue-styler': 35,
'uni-app-vite': 31,
'uni-app-uts': 31,
'uni-app-plus': 30,
'vite-plugin-uni': 20,
'uni-cloud': 10,
'uni-automator': 10,
'uni-stacktracey': 8,
'uni-vue-devtools': 6,
'size-check': 1,
}
exports.priority = priority
const targets = (exports.targets = fs.readdirSync('packages').filter((f) => {
if (!fs.statSync(`packages/${f}`).isDirectory()) {
return false
}
try {
return (
fs.existsSync(path.resolve(__dirname, `../packages/${f}/build.json`)) ||
fs.existsSync(
path.resolve(__dirname, `../packages/${f}/vite.config.ts`)
) ||
fs.existsSync(path.resolve(__dirname, `../packages/${f}/tsconfig.json`))
)
} catch (e) { }
return false
}).sort((a, b) => {
const priorityA = priority[a] || 0
const priorityB = priority[b] || 0
return priorityB - priorityA
}));
exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
const matched = new Set()
// 优先完整匹配
if (!includeAllMatching) {
partialTargets.forEach((partialTarget) => {
for (const target of targets) {
if (target === partialTarget) {
matched.add(target)
break
}
}
})
}
if (includeAllMatching || !matched.size) {
partialTargets.forEach((partialTarget) => {
for (const target of targets) {
if (target.match(partialTarget)) {
matched.add(target)
if (!includeAllMatching) {
break
}
}
}
})
}
if (matched.size) {
return Array.from(matched).sort((a, b) => priority[b] - priority[a])
} else {
console.log()
console.error(
` ${colors.bgRed(' ERROR ')} ${colors.red(
`Target ${colors.underline(partialTargets)} not found!`
)}`
)
console.log()
process.exit(1)
}
}
exports.resolvePackages = (dirname) => {
dirname = path.resolve(__dirname, dirname)
return fs
.readdirSync(dirname)
.filter(
(p) =>
!p.endsWith('.ts') &&
!p.startsWith('.') &&
fs.existsSync(path.join(dirname, p, 'package.json'))
)
}