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