MCPcopy Create free account
hub / github.com/IAmUnbounded/devctx / shareCommand

Function shareCommand

devctx/src/commands/share.ts:9–65  ·  view source on GitHub ↗
(options?: { stop?: boolean })

Source from the content-addressed store, hash-verified

7const git = simpleGit();
8
9export async function shareCommand(options?: { stop?: boolean }) {
10 try {
11 const root = await getRepoRoot();
12 const gitignorePath = path.join(root, ".gitignore");
13 const devctxDir = path.join(root, ".devctx");
14
15 if (!fs.existsSync(devctxDir)) {
16 console.log(chalk.red("✗ DevContext not initialized. Run `devctx init` first."));
17 return;
18 }
19
20 if (options?.stop) {
21 // Add .devctx/ back to .gitignore
22 const gitignoreContent = fs.existsSync(gitignorePath)
23 ? fs.readFileSync(gitignorePath, "utf-8")
24 : "";
25
26 if (!gitignoreContent.includes(".devctx/")) {
27 fs.appendFileSync(gitignorePath, "\n.devctx/\n");
28 }
29
30 console.log(chalk.green("✓ Stopped sharing DevContext"));
31 console.log(chalk.gray(" .devctx/ added back to .gitignore"));
32 console.log(
33 chalk.gray(" Note: Existing .devctx/ files remain in git history.")
34 );
35 return;
36 }
37
38 // Remove .devctx/ from .gitignore
39 if (fs.existsSync(gitignorePath)) {
40 let content = fs.readFileSync(gitignorePath, "utf-8");
41 content = content
42 .split("\n")
43 .filter(
44 (line) =>
45 line.trim() !== ".devctx/" &&
46 line.trim() !== ".devctx" &&
47 line.trim() !== "# DevContext - AI coding context"
48 )
49 .join("\n");
50 fs.writeFileSync(gitignorePath, content);
51 }
52
53 // Stage .devctx/ and commit
54 await git.add([".devctx/", ".gitignore"]);
55 await git.commit("chore: share DevContext with team");
56
57 console.log(chalk.green("✓ DevContext is now shared with your team!"));
58 console.log(chalk.gray(" .devctx/ removed from .gitignore"));
59 console.log(chalk.gray(" Committed: \"chore: share DevContext with team\""));
60 console.log(chalk.gray("\n Push to share: git push"));
61 console.log(chalk.gray(" Stop sharing: devctx share --stop"));
62 } catch (err: any) {
63 console.log(chalk.red(`✗ Error: ${err.message}`));
64 }
65}

Callers

nothing calls this directly

Calls 1

getRepoRootFunction · 0.90

Tested by

no test coverage detected