UNPKG

1.75 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 isPnpm = __dirname.includes('/pnpm-global/')
27 const isYarn = !isPnpm && yarnGlobal.hasDependency('sao')
28 logger.tip(
29 `To upgrade SAO, run the following command:\n${chalk.dim(
30 isYarn
31 ? '$ yarn global add sao'
32 : `$ ${isPnpm ? 'pnpm' : 'npm'} i -g sao`
33 )}`
34 )
35 })
36 }
37}
38
39function performGeneratorUpdateCheck(generator, showNotifier) {
40 const pkg = require(path.join(generator.path, 'package.json'))
41
42 const notifier = updateNotifier({ pkg })
43
44 if (notifier.update && showNotifier) {
45 process.on('exit', () => {
46 logger.warn(
47 `The generator you were running is out of date. The latest version is "${
48 notifier.update.latest
49 }", while you're on "${notifier.update.current}".`
50 )
51
52 logger.tip(
53 `To run the generator with an updated version, run the following command:\n${chalk.dim(
54 '$ sao ' + process.argv.slice(2).join(' ') + ' --update'
55 )}`
56 )
57 })
58 }
59}