-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheva.js
executable file
·164 lines (148 loc) · 3.69 KB
/
eva.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env node
/**
* @description: node脚本命令行工具
* @author: bubao
* @date: 2017-7-16 17:28:33
* @last author: bubao
* @last edit time: 2021-05-05 23:46:56
*/
const program = require("commander");
// const xmly = require("./src/command/xmly");
const download = require("./src/command/download");
const zhihu = require("./src/command/zhihuzhuanlan");
const qrcode = require("./src/command/qrcode");
const update = require("./src/command/update");
const wifi = require("./src/command/wifi");
const { console } = require("./src/tools/commonModules");
let noLog = false;
// 知乎专栏爬虫
program
.command("zhuanlan [zhuanlanId]")
.alias("z")
.description("🔄 知乎专栏爬虫 ⛎")
.option("-o ,--out <path>", "🔙 输出位置")
.option("-f ,--format <ebook>", "🔙 输出位置")
.action((zhuanlanId, options) => {
// zhuanlanId = zhuanlanId || "leanreact";
noLog = true;
if (zhuanlanId) {
const runpath = options.out || process.cwd(); // 当前执行路径
const format = options.format || "md";
console.log("🐛 知乎专栏爬取 %s 到 %s 文件夹", zhuanlanId, runpath);
zhihu(zhuanlanId, runpath, format);
}
})
.on("--help", () => {
console.log(`
example:
$ eva zhuanlan leanreact
$ eva z leanreact -o ~/
`);
});
// 喜马拉雅fm爬虫
// program
// .command("xmly [ID]")
// .alias("x")
// .description("🔄 喜马拉雅爬虫 ⛎")
// .option("-o ,--out <path>", "🔙 输出位置")
// .option("-t , --type <type>", "🔙 tracks 或者 albums")
// .action((ID, options) => {
// noLog = true;
// if (ID) {
// const runpath = options.out || `${ID}.txt`; // 当前执行路径
// xmly(options.type || "tracks", ID, runpath);
// }
// })
// .on("--help", () => {
// console.log(`
// example:
// $ eva xmly ID
// $ eva x ID -o ~/ID.txt
// `);
// });
// 下载器
program
.command("download [url]")
.alias("d")
.description("🔄 下载器 ⛎")
.option("-o ,--out <path>", "🔙 输出位置")
.option("-d ,--description <description>", "🔙 头部信息")
.option("-l ,--length <length>", "🔙 进度条长度")
.option("-n ,--name <name>", "🔙 文件名")
.option("-hd ,--hiden <hiden>", "🔙 完成后隐藏进度条信息")
.action(url => {
noLog = true;
if (url) {
const opts = {
url: url || "leanreact",
out: program.out || process.cwd(),
length: parseInt(program.length, 10) || 50,
name: typeof program.name === "string" ? program.name : undefined,
hiden: program.hiden
};
download(opts);
}
})
.on("--help", () => {
console.log(`
example:
$ eva download https://www.baidu.com
$ eva d https://www.baidu.com -o ~/
`);
});
// 二维码
program
.command("qrcode <str>")
.alias("q")
.description("Generate qrcode")
.action(str => {
qrcode(str);
})
.on("--help", () => {
console.log(`
example:
$ eva qrcode https://www.baidu.com
$ eva q https://www.baidu.com
`);
});
// wifi 二维码
program
.command("qwifi")
.alias("qw")
.description("Generate wifi qrcode")
.action(ssid => {
noLog = true;
wifi(ssid, program.password);
})
.on("--help", () => {
console.log(`
example:
$ eva qwifi
$ eva qw
`);
});
// update
program
.command("update [path]")
.alias("u")
.description("update eva")
.action(str => {
noLog = true;
update(str);
})
.on("--help", () => {
console.log(`
example:
$ eva update # 可以接受参数制定eva的所在绝对路径
$ eva u
`);
});
// function ReadMe() {
// const README = fs.readFileSync(path.join(__dirname, "README.md"));
// return `${README}`;
// }
program.parse(process.argv);
if (!program.args.length && !noLog) {
// program.outputHelp(ReadMe);
program.outputHelp();
}