Spaces:
Sleeping
Sleeping
File size: 1,888 Bytes
4cadbaf |
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 |
const pluginRE = /^(@vue\/|vue-|@[\w-]+(\.)?[\w-]+\/vue-)cli-plugin-/
const scopeRE = /^@[\w-]+(\.)?[\w-]+\//
const officialRE = /^@vue\//
const officialPlugins = [
'babel',
'e2e-cypress',
'e2e-nightwatch',
'e2e-webdriverio',
'eslint',
'pwa',
'router',
'typescript',
'unit-jest',
'unit-mocha',
'vuex'
]
exports.isPlugin = id => pluginRE.test(id)
exports.isOfficialPlugin = id => exports.isPlugin(id) && officialRE.test(id)
exports.toShortPluginId = id => id.replace(pluginRE, '')
exports.resolvePluginId = id => {
// already full id
// e.g. vue-cli-plugin-foo, @vue/cli-plugin-foo, @bar/vue-cli-plugin-foo
if (pluginRE.test(id)) {
return id
}
if (id === '@vue/cli-service') {
return id
}
if (officialPlugins.includes(id)) {
return `@vue/cli-plugin-${id}`
}
// scoped short
// e.g. @vue/foo, @bar/foo
if (id.charAt(0) === '@') {
const scopeMatch = id.match(scopeRE)
if (scopeMatch) {
const scope = scopeMatch[0]
const shortId = id.replace(scopeRE, '')
return `${scope}${scope === '@vue/' ? `` : `vue-`}cli-plugin-${shortId}`
}
}
// default short
// e.g. foo
return `vue-cli-plugin-${id}`
}
exports.matchesPluginId = (input, full) => {
const short = full.replace(pluginRE, '')
return (
// input is full
full === input ||
// input is short without scope
short === input ||
// input is short with scope
short === input.replace(scopeRE, '')
)
}
exports.getPluginLink = id => {
if (officialRE.test(id)) {
return `https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-${
exports.toShortPluginId(id)
}`
}
let pkg = {}
try {
pkg = require(`${id}/package.json`)
} catch (e) {}
return (
pkg.homepage ||
(pkg.repository && pkg.repository.url) ||
`https://www.npmjs.com/package/${id.replace(`/`, `%2F`)}`
)
}
|