-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcli.js
executable file
·72 lines (59 loc) · 1.55 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
const join = require('path').join
const yargs = require('yargs')
const fetch = require('./lib/fetch')
const package = require('./package.json')
// process.on('exit', (code) => {
// console.log(`exit with code: ${code}`)
// })
// process.on('SIGHUP', (code) => {
// console.log(`SIGHUP exit with code: ${code}`)
// })
// process.on('SIGINT', (code) => {
// console.log(`SIGINT exit with code: ${code}`)
// })
// process.on('SIGTERM', (code) => {
// console.log(`SIGTERM exit with code: ${code}`)
// })
// process.on('uncaughtException', (err) => {
// console.log(`uncaught exception: ${err}`)
// })
// process.on('unhandledRejection', (err) => {
// console.log(`uncaught rejection: ${err}`)
// })
let argv = yargs
.option('u', {
alias : 'uid',
demand: false,
requiresArg: true,
describe: '博客uid',
type: 'string'
})
.option('c', {
alias : 'cookie',
demand: false,
requiresArg: false,
describe: '登录后的cookie',
type: 'string'
})
.usage('Usage: dature [options]')
.help('h')
.alias('h', 'help')
.example('dature -u 1263917762')
.epilog('@junyiz')
.argv;
if (argv.uid) {
console.log(`dature@${package.version}\n`)
const dir = join(process.cwd(), `./blog-${argv.uid}`)
const cookie = (argv.cookie || '')
.replace(/(NowDate|BLOG_TITLE|mblog_userinfo)[^;]*;/g, '')
console.info(`\n博客存储目录:${dir}\n`)
fetch(dir, argv.uid, cookie).then(() => {
console.info(`\n备份完毕\n`)
})
} else {
yargs.showHelp()
}
/*
新浪博客UID, 例 1263917762
*/