@sidekick-coder/zenith-kit 0.0.5 → 0.0.6
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/dist/server/index.d.mts +9 -2
- package/dist/server/index.mjs +47 -11
- package/package.json +1 -1
package/dist/server/index.d.mts
CHANGED
|
@@ -11,14 +11,21 @@ interface GitRepoInfo {
|
|
|
11
11
|
interface GitGatewayOptions {
|
|
12
12
|
cwd: string;
|
|
13
13
|
sshKey?: string;
|
|
14
|
+
sshKeyFile?: string;
|
|
15
|
+
sshKeyTmpFileName?: string;
|
|
14
16
|
}
|
|
15
17
|
declare class GitGateway {
|
|
16
18
|
private readonly cwd;
|
|
17
|
-
private readonly
|
|
19
|
+
private readonly sshKey?;
|
|
20
|
+
private readonly sshKeyFile?;
|
|
21
|
+
private readonly sshKeyTmpFileName?;
|
|
18
22
|
constructor({
|
|
19
23
|
cwd,
|
|
20
|
-
sshKey
|
|
24
|
+
sshKey,
|
|
25
|
+
sshKeyFile,
|
|
26
|
+
sshKeyTmpFileName
|
|
21
27
|
}: GitGatewayOptions);
|
|
28
|
+
private buildEnv;
|
|
22
29
|
run(args: string): Promise<string>;
|
|
23
30
|
tryRun(args: string): Promise<string | null>;
|
|
24
31
|
checkout(ref: string): Promise<void>;
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { exec } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
+
import { unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
3
7
|
//#region src/server/services/GitBranchRepository.ts
|
|
4
8
|
var GitBranchRepository = class {
|
|
5
9
|
constructor(gateway) {
|
|
@@ -280,20 +284,52 @@ function escapeShellArgument(value) {
|
|
|
280
284
|
}
|
|
281
285
|
var GitGateway = class {
|
|
282
286
|
cwd;
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
sshKey;
|
|
288
|
+
sshKeyFile;
|
|
289
|
+
sshKeyTmpFileName;
|
|
290
|
+
constructor({ cwd, sshKey, sshKeyFile, sshKeyTmpFileName }) {
|
|
285
291
|
this.cwd = cwd;
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
292
|
+
this.sshKey = sshKey;
|
|
293
|
+
this.sshKeyFile = sshKeyFile;
|
|
294
|
+
this.sshKeyTmpFileName = sshKeyTmpFileName;
|
|
295
|
+
}
|
|
296
|
+
async buildEnv() {
|
|
297
|
+
if (this.sshKeyFile) return {
|
|
298
|
+
env: {
|
|
299
|
+
...process.env,
|
|
300
|
+
GIT_SSH_COMMAND: `ssh -i ${escapeShellArgument(this.sshKeyFile)} -o StrictHostKeyChecking=no`
|
|
301
|
+
},
|
|
302
|
+
cleanup: async () => {}
|
|
303
|
+
};
|
|
304
|
+
if (this.sshKey) {
|
|
305
|
+
const tempFile = this.sshKeyTmpFileName ?? join(tmpdir(), `git-ssh-key-${randomUUID()}`);
|
|
306
|
+
await writeFile(tempFile, this.sshKey, { mode: 384 });
|
|
307
|
+
return {
|
|
308
|
+
env: {
|
|
309
|
+
...process.env,
|
|
310
|
+
GIT_SSH_COMMAND: `ssh -i ${escapeShellArgument(tempFile)} -o StrictHostKeyChecking=no`
|
|
311
|
+
},
|
|
312
|
+
cleanup: async () => {
|
|
313
|
+
await unlink(tempFile).catch(() => {});
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
env: process.env,
|
|
319
|
+
cleanup: async () => {}
|
|
320
|
+
};
|
|
290
321
|
}
|
|
291
322
|
async run(args) {
|
|
292
|
-
const {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
323
|
+
const { env, cleanup } = await this.buildEnv();
|
|
324
|
+
try {
|
|
325
|
+
const { stdout } = await execAsync(`git ${args}`, {
|
|
326
|
+
cwd: this.cwd,
|
|
327
|
+
env
|
|
328
|
+
});
|
|
329
|
+
return stdout.trim();
|
|
330
|
+
} finally {
|
|
331
|
+
await cleanup();
|
|
332
|
+
}
|
|
297
333
|
}
|
|
298
334
|
async tryRun(args) {
|
|
299
335
|
try {
|