-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
loadCommand.js
32 lines (31 loc) · 951 Bytes
/
loadCommand.js
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
const { chalk } = require('@vue/cli-shared-utils')
const getGlobalInstallCommand = require('./getGlobalInstallCommand')
module.exports = function loadCommand (commandName, moduleName) {
const isNotFoundError = err => {
return err.message.match(/Cannot find module/)
}
try {
return require(moduleName)
} catch (err) {
if (isNotFoundError(err)) {
try {
return require('import-global')(moduleName)
} catch (err2) {
if (isNotFoundError(err2)) {
const installCommand = getGlobalInstallCommand()
console.log()
console.log(
` Command ${chalk.cyan(`vue ${commandName}`)} requires a global addon to be installed.\n` +
` Please run ${chalk.cyan(`${installCommand} ${moduleName}`)} and try again.`
)
console.log()
process.exit(1)
} else {
throw err2
}
}
} else {
throw err
}
}
}