version: '3'

vars:
    DATE: '{{now | date "2006-01-02 15:04:05"}}'
    CURRENT_VERSION: '2.1.5'
    NEW_VERSION: '{{.CLI_ARGS | default ""}}'

tasks:
    default:
        desc: Show available tasks
        cmds:
            - task -l
        silent: true

    bump:
        desc: Bump version in all necessary files
        cmds:
            - |
                if [ -f "bin/bump" ]; then
                    chmod +x bin/bump
                    ./bin/bump {{.NEW_VERSION}}
                else
                    echo " ❌ Bump script not found in bin/bump"
                    exit 1
                fi
        silent: true

    split:
        desc: Split repositories
        cmds:
            - |
                if [ -f "bin/split" ]; then
                    chmod +x bin/split
                    ./bin/split
                else
                    echo " ❌ Split script not found in bin/split"
                    exit 1
                fi
        silent: true

    npm:publish:
        desc: Publish NPM packages
        cmds:
            - |
                if [ -f "bin/npm" ]; then
                    chmod +x bin/npm
                    ./bin/npm {{.NEW_VERSION}}
                else
                    echo " ❌ NPM script not found in bin/npm"
                    exit 1
                fi
        silent: true

    git:tag:
        desc: Create and push git tags
        cmds:
            - |
                if [ -f "bin/git-tag" ]; then
                    chmod +x bin/git-tag
                    ./bin/git-tag {{.NEW_VERSION}}
                else
                    echo " ❌ Git-tag script not found in bin/git-tag"
                    exit 1
                fi
        silent: true

    status:
        desc: Show repository status
        cmds:
            - |
                if [ -f "bin/status" ]; then
                    chmod +x bin/status
                    ./bin/status
                else
                    echo " ❌ Status script not found in bin/status"
                    exit 1
                fi
        silent: true

    lint:
        desc: Analyze code quality and standards
        cmds:
            - |
                if [ -f "bin/lint" ]; then
                    chmod +x bin/lint
                    ./bin/lint
                else
                    echo " ❌ Lint script not found in bin/lint"
                    exit 1
                fi
        silent: true

    update:
        desc: Update project dependencies and rebuild assets
        cmds:
            - |
                if [ -f "bin/update" ]; then
                    chmod +x bin/update
                    ./bin/update
                else
                    echo " ❌ Update script not found in bin/update"
                    exit 1
                fi
        silent: true

    docs:build:
        desc: Build documentation
        cmds:
            - |
                if [ -f "bin/docs" ]; then
                    chmod +x bin/docs
                    ./bin/docs build
                else
                    echo " ❌ Docs script not found in bin/docs"
                    exit 1
                fi
        silent: true

    release:
        desc: Create and publish a new release
        cmds:
            -   task: validate
            -   task: bump
            -   task: lint
            -   task: split
            -   task: npm:publish
            -   task: git:tag
        silent: true
