dirfly 0.6.0 → 0.8.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 +18 -3
- 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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
import path, { basename } from "node:path";
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
|
-
import {
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
8
|
var { positionals } = parseArgs({ allowPositionals: true });
|
|
9
9
|
var serverUrlIdx = positionals.findIndex((it) => it.startsWith("svn+ssh://"));
|
|
10
10
|
if (serverUrlIdx === -1)
|
|
@@ -24,10 +24,25 @@ var serverFullUrl = `${serverUrl}/${serverDir}`;
|
|
|
24
24
|
console.log(`准备导入: ${localDir} → ${serverFullUrl}`);
|
|
25
25
|
var cmds = [
|
|
26
26
|
`svn import -m "导入临时占位文件" ${gitignore} ${serverFullUrl}/${gitignore}`,
|
|
27
|
-
`svn checkout
|
|
27
|
+
`svn checkout ${serverFullUrl} .`,
|
|
28
28
|
`svn propset svn:ignore -F ./.gitignore ./`,
|
|
29
29
|
`svn resolve --accept working ./.gitignore`,
|
|
30
30
|
`svn add --force . `,
|
|
31
31
|
`svn commit -m "新增项目${serverDir}"`
|
|
32
32
|
];
|
|
33
|
-
cmds.forEach((cmd) =>
|
|
33
|
+
cmds.forEach((cmd) => {
|
|
34
|
+
const res = crossSpawnExec(cmd, { stdio: "inherit" });
|
|
35
|
+
if (res.status) {
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
function crossSpawnExec(cmd, options) {
|
|
40
|
+
let [bin, ...params] = cmd.trim().split(/\s+/);
|
|
41
|
+
if (!bin)
|
|
42
|
+
throw new Error("执行命令有误");
|
|
43
|
+
if (process.platform === "win32") {
|
|
44
|
+
params.unshift("-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", bin);
|
|
45
|
+
bin = "powershell.exe";
|
|
46
|
+
}
|
|
47
|
+
return spawnSync(bin, params, { stdio: "inherit", ...options });
|
|
48
|
+
}
|