-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.ts
More file actions
56 lines (46 loc) · 1.17 KB
/
Copy pathpush.ts
File metadata and controls
56 lines (46 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { resolveVaultRoot, VaultNotFoundError } from "@kibhq/core";
import { debug } from "../ui/debug.js";
import * as log from "../ui/logger.js";
import { createSpinner } from "../ui/spinner.js";
interface PushOpts {
message?: string;
json?: boolean;
}
export async function push(opts: PushOpts) {
let root: string;
try {
root = resolveVaultRoot();
} catch (err) {
if (err instanceof VaultNotFoundError) {
log.error(err.message);
process.exit(1);
}
throw err;
}
debug(`vault root: ${root}`);
const spinner = opts.json ? null : createSpinner("Pushing to remote...");
spinner?.start();
try {
const { pushVault } = await import("@kibhq/core");
const result = await pushVault(root, opts.message);
spinner?.stop();
if (opts.json) {
console.log(JSON.stringify(result, null, 2));
return;
}
log.header("push");
if (!result.pushed) {
log.dim("Nothing to push — vault is clean.");
log.blank();
return;
}
log.success(
`Pushed ${result.filesChanged} file${result.filesChanged === 1 ? "" : "s"} (${result.commit})`,
);
log.blank();
} catch (err) {
spinner?.stop();
log.error((err as Error).message);
process.exit(1);
}
}