Skip to content

Commit

Permalink
Suggest yarn when installed with yarn (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore authored and SBoudrias committed May 10, 2019
1 parent 5f06620 commit ad8ed1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const semverDiff = importLazy('semver-diff');
const latestVersion = importLazy('latest-version');
const isNpm = importLazy('is-npm');
const isInstalledGlobally = importLazy('is-installed-globally');
const isYarnGlobal = importLazy('is-yarn-global');
const hasYarn = importLazy('has-yarn');
const boxen = importLazy('boxen');
const xdgBasedir = importLazy('xdg-basedir');
const isCi = importLazy('is-ci');
Expand Down Expand Up @@ -126,11 +128,22 @@ class UpdateNotifier {

options = {
isGlobal: isInstalledGlobally(),
isYarnGlobal: isYarnGlobal()(),
...options
};

let installCommand;

if (options.isYarnGlobal) {
installCommand = `yarn global add ${this.packageName}`;
} else if (hasYarn()()) {
installCommand = `yarn add ${this.packageName}`;
} else {
installCommand = `npm i ${options.isGlobal ? '-g ' : ''}${this.packageName}`;
}

options.message = options.message || 'Update available ' + chalk().dim(this.update.current) + chalk().reset(' → ') +
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan('npm i ' + (options.isGlobal ? '-g ' : '') + this.packageName) + ' to update';
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan(installCommand) + ' to update';

options.boxenOpts = options.boxenOpts || {
padding: 1,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
"boxen": "^3.0.0",
"chalk": "^2.0.1",
"configstore": "^4.0.0",
"has-yarn": "^2.1.0",
"import-lazy": "^2.1.0",
"is-ci": "^2.0.0",
"is-installed-globally": "^0.1.0",
"is-npm": "^3.0.0",
"is-yarn-global": "^0.3.0",
"latest-version": "^5.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
Expand Down

0 comments on commit ad8ed1b

Please # to comment.