# Copyright 2022 Weavers @ Eternal Loom. All rights reserved.
# Use of this software is governed by the license that can be
# found in LICENSE file in the source repository.

#!/usr/bin/env just --justfile

# Build, serve and publish markdown books. 
# This file is run from the book root directory (one created using mdbook init).
# This is upated during book setup
publish_dir := "/Users/al/projects/spaces/compos-ws/books/metal-book"

# Default build directory
build_dir := justfile_directory() / "build"

# Setup default recepe
default: serve

# Start the mdbook server
# - Builds the book
# - Starts the server and opens default browser
serve:
    mdbook serve --open

# Build the book
build:
    mdbook build

# Publish the book
# - Builds the book
# - Removes content in current publish Directory
# - Copies the build content to the publish directory
# - Commits and pushes the changes from the publish directory
# NOTE: May need some code to purge history when we start
publish: build
    #!/usr/bin/env bash
    echo "Initiating publish..."
    echo "Removing existing content in {{publish_dir}}..."
    rm -rf {{publish_dir}}/*
    echo "Copying updated book contents to {{publish_dir}}..."
    cp -rpf {{build_dir}}/* {{publish_dir}}
    echo "Committing changes..."
    cd {{publish_dir}}
    git add -A
    git commit -m "deployed on by ${USER}"
    git push origin main
    echo "Publish completed."


