-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·78 lines (62 loc) · 1.67 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
'use strict'
const chalk = require('chalk')
const chunk = require('even-chunks')
const meow = require('meow')
const namesake = require('namesake')
const ora = require('ora')
const table = require('text-table')
const { log, error } = console
const help = chalk`
{bold Usage}: {yellow namesake} [word] [options]
Generate a list of words that just so happen to also
be available as npm package names.
Optionally, you can use any word as input to find
related words and terms.
{bold Options}:
-l, --limit <n> Limit the number of results returned (defaults to 50)
-h, --help Show this help message
-v, --version Output the {yellow namesake} version number
\n
`
const { input, flags } =
meow({ description: false, help }, {
alias: {
l: 'limit',
h: 'help',
v: 'version'
}
})
flags.limit = Number(flags.limit) || 50
const word = input[0]
const text = word
? `finding available package names related to '${word}'...`
: `finding available package names...`
const spinner = ora({
text,
spinner: {
interval: 100,
frames: ['◜', '◠', '◝', '◞', '◡', '◟']
}
}).start()
namesake(word, flags)
.then(names => {
spinner.stop()
const chunked = chunk(
names,
Math.floor(names.length / 3),
chunk.PRIORITIZE_FIRST
)
const header = word
? `Available package names related to '${word}':\n`
: `Some available package names:\n`
log('')
log(header)
log(table(chunked))
})
.catch(err => {
const { stack, message } = err
spinner.fail(`Oops! -> ${message}`)
error(stack.slice(stack.indexOf('\n')))
process.exit(1)
})