Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check pm with a version number #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@ if (argv.length === 0) {
process.exit(1)
}
const wantedPM = argv[0]
const wantedVersion = arg[1]

if (wantedPM !== 'npm' && wantedPM !== 'pnpm' && wantedPM !== 'yarn') {
console.log(`"${wantedPM}" is not a valid package manager. Available package managers are: npm, pnpm, or yarn.`)
process.exit(1)
}
const usedPM = whichPMRuns()
if (usedPM && usedPM.name !== wantedPM) {
if (usedPM && usedPM.name !== wantedPM && usedPM.version !== wantedVersion) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about when the version is not specified? In that case it shouldn't be checked, right?

Suggested change
if (usedPM && usedPM.name !== wantedPM && usedPM.version !== wantedVersion) {
if (usedPM && (usedPM.name !== wantedPM || wantedVersion && usedPM.version !== wantedVersion)) {

const boxenOpts = { borderColor: 'red', borderStyle: 'double', padding: 1 }
switch (wantedPM) {
case 'npm':
console.log(boxen('Use "npm install" for installation in this project', boxenOpts))
console.log(boxen(`Use "npm install" with npm version "${wantedVersion}" for installation in this project

If you don't have version ${wantedPM} of npm, install it via "npm i -g npm@${wantedVersion}".
For more details, go to https://www.npmjs.com/`, boxenOpts))
break
case 'pnpm':
console.log(boxen(`Use "pnpm install" for installation in this project.
console.log(boxen(`Use "pnpm install" with pnpm version "${wantedVersion}" for installation in this project.

If you don't have pnpm, install it via "npm i -g pnpm".
If you don't have pnpm, install it via "npm i -g pnpm@${wantedVersion}".
For more details, go to https://pnpm.js.org/`, boxenOpts))
break
case 'yarn':
console.log(boxen(`Use "yarn" for installation in this project.
console.log(boxen(`Use "yarn" with yarn version "${wantedVersion}" for installation in this project.

If you don't have Yarn, install it via "npm i -g yarn".
If you don't have Yarn, install it via "npm i -g yarn@${wantedVersion}".
For more details, go to https://yarnpkg.com/`, boxenOpts))
break
}
Expand Down