2022-04-01 15:07:08 +00:00
|
|
|
import { run } from "plugos-syscall/shell";
|
|
|
|
import { flashNotification, prompt } from "plugos-silverbullet-syscall/editor";
|
|
|
|
import { invokeFunctionOnServer } from "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-01 15:07:08 +00:00
|
|
|
await invokeFunctionOnServer("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");
|
|
|
|
await invokeFunctionOnServer("sync");
|
|
|
|
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!");
|
|
|
|
}
|