@guchen_0521/create-temp 0.1.1 → 0.1.3
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 +21 -9
- package/package.json +1 -1
package/bin/cli.js
CHANGED
package/lib/scaffold.js
CHANGED
|
@@ -21,7 +21,9 @@ const IGNORE_NAMES = new Set([
|
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
23
|
const execFileAsync = promisify(execFile);
|
|
24
|
-
const
|
|
24
|
+
const TEMPLATE_REPO_URL =
|
|
25
|
+
process.env.TEMPLATE_REPO_URL ||
|
|
26
|
+
"https://github.com/GuChena/template.git";
|
|
25
27
|
const CLONE_RETRIES = 3;
|
|
26
28
|
const GIT_SSH_COMMAND =
|
|
27
29
|
"ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=6";
|
|
@@ -33,15 +35,14 @@ async function cloneTemplateRepo() {
|
|
|
33
35
|
let lastError = null;
|
|
34
36
|
for (let attempt = 1; attempt <= CLONE_RETRIES; attempt += 1) {
|
|
35
37
|
try {
|
|
38
|
+
const env = { ...process.env };
|
|
39
|
+
if (TEMPLATE_REPO_URL.startsWith("ssh://")) {
|
|
40
|
+
env.GIT_SSH_COMMAND = GIT_SSH_COMMAND;
|
|
41
|
+
}
|
|
36
42
|
await execFileAsync(
|
|
37
43
|
"git",
|
|
38
|
-
["clone", "--depth", "1",
|
|
39
|
-
{
|
|
40
|
-
env: {
|
|
41
|
-
...process.env,
|
|
42
|
-
GIT_SSH_COMMAND,
|
|
43
|
-
},
|
|
44
|
-
}
|
|
44
|
+
["clone", "--depth", "1", TEMPLATE_REPO_URL, repoDir],
|
|
45
|
+
{ env }
|
|
45
46
|
);
|
|
46
47
|
return { repoDir, tempDir };
|
|
47
48
|
} catch (error) {
|
|
@@ -90,6 +91,16 @@ function formatTemplateKey(projectRoot, templateDir) {
|
|
|
90
91
|
.join("/");
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
function normalizeTemplateKey(templateKey) {
|
|
95
|
+
if (!templateKey) {
|
|
96
|
+
return templateKey;
|
|
97
|
+
}
|
|
98
|
+
return templateKey
|
|
99
|
+
.trim()
|
|
100
|
+
.replaceAll("\\", "/")
|
|
101
|
+
.replace(/^\.\/+/, "");
|
|
102
|
+
}
|
|
103
|
+
|
|
93
104
|
async function promptSelectTemplate(templates) {
|
|
94
105
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
95
106
|
console.log("Available templates:");
|
|
@@ -195,8 +206,9 @@ export async function scaffold({ templateKey, targetDir }) {
|
|
|
195
206
|
|
|
196
207
|
let selectedTemplate = null;
|
|
197
208
|
if (templateKey) {
|
|
209
|
+
const normalizedKey = normalizeTemplateKey(templateKey);
|
|
198
210
|
selectedTemplate = templates.find(
|
|
199
|
-
(template) => template.key ===
|
|
211
|
+
(template) => normalizeTemplateKey(template.key) === normalizedKey
|
|
200
212
|
);
|
|
201
213
|
if (!selectedTemplate) {
|
|
202
214
|
const keys = templates.map((template) => template.key).join(", ");
|