dirfly 0.7.0 → 0.9.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/README.md +4 -4
- package/dist/index.js +48 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,13 +20,13 @@ npx dirfly [localPath] <repoUrl> [repoSubDir]
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
## 使用示例
|
|
23
|
+
## 使用示例(推荐svn+ssh协议,避免频繁输入密码)
|
|
24
24
|
|
|
25
25
|
### 1. 使用当前目录上传
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
cd ./my-project
|
|
29
|
-
npx dirfly
|
|
29
|
+
npx dirfly svn+ssh://github.com/user/repo
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
* 使用当前目录作为 `[localPath]`
|
|
@@ -37,7 +37,7 @@ npx dirfly https://github.com/user/repo.git
|
|
|
37
37
|
### 2. 指定本地目录
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
npx dirfly ./dist
|
|
40
|
+
npx dirfly ./dist svn+ssh://github.com/user/repo
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
* `[localPath]` = `./dist`
|
|
@@ -48,7 +48,7 @@ npx dirfly ./dist https://github.com/user/repo.git
|
|
|
48
48
|
### 3. 指定本地目录和仓库子目录
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
npx dirfly ./dist
|
|
51
|
+
npx dirfly ./dist svn+ssh://github.com/user/repo frontend
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
* `[localPath]` = `./dist`
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,53 @@
|
|
|
3
3
|
// index.ts
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
import path, { basename } from "node:path";
|
|
6
|
-
import { existsSync } from "node:fs";
|
|
6
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { spawnSync } from "node:child_process";
|
|
8
|
+
|
|
9
|
+
// .gitignore
|
|
10
|
+
var __default = `# dependencies (bun install)
|
|
11
|
+
node_modules
|
|
12
|
+
|
|
13
|
+
# output
|
|
14
|
+
out
|
|
15
|
+
dist
|
|
16
|
+
*.tgz
|
|
17
|
+
|
|
18
|
+
# code coverage
|
|
19
|
+
coverage
|
|
20
|
+
*.lcov
|
|
21
|
+
|
|
22
|
+
# logs
|
|
23
|
+
logs
|
|
24
|
+
_.log
|
|
25
|
+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|
26
|
+
|
|
27
|
+
# dotenv environment variable files
|
|
28
|
+
.env
|
|
29
|
+
.env.development.local
|
|
30
|
+
.env.test.local
|
|
31
|
+
.env.production.local
|
|
32
|
+
.env.local
|
|
33
|
+
|
|
34
|
+
# caches
|
|
35
|
+
.eslintcache
|
|
36
|
+
.cache
|
|
37
|
+
*.tsbuildinfo
|
|
38
|
+
|
|
39
|
+
# IntelliJ based IDEs
|
|
40
|
+
.idea
|
|
41
|
+
|
|
42
|
+
# Finder (MacOS) folder config
|
|
43
|
+
.DS_Store
|
|
44
|
+
|
|
45
|
+
.git
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
// index.ts
|
|
8
49
|
var { positionals } = parseArgs({ allowPositionals: true });
|
|
9
|
-
var serverUrlIdx = positionals.findIndex((it) => it.
|
|
50
|
+
var serverUrlIdx = positionals.findIndex((it) => it.match(/\S+:\/\//));
|
|
10
51
|
if (serverUrlIdx === -1)
|
|
11
|
-
throw new Error("缺少svn
|
|
52
|
+
throw new Error("缺少svn服务地址");
|
|
12
53
|
var serverUrl = positionals[serverUrlIdx];
|
|
13
54
|
var localDir = path.resolve(positionals[serverUrlIdx - 1] || process.cwd());
|
|
14
55
|
if (!existsSync(localDir))
|
|
@@ -17,10 +58,10 @@ var serverDir = positionals[serverUrlIdx + 1] || basename(localDir);
|
|
|
17
58
|
process.chdir(localDir);
|
|
18
59
|
var gitignore = ".gitignore";
|
|
19
60
|
if (!existsSync(gitignore))
|
|
20
|
-
|
|
61
|
+
writeFileSync(gitignore, __default);
|
|
21
62
|
if (existsSync(".svn"))
|
|
22
63
|
throw new Error('当前目录已经被初始化过了,可以直接提交,如 `svn commit . -m "批量更新"`');
|
|
23
|
-
var serverFullUrl = `${serverUrl}/${serverDir}`;
|
|
64
|
+
var serverFullUrl = `${serverUrl.replace(/\/$/, "")}/${serverDir}`;
|
|
24
65
|
console.log(`准备导入: ${localDir} → ${serverFullUrl}`);
|
|
25
66
|
var cmds = [
|
|
26
67
|
`svn import -m "导入临时占位文件" ${gitignore} ${serverFullUrl}/${gitignore}`,
|
|
@@ -31,10 +72,9 @@ var cmds = [
|
|
|
31
72
|
`svn commit -m "新增项目${serverDir}"`
|
|
32
73
|
];
|
|
33
74
|
cmds.forEach((cmd) => {
|
|
34
|
-
const res = crossSpawnExec(cmd
|
|
35
|
-
if (res.status)
|
|
75
|
+
const res = crossSpawnExec(cmd);
|
|
76
|
+
if (res.status)
|
|
36
77
|
process.exit(0);
|
|
37
|
-
}
|
|
38
78
|
});
|
|
39
79
|
function crossSpawnExec(cmd, options) {
|
|
40
80
|
let [bin, ...params] = cmd.trim().split(/\s+/);
|