vue3-yuanma/scripts/utils.js
2019-10-04 13:08:17 -04:00

32 lines
749 B
JavaScript

const fs = require('fs')
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.some(partialTarget => {
for (const target of targets) {
if (target.match(partialTarget)) {
matched.push(target)
if (!includeAllMatching) {
break
}
}
}
})
if (matched.length) {
return matched
} else {
throw new Error(`Target ${partialTargets} not found!`)
}
}