@guchen_0521/create-temp 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/lib/scaffold.js +25 -8
  2. package/package.json +1 -1
package/lib/scaffold.js CHANGED
@@ -22,20 +22,37 @@ const IGNORE_NAMES = new Set([
22
22
 
23
23
  const execFileAsync = promisify(execFile);
24
24
  const TEMPLATE_REPO_SSH = "ssh://git@ssh.github.com:443/GuChena/template.git";
25
+ const CLONE_RETRIES = 3;
26
+ const GIT_SSH_COMMAND =
27
+ "ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=6";
25
28
 
26
29
  async function cloneTemplateRepo() {
27
30
  const tempDir = await mkdtemp(path.join(os.tmpdir(), "template-cli-"));
28
31
  const repoDir = path.join(tempDir, `repo-${Date.now().toString(36)}`);
29
32
 
30
- await execFileAsync("git", [
31
- "clone",
32
- "--depth",
33
- "1",
34
- TEMPLATE_REPO_SSH,
35
- repoDir,
36
- ]);
33
+ let lastError = null;
34
+ for (let attempt = 1; attempt <= CLONE_RETRIES; attempt += 1) {
35
+ try {
36
+ await execFileAsync(
37
+ "git",
38
+ ["clone", "--depth", "1", TEMPLATE_REPO_SSH, repoDir],
39
+ {
40
+ env: {
41
+ ...process.env,
42
+ GIT_SSH_COMMAND,
43
+ },
44
+ }
45
+ );
46
+ return { repoDir, tempDir };
47
+ } catch (error) {
48
+ lastError = error;
49
+ if (attempt < CLONE_RETRIES) {
50
+ await new Promise((resolve) => setTimeout(resolve, attempt * 500));
51
+ }
52
+ }
53
+ }
37
54
 
38
- return { repoDir, tempDir };
55
+ throw lastError;
39
56
  }
40
57
 
41
58
  async function findTemplateDirs(rootDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guchen_0521/create-temp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Project scaffolding CLI (templates pulled from GitHub)",
5
5
  "type": "module",
6
6
  "bin": {