Refactoring

This commit is contained in:
Zef Hemel
2022-03-25 12:03:06 +01:00
parent b51730d33f
commit 08e6c3bad8
52 changed files with 796 additions and 326 deletions
+37
View File
@@ -0,0 +1,37 @@
{
"requiredPermissions": ["shell"],
"hooks": {
"commands": {
"Git: Snapshot": {
"invoke": "snapshotCommand"
},
"Git: Sync": {
"invoke": "syncCommand"
}
},
"crons": [
{
"cron": "*/15 * * * *",
"handler": "commit"
}
]
},
"functions": {
"snapshotCommand": {
"path": "./git.ts:snapshotCommand",
"env": "client"
},
"syncCommand": {
"path": "./git.ts:syncCommand",
"env": "client"
},
"commit": {
"path": "./git.ts:commit",
"env": "server"
},
"sync": {
"path": "./git.ts:sync",
"env": "server"
}
}
}
+42
View File
@@ -0,0 +1,42 @@
import { syscall } from "../lib/syscall";
export async function commit(message?: string) {
if (!message) {
message = "Snapshot";
}
console.log(
"Snapshotting the current space to git with commit message",
message
);
await syscall("shell.run", "git", ["add", "./*.md"]);
try {
await syscall("shell.run", "git", ["commit", "-a", "-m", message]);
} catch (e) {
// We can ignore, this happens when there's no changes to commit
}
console.log("Done!");
}
export async function snapshotCommand() {
let revName = await syscall("editor.prompt", `Revision name:`);
if (!revName) {
revName = "Snapshot";
}
console.log("Revision name", revName);
await syscall("system.invokeFunctionOnServer", "commit", revName);
}
export async function syncCommand() {
await syscall("system.invokeFunctionOnServer", "sync");
}
export async function sync() {
console.log("Going to sync with git");
console.log("First locally committing everything");
await commit();
console.log("Then pulling from remote");
await syscall("shell.run", "git", ["pull"]);
console.log("And then pushing to remote");
await syscall("shell.run", "git", ["push"]);
console.log("Done!");
}