2018-09-19 23:35:38 +08:00
|
|
|
const fs = require('fs')
|
2019-10-16 05:13:35 +08:00
|
|
|
const chalk = require('chalk')
|
2018-09-19 23:35:38 +08:00
|
|
|
|
2018-10-17 03:47:51 +08:00
|
|
|
const targets = (exports.targets = fs.readdirSync('packages').filter(f => {
|
2018-10-17 05:41:59 +08:00
|
|
|
if (!fs.statSync(`packages/${f}`).isDirectory()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const pkg = require(`../packages/${f}/package.json`)
|
2019-10-05 01:08:06 +08:00
|
|
|
if (pkg.private && !pkg.buildOptions) {
|
2018-10-17 05:41:59 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2018-10-17 03:47:51 +08:00
|
|
|
}))
|
2018-09-19 23:35:38 +08:00
|
|
|
|
2019-10-02 23:19:30 +08:00
|
|
|
exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
|
2018-09-19 23:35:38 +08:00
|
|
|
const matched = []
|
2019-10-02 23:19:30 +08:00
|
|
|
partialTargets.some(partialTarget => {
|
|
|
|
for (const target of targets) {
|
|
|
|
if (target.match(partialTarget)) {
|
|
|
|
matched.push(target)
|
|
|
|
if (!includeAllMatching) {
|
|
|
|
break
|
|
|
|
}
|
2018-10-23 23:58:37 +08:00
|
|
|
}
|
2018-09-19 23:35:38 +08:00
|
|
|
}
|
2019-10-02 23:19:30 +08:00
|
|
|
})
|
2018-09-19 23:35:38 +08:00
|
|
|
if (matched.length) {
|
|
|
|
return matched
|
|
|
|
} else {
|
2019-10-16 05:13:35 +08:00
|
|
|
console.log()
|
|
|
|
console.error(
|
|
|
|
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
|
|
|
|
`Target ${chalk.underline(partialTargets)} not found!`
|
|
|
|
)}`
|
|
|
|
)
|
|
|
|
console.log()
|
|
|
|
|
|
|
|
process.exit(1)
|
2018-09-19 23:35:38 +08:00
|
|
|
}
|
|
|
|
}
|