hennzau

21 commits
Updated 2026-04-25 12:39:37
.
./config.nu
def jit [...args] {
    if ($args | length) > 0 and ($args.0 == "init") {
        let repo_name = match ($args | length) {
            2 => $args.1,
            _ => '.'
        }

        git init --bare $repo_name out> /dev/null err> /dev/null
        cd $repo_name
        jj git init --git-repo . --no-colocate out> /dev/null err> /dev/null
        jj --ignore-working-copy abandon
        jj --ignore-working-copy workspace forget out> /dev/null err> /dev/null
        install_hook (pwd)
        cd ..
        print $"Initialized repo in "($repo_name)""
    } else {
        jj ...$args
    }
}

def get_hook_content [repo_name: string] {
    $"jj --ignore-working-copy git import
git --work-tree=/var/www/hennzau --git-dir=/home/jj/($repo_name) checkout -f trunk

hnz gen-front /home/jj/($repo_name) /var/www/hennzau/frontend/content/jj
hnz gen-back /home/jj/($repo_name) /var/www/hennzau/frontend/static/jj

cd /var/www/hennzau/frontend
zola build
"
}

def install_hook [repo_path: string] {
    let repo_name = ($repo_path | path basename)
    let hook_path = ($repo_path | path join "hooks" "post-receive")

    get_hook_content $repo_name | save -f $hook_path
    chmod +x $hook_path
}

def update_hooks [] {
    ls /home/jj
    | where type == dir
    | each { |it|
        let repo = $it.name
        let hooks = ($repo | path join "hooks")

        if ($hooks | path exists) {
            print $"Updating hook in ($repo)"
            install_hook $repo
        }
    }
}

def reset_remotes [] {
    ls /home/jj
    | where type == dir
    | each { |it|
        let dir = $it.name
        print $"Reset ($dir)"

        rm -r $dir
        jit init $dir
    }
}

def repush_locals [] {
    ls /home/jj
    | where type == dir
    | each { |it|
        let dir = $it.name

        cd $dir
        jj git remote remove origin
        jj git remote add origin jj@hennzau.fr:($dir)
        jj git push --allow-new
        cd ..
    }
}

def rebuild_all [] {
    ls /home/jj
    | where type == dir
    | each { |it|
        hnz sync /home/jj /var/www/hennzau/frontend/content/jj /var/www/hennzau/frontend/static/jj;
        hnz gen-front $it.name /var/www/hennzau/frontend/content/jj;
        hnz gen-back $it.name /var/www/hennzau/frontend/static/jj;
    }

    cd /var/www/hennzau/frontend
    zola build
    cd /home/jj
}