dirfly 0.1.0
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/.prototools +1 -0
- package/README.md +235 -0
- package/index.ts +53 -0
- package/package.json +31 -0
- package/tsconfig.json +31 -0
package/.prototools
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node = "~25"
|
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# dirfly
|
|
2
|
+
|
|
3
|
+
用于将本地目录同步到指定`SVN`仓库。
|
|
4
|
+
|
|
5
|
+
## 安装与运行
|
|
6
|
+
|
|
7
|
+
无需全局安装,直接使用 `npx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx dirfly [localPath] <repoUrl> [repoSubDir]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 参数说明
|
|
14
|
+
|
|
15
|
+
| 参数 | 是否必填 | 默认值 | 描述 |
|
|
16
|
+
| -------------- | ---- | -------------- | ------------------------------------------ |
|
|
17
|
+
| `[localPath]` | 可选 | 当前工作目录 (`cwd`) | 本地目录路径,可以是相对或绝对路径 |
|
|
18
|
+
| `<repoUrl>` | 必填 | — | 仓库地址,例如 `https://github.com/user/repo.git` |
|
|
19
|
+
| `[repoSubDir]` | 可选 | 本地目录名 | 仓库内的目标子目录名称,不指定时自动使用本地目录名 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 使用示例
|
|
24
|
+
|
|
25
|
+
### 1. 使用当前目录上传
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cd ./my-project
|
|
29
|
+
npx dirfly https://github.com/user/repo.git
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
* 使用当前目录作为 `[localPath]`
|
|
33
|
+
* 仓库子目录默认使用 `my-project`
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### 2. 指定本地目录
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx dirfly ./dist https://github.com/user/repo.git
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
* `[localPath]` = `./dist`
|
|
44
|
+
* `[repoSubDir]` 未指定,默认使用 `dist`
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
### 3. 指定本地目录和仓库子目录
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx dirfly ./dist https://github.com/user/repo.git frontend
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
* `[localPath]` = `./dist`
|
|
55
|
+
* `[repoSubDir]` = `frontend`
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## 依赖
|
|
59
|
+
|
|
60
|
+
本工具依赖 SVN 命令行工具。可以在下面的页面查找或下载适合您平台的 SVN 客户端:
|
|
61
|
+
|
|
62
|
+
- https://tortoisesvn.net/downloads.zh.html — 在该页面可以直接下载适用于不同系统架构的安装包(例如 32-bit、64-bit、ARM64)
|
|
63
|
+
- macOS / Linux:推荐通过包管理器安装 `subversion`(例如 macOS 使用 `brew install subversion`),或查看 Apache Subversion 官方包列表:https://subversion.apache.org/packages.html
|
|
64
|
+
|
|
65
|
+
安装完成后,请在终端中确认 `svn` 可用:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
svn --version
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## SVN 服务(托管与私有仓库)
|
|
74
|
+
|
|
75
|
+
下面列出了一些可以托管 SVN 仓库或提供 SVN 服务的平台供参考:
|
|
76
|
+
|
|
77
|
+
- 国际:SourceForge(https://sourceforge.net)
|
|
78
|
+
- gitee.com : 支持git SVN 二合一仓库
|
|
79
|
+
- svnbucket(https://svnbucket.com) — 支持绑定微信,提供免费与付费套餐,适合需要国内支付/本地化支持的团队
|
|
80
|
+
|
|
81
|
+
svnbucket 示例套餐(仅供参考,以服务商官网为准):
|
|
82
|
+
- 免费版:
|
|
83
|
+
- ¥0/月
|
|
84
|
+
- 100M 仓库空间
|
|
85
|
+
- 不限私有项目数量
|
|
86
|
+
- 不限项目成员数量
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 注意事项
|
|
90
|
+
|
|
91
|
+
1. `[localPath]` 必须存在,否则命令会报错。
|
|
92
|
+
2. `<repoUrl>` 必填,SVN仓库地址。
|
|
93
|
+
3. `[repoSubDir]` 未填时默认使用本地目录名。
|
|
94
|
+
4. 支持相对路径和绝对路径,兼容 Windows / macOS / Linux。
|
|
95
|
+
5. 路径或子目录名中含空格时请使用双引号,例如:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx dirfly "C:\My Project\dist" "https://github.com/user/repo.git" "frontend dir"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 推荐用法
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# 使用当前目录,默认子目录
|
|
107
|
+
npx dirfly <repoUrl>
|
|
108
|
+
|
|
109
|
+
# 指定本地目录,自动使用目录名作为仓库子目录
|
|
110
|
+
npx dirfly ./dist <repoUrl>
|
|
111
|
+
|
|
112
|
+
# 指定本地目录和仓库子目录
|
|
113
|
+
npx dirfly ./dist <repoUrl> frontend
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Git 与 SVN 常用命令对比(按使用频率排序)
|
|
118
|
+
|
|
119
|
+
> 按照日常开发中的使用频率从高到低排列
|
|
120
|
+
|
|
121
|
+
## 🔥 最高频命令(日常必用)
|
|
122
|
+
|
|
123
|
+
### 1. 查看状态与差异
|
|
124
|
+
**使用频率:★★★★★ 每天多次**
|
|
125
|
+
|
|
126
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
127
|
+
|------|----------|----------|------|
|
|
128
|
+
| 查看工作区状态 | `git status` | `svn status` | 显示修改的文件 |
|
|
129
|
+
| 查看文件差异 | `git diff` | `svn diff` | 显示具体的代码变更 |
|
|
130
|
+
| 查看提交历史 | `git log --oneline` | `svn log` | 显示提交记录 |
|
|
131
|
+
|
|
132
|
+
### 2. 日常更新与提交
|
|
133
|
+
**使用频率:★★★★★ 每天多次**
|
|
134
|
+
|
|
135
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
136
|
+
|------|----------|----------|------|
|
|
137
|
+
| 更新到最新版本 | `git pull` | `svn update` | 获取团队最新代码 |
|
|
138
|
+
| 添加文件到版本控制 | `git add <file>` | `svn add <file>` | 标记新文件 |
|
|
139
|
+
| 提交代码更改 | `git commit -m "<message>"` | `svn commit -m "<message>"` | 提交本地修改 |
|
|
140
|
+
|
|
141
|
+
### 3. 推送与同步
|
|
142
|
+
**使用频率:★★★★☆ 每天多次**
|
|
143
|
+
|
|
144
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
145
|
+
|------|----------|----------|------|
|
|
146
|
+
| 推送本地提交 | `git push` | (已内置于 commit) | 同步到远程仓库 |
|
|
147
|
+
| 查看远程仓库 | `git remote -v` | `svn info` | 显示仓库信息 |
|
|
148
|
+
|
|
149
|
+
## ⚡ 中频命令(经常使用)
|
|
150
|
+
|
|
151
|
+
### 4. 文件操作
|
|
152
|
+
**使用频率:★★★☆☆ 每周多次**
|
|
153
|
+
|
|
154
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
155
|
+
|------|----------|----------|------|
|
|
156
|
+
| 删除文件 | `git rm <file>` | `svn rm <file>` | 删除文件 |
|
|
157
|
+
| 重命名/移动文件 | `git mv <old> <new>` | `svn mv <old> <new>` | 移动或重命名 |
|
|
158
|
+
|
|
159
|
+
### 5. 分支操作(基础)
|
|
160
|
+
**使用频率:★★★☆☆ 每周多次**
|
|
161
|
+
|
|
162
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
163
|
+
|------|----------|----------|------|
|
|
164
|
+
| 切换分支 | `git checkout <branch>`<br>`git switch <branch>` | `svn switch <branch-url>` | 切换到指定分支 |
|
|
165
|
+
| 创建分支 | `git branch <branch>`<br>`git checkout -b <branch>` | `svn copy <trunk-url> <branch-url>` | 创建新分支 |
|
|
166
|
+
|
|
167
|
+
## 🚀 中低频命令(偶尔使用)
|
|
168
|
+
|
|
169
|
+
### 6. 分支管理(高级)
|
|
170
|
+
**使用频率:★★☆☆☆ 每月几次**
|
|
171
|
+
|
|
172
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
173
|
+
|------|----------|----------|------|
|
|
174
|
+
| 查看分支列表 | `git branch -a` | `svn list <repo-url>/branches` | 显示所有分支 |
|
|
175
|
+
| 合并分支 | `git merge <branch>` | `svn merge <branch-url>` | 合并代码 |
|
|
176
|
+
| 删除分支 | `git branch -d <branch>` | `svn rm <branch-url>` | 删除分支 |
|
|
177
|
+
|
|
178
|
+
### 7. 版本回退
|
|
179
|
+
**使用频率:★★☆☆☆ 每月几次**
|
|
180
|
+
|
|
181
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
182
|
+
|------|----------|----------|------|
|
|
183
|
+
| 撤销本地修改 | `git checkout -- <file>`<br>`git restore <file>` | `svn revert <file>` | 放弃未提交的更改 |
|
|
184
|
+
| 回滚到指定版本 | `git checkout <commit-id>` | `svn update -r <revision>` | 切换到历史版本 |
|
|
185
|
+
|
|
186
|
+
## 🛠️ 低频命令(功能维护)
|
|
187
|
+
|
|
188
|
+
### 8. 仓库初始化
|
|
189
|
+
**使用频率:★☆☆☆☆ 项目初期**
|
|
190
|
+
|
|
191
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
192
|
+
|------|----------|----------|------|
|
|
193
|
+
| 初始化仓库 | `git init` | `svnadmin create <repo>` | 新建仓库 |
|
|
194
|
+
| 克隆仓库 | `git clone <repo>` | `svn checkout <repo>` | 获取现有仓库 |
|
|
195
|
+
|
|
196
|
+
### 9. 标签管理
|
|
197
|
+
**使用频率:★☆☆☆☆ 发布版本时**
|
|
198
|
+
|
|
199
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
200
|
+
|------|----------|----------|------|
|
|
201
|
+
| 创建标签 | `git tag <tag>` | `svn copy <trunk-url> <tag-url>` | 创建版本标签 |
|
|
202
|
+
| 切换到标签 | `git checkout <tag>` | `svn switch <tag-url>` | 切换到标签版本 |
|
|
203
|
+
|
|
204
|
+
### 10. 高级功能
|
|
205
|
+
**使用频率:★☆☆☆☆ 特殊需要时**
|
|
206
|
+
|
|
207
|
+
| 操作 | Git 命令 | SVN 命令 | 说明 |
|
|
208
|
+
|------|----------|----------|------|
|
|
209
|
+
| 查看特定版本文件 | `git show <commit>:<file>` | `svn cat <file>@<revision>` | 查看历史文件 |
|
|
210
|
+
| 忽略文件配置 | `.gitignore` 文件 | `svn propset svn:ignore` | 设置忽略规则 |
|
|
211
|
+
| 撤销特定提交 | `git revert <commit>` | `svn merge -c -<revision>` | 回退指定提交 |
|
|
212
|
+
|
|
213
|
+
## 📊 使用场景总结
|
|
214
|
+
|
|
215
|
+
### 日常开发工作流(90%场景)
|
|
216
|
+
```
|
|
217
|
+
# Git 工作流
|
|
218
|
+
git pull # 更新
|
|
219
|
+
git status # 查看状态
|
|
220
|
+
git add . # 添加修改
|
|
221
|
+
git commit -m "msg" # 提交
|
|
222
|
+
git push # 推送
|
|
223
|
+
|
|
224
|
+
# SVN 工作流
|
|
225
|
+
svn update # 更新
|
|
226
|
+
svn status # 查看状态
|
|
227
|
+
svn add <files> # 添加新文件
|
|
228
|
+
svn commit -m "msg" # 提交并推送
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 关键差异提醒
|
|
232
|
+
- **Git** 分两步:`commit`(本地)→ `push`(远程)
|
|
233
|
+
- **SVN** 一步到位:`commit`(直接到服务器)
|
|
234
|
+
- **分支成本**:Git 分支是轻量级指针,SVN 分支是完整拷贝
|
|
235
|
+
- **离线工作**:Git 可完全离线,SVN 依赖网络连接
|
package/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import path, { basename } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
const { positionals } = parseArgs({ allowPositionals: true });
|
|
9
|
+
const serverUrlIdx = positionals.findIndex(it => it.match(/\S+:\/\//))
|
|
10
|
+
if (serverUrlIdx === -1) throw new Error('缺少svn服务地址')
|
|
11
|
+
const serverUrl = positionals[serverUrlIdx]
|
|
12
|
+
const localDir = path.resolve(positionals[serverUrlIdx - 1] || process.cwd())
|
|
13
|
+
if (!existsSync(localDir)) throw new Error(`本地路径不存在: ${localDir}`)
|
|
14
|
+
const serverDir = positionals[serverUrlIdx + 1] || basename(localDir)
|
|
15
|
+
|
|
16
|
+
process.chdir(localDir)
|
|
17
|
+
|
|
18
|
+
const gitignore = '.gitignore'
|
|
19
|
+
if (!existsSync(gitignore)) throw new Error(`请先创建${path.resolve(gitignore)},如 svn commit . -m "批量更新"`)
|
|
20
|
+
if (existsSync('.svn')) throw new Error('当前目录已经被初始化过了,可以直接提交,如 `svn commit . -m "批量更新"`')
|
|
21
|
+
|
|
22
|
+
const serverFullUrl = `${serverUrl}/${serverDir}`
|
|
23
|
+
console.log(`准备导入: ${localDir} → ${serverFullUrl}`);
|
|
24
|
+
// 期待的使用方式:npx git-svn [local] <serverurl>/[xxx]
|
|
25
|
+
// 期待的使用方式:npx xxxlib [localfilepath] <serverurl> [localfilepath的dirname]
|
|
26
|
+
/**
|
|
27
|
+
* TODO
|
|
28
|
+
* 整理一些常用的SVN命令:
|
|
29
|
+
* - 推送
|
|
30
|
+
* - 拉取
|
|
31
|
+
* 拉取指定目录
|
|
32
|
+
* 测试目录里面有很多嵌套的子项目; 就如ebase; 会把子项目的文件上传马
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
const cmds = [
|
|
36
|
+
// local直接是当前cwd,或者手动指定一个路径
|
|
37
|
+
// 1. 先导入一个临时文件占个位置文件 .gitignore/没有的话临时创建一个文件事成之后在删除
|
|
38
|
+
// svn import yourfile.txt http://svn.example.com/repo/trunk/project/yourfile.txt -m "导入单个文件"
|
|
39
|
+
`svn import -m "导入临时占位文件" ${gitignore} ${serverFullUrl}/${gitignore}`,
|
|
40
|
+
// 2. checkout " .
|
|
41
|
+
`svn checkout "${serverFullUrl}" .`,
|
|
42
|
+
// `svn checkout "${serverFullUrl}" ./`,
|
|
43
|
+
// 3. 添加忽略文件
|
|
44
|
+
`svn propset svn:ignore -F ./.gitignore ./`,
|
|
45
|
+
`svn resolve --accept working ./.gitignore`,
|
|
46
|
+
// 4. 添加所有文件
|
|
47
|
+
`svn add --force . `,
|
|
48
|
+
// 5. 忽略 临时文件
|
|
49
|
+
// `svn delete --force ${tmpFile.name}`,
|
|
50
|
+
// 6. 提交
|
|
51
|
+
`svn commit -m "新增项目${serverDir}"`
|
|
52
|
+
]
|
|
53
|
+
cmds.forEach(cmd => execSync(cmd))
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dirfly",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "命令行工具,用于将本地目录同步到指定仓库",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"directory",
|
|
7
|
+
"sync",
|
|
8
|
+
"repository",
|
|
9
|
+
"git",
|
|
10
|
+
"SVN",
|
|
11
|
+
"upload",
|
|
12
|
+
"cli",
|
|
13
|
+
"npm",
|
|
14
|
+
"npx",
|
|
15
|
+
"目录同步"
|
|
16
|
+
],
|
|
17
|
+
"bin": {
|
|
18
|
+
"dirfly": "./index.ts"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"pub": "npm publish --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$token "
|
|
22
|
+
},
|
|
23
|
+
"module": "index.ts",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.18.0"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.18.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": [
|
|
5
|
+
"ESNext"
|
|
6
|
+
],
|
|
7
|
+
"types": [
|
|
8
|
+
"node"
|
|
9
|
+
],
|
|
10
|
+
"target": "ESNext",
|
|
11
|
+
"module": "Preserve",
|
|
12
|
+
"moduleDetection": "force",
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
// Bundler mode
|
|
16
|
+
"moduleResolution": "bundler",
|
|
17
|
+
"allowImportingTsExtensions": true,
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
// Best practices
|
|
21
|
+
"strict": true,
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
"noFallthroughCasesInSwitch": true,
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"noImplicitOverride": true,
|
|
26
|
+
// Some stricter flags (disabled by default)
|
|
27
|
+
"noUnusedLocals": false,
|
|
28
|
+
"noUnusedParameters": false,
|
|
29
|
+
"noPropertyAccessFromIndexSignature": false
|
|
30
|
+
}
|
|
31
|
+
}
|