create-egregore 0.3.8 → 0.3.10
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 +9 -2
- package/lib/setup.js +31 -10
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -67,10 +67,10 @@ async function main() {
|
|
|
67
67
|
|
|
68
68
|
async function tokenFlow(api, token) {
|
|
69
69
|
const s = ui.spinner("Claiming setup token...");
|
|
70
|
+
let data;
|
|
70
71
|
try {
|
|
71
|
-
|
|
72
|
+
data = await api.claimToken(token);
|
|
72
73
|
s.stop(`Claimed — setting up ${ui.bold(data.org_name)}`);
|
|
73
|
-
await install(data, ui);
|
|
74
74
|
} catch (err) {
|
|
75
75
|
s.fail("Token claim failed");
|
|
76
76
|
ui.error(err.message);
|
|
@@ -80,6 +80,13 @@ async function tokenFlow(api, token) {
|
|
|
80
80
|
ui.info(" npx create-egregore");
|
|
81
81
|
process.exit(1);
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
await install(data, ui);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
ui.error(`Install failed: ${err.message}`);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
async function interactiveFlow(api) {
|
package/lib/setup.js
CHANGED
|
@@ -23,8 +23,9 @@ async function install(data, ui, targetDir) {
|
|
|
23
23
|
const { fork_url, memory_url, github_token, org_name, github_org, slug, api_key, repos = [], telegram_group_link } = data;
|
|
24
24
|
const base = targetDir || process.cwd();
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
const
|
|
26
|
+
// Directory name from fork URL (what git clone would use), e.g. "egregore-core"
|
|
27
|
+
const forkDirName = fork_url.split("/").pop().replace(/\.git$/, "");
|
|
28
|
+
const egregoreDir = path.join(base, forkDirName);
|
|
28
29
|
const memoryDirName = memory_url
|
|
29
30
|
.split("/")
|
|
30
31
|
.pop()
|
|
@@ -36,13 +37,18 @@ async function install(data, ui, targetDir) {
|
|
|
36
37
|
// Configure git credential helper for HTTPS cloning
|
|
37
38
|
configureGitCredentials(github_token);
|
|
38
39
|
|
|
40
|
+
// Embed token in URLs as fallback for private repos (credential helper may not work)
|
|
41
|
+
const authedForkUrl = embedToken(fork_url, github_token);
|
|
42
|
+
const authedMemoryUrl = embedToken(memory_url, github_token);
|
|
43
|
+
|
|
39
44
|
// 1. Clone fork
|
|
40
45
|
ui.step(1, totalSteps, "Cloning egregore...");
|
|
41
46
|
if (fs.existsSync(egregoreDir)) {
|
|
42
47
|
ui.warn("egregore/ already exists — pulling latest");
|
|
43
48
|
run("git pull", { cwd: egregoreDir });
|
|
44
49
|
} else {
|
|
45
|
-
execFileSync("git", ["clone",
|
|
50
|
+
execFileSync("git", ["clone", authedForkUrl, egregoreDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
|
|
51
|
+
try { run(`git remote set-url origin ${fork_url}`, { cwd: egregoreDir }); } catch {}
|
|
46
52
|
}
|
|
47
53
|
ui.success("Cloned egregore");
|
|
48
54
|
|
|
@@ -52,18 +58,24 @@ async function install(data, ui, targetDir) {
|
|
|
52
58
|
ui.warn(`${memoryDirName}/ already exists — pulling latest`);
|
|
53
59
|
run("git pull", { cwd: memoryDir });
|
|
54
60
|
} else {
|
|
55
|
-
execFileSync("git", ["clone",
|
|
61
|
+
execFileSync("git", ["clone", authedMemoryUrl, memoryDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
|
|
62
|
+
try { run(`git remote set-url origin ${memory_url}`, { cwd: memoryDir }); } catch {}
|
|
56
63
|
}
|
|
57
64
|
ui.success("Cloned memory");
|
|
58
65
|
|
|
59
|
-
// 3. Symlink
|
|
66
|
+
// 3. Symlink (use junction on Windows — no admin required)
|
|
60
67
|
ui.step(3, totalSteps, "Linking memory...");
|
|
61
68
|
const symlinkTarget = path.join(egregoreDir, "memory");
|
|
62
69
|
if (fs.existsSync(symlinkTarget)) {
|
|
63
70
|
ui.warn("memory/ symlink already exists");
|
|
64
71
|
} else {
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
if (process.platform === "win32") {
|
|
73
|
+
// Junctions require absolute paths on Windows
|
|
74
|
+
fs.symlinkSync(path.resolve(memoryDir), symlinkTarget, "junction");
|
|
75
|
+
} else {
|
|
76
|
+
const relPath = path.relative(egregoreDir, memoryDir);
|
|
77
|
+
fs.symlinkSync(relPath, symlinkTarget);
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
ui.success("Linked");
|
|
69
81
|
|
|
@@ -77,7 +89,7 @@ async function install(data, ui, targetDir) {
|
|
|
77
89
|
|
|
78
90
|
// 5. Register instance + shell alias
|
|
79
91
|
ui.step(5, totalSteps, "Registering instance...");
|
|
80
|
-
registerInstance(
|
|
92
|
+
registerInstance(forkDirName, org_name, egregoreDir);
|
|
81
93
|
const alias = await installShellAlias(egregoreDir, ui);
|
|
82
94
|
|
|
83
95
|
// 6+. Clone managed repos (if any)
|
|
@@ -91,7 +103,8 @@ async function install(data, ui, targetDir) {
|
|
|
91
103
|
run("git pull", { cwd: repoDir });
|
|
92
104
|
} else {
|
|
93
105
|
const repoUrl = `https://github.com/${github_org}/${repoName}.git`;
|
|
94
|
-
execFileSync("git", ["clone", repoUrl, repoDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
|
|
106
|
+
execFileSync("git", ["clone", embedToken(repoUrl, github_token), repoDir], { stdio: "pipe", encoding: "utf-8", timeout: 60000 });
|
|
107
|
+
try { run(`git remote set-url origin ${repoUrl}`, { cwd: repoDir }); } catch {}
|
|
95
108
|
}
|
|
96
109
|
clonedRepos.push(repoName);
|
|
97
110
|
ui.success(`Cloned ${repoName}`);
|
|
@@ -102,7 +115,7 @@ async function install(data, ui, targetDir) {
|
|
|
102
115
|
ui.success(`Egregore is ready for ${ui.bold(org_name)}`);
|
|
103
116
|
console.log("");
|
|
104
117
|
ui.info(`Your workspace:`);
|
|
105
|
-
ui.info(` ${ui.cyan(
|
|
118
|
+
ui.info(` ${ui.cyan(`./${forkDirName}/`)} — Your Egregore instance`);
|
|
106
119
|
ui.info(` ${ui.cyan(`./${memoryDirName}/`)} — Shared knowledge`);
|
|
107
120
|
for (const repoName of clonedRepos) {
|
|
108
121
|
ui.info(` ${ui.cyan(`./${repoName}/`)} — Managed repo`);
|
|
@@ -117,6 +130,14 @@ async function install(data, ui, targetDir) {
|
|
|
117
130
|
console.log("");
|
|
118
131
|
}
|
|
119
132
|
|
|
133
|
+
function embedToken(url, token) {
|
|
134
|
+
try {
|
|
135
|
+
return url.replace("https://github.com/", `https://x-access-token:${token}@github.com/`);
|
|
136
|
+
} catch {
|
|
137
|
+
return url;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
120
141
|
function configureGitCredentials(token) {
|
|
121
142
|
try {
|
|
122
143
|
run("git config credential.helper store");
|