vue3-yuanma/scripts/utils.js
2019-11-04 14:28:11 -05:00

41 lines
933 B
JavaScript

const fs = require('fs')
const chalk = require('chalk')
const targets = (exports.targets = fs.readdirSync('packages').filter(f => {
if (!fs.statSync(`packages/${f}`).isDirectory()) {
return false
}
const pkg = require(`../packages/${f}/package.json`)
if (pkg.private && !pkg.buildOptions) {
return false
}
return true
}))
exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
const matched = []
partialTargets.forEach(partialTarget => {
for (const target of targets) {
if (target.match(partialTarget)) {
matched.push(target)
if (!includeAllMatching) {
break
}
}
}
})
if (matched.length) {
return matched
} else {
console.log()
console.error(
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
`Target ${chalk.underline(partialTargets)} not found!`
)}`
)
console.log()
process.exit(1)
}
}