feat: add notification about available new version (#853)

Co-authored-by: Anton Kozachuk <antonkozachuk@Antons-MacBook-Pro.local>
This commit is contained in:
Anton Kozachuk
2022-09-12 15:16:46 +03:00
committed by GitHub
parent 890ba5f533
commit 9b1551e208
4 changed files with 1124 additions and 57 deletions

View File

@@ -16,6 +16,7 @@ import {
stringifyYaml,
} from '@redocly/openapi-core';
import { Totals, outputExtensions, Entrypoint } from './types';
import * as updateNotifier from 'update-notifier';
export async function getFallbackApisOrExit(
argsApis: string[] | undefined,
@@ -323,3 +324,16 @@ export function isSubdir(parent: string, dir: string): boolean {
const relative = path.relative(parent, dir);
return !!relative && !/^..($|\/)/.test(relative) && !path.isAbsolute(relative);
}
export function notifyUpdateCliVersion() {
const pkg = require('../package.json');
const notifier = updateNotifier({
pkg,
updateCheckInterval: 0,
shouldNotifyInNpmScript: true,
});
notifier.notify({
message:
'A new version of Redocly CLI ({latestVersion}) is available.\nUpdate now: `npx @redocly/cli@latest upgrade`.\nChangelog: https://redocly.com/docs/cli/changelog',
});
}