@guchen_0521/create-temp 0.1.0 → 0.1.2
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/bin/cli.js +1 -1
- package/lib/scaffold.js +37 -9
- package/package.json +1 -1
package/bin/cli.js
CHANGED
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
55
|
+
throw lastError;
|
|
39
56
|
}
|
|
40
57
|
|
|
41
58
|
async function findTemplateDirs(rootDir) {
|
|
@@ -73,6 +90,16 @@ function formatTemplateKey(projectRoot, templateDir) {
|
|
|
73
90
|
.join("/");
|
|
74
91
|
}
|
|
75
92
|
|
|
93
|
+
function normalizeTemplateKey(templateKey) {
|
|
94
|
+
if (!templateKey) {
|
|
95
|
+
return templateKey;
|
|
96
|
+
}
|
|
97
|
+
return templateKey
|
|
98
|
+
.trim()
|
|
99
|
+
.replaceAll("\\", "/")
|
|
100
|
+
.replace(/^\.\/+/, "");
|
|
101
|
+
}
|
|
102
|
+
|
|
76
103
|
async function promptSelectTemplate(templates) {
|
|
77
104
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
78
105
|
console.log("Available templates:");
|
|
@@ -178,8 +205,9 @@ export async function scaffold({ templateKey, targetDir }) {
|
|
|
178
205
|
|
|
179
206
|
let selectedTemplate = null;
|
|
180
207
|
if (templateKey) {
|
|
208
|
+
const normalizedKey = normalizeTemplateKey(templateKey);
|
|
181
209
|
selectedTemplate = templates.find(
|
|
182
|
-
(template) => template.key ===
|
|
210
|
+
(template) => normalizeTemplateKey(template.key) === normalizedKey
|
|
183
211
|
);
|
|
184
212
|
if (!selectedTemplate) {
|
|
185
213
|
const keys = templates.map((template) => template.key).join(", ");
|