-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A merge from dev to main (v1.3.0) #15
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3faf8ce
dev branch正式推出 (#10)
Minemetero 214ad8c
1.3.0 Add backup feature and README.md update
2f41226
a fix
7527238
Update README-dev.md
Minemetero 5512a7d
Update README.md
Minemetero 0cbb474
Update README.md
Minemetero 3d124b4
Update updateHosts.js
Minemetero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Easy GitHub Hosts - Development Guide | ||
|
||
This document provides a detailed guide for developers who wish to understand, modify, or contribute to the Easy GitHub Hosts project. | ||
|
||
## Table of Contents | ||
|
||
1. [Project Structure](#project-structure) | ||
2. [Installation](#installation) | ||
3. [Usage](#usage) | ||
4. [Scripts](#scripts) | ||
5. [Development Workflow](#development-workflow) | ||
6. [Code Overview](#code-overview) | ||
- [ipFetcher.js](#ipfetcherjs) | ||
- [updateHosts.js](#updatehostsjs) | ||
- [restoreHosts.js](#restorehostsjs) | ||
- [main.js](#mainjs) | ||
7. [Contributing](#contributing) | ||
8. [License](#license) | ||
|
||
## Project Structure | ||
|
||
The project has the following structure: | ||
|
||
easy-github-hosts/ | ||
├── .github/ | ||
│ ├── bug_report.md | ||
│ ├── feature_request.md | ||
├── docs/ | ||
│ ├── README.md | ||
│ ├── README-dev.md | ||
├── ipFetcher.js | ||
├── main.js | ||
├── package.json | ||
├── restoreHosts.js | ||
├── updateHosts.js | ||
|
||
- **.github/**: Contains the issue template files. | ||
- **bug_report.md**: Yes! It for bug report issue. | ||
- **feature_request.md**: Yes! It for feature request issue. | ||
- **docs/**: Contains the documentation files. | ||
- **README.md**: Provides general information and usage instructions. | ||
- **README-dev.md**: This development guide. | ||
- **ipFetcher.js**: Contains functions to fetch the IP addresses for GitHub-related domains. | ||
- **main.js**: The main entry point for the program. | ||
- **package.json**: Manages project dependencies and scripts. | ||
- **restoreHosts.js**: Contains functions to restore the original `hosts` file. | ||
- **updateHosts.js**: Contains functions to update the `hosts` file with new IP addresses. | ||
|
||
## Code Overview | ||
|
||
### ipFetcher.js | ||
|
||
This file contains the logic to fetch IP addresses for a list of GitHub-related domains using axios and cheerio: | ||
|
||
**getIP(host)**: Fetches the IP address for a given host. | ||
**getIPs()**: Fetches IP addresses for all predefined GitHub-related domains. | ||
|
||
|
||
### updateHosts.js | ||
This file contains the logic to update the hosts file: | ||
|
||
**checkIPv4(IP)**: Checks if a string is a valid IPv4 address. | ||
**parseHostsRecord(record)**: Parses a single record from the hosts file. | ||
**getHostsRecords(content)**: Parses all records from the hosts file. | ||
**getHostsRecordIndexByHost(records, host)**: Finds the index of a record by host. | ||
**genHosts(records)**: Generates the content for the hosts file from records. | ||
**createBackup(hostsPath)**: Creates a backup of the hosts file. | ||
**updateHosts()**: Main function to update the hosts file. | ||
|
||
### restoreHosts.js | ||
This file contains the logic to restore the original hosts file from a backup: | ||
|
||
**restoreHosts()**: Main function to restore the hosts file from a backup. | ||
|
||
### main.js | ||
This file serves as the entry point for the program. It imports and runs the updateHosts function from updateHosts.js. | ||
|
||
## Contributing | ||
Contributions are welcome! Please follow these guidelines: | ||
|
||
Fork the repository. | ||
Create a new branch for your feature or bug fix. | ||
Commit your changes with a descriptive message. | ||
Push your branch to your fork. | ||
Submit a pull request to the main repository **(dev branch)**. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
|
||
"use strict"; | ||
|
||
const fs = require("fs"); | ||
const os = require("os"); | ||
|
||
const appName = "Easy GitHub Hosts"; | ||
|
||
/** | ||
* 恢复 HOSTS 文件的备份 | ||
*/ | ||
function restoreHosts() { | ||
console.log(`${appName}: Starting restoration`); | ||
|
||
const hostsPath = os.type().includes("Windows") ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts"; | ||
const backupPath = `${hostsPath}.backup`; | ||
|
||
if (!fs.existsSync(backupPath)) { | ||
console.error(`${appName}: ERROR - Backup file not found: ${backupPath}`); | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
fs.copyFileSync(backupPath, hostsPath); | ||
console.log(`${appName}: Successfully restored HOSTS file from backup`); | ||
process.exit(0); | ||
} catch (err) { | ||
console.error(`${appName}: ERROR - An unexpected error occurred while restoring:`, err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
module.exports = { restoreHosts }; | ||
|
||
if (require.main === module) { | ||
restoreHosts(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个写在上面的文字那吧,别放在代码块里了
而且,这就是Linux的命令,Windows不用改权限