1
0
silverbullet/packages/plugs/git/git.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-04-25 08:33:38 +00:00
import { run } from "@plugos/plugos-syscall/shell";
import {
flashNotification,
prompt,
2022-04-25 09:24:13 +00:00
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import { invokeFunction } from "@silverbulletmd/plugos-silverbullet-syscall/system";
2022-03-25 11:03:06 +00:00
export async function commit(message?: string) {
if (!message) {
message = "Snapshot";
}
console.log(
"Snapshotting the current space to git with commit message",
message
);
2022-04-01 15:07:08 +00:00
await run("git", ["add", "./*.md"]);
2022-03-25 11:03:06 +00:00
try {
2022-04-01 15:07:08 +00:00
await run("git", ["commit", "-a", "-m", message]);
2022-03-25 11:03:06 +00:00
} catch (e) {
// We can ignore, this happens when there's no changes to commit
}
console.log("Done!");
}
export async function snapshotCommand() {
2022-04-01 15:07:08 +00:00
let revName = await prompt(`Revision name:`);
2022-03-25 11:03:06 +00:00
if (!revName) {
revName = "Snapshot";
}
console.log("Revision name", revName);
2022-04-05 15:02:17 +00:00
await invokeFunction("server", "commit", revName);
2022-03-25 11:03:06 +00:00
}
export async function syncCommand() {
2022-04-01 15:07:08 +00:00
await flashNotification("Syncing with git");
2022-04-05 15:02:17 +00:00
await invokeFunction("server", "sync");
2022-04-01 15:07:08 +00:00
await flashNotification("Git sync complete!");
2022-03-25 11:03:06 +00:00
}
export async function sync() {
console.log("Going to sync with git");
await commit();
console.log("Then pulling from remote");
2022-04-01 15:07:08 +00:00
await run("git", ["pull"]);
2022-03-25 11:03:06 +00:00
console.log("And then pushing to remote");
2022-04-01 15:07:08 +00:00
await run("git", ["push"]);
2022-03-25 11:03:06 +00:00
console.log("Done!");
}