@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { scaffold } from "../lib/scaffold.js";
3
3
 
4
- const args = process.argv.slice(2);
4
+ const args = process.argv.slice(2).filter((arg) => arg !== "--");
5
5
  const [templateArg, targetArg] = args;
6
6
 
7
7
  try {
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) {
@@ -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 === templateKey
210
+ (template) => normalizeTemplateKey(template.key) === normalizedKey
183
211
  );
184
212
  if (!selectedTemplate) {
185
213
  const keys = templates.map((template) => template.key).join(", ");
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.2",
4
4
  "description": "Project scaffolding CLI (templates pulled from GitHub)",
5
5
  "type": "module",
6
6
  "bin": {