From 56bdce57004de13718799b5e6d3e6e6673b20f42 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sat, 20 Feb 2021 13:22:24 +0300 Subject: [PATCH 1/2] refactor(v2): improve notifier message --- packages/docusaurus/bin/docusaurus.js | 34 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index 7b8d6809e995..61551418dd79 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -11,6 +11,8 @@ const chalk = require('chalk'); const semver = require('semver'); const path = require('path'); const cli = require('commander'); +const updateNotifier = require('update-notifier'); +const boxen = require('boxen'); const { build, swizzle, @@ -21,15 +23,18 @@ const { clear, writeTranslations, } = require('../lib'); -const requiredVersion = require('../package.json').engines.node; -const pkg = require('../package.json'); -const updateNotifier = require('update-notifier'); -const boxen = require('boxen'); +const { + name, + version, + engines: {node: requiredVersion}, +} = require('../package.json'); -// notify user if @docusaurus/core is outdated +// notify user if @docusaurus packages is outdated const notifier = updateNotifier({ - pkg, - updateCheckInterval: 1000 * 60 * 60 * 24, // one day + pkg: { + name, + version, + }, }); // allow the user to be notified for updates on the first run @@ -38,6 +43,13 @@ if (notifier.lastUpdateCheck === Date.now()) { } if (notifier.update && notifier.update.current !== notifier.update.latest) { + // eslint-disable-next-line import/no-dynamic-require + const sitePkg = require(path.resolve(process.cwd(), 'package.json')); + const siteDocusaurusPackagesForUpdate = Object.keys(sitePkg.dependencies) + .filter((p) => p.startsWith('@docusaurus')) + .map((p) => p.concat('@latest')) + .join(' '); + const boxenOptions = { padding: 1, margin: 1, @@ -49,9 +61,11 @@ if (notifier.update && notifier.update.current !== notifier.update.latest) { const docusaurusUpdateMessage = boxen( `Update available ${chalk.dim(`${notifier.update.current}`)}${chalk.reset( ' → ', - )}${chalk.green(`${notifier.update.latest}`)}\nRun ${chalk.cyan( - 'yarn upgrade @docusaurus/core', - )} to update`, + )}${chalk.green( + `${notifier.update.latest}`, + )}\n\nTo upgrade Docusaurus packages with the latest version, run the following command:\n${chalk.cyan( + `yarn upgrade ${siteDocusaurusPackagesForUpdate}`, + )}`, boxenOptions, ); From ccd0694f6bef09024ddfb10ee9d8bf72459d7f46 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Tue, 23 Feb 2021 18:24:09 +0300 Subject: [PATCH 2/2] Add support for npm --- packages/docusaurus/bin/docusaurus.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index 61551418dd79..ff0969cb35a9 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -8,6 +8,7 @@ */ const chalk = require('chalk'); +const fs = require('fs-extra'); const semver = require('semver'); const path = require('path'); const cli = require('commander'); @@ -49,6 +50,10 @@ if (notifier.update && notifier.update.current !== notifier.update.latest) { .filter((p) => p.startsWith('@docusaurus')) .map((p) => p.concat('@latest')) .join(' '); + const isYarnUsed = fs.existsSync(path.resolve(process.cwd(), 'yarn.lock')); + const upgradeCommand = isYarnUsed + ? `yarn upgrade ${siteDocusaurusPackagesForUpdate}` + : `npm i ${siteDocusaurusPackagesForUpdate}`; const boxenOptions = { padding: 1, @@ -64,7 +69,7 @@ if (notifier.update && notifier.update.current !== notifier.update.latest) { )}${chalk.green( `${notifier.update.latest}`, )}\n\nTo upgrade Docusaurus packages with the latest version, run the following command:\n${chalk.cyan( - `yarn upgrade ${siteDocusaurusPackagesForUpdate}`, + `${upgradeCommand}`, )}`, boxenOptions, );