Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@gitnestr/electron-gitnestr-bridge) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@gitnestr/electron-gitnestr-bridge
A Node.js package for Electron's main process to interact with the gitnestr CLI application.
Installation
npm install @gitnestr/electron-gitnestr-bridge
Requirements
- Node.js 14+
- Electron 22+
- gitnestr CLI installed and available in PATH (or specify the path in options)
Usage
Basic Usage
import { GitnestrBridge } from "@gitnestr/electron-gitnestr-bridge";
// Create a new GitnestrBridge instance
const gitnestr = new GitnestrBridge({
gitnestrPath: "/path/to/gitnestr", // Optional: defaults to 'gitnestr' in PATH
timeout: 30000, // Optional: timeout in milliseconds, defaults to 60000
env: {
/* Custom environment variables */
}, // Optional
});
// Initialize a new repository
await gitnestr.init("/path/to/repo");
// Clone a repository
await gitnestr.clone(
"gitnestr://example.com/repo",
"/path/to/destination",
"keyAlias"
);
// Pull changes
await gitnestr.pull("/path/to/repo", "branch");
// Push changes
await gitnestr.push("/path/to/repo", "privateKey");
// Fetch changes without merging
await gitnestr.fetch("/path/to/repo", "branch", "privateKey");
// Retrieve archive DAG for a repository
const paths = await gitnestr.archive(
"gitnestr://example.com/repo",
"branch",
"privateKey",
"keyAlias"
);
// Generate keys
const { privateKey, publicKey } = await gitnestr.generateKeys();
// Store a key
await gitnestr.storeKey("alias", privateKey, "passphrase");
// Unlock a key
const key = await gitnestr.unlockKey("alias", "passphrase");
Event Handling
// Listen for events
gitnestr.addListener("event", (event) => {
if (event.type === "progress") {
console.log(`Progress: ${event.message}`);
} else if (event.type === "error") {
console.error(`Error: ${event.message}`);
} else if (event.type === "success") {
console.log(`Success: ${event.message}`);
}
});
// Remove event listener
gitnestr.removeListener("event", listener);
// Cancel all active processes
gitnestr.cancelAll();
Error Handling
import {
GitnestrError,
GitnestrErrorCode,
} from "@gitnestr/electron-gitnestr-bridge";
try {
await gitnestr.pull("/path/to/repo");
} catch (error) {
if (error instanceof GitnestrError) {
console.error(`Error code: ${error.code}`);
console.error(`Error message: ${error.message}`);
console.error(`Error details: ${JSON.stringify(error.details)}`);
if (error.code === GitnestrErrorCode.TIMEOUT) {
// Handle timeout error
} else if (error.code === GitnestrErrorCode.COMMAND_FAILED) {
// Handle command failure
}
} else {
// Handle other errors
console.error(error);
}
}
API Reference
GitnestrBridge
The main class for interacting with the gitnestr CLI.
Constructor
new GitnestrBridge(options?: GitnestrBridgeOptions)
Methods
executeCommand(command: string, args?: string[], options?: GitnestrCommandOptions): Promise<GitnestrCommandResult>
- Execute a gitnestr commandinit(repoPath: string): Promise<GitnestrRepository>
- Initialize a new repositoryclone(url: string, destPath: string, keyAlias?: string): Promise<GitnestrRepository>
- Clone a repositorypull(repoPath: string, branch?: string): Promise<GitnestrCommandResult>
- Pull changespush(repoPath: string, privateKey?: string): Promise<GitnestrCommandResult>
- Push changesfetch(repoPath: string, branch?: string, privateKey?: string): Promise<GitnestrCommandResult>
- Fetch changes without mergingarchive(url: string, branch: string, privateKey: string, keyAlias?: string): Promise<string[]>
- Retrieve archive DAG for a repositorygenerateKeys(): Promise<{ privateKey: string; publicKey: string }>
- Generate a new key pairstoreKey(alias: string, privateKey: string, passphrase: string): Promise<void>
- Store a keyunlockKey(alias: string, passphrase: string): Promise<string>
- Unlock a keyaddListener(event: 'event', listener: GitnestrEventListener): this
- Add an event listenerremoveListener(event: 'event', listener: GitnestrEventListener): this
- Remove an event listenercancelAll(): void
- Cancel all active processes