Skip to content

Commit 1cfb8c8

Browse files
committed
docs: enhance README with detailed usage instructions and examples
1 parent d6f6cde commit 1cfb8c8

File tree

2 files changed

+120
-16
lines changed

2 files changed

+120
-16
lines changed

README.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,81 @@ English | [中文](./README_zh.md)
22

33
# Resource Saving Script
44

5-
A simple but powerful Node.js script that runs a local web server and automatically downloads missing resources.
5+
A Node.js tool for local development that starts a local server while automatically fetching missing remote resource files.
66

7-
### Global Installation
7+
## Table of Contents
8+
9+
- [Installation](#installation)
10+
- [Usage](#usage)
11+
- [How It Works](#how-it-works)
12+
- [Usage Example](#usage-example)
13+
- [Use Cases](#use-cases)
14+
15+
## Installation
816

917
```bash
1018
npm install -g resource-save-script
1119
```
1220

13-
### Usage
21+
## Usage
1422

15-
Once installed, you can use the `h` command in your terminal.
23+
Once installed, use the `h` command in your terminal:
1624

1725
```bash
18-
# Run on a custom port (e.g., 8080)
26+
# Run on a custom port
1927
h 8080
2028

21-
# Run on the default port (4000)
29+
# Run on the default port 4000
2230
h
2331
```
2432

25-
After running the command, the script will prompt you to enter the base URL of the remote server where the resources are located.
33+
You'll be prompted to enter the remote server URL:
2634

2735
```text
2836
→ Please enter the base URL for resources: https://your-remote-server.com
2937
```
30-
The local server will then start, and any missing files will be downloaded automatically.
38+
39+
## How It Works
40+
41+
The script monitors 404 requests on the local server. When a missing file is detected, it automatically downloads the file from the specified remote server to your local directory.
42+
43+
## Usage Example
44+
45+
Let's say you want to debug a page from `luckfunc.com` locally:
46+
47+
**1. Create and enter project directory**
48+
```bash
49+
mkdir my-project
50+
cd my-project
51+
```
52+
53+
**2. Download the main page**
54+
```bash
55+
curl -o index.html https://luckfunc.com/
56+
```
57+
58+
**3. Start the script in your project directory**
59+
```bash
60+
h
61+
# Enter: https://luckfunc.com/
62+
```
63+
64+
**4. Access the page**
65+
66+
Open your browser and visit `http://127.0.0.1:4000/index.html`
67+
68+
When the page loads, if it references local files like `i18n.js` that don't exist, the script will automatically download them from `luckfunc.com` to your local directory.
69+
70+
Terminal output will show download progress:
71+
```text
72+
Missing file detected: /i18n.js
73+
Download complete: /path/to/your/project/i18n.js (1234 bytes)
74+
```
75+
76+
Refresh the page and all resources will load properly.
77+
78+
## Use Cases
79+
80+
- Local debugging of live websites
81+
- Setting up offline development environments
82+
- Bulk downloading of static resources

README_zh.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,81 @@
22

33
# 资源保存脚本
44

5-
一个简单但功能强大的 Node.js 脚本,可以运行一个本地 Web 服务器并自动下载缺失的资源
5+
一个用于本地开发的 Node.js 工具,启动本地服务器的同时自动抓取缺失的远程资源文件
66

7-
### 全局安装
7+
## 目录
8+
9+
- [安装](#安装)
10+
- [使用](#使用)
11+
- [工作原理](#工作原理)
12+
- [使用场景示例](#使用场景示例)
13+
- [适用场景](#适用场景)
14+
15+
## 安装
816

917
```bash
1018
npm install -g resource-save-script
1119
```
1220

13-
### 使用方法
21+
## 使用
1422

15-
安装后,您可以在终端中使用 `h` 命令。
23+
安装完成后,在终端中使用 `h` 命令启动:
1624

1725
```bash
18-
# 使用自定义端口 (例如 8080)
26+
# 指定端口号
1927
h 8080
2028

21-
# 使用默认端口 (4000)
29+
# 使用默认端口 4000
2230
h
2331
```
2432

25-
运行命令后,脚本将提示您输入存放资源的远程服务器的基础 URL。
33+
启动时会提示输入远程服务器地址:
2634

2735
```text
2836
→ 请输入资源所在的根 URL: https://your-remote-server.com
2937
```
30-
之后本地服务器将启动,并自动下载任何缺失的文件。
38+
39+
## 工作原理
40+
41+
脚本会监听本地服务器的 404 请求,当检测到缺失文件时自动从指定的远程服务器下载到本地。
42+
43+
## 使用场景示例
44+
45+
假设你想在本地调试 `luckfunc.com` 的页面:
46+
47+
**1. 创建并进入项目目录**
48+
```bash
49+
mkdir my-project
50+
cd my-project
51+
```
52+
53+
**2. 下载主页面**
54+
```bash
55+
curl -o index.html https://luckfunc.com/
56+
```
57+
58+
**3. 在项目目录下启动脚本**
59+
```bash
60+
h
61+
# 输入: https://luckfunc.com/
62+
```
63+
64+
**3. 访问页面**
65+
66+
打开浏览器访问 `http://127.0.0.1:4000/index.html`
67+
68+
当页面加载时,如果引用了本地不存在的 `i18n.js` 等文件,脚本会自动从 `luckfunc.com` 下载这些文件到本地目录。
69+
70+
终端会显示下载进度:
71+
```text
72+
检测到缺失文件: /i18n.js
73+
下载完成: /path/to/your/project/i18n.js (1234 bytes)
74+
```
75+
76+
再次刷新页面,所有资源都能正常加载了。
77+
78+
## 适用场景
79+
80+
- 本地调试线上页面
81+
- 离线开发环境搭建
82+
- 静态资源批量下载

0 commit comments

Comments
 (0)