qdmp-cli 0.1.5 → 0.1.6
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/package.json +1 -1
- package/utils/gitClone.js +23 -7
package/package.json
CHANGED
package/utils/gitClone.js
CHANGED
|
@@ -3,9 +3,9 @@ import path from "path";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { rm } from "fs/promises";
|
|
5
5
|
import { existsSync } from "fs";
|
|
6
|
+
import { spawn } from "child_process";
|
|
6
7
|
import { inquirerConfirm } from "./interactive.js";
|
|
7
8
|
import { error } from "./logHandler.js";
|
|
8
|
-
import { execSync } from "./common.js";
|
|
9
9
|
/**
|
|
10
10
|
* 下载项目
|
|
11
11
|
* @param {string} projectName - 项目名称
|
|
@@ -38,13 +38,29 @@ export const download = async (projectName, repo) => {
|
|
|
38
38
|
const clone = async (repo, name) => {
|
|
39
39
|
const spinner = ora("正在拉取项目......").start();
|
|
40
40
|
try {
|
|
41
|
-
|
|
41
|
+
// 使用 spawn 并继承 stdio,允许 SSH 首次连接时用户交互确认
|
|
42
|
+
spinner.stop();
|
|
43
|
+
await new Promise((resolve, reject) => {
|
|
44
|
+
const child = spawn(
|
|
45
|
+
"git",
|
|
46
|
+
["clone", "--depth", "1", `git@g.echo.tech:${repo}.git`, name],
|
|
47
|
+
{ stdio: "inherit" }
|
|
48
|
+
);
|
|
49
|
+
child.on("close", (code) => {
|
|
50
|
+
if (code === 0) {
|
|
51
|
+
resolve();
|
|
52
|
+
} else {
|
|
53
|
+
reject(new Error(`git clone 退出码: ${code}`));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
child.on("error", (err) => {
|
|
57
|
+
reject(err);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
42
60
|
const gitPath = path.join(process.cwd(), name, ".git");
|
|
43
61
|
await rm(gitPath, { recursive: true, force: true });
|
|
44
|
-
|
|
45
|
-
} catch (
|
|
46
|
-
|
|
47
|
-
} finally {
|
|
48
|
-
spinner.stop();
|
|
62
|
+
console.log(chalk.green(`✔ 模版创建成功!请进入 ${name} 目录开始开发`));
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.log(chalk.red(`✖ 模版创建失败: ${err.message}`));
|
|
49
65
|
}
|
|
50
66
|
};
|