diff --git a/src/lib/conf.ts b/src/lib/conf.ts index 82821a9..e6996bb 100644 --- a/src/lib/conf.ts +++ b/src/lib/conf.ts @@ -29,7 +29,7 @@ export async function config_default() { "$schema": "https://git.barnulf.net/mb/feseur/raw/branch/master/asset/config_schema.json", file_path: join(await home_path(), "todo"), repo_path: join(await home_path(), ".local", "share", "feseur"), - remote_url: "ssh://forgejo@barnulf.net/mb/todo.git", + remote_url: "ssh://git.barnulf.net/mb/todo.git", } as ConfigType } diff --git a/src/lib/debounce.ts b/src/lib/debounce.ts deleted file mode 100644 index 4b9d0f0..0000000 --- a/src/lib/debounce.ts +++ /dev/null @@ -1,14 +0,0 @@ -export class Debouncer { - last = 0 - - public constructor( - public timeout: number, - ) {} - - public should_skip() { - const now = Date.now() - const delay = now - this.last - this.last = now - return (delay < this.timeout) - } -} diff --git a/src/lib/repo.ts b/src/lib/repo.ts deleted file mode 100644 index b19b44d..0000000 --- a/src/lib/repo.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { exists } from "https://deno.land/std@0.224.0/fs/mod.ts" -import { join } from "https://deno.land/std@0.224.0/path/mod.ts" -import { crayon } from "https://deno.land/x/crayon@3.3.3/mod.ts" - -export async function fetch_repo(repo_path: string, remote_url: string) { - if (!await exists(join(repo_path, ".git"))) await create_repo(repo_path, remote_url) - const status = await run("git", "-C", repo_path, "pull") - if (!status.success) warn("Failed to fetch : " + new TextDecoder().decode(status.stderr)) - await run("git", "-C", repo_path, "push") -} - -async function create_repo(repo_path: string, remote_url: string) { - await Deno.mkdir(repo_path, { recursive: true }) - const status = await run("git", "clone", remote_url, repo_path) - if (!status.success) warn("Failed to clone : " + new TextDecoder().decode(status.stderr)) -} - -async function run(cmd: string, ...args: string[]) { - return await new Deno.Command(cmd, { args, stderr: "piped", stdout: "piped" }).output() -} - -export async function link_todo(repo_path: string, todo_path: string) { - const status = await run("ln", "-sf", join(repo_path, "todo"), todo_path) - if (!status.success) warn("Failed to link : " + new TextDecoder().decode(status.stderr)) -} - -function warn(text: string) { - console.warn(crayon.yellow(text)) -} - -function decode(beuffeur: Uint8Array) { - return new TextDecoder().decode(beuffeur) -} - -export async function push_repo(repo_path: string) { - console.log(repo_path) - const status = await run("git", "-C", repo_path, "status", "--short") - if (!status.success) { - console.error("Failed to stat : " + decode(status.stderr)) - return - } - if (decode(status.stdout) === "") return - await run("git", "-C", repo_path, "add", "-A") - await run("git", "-C", repo_path, "commit", "-m", "update " + await hostname()) - await run("git", "-C", repo_path, "push") -} - -async function hostname() { - return (await Deno.readTextFile("/etc/hostname")).trim() -} diff --git a/src/service.ts b/src/service.ts index 7796d50..92a31ab 100755 --- a/src/service.ts +++ b/src/service.ts @@ -1,22 +1,6 @@ -#!/usr/bin/env -S deno run --allow-all - -import { join } from "https://deno.land/std@0.224.0/path/mod.ts" -import { read_conf } from "./lib/conf.ts" -import { Debouncer } from "./lib/debounce.ts" -import { fetch_repo, push_repo } from "./lib/repo.ts" -import { log } from "./lib/utils.ts" +#!/usr/bin/env -S deno run await main() async function main() { - const config = await read_conf() - await fetch_repo(config.repo_path, config.remote_url) - const debouncer = new Debouncer(200) - const repo_file = join(config.repo_path, "todo") - log("Watching file", repo_file) - for await (const _ of Deno.watchFs(repo_file)) { - if (debouncer.should_skip()) continue - log("Commiting event " + Date.now()) - await fetch_repo(config.repo_path, config.remote_url) - await push_repo(config.repo_path) - } + // } diff --git a/src/todo.ts b/src/todo.ts index 5e2ff60..2cb7ac3 100755 --- a/src/todo.ts +++ b/src/todo.ts @@ -2,14 +2,11 @@ import { read_conf } from "./lib/conf.ts" import { print_todo } from "./lib/display.ts" -import { fetch_repo, link_todo } from "./lib/repo.ts" import { read_todo } from "./lib/task.ts" await main() async function main() { const config = await read_conf() - await fetch_repo(config.repo_path, config.remote_url) - await link_todo(config.repo_path, config.file_path) const todo = await read_todo(config.file_path) print_todo(todo) }