-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·102 lines (89 loc) · 2.62 KB
/
cli.js
File metadata and controls
executable file
·102 lines (89 loc) · 2.62 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
// making lib the article link - https://medium.com/netscape/a-guide-to-create-a-nodejs-command-line-package-c2166ad0452e
const dai = require('./index');
// TODO: доработать аргументы из cli
// const [,, ...args] = process.argv;
// TODO: доработать опции из package.json
var inquirer = require('inquirer');
async function localPath() {
dai(undefined, {
pathType: 'fs'
});
}
async function urlPath() {
const link = await new Promise((resolve, reject) => {
inquirer.prompt([
{
type: "string",
name: "link",
message: "Provide a link to the package.json (RAW file. For example https://raw.githubusercontent.com/alfa-code/dependency-aging-index/main/package.json)"
},
// TODO: докрутить basic аутентификацию
]).then(async (answers) => {
// console.log("answers", answers);
resolve(answers['link']);
}).catch(error => {
console.log(error)
if (error.isTtyError) {
reject(null);
} else {
reject(null);
}
});
});
if (link) {
dai(link, {
pathType: 'url'
})
} else {
console.log('The link is incorrect!');
}
}
function main() {
inquirer.prompt([
{
type: "list",
name: "selectPath",
message: "Read the package.json locally in the current directory or specify a direct link to package.json?",
choices: [
{
name: "Find package.json in the current directory",
value: 0,
},
{
name: "Specify a link to package.json",
value: 1,
},
]
},
])
.then(async (answers) => {
switch (answers.selectPath) {
case 0: {
await localPath();
break;
}
case 1: {
await urlPath();
break;
}
default: {
console.log('You didn\'t choose any of the answers.');
break;
}
}
})
.catch(error => {
console.log(error)
if (error.isTtyError) {
// Prompt couldn't be rendered in the current environment
} else {
// Something else went wrong
}
});
}
try {
main();
} catch (err) {
console.error("An error occurred. More detailed: ", err);
}