-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtfpython
85 lines (73 loc) · 1.79 KB
/
wtfpython
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
#!/usr/bin/env node
const fs = require('fs');
const obj = require('through2').obj;
const pager = require('default-pager');
const msee = require('msee');
const join = require('path').join;
const boxen = require('boxen');
const chalk = require('chalk');
const updateNotifier = require('update-notifier');
const pkg = require('./package.json');
const meow = require('meow');
const cli = meow([
'Usage',
' bash-handbook',
'',
'Options',
' --lang, -l Translation language',
'',
'Examples',
' bash-handbook',
' bash-handbook --lang pt-br'
], {
string: [
'lang'
],
alias: {
l: 'lang',
h: 'help'
},
default: {
lang: ''
}
});
const boxenOpts = {
borderColor: 'yellow',
margin: {
bottom: 1
},
padding: {
right: 1,
left: 1
}
};
const mseeOpts = {
paragraphEnd: '\n\n'
};
const notifier = updateNotifier({ pkg });
process.env.PAGER = process.env.PAGER || 'less';
process.env.LESS = process.env.LESS || 'FRX';
const lang = cli.flags.lang
.toLowerCase()
.split('-')
.map((l, i) => i === 0 ? l : l.toUpperCase())
.join('-');
const translation = join(__dirname, !lang ? './README.md' : `./README-${lang}.md`);
fs.stat(translation, function (err, stats) {
if (err) {
console.log('The %s translation does not exist', chalk.bold(lang));
return;
}
fs.createReadStream(translation)
.pipe(obj(function (chunk, enc, cb) {
const message = [];
if (notifier.update) {
message.push(`Update available: {green.bold ${notifier.update.latest}} {dim current: ${notifier.update.current}}`);
message.push(`Run {blue npm install -g ${pkg.name}} to update.`);
this.push(boxen(message.join('\n'), boxenOpts));
}
this.push(msee.parse(chunk.toString(), mseeOpts));
cb();
}))
.pipe(pager());
});