-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
116 lines (105 loc) · 2.69 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
const chalk = require('chalk');
const program = require('commander');
const pkg = require('../package.json');
const inquirer = require('inquirer');
const {
fetchHackerNews,
fetchProductHunt,
fetchGitHubTrending,
fetchReddit,
fetchV2ex,
config,
t,
} = require('../utils');
program.on('--help', () => {
console.log(
chalk.green(`
Example:
$ hfeeds github`),
);
});
// settings
program
.command('config')
.description(t('program.configDesc'))
.option('-l, --lang <optional>', t('program.configLang'))
.action(({ args }) => {
if (args.length === 0) {
setConfig();
return;
}
const { lang = 'en' } = args;
config.write({ lang });
});
// get github feeds
program
.command('github')
.description(t('program.ghDesc'))
.option('-s, --since <optional>', t('program.ghSince'))
.option('-l, --lang <optional>', t('program.ghLang'))
.action((args) => {
const { since = 'daily', lang = '' } = args;
fetchGitHubTrending(since, lang);
});
// get hacker news feeds
program
.command('news')
.description(t('program.hnDesc'))
.option('-t, --top <optional>', t('program.hnTop'))
.action((args) => {
const { top = 10 } = args;
fetchHackerNews(0, top);
});
// get product hunt feeds
program
.command('product')
.description(t('program.phDesc'))
.option('-c, --count <optional>', t('program.phCount'))
.option('-p, --past <optional>', t('program.phPast'))
.action((args) => {
const { past = 0, count = 10 } = args;
fetchProductHunt(count, past);
});
// get v2ex feeds
program
.command('v2ex')
.description(t('program.v2ex'))
.option('-n, --node <optional>', t('program.v2exNode'))
.action((args) => {
const { node } = args;
fetchV2ex(node);
});
// get reddit feeds
program
.command('reddit')
.description(t('program.redditDesc'))
.option('-t, --topic <optional>', t('program.redditTopic'))
.option('-s, --sort <optional>', t('program.redditSort'))
.action((args) => {
const { topic, sort } = args;
fetchReddit(sort, topic);
});
program.addHelpCommand('help [command]', t('program.help'));
program.helpOption('-h, --help', t('program.help'));
program.version(pkg.version, '-v, --version', t('program.version'));
program.parse(process.argv);
// trigger without param
if (!process.argv.slice(2).length) {
program.outputHelp();
}
async function setConfig() {
// inquire for a api link
const { lang } = await inquirer.prompt([
{
type: 'list',
message: t('program.langConfig'),
name: 'lang',
choices: [
{ name: 'EN(English)', value: 'en' },
{ name: 'ZH(简体中文)', value: 'zh' },
],
},
]);
config.write({ lang });
}