UNPKG

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