-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·56 lines (49 loc) · 1.13 KB
/
cli.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
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const inquirer = require('inquirer');
const meow = require('meow');
const normalizeUrl = require('normalize-url');
const registryUrl = require('registry-url');
const m = require('.');
meow(`
Usage
$ registry-swap
`);
const getItems = () => inquirer.prompt([{
name: 'registry',
type: 'list',
message: 'Choose a registry',
choices: Array.from(m.list()).map(x => ({
name: `${normalizeUrl(x)} ${x === registryUrl() ? chalk.green('*') : ''}`,
value: x
}))
}]);
const set = () => getItems().then(answer => {
m.set(answer.registry);
});
const add = () => inquirer.prompt([{
name: 'registry',
message: 'Enter registry URL'
}]).then(answer => {
m.add(answer.registry);
});
const del = () => getItems().then(answer => {
m.delete(answer.registry);
});
const init = () => inquirer.prompt([{
name: 'type',
type: 'list',
message: 'What do you want to do?',
choices: [{
name: 'Set the active registry',
value: set
}, {
name: 'Add a new registry',
value: add
}, {
name: 'Delete a registry',
value: del
}]
}]).then(answer => answer.type().then(init));
init();