vue3-yuanma/scripts/utils.js

30 lines
673 B
JavaScript
Raw Normal View History

2018-09-19 23:35:38 +08:00
const fs = require('fs')
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`)
if (pkg.private) {
return false
}
return true
}))
2018-09-19 23:35:38 +08:00
2018-10-23 23:58:37 +08:00
exports.fuzzyMatchTarget = (partialTarget, includeAllMatching) => {
2018-09-19 23:35:38 +08:00
const matched = []
for (const target of targets) {
if (target.match(partialTarget)) {
matched.push(target)
2018-10-23 23:58:37 +08:00
if (!includeAllMatching) {
return matched
}
2018-09-19 23:35:38 +08:00
}
}
if (matched.length) {
return matched
} else {
throw new Error(`Target ${partialTarget} not found!`)
}
}