npm-name-cli
Advanced tools
Comparing version 1.2.0 to 2.0.0
50
cli.js
@@ -6,2 +6,3 @@ #!/usr/bin/env node | ||
const chalk = require('chalk'); | ||
const squatter = require('squatter'); | ||
const npmName = require('npm-name'); | ||
@@ -16,28 +17,49 @@ | ||
${logSymbols.error} ${chalk.bold('chalk')} is unavailable | ||
$ npm-name abc123 | ||
${logSymbols.warning} ${chalk.bold('abc123')} is squatted | ||
$ npm-name unicorn-cake | ||
${logSymbols.success} ${chalk.bold('unicorn-cake')} is available | ||
$ npm-name chalk unicorn-cake | ||
${logSymbols.error} ${chalk.bold('chalk')} is unavailable | ||
$ npm-name @sindresorhus/is unicorn-cake | ||
${logSymbols.error} ${chalk.bold('@sindresorhus/is')} is unavailable | ||
${logSymbols.success} ${chalk.bold('unicorn-cake')} is available | ||
Exits with code 0 when all names are available or 2 when any names are taken | ||
`, { | ||
string: ['_'] | ||
}); | ||
`); | ||
const input = cli.input; | ||
const {input} = cli; | ||
if (input.length === 0) { | ||
console.error('Specify a package name'); | ||
console.error('Specify one or more package names'); | ||
process.exit(1); | ||
} | ||
function log(val, key) { | ||
const name = chalk.bold(key); | ||
console.log(val ? `${logSymbols.success} ${name} is available` : `${logSymbols.error} ${name} is unavailable`); | ||
function log(pkg) { | ||
const name = chalk.bold(pkg.name); | ||
if (pkg.isAvailable) { | ||
console.log(`${logSymbols.success} ${name} is available`); | ||
} else if (pkg.isSquatter) { | ||
console.log(`${logSymbols.warning} ${name} is squatted`); | ||
} else { | ||
console.log(`${logSymbols.error} ${name} is unavailable`); | ||
} | ||
} | ||
npmName.many(input).then(available => { | ||
available.forEach(log); | ||
process.exit(Array.from(available.values()).every(Boolean) ? 0 : 2); | ||
}); | ||
(async () => { | ||
const result = await npmName.many(input); | ||
const packages = await Promise.all([...result].map(async ([name, isAvailable]) => { | ||
const ret = {name, isAvailable}; | ||
if (!isAvailable) { | ||
ret.isSquatter = await squatter(name); | ||
} | ||
return ret; | ||
})); | ||
for (const pkg of packages) { | ||
log(pkg); | ||
} | ||
process.exit(packages.every(pkg => Boolean(pkg.isAvailable || pkg.isSquatter)) ? 0 : 2); | ||
})(); |
{ | ||
"name": "npm-name-cli", | ||
"version": "1.2.0", | ||
"description": "Check whether a package name is available on npm", | ||
"license": "MIT", | ||
"repository": "sindresorhus/npm-name-cli", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"bin": { | ||
"npm-name": "cli.js" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"cli.js" | ||
], | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"app", | ||
"npm", | ||
"package", | ||
"pkg", | ||
"name", | ||
"check", | ||
"available", | ||
"unavailable", | ||
"taken", | ||
"find" | ||
], | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"log-symbols": "^1.0.2", | ||
"meow": "^3.4.2", | ||
"npm-name": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"execa": "^0.2.2", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "npm-name-cli", | ||
"version": "2.0.0", | ||
"description": "Check whether a package name is available on npm", | ||
"license": "MIT", | ||
"repository": "sindresorhus/npm-name-cli", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"bin": { | ||
"npm-name": "cli.js" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"cli.js" | ||
], | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"app", | ||
"npm", | ||
"package", | ||
"pkg", | ||
"name", | ||
"check", | ||
"available", | ||
"unavailable", | ||
"taken", | ||
"find" | ||
], | ||
"dependencies": { | ||
"chalk": "^2.3.2", | ||
"log-symbols": "^2.2.0", | ||
"meow": "^4.0.0", | ||
"npm-name": "^3.2.0", | ||
"squatter": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"execa": "^0.10.0", | ||
"xo": "*" | ||
} | ||
} |
@@ -7,3 +7,5 @@ # npm-name-cli [![Build Status](https://travis-ci.org/sindresorhus/npm-name-cli.svg?branch=master)](https://travis-ci.org/sindresorhus/npm-name-cli) | ||
*Feedback about the squatter detection should be opened on the [`squatter`](https://github.com/sholladay/squatter) repo.* | ||
## Install | ||
@@ -27,6 +29,8 @@ | ||
✖ chalk is unavailable | ||
$ npm-name abc123 | ||
⚠ abc123 is squatted | ||
$ npm-name unicorn-cake | ||
✔ unicorn-cake is available | ||
$ npm-name chalk unicorn-cake | ||
✖ chalk is unavailable | ||
$ npm-name @sindresorhus/is unicorn-cake | ||
✖ @sindresorhus/is is unavailable | ||
✔ unicorn-cake is available | ||
@@ -38,2 +42,26 @@ | ||
## FAQ | ||
### Why would I use `npm-name` rather than npm's built-in search? | ||
1. Nicer & simpler output | ||
2. [npm search is only supported on npm 4](https://github.com/npm/npm/issues/14649#issuecomment-262820415), which is only bundled with Node.js 7.4+ | ||
3. [Squatter detection](https://github.com/sholladay/squatter) | ||
4. Performance | ||
Using npm 4.0.2 | ||
``` | ||
$ time npm search unicorn-cake | ||
No matches found for "unicorn-cake" | ||
npm search unicorn-cake 55.50s user 0.82s system 101% cpu 55.380 total | ||
$ time npm-name unicorn-cake | ||
✔ unicorn-cake is available | ||
npm-name unicorn-cake 0.17s user 0.02s system 35% cpu 0.535 total | ||
``` | ||
## Related | ||
@@ -40,0 +68,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5191
51
72
5
+ Addedsquatter@^0.1.1
+ Addedansi-styles@3.2.1(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedcamelcase-keys@4.2.0(transitive)
+ Addedcapture-stack-trace@1.0.2(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcreate-error-class@3.0.2(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addedfind-up@2.1.0(transitive)
+ Addedgot@6.7.17.1.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedindent-string@3.2.0(transitive)
+ Addedis-redirect@1.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedjson-parse-better-errors@1.0.2(transitive)
+ Addedload-json-file@4.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedlog-symbols@2.2.0(transitive)
+ Addedmap-obj@2.0.0(transitive)
+ Addedmeow@4.0.1(transitive)
+ Addedminimist-options@3.0.2(transitive)
+ Addedp-cancelable@0.3.0(transitive)
+ Addedp-every@1.0.2(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-map@1.2.0(transitive)
+ Addedp-one@1.0.0(transitive)
+ Addedp-timeout@1.2.1(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedpackage-json@4.0.1(transitive)
+ Addedparse-json@4.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedprepend-http@1.0.4(transitive)
+ Addedquick-lru@1.1.0(transitive)
+ Addedread-pkg@3.0.0(transitive)
+ Addedread-pkg-up@3.0.0(transitive)
+ Addedredent@2.0.0(transitive)
+ Addedregistry-auth-token@3.4.0(transitive)
+ Addedsquatter@0.1.1(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-indent@2.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedtrim-newlines@2.0.0(transitive)
+ Addedunzip-response@2.0.1(transitive)
+ Addedurl-parse-lax@1.0.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlog-symbols@1.0.2(transitive)
- Removedmeow@3.7.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
Updatedchalk@^2.3.2
Updatedlog-symbols@^2.2.0
Updatedmeow@^4.0.0
Updatednpm-name@^3.2.0