visit-github 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +31 -24
- package/bin/index.js +11 -11
- package/exe//344/277/256/346/224/271hosts.exe +0 -0
- package/lib/darwin.js +10 -10
- package/lib/win.js +11 -11
- package/package.json +19 -19
- package/util/commander.js +16 -16
- package/util/darwin.js +28 -28
- package/util/index.js +56 -59
- package/util/win.js +29 -29
package/Readme.md
CHANGED
@@ -1,25 +1,32 @@
|
|
1
|
-
## 访问GitHub
|
2
|
-
|
3
|
-
|
4
|
-
### 注意
|
5
|
-
> 1. windows 使用时请时使用`管理员权限`打开命令行工具
|
6
|
-
> 2. 如果您的hosts文件特别重要,请自己手动备份
|
7
|
-
> 3. mac 电脑上要使用`sudo zx-github`命令,需要管理员权限
|
8
|
-
|
9
|
-
#### 介绍
|
10
|
-
> 当前项目已经在mac与windows电脑运行成功,余下linux
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
## 访问GitHub
|
2
|
+
|
3
|
+
|
4
|
+
### 注意
|
5
|
+
> 1. windows 使用时请时使用`管理员权限`打开命令行工具
|
6
|
+
> 2. 如果您的hosts文件特别重要,请自己手动备份
|
7
|
+
> 3. mac 电脑上要使用`sudo zx-github`命令,需要管理员权限
|
8
|
+
|
9
|
+
#### 介绍
|
10
|
+
> 当前项目已经在mac与windows电脑运行成功,余下linux
|
11
|
+
|
12
|
+
|
13
|
+
#### windows
|
14
|
+
> 使用windows系统的同学可以通过exe下的`修改hosts.exe`来操作,这个软件是一个绿色免安装的软件,操作十分简单只用两个按钮,一个修改,一个恢复。`注意:要使用管理员的方式打开,不然没有效果`
|
15
|
+
|
16
|
+
#### 安装
|
17
|
+
```
|
18
|
+
npm install visit-github -g
|
19
|
+
```
|
20
|
+
|
21
|
+
#### 使用
|
22
|
+
|
23
|
+
> visit-github 两条功能命令
|
24
|
+
1. `zx-github` 更新备份hosts文件,只备份第一次的hosts文件
|
25
|
+
2. `zx-github -r` 恢复备份的hosts文件
|
26
|
+
|
27
|
+
#### github
|
28
|
+
[项目github地址](https://github.com/HouDiZhong/visit-github)
|
29
|
+
|
30
|
+
|
31
|
+
#### 感谢
|
25
32
|
使用了[GitHub520](https://github.com/521xueweihan/GitHub520)提供的更新的hosts接口
|
package/bin/index.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#! /usr/bin/env node
|
2
|
-
|
3
|
-
const os = require('os'),
|
4
|
-
platform = os.platform(),
|
5
|
-
program = require('../util/commander')()
|
6
|
-
|
7
|
-
const platforms = {
|
8
|
-
win32: require('../lib/win'),
|
9
|
-
darwin: require('../lib/darwin')
|
10
|
-
}
|
11
|
-
|
1
|
+
#! /usr/bin/env node
|
2
|
+
|
3
|
+
const os = require('os'),
|
4
|
+
platform = os.platform(),
|
5
|
+
program = require('../util/commander')()
|
6
|
+
|
7
|
+
const platforms = {
|
8
|
+
win32: require('../lib/win'),
|
9
|
+
darwin: require('../lib/darwin')
|
10
|
+
}
|
11
|
+
|
12
12
|
platforms[platform](program.opts().reset)
|
Binary file
|
package/lib/darwin.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
const { init, reset } = require('../util/darwin')
|
2
|
-
|
3
|
-
const darwin = function (isReset) {
|
4
|
-
if(isReset) {
|
5
|
-
reset('/etc/', 'hosts_zx_backups')
|
6
|
-
}else {
|
7
|
-
init('/etc/', 'hosts_zx_temporary')
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
1
|
+
const { init, reset } = require('../util/darwin')
|
2
|
+
|
3
|
+
const darwin = function (isReset) {
|
4
|
+
if(isReset) {
|
5
|
+
reset('/etc/', 'hosts_zx_backups')
|
6
|
+
}else {
|
7
|
+
init('/etc/', 'hosts_zx_temporary')
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
11
|
module.exports = darwin
|
package/lib/win.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
const { init, reset } = require('../util/win'),
|
2
|
-
MIN_DEFAULT_PATH = 'C:/Windows/System32/drivers/etc/'
|
3
|
-
|
4
|
-
const win = function (isReset) {
|
5
|
-
if(isReset) {
|
6
|
-
reset(MIN_DEFAULT_PATH, 'hosts_zx_backups')
|
7
|
-
}else {
|
8
|
-
init(MIN_DEFAULT_PATH, 'hosts_zx_temporary')
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
1
|
+
const { init, reset } = require('../util/win'),
|
2
|
+
MIN_DEFAULT_PATH = 'C:/Windows/System32/drivers/etc/'
|
3
|
+
|
4
|
+
const win = function (isReset) {
|
5
|
+
if(isReset) {
|
6
|
+
reset(MIN_DEFAULT_PATH, 'hosts_zx_backups')
|
7
|
+
}else {
|
8
|
+
init(MIN_DEFAULT_PATH, 'hosts_zx_temporary')
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
12
|
module.exports = win
|
package/package.json
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
{
|
2
|
-
"name": "visit-github",
|
3
|
-
"version": "0.0.
|
4
|
-
"description": "替换系统中的hosts文件",
|
5
|
-
"main": "index.js",
|
6
|
-
"bin": {
|
7
|
-
"zx-github": "bin/index.js"
|
8
|
-
},
|
9
|
-
"scripts": {
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
11
|
-
},
|
12
|
-
"keywords": [],
|
13
|
-
"author": "zxhou",
|
14
|
-
"license": "ISC",
|
15
|
-
"dependencies": {
|
16
|
-
"commander": "^9.3.0",
|
17
|
-
"iconv-lite": "^0.6.3"
|
18
|
-
}
|
19
|
-
}
|
1
|
+
{
|
2
|
+
"name": "visit-github",
|
3
|
+
"version": "0.0.3",
|
4
|
+
"description": "替换系统中的hosts文件",
|
5
|
+
"main": "bin/index.js",
|
6
|
+
"bin": {
|
7
|
+
"zx-github": "bin/index.js"
|
8
|
+
},
|
9
|
+
"scripts": {
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
11
|
+
},
|
12
|
+
"keywords": [],
|
13
|
+
"author": "zxhou",
|
14
|
+
"license": "ISC",
|
15
|
+
"dependencies": {
|
16
|
+
"commander": "^9.3.0",
|
17
|
+
"iconv-lite": "^0.6.3"
|
18
|
+
}
|
19
|
+
}
|
package/util/commander.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
module.exports = function () {
|
2
|
-
const { program } = require('commander'),
|
3
|
-
op = require('../package.json')
|
4
|
-
|
5
|
-
program
|
6
|
-
.version(op.version, '-v, --version', '输出当前版本')
|
7
|
-
.option('-r, --reset', '恢复原来的hosts文件')
|
8
|
-
.helpOption('-h, --help', '显示命令帮助')
|
9
|
-
.addHelpText('after', `
|
10
|
-
示例:
|
11
|
-
$ zx-github 备份原来hosts文件,替换hosts
|
12
|
-
$ zx-github -r, --rest 恢复原来的hosts文件`
|
13
|
-
)
|
14
|
-
.parse(process.argv)
|
15
|
-
|
16
|
-
return program
|
1
|
+
module.exports = function () {
|
2
|
+
const { program } = require('commander'),
|
3
|
+
op = require('../package.json')
|
4
|
+
|
5
|
+
program
|
6
|
+
.version(op.version, '-v, --version', '输出当前版本')
|
7
|
+
.option('-r, --reset', '恢复原来的hosts文件')
|
8
|
+
.helpOption('-h, --help', '显示命令帮助')
|
9
|
+
.addHelpText('after', `
|
10
|
+
示例:
|
11
|
+
$ zx-github 备份原来hosts文件,替换hosts
|
12
|
+
$ zx-github -r, --rest 恢复原来的hosts文件`
|
13
|
+
)
|
14
|
+
.parse(process.argv)
|
15
|
+
|
16
|
+
return program
|
17
17
|
}
|
package/util/darwin.js
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
const { isExists, rename, runShellFlushDns, download, delFile } = require('./index')
|
2
|
-
|
3
|
-
const init = async (path, n) => {
|
4
|
-
if(!isExists(path + 'hosts_zx_backups')) {
|
5
|
-
rename(
|
6
|
-
path,
|
7
|
-
'hosts',
|
8
|
-
'hosts_zx_backups',
|
9
|
-
'备份系统hosts文件时出错'
|
10
|
-
)
|
11
|
-
}
|
12
|
-
await download(path, n) && runShellFlushDns('sudo killall -HUP mDNSResponder')
|
13
|
-
}
|
14
|
-
|
15
|
-
const reset = (path, n) => {
|
16
|
-
const isOk = isExists(path + n)
|
17
|
-
if(isOk) {
|
18
|
-
if(isExists(path + 'hosts')) {
|
19
|
-
delFile(path + 'hosts')
|
20
|
-
}
|
21
|
-
rename(path, 'hosts_zx_backups', 'hosts', '还原系统hosts文件时出错')
|
22
|
-
console.log('还原系统hosts文件成功')
|
23
|
-
runShellFlushDns('sudo killall -HUP mDNSResponder')
|
24
|
-
}else {
|
25
|
-
console.log('没有找到备份文件,无法恢复')
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
1
|
+
const { isExists, rename, runShellFlushDns, download, delFile } = require('./index')
|
2
|
+
|
3
|
+
const init = async (path, n) => {
|
4
|
+
if(!isExists(path + 'hosts_zx_backups')) {
|
5
|
+
rename(
|
6
|
+
path,
|
7
|
+
'hosts',
|
8
|
+
'hosts_zx_backups',
|
9
|
+
'备份系统hosts文件时出错'
|
10
|
+
)
|
11
|
+
}
|
12
|
+
await download(path, n) && runShellFlushDns('sudo killall -HUP mDNSResponder')
|
13
|
+
}
|
14
|
+
|
15
|
+
const reset = (path, n) => {
|
16
|
+
const isOk = isExists(path + n)
|
17
|
+
if(isOk) {
|
18
|
+
if(isExists(path + 'hosts')) {
|
19
|
+
delFile(path + 'hosts')
|
20
|
+
}
|
21
|
+
rename(path, 'hosts_zx_backups', 'hosts', '还原系统hosts文件时出错')
|
22
|
+
console.log('还原系统hosts文件成功')
|
23
|
+
runShellFlushDns('sudo killall -HUP mDNSResponder')
|
24
|
+
}else {
|
25
|
+
console.log('没有找到备份文件,无法恢复')
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
29
|
module.exports = { init, reset }
|
package/util/index.js
CHANGED
@@ -1,60 +1,57 @@
|
|
1
|
-
const fs = require('fs'),
|
2
|
-
https = require('https'),
|
3
|
-
iconv = require('iconv-lite'),
|
4
|
-
process = require('child_process')
|
5
|
-
|
6
|
-
const isExists = path => {
|
7
|
-
try {
|
8
|
-
const o = fs.statSync(path)
|
9
|
-
return o.isFile()
|
10
|
-
}catch(err) {
|
11
|
-
return false
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
const download = (path, n) => {
|
16
|
-
return new Promise((resolve, reject) => {
|
17
|
-
https.get('https://raw.hellogithub.com/hosts', res => {
|
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
|
-
|
1
|
+
const fs = require('fs'),
|
2
|
+
https = require('https'),
|
3
|
+
iconv = require('iconv-lite'),
|
4
|
+
process = require('child_process')
|
5
|
+
|
6
|
+
const isExists = path => {
|
7
|
+
try {
|
8
|
+
const o = fs.statSync(path)
|
9
|
+
return o.isFile()
|
10
|
+
}catch(err) {
|
11
|
+
return false
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
const download = (path, n) => {
|
16
|
+
return new Promise((resolve, reject) => {
|
17
|
+
https.get('https://raw.hellogithub.com/hosts', res => {
|
18
|
+
try {
|
19
|
+
res.pipe(fs.createWriteStream(path + n))
|
20
|
+
res.on('end', _ => {
|
21
|
+
rename(path, n, 'hosts', '替换下载hosts文件时出错')
|
22
|
+
console.log('替换hosts文件成功')
|
23
|
+
resolve(true)
|
24
|
+
})
|
25
|
+
}catch {
|
26
|
+
reject(false)
|
27
|
+
console.log('写入临时文件出错')
|
28
|
+
}
|
29
|
+
}).on('error', (e) => {
|
30
|
+
console.error(`Got error: ${e.message}`)
|
31
|
+
})
|
32
|
+
})
|
33
|
+
}
|
34
|
+
|
35
|
+
const rename = (root, path, nPath, info) => {
|
36
|
+
const isOk = isExists(root + path)
|
37
|
+
if(isOk) {
|
38
|
+
try {
|
39
|
+
fs.renameSync(root + path, root + nPath)
|
40
|
+
}catch (err) {
|
41
|
+
console.log(info)
|
42
|
+
}
|
43
|
+
}else {
|
44
|
+
console.log(path + '文件不存在')
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
const delFile = path => fs.unlinkSync(path)
|
49
|
+
|
50
|
+
const runShellFlushDns = shell => {
|
51
|
+
process.exec(shell, { encoding: 'binary' }, (err, stdout) => {
|
52
|
+
if(err) return
|
53
|
+
console.log(iconv.decode(Buffer.from(stdout, 'binary'), 'cp936'))
|
54
|
+
})
|
55
|
+
}
|
56
|
+
|
60
57
|
module.exports = { isExists, rename, runShellFlushDns, download, delFile }
|
package/util/win.js
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
const { isExists, rename, runShellFlushDns, download, delFile } = require('./index')
|
2
|
-
|
3
|
-
const init = async (path, n) => {
|
4
|
-
if(!isExists(path + 'hosts_zx_backups')) {
|
5
|
-
rename(
|
6
|
-
path,
|
7
|
-
'hosts',
|
8
|
-
'hosts_zx_backups',
|
9
|
-
'备份系统hosts文件时出错'
|
10
|
-
)
|
11
|
-
}
|
12
|
-
await download(path, n) && runShellFlushDns('ipconfig /flushdns')
|
13
|
-
}
|
14
|
-
|
15
|
-
const reset = (path, n) => {
|
16
|
-
const isOk = isExists(path + n)
|
17
|
-
if(isOk) {
|
18
|
-
if(isExists(path + 'hosts')) {
|
19
|
-
delFile(path + 'hosts')
|
20
|
-
}
|
21
|
-
rename(path, 'hosts_zx_backups', 'hosts', '还原系统hosts文件时出错')
|
22
|
-
console.log('还原系统hosts文件成功')
|
23
|
-
runShellFlushDns('ipconfig /flushdns')
|
24
|
-
}else {
|
25
|
-
console.log('没有找到备份文件,无法恢复')
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
|
1
|
+
const { isExists, rename, runShellFlushDns, download, delFile } = require('./index')
|
2
|
+
|
3
|
+
const init = async (path, n) => {
|
4
|
+
if(!isExists(path + 'hosts_zx_backups')) {
|
5
|
+
rename(
|
6
|
+
path,
|
7
|
+
'hosts',
|
8
|
+
'hosts_zx_backups',
|
9
|
+
'备份系统hosts文件时出错'
|
10
|
+
)
|
11
|
+
}
|
12
|
+
await download(path, n) && runShellFlushDns('ipconfig /flushdns')
|
13
|
+
}
|
14
|
+
|
15
|
+
const reset = (path, n) => {
|
16
|
+
const isOk = isExists(path + n)
|
17
|
+
if(isOk) {
|
18
|
+
if(isExists(path + 'hosts')) {
|
19
|
+
delFile(path + 'hosts')
|
20
|
+
}
|
21
|
+
rename(path, 'hosts_zx_backups', 'hosts', '还原系统hosts文件时出错')
|
22
|
+
console.log('还原系统hosts文件成功')
|
23
|
+
runShellFlushDns('ipconfig /flushdns')
|
24
|
+
}else {
|
25
|
+
console.log('没有找到备份文件,无法恢复')
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
30
|
module.exports = { init, reset }
|