create-egregore 0.16.0 → 0.16.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/setup.js +41 -14
  2. package/package.json +1 -1
package/lib/setup.js CHANGED
@@ -118,24 +118,18 @@ async function install(data, ui, targetDir) {
118
118
 
119
119
  const totalSteps = 5 + repos.length;
120
120
 
121
- // Configure git credential helper for HTTPS cloning
122
- configureGitCredentials(github_token);
123
-
124
121
  // Accept pending repo collaboration invitations (joiners get invited as collaborators)
125
122
  await acceptPendingInvitations(github_token, github_org, ui);
126
123
 
127
- // Embed token in URLs as fallback for private repos (credential helper may not work)
128
- const authedForkUrl = embedToken(fork_url, github_token);
129
- const authedMemoryUrl = embedToken(memory_url, github_token);
130
-
131
- // 1. Clone fork
124
+ // 1. Clone fork (SSH first, HTTPS fallback — no token embedding)
132
125
  ui.step(1, totalSteps, "Cloning egregore...");
133
126
  if (fs.existsSync(egregoreDir)) {
134
127
  ui.warn("egregore/ already exists — pulling latest");
135
128
  run("git pull", { cwd: egregoreDir });
136
129
  } else {
137
- execFileSync("git", ["clone", authedForkUrl, egregoreDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
138
- try { run(`git remote set-url origin ${fork_url}`, { cwd: egregoreDir }); } catch {}
130
+ if (!cloneRepo(fork_url, egregoreDir)) {
131
+ throw new Error(`Command failed: git clone ${fork_url} ${egregoreDir}\nCloning into '${egregoreDir}'...\nMake sure you have SSH keys set up or run 'gh auth login' first.`);
132
+ }
139
133
  }
140
134
  try { run("git config credential.helper store", { cwd: egregoreDir }); } catch {}
141
135
  ensureDevelop(egregoreDir);
@@ -157,8 +151,9 @@ async function install(data, ui, targetDir) {
157
151
  ui.warn(`${memoryDirName}/ already exists — pulling latest`);
158
152
  run("git pull", { cwd: memoryDir });
159
153
  } else {
160
- execFileSync("git", ["clone", authedMemoryUrl, memoryDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
161
- try { run(`git remote set-url origin ${memory_url}`, { cwd: memoryDir }); } catch {}
154
+ if (!cloneRepo(memory_url, memoryDir)) {
155
+ ui.warn(`Could not clone memory repo — you may need SSH keys or 'gh auth login'`);
156
+ }
162
157
  }
163
158
  try { run("git config credential.helper store", { cwd: memoryDir }); } catch {}
164
159
  if (github_username) {
@@ -243,8 +238,9 @@ async function install(data, ui, targetDir) {
243
238
  run("git pull", { cwd: repoDir });
244
239
  } else {
245
240
  const repoUrl = `https://github.com/${github_org}/${repoName}.git`;
246
- execFileSync("git", ["clone", embedToken(repoUrl, github_token), repoDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
247
- try { run(`git remote set-url origin ${repoUrl}`, { cwd: repoDir }); } catch {}
241
+ if (!cloneRepo(repoUrl, repoDir)) {
242
+ throw new Error(`Clone failed for ${repoName}`);
243
+ }
248
244
  }
249
245
  try { run("git config credential.helper store", { cwd: repoDir }); } catch {}
250
246
  ensureDevelop(repoDir);
@@ -329,6 +325,37 @@ function embedToken(url, token) {
329
325
  }
330
326
  }
331
327
 
328
+ function toSSH(url) {
329
+ const m = url.match(/https:\/\/github\.com\/(.+?)(?:\.git)?$/);
330
+ return m ? `git@github.com:${m[1]}.git` : null;
331
+ }
332
+
333
+ /**
334
+ * Clone a repo, trying SSH first then HTTPS (no token embedded).
335
+ * The repo:invite-scoped OAuth token can't clone — we rely on the
336
+ * user's own git credentials (SSH keys / gh CLI / credential helper).
337
+ */
338
+ function cloneRepo(httpsUrl, dir, timeout = 60000) {
339
+ const env = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
340
+ const sshUrl = toSSH(httpsUrl);
341
+
342
+ if (sshUrl) {
343
+ try {
344
+ execFileSync("git", ["clone", sshUrl, dir], { stdio: "pipe", encoding: "utf-8", timeout, env });
345
+ return true;
346
+ } catch {
347
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
348
+ }
349
+ }
350
+
351
+ try {
352
+ execFileSync("git", ["clone", httpsUrl, dir], { stdio: "pipe", encoding: "utf-8", timeout, env });
353
+ return true;
354
+ } catch {}
355
+
356
+ return false;
357
+ }
358
+
332
359
  function configureGitCredentials(token) {
333
360
  try {
334
361
  // Use --global since this runs before any repos are cloned (no local .git exists)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-egregore",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Set up Egregore for your team in one command",
5
5
  "license": "MIT",
6
6
  "bin": {