UNPKG

1.62 kBJavaScriptView Raw
1const { path, logger, chalk } = require('sherry-utils')
2const updateNotifier = require('update-notifier')
3const yarnGlobal = require('yarn-global')
4
5module.exports = ({ generator, checkGenerator, showNotifier }) => {
6 performSelfUpdateCheck()
7 if (checkGenerator) {
8 performGeneratorUpdateCheck(generator, showNotifier)
9 }
10}
11
12function performSelfUpdateCheck() {
13 const pkg = require('../package')
14 const notifier = updateNotifier({ pkg })
15
16 if (notifier.update) {
17 process.on('exit', () => {
18 logger.warn(
19 `Your current version of Sherry is out of date. The latest version is "${
20 notifier.update.latest
21 }", while you're on "${notifier.update.current}".`
22 )
23 const isYarn = yarnGlobal.hasDependency('sherry')
24 logger.tip(
25 `To upgrade Sherry, run the following command:\n${chalk.dim(
26 isYarn ? '$ yarn global add sherry' : '$ npm i -g sherry'
27 )}`
28 )
29 })
30 }
31}
32
33function performGeneratorUpdateCheck(generator, showNotifier) {
34 const pkg = require(path.join(generator.path, 'package.json'))
35
36 const notifier = updateNotifier({ pkg })
37
38 if (notifier.update && showNotifier) {
39 process.on('exit', () => {
40 logger.warn(
41 `The generator you were running is out of date. The latest version is "${
42 notifier.update.latest
43 }", while you're on "${notifier.update.current}".`
44 )
45
46 logger.tip(
47 `To run the generator with an updated version, run the following command:\n${chalk.dim(
48 '$ sherry ' + process.argv.slice(2).join(' ') + ' --update'
49 )}`
50 )
51 })
52 }
53}