Skip to content

Instantly share code, notes, and snippets.

@ikskuh
Last active February 19, 2022 10:06
Show Gist options
  • Select an option

  • Save ikskuh/8c71e794a654b41f07510af96992dba7 to your computer and use it in GitHub Desktop.

Select an option

Save ikskuh/8c71e794a654b41f07510af96992dba7 to your computer and use it in GitHub Desktop.

Revisions

  1. ikskuh revised this gist Feb 19, 2022. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions zpm
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ PACKAGE_LIBRARY="/home/felix/software/zig-packages.json"

    set -e

    if ! which jq git git-patch-configs > /dev/null ; then
    if ! which jq git > /dev/null ; then
    echo "Not all required tools are installed!" >&2
    exit 1
    fi
    @@ -59,4 +59,3 @@ cd "${ROOT}/vendor"
    git submodule add "${PACKAGE_REPO}" "${PACKAGE}"
    git submodule update --init --recursive
    cd "${ROOT}"
    git-patch-configs
  2. ikskuh created this gist Feb 19, 2022.
    14 changes: 14 additions & 0 deletions zig-packages.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    {
    "ihex": {
    "git": "https://github.com/MasterQ32/zig-ihex"
    },
    "args": {
    "git": "https://github.com/MasterQ32/zig-args"
    },
    "parser-toolkit": {
    "git": "https://github.com/MasterQ32/parser-toolkit"
    },
    "serial": {
    "git": "https://github.com/MasterQ32/zig-serial"
    }
    }
    62 changes: 62 additions & 0 deletions zpm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    #!/bin/bash

    ### CONFIG ###

    PACKAGE_LIBRARY="/home/felix/software/zig-packages.json"

    ### CODE STARTS HERE ###

    set -e

    if ! which jq git git-patch-configs > /dev/null ; then
    echo "Not all required tools are installed!" >&2
    exit 1
    fi


    PACKAGE="$1"
    if [ -z "${PACKAGE}" ]; then
    echo "missing package name!" >&2
    exit 1
    fi

    if [ "$(jq "has(\"${PACKAGE}\")" "${PACKAGE_LIBRARY}")" != "true" ]; then
    echo "package ${PACKAGE} does not exist!" >&2
    echo "add ${PACKAGE} to ${PACKAGE_LIBRARY} in order to install it." >&2
    exit 1
    fi

    ROOT="$(git rev-parse --show-superproject-working-tree)"

    if [ -z "${ROOT}" ]; then
    ROOT="$(git rev-parse --show-toplevel)"
    fi

    if [ ! -d "${ROOT}/.git" ]; then
    echo "not in a git repository!" >&2
    exit 1
    fi

    # if [ ! -f "${ROOT}/.gitmodules" ]; then
    # echo "submodules not initialized!" >&2
    # exit 1
    # fi

    if [ ! -d "${ROOT}/vendor" ]; then
    echo "no vendor subfolder!" >&2
    exit 1
    fi

    if [ -d "${ROOT}/vendor/${PACKAGE}" ]; then
    echo "package ${PACKAGE} is already installed!" >&2
    exit 1
    fi


    PACKAGE_REPO="$(jq --raw-output ".\"${PACKAGE}\".git" "${PACKAGE_LIBRARY}")"

    cd "${ROOT}/vendor"
    git submodule add "${PACKAGE_REPO}" "${PACKAGE}"
    git submodule update --init --recursive
    cd "${ROOT}"
    git-patch-configs