create-egregore 0.16.0 → 0.16.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/lib/setup.js +43 -15
- 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
|
-
//
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
|
|
161
|
-
|
|
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) {
|
|
@@ -234,7 +229,8 @@ async function install(data, ui, targetDir) {
|
|
|
234
229
|
const clonedRepos = [];
|
|
235
230
|
const failedRepos = [];
|
|
236
231
|
for (let i = 0; i < repos.length; i++) {
|
|
237
|
-
const
|
|
232
|
+
const repoEntry = repos[i];
|
|
233
|
+
const repoName = typeof repoEntry === 'string' ? repoEntry : repoEntry.name;
|
|
238
234
|
ui.step(6 + i, totalSteps, `Cloning ${repoName}...`);
|
|
239
235
|
const repoDir = path.join(base, repoName);
|
|
240
236
|
try {
|
|
@@ -243,8 +239,9 @@ async function install(data, ui, targetDir) {
|
|
|
243
239
|
run("git pull", { cwd: repoDir });
|
|
244
240
|
} else {
|
|
245
241
|
const repoUrl = `https://github.com/${github_org}/${repoName}.git`;
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
if (!cloneRepo(repoUrl, repoDir)) {
|
|
243
|
+
throw new Error(`Clone failed for ${repoName}`);
|
|
244
|
+
}
|
|
248
245
|
}
|
|
249
246
|
try { run("git config credential.helper store", { cwd: repoDir }); } catch {}
|
|
250
247
|
ensureDevelop(repoDir);
|
|
@@ -329,6 +326,37 @@ function embedToken(url, token) {
|
|
|
329
326
|
}
|
|
330
327
|
}
|
|
331
328
|
|
|
329
|
+
function toSSH(url) {
|
|
330
|
+
const m = url.match(/https:\/\/github\.com\/(.+?)(?:\.git)?$/);
|
|
331
|
+
return m ? `git@github.com:${m[1]}.git` : null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Clone a repo, trying SSH first then HTTPS (no token embedded).
|
|
336
|
+
* The repo:invite-scoped OAuth token can't clone — we rely on the
|
|
337
|
+
* user's own git credentials (SSH keys / gh CLI / credential helper).
|
|
338
|
+
*/
|
|
339
|
+
function cloneRepo(httpsUrl, dir, timeout = 60000) {
|
|
340
|
+
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
|
|
341
|
+
const sshUrl = toSSH(httpsUrl);
|
|
342
|
+
|
|
343
|
+
if (sshUrl) {
|
|
344
|
+
try {
|
|
345
|
+
execFileSync("git", ["clone", sshUrl, dir], { stdio: "pipe", encoding: "utf-8", timeout, env });
|
|
346
|
+
return true;
|
|
347
|
+
} catch {
|
|
348
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
try {
|
|
353
|
+
execFileSync("git", ["clone", httpsUrl, dir], { stdio: "pipe", encoding: "utf-8", timeout, env });
|
|
354
|
+
return true;
|
|
355
|
+
} catch {}
|
|
356
|
+
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
|
|
332
360
|
function configureGitCredentials(token) {
|
|
333
361
|
try {
|
|
334
362
|
// Use --global since this runs before any repos are cloned (no local .git exists)
|