forked from pnpm/only-allow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
53 lines (49 loc) · 1.67 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const whichPMRuns = require('which-pm-runs')
const boxen = require('boxen')
const argv = process.argv.slice(2)
if (argv.length === 0) {
console.log('Please specify the wanted package manager: only-allow <npm|cnpm|pnpm|yarn>')
process.exit(1)
}
const wantedPM = argv[0]
if (
wantedPM !== "npm" &&
wantedPM !== "cnpm" &&
wantedPM !== "pnpm" &&
wantedPM !== "yarn" &&
wantedPM !== "enpm"
) {
console.log(
`"${wantedPM}" is not a valid package manager. Available package managers are: npm, cnpm, pnpm, or yarn.`
);
process.exit(1);
}
const usedPM = whichPMRuns()
if (usedPM && usedPM.name !== wantedPM) {
const boxenOpts = { borderColor: 'red', borderStyle: 'double', padding: 1 }
switch (wantedPM) {
case 'npm':
console.log(boxen('Use "npm install" for installation in this project', boxenOpts))
break
case 'cnpm':
console.log(boxen('Use "cnpm install" for installation in this project', boxenOpts))
break
case 'pnpm':
console.log(boxen(`Use "pnpm install" for installation in this project.
If you don't have pnpm, install it via "npm i -g pnpm".
For more details, go to https://pnpm.js.org/`, boxenOpts))
break
case 'yarn':
console.log(boxen(`Use "yarn" for installation in this project.
If you don't have Yarn, install it via "npm i -g yarn".
For more details, go to https://yarnpkg.com/`, boxenOpts))
break
case 'enpm':
console.log(boxen(`Use "enpm" for installation in this project.
If you don't have Yarn, install it via "npm install -g enpm --registry=https://registry-npm.ennew.com/".
For more details, go to https://yarnpkg.com/`, boxenOpts))
break
}
process.exit(1)
}