Skip to content

Commit

Permalink
add jd, great for json/yaml diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Feb 4, 2022
1 parent 8befc51 commit 65e0114
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CONST.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ YP_ECCHECKER_VSN=2.4.0
# https://github.com/stedolan/jq
YP_JQ_VSN=1.6

# https://github.com/josephburnett/jd
YP_JD_VSN=1.4.0

# https://github.com/zricethezav/gitleaks
YP_GITLEAKS_VSN=8.2.4

Expand Down
7 changes: 7 additions & 0 deletions bin/.jd/jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

# can't symlink to ../jd or else YP_DIR detection in ../jd fails

YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
${YP_DIR}/bin/jd "$@"
13 changes: 13 additions & 0 deletions bin/.jd/yp-jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

# NOTE since this folder is meant to be appended to $PATH as
# PATH=${PATH}:path/to/yplatform/bin/.jd
# calling 'jd' might call the system executable 'jd'.
# This scripts assumes that there's no system executable 'yp-jd',
# so it will always call our 'bin/jd' script.

# can't symlink to ../jd or else YP_DIR detection in ../jd fails

YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
${YP_DIR}/bin/jd "$@"
44 changes: 44 additions & 0 deletions bin/jd
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail

YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source ${YP_DIR}/sh/common.inc.sh

# shellcheck disable=SC1091
VSN=$(source ${YP_DIR}/CONST.inc && echo "${YP_JD_VSN}")
JD_URL=https://github.com/josephburnett/jd/releases/download

case ${OS_SHORT}-${ARCH_NORMALIZED} in
darwin-amd64|darwin-arm64)
# local arm64; not available in a github release
BINARY=jd-${ARCH_NORMALIZED}-${OS_SHORT}
;;
linux-linux-amd64|linux-arm64)
# local arm64; not available in a github release
BINARY=jd-${ARCH_NORMALIZED}-${OS_SHORT}
;;
*)
echo_err "jd: ${OS_SHORT}-${ARCH_NORMALIZED} is an unsupported OS-ARCH."
exit 1
;;
esac
ASSET_LOCAL=${YP_DIR}/bin/jd-${VSN}/${BINARY}
ASSET_REMOTE=${JD_URL}/v${VSN}/${BINARY}
BINARY_LOCAL=${ASSET_LOCAL}

[[ -f ${BINARY_LOCAL} ]] || {
ASSET_LOCAL=${HOME}/.cache/yplatform/jd-${VSN}/${BINARY}
BINARY_LOCAL=${ASSET_LOCAL}
}

[[ -f ${BINARY_LOCAL} ]] || {
echo_info "Fetching ${ASSET_REMOTE}..."
mkdir -p $(dirname ${ASSET_LOCAL})
curl -qfsSL \
-o ${ASSET_LOCAL} \
${ASSET_REMOTE}
chmod +x ${BINARY_LOCAL}
}

echo_info "Proxying to 'jd' as ${BINARY_LOCAL}."
${BINARY_LOCAL} "$@"
Binary file added bin/jd-1.4.0/jd-arm64-darwin
Binary file not shown.
4 changes: 4 additions & 0 deletions bin/yp-env
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ fi
# NOTE if needed to bypass system's jq, call yp-jq
yp::path_append ${YP_DIR}/bin/.jq

# jd becomes always available
# NOTE if needed to bypass system's jd, call yp-jd
yp::path_append ${YP_DIR}/bin/.jd

# yq becomes always available
# NOTE if needed to bypass system's yq, call yp-yq
yp::path_append ${YP_DIR}/bin/.yq
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/brew-install-ci.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ brew_install_one_unless jq "jq --version | head -1" "^jq-1\."
[[ -f "${YP_DIR}/bin/.jq/jq" ]]
if_exe_and_grep_q "which jq" "^${YP_DIR}/bin/\.jq/jq$" brew_install_one jq

brew_install_one_unless jd "jd --version | head -1" "^jd version 1\."
# install if we're falling back to our jd proxy
[[ -f "${YP_DIR}/bin/.jd/jd" ]]
if_exe_and_grep_q "which jd" "^${YP_DIR}/bin/\.jd/jd$" brew_install_one jd

brew_install_one_unless yq "yq --version | head -1" " version 4\."
# install if we're falling back to our yq proxy
[[ -f "${YP_DIR}/bin/.yq/yq" ]]
Expand Down
6 changes: 6 additions & 0 deletions bootstrap/brew-install-core.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo_do "brew: Installing core packages..."
${YP_DIR}/bin/editorconfig-checker -version >/dev/null
${YP_DIR}/bin/gitleaks -h >/dev/null
${YP_DIR}/bin/jq -h >/dev/null
${YP_DIR}/bin/jd -h >/dev/null
${YP_DIR}/bin/yq -h >/dev/null

brew_install_one_unless curl "curl --version | head -1" "^curl 7\."
Expand All @@ -17,6 +18,11 @@ brew_install_one_unless jq "jq --version | head -1" "^jq-1\."
[[ -f "${YP_DIR}/bin/.jq/jq" ]]
if_exe_and_grep_q "which jq" "^${YP_DIR}/bin/\.jq/jq$" brew_install_one jq

brew_install_one_unless jd "jd --version | head -1" "^jd version 1\."
# install if we're falling back to our jd proxy
[[ -f "${YP_DIR}/bin/.jd/jd" ]]
if_exe_and_grep_q "which jd" "^${YP_DIR}/bin/\.jd/jd$" brew_install_one jd

brew_install_one_unless yq "yq --version | head -1" " version 4\."
# install if we're falling back to our yq proxy
[[ -f "${YP_DIR}/bin/.yq/yq" ]]
Expand Down
3 changes: 2 additions & 1 deletion mk/exe.misc.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ $(foreach VAR,CP_NOSYM EDITOR FIND_Q FIND_Q_NOSYM GREP_FILENAME LS_ALL,$(call ma
$(foreach VAR,DIFF_SS,$(call make-lazy-once,$(VAR)))

CURL = $(call which,CURL,curl) -qfsSL
JD = $(call which,JD,jd)
JQ = $(call which,JQ,jq)
$(foreach VAR,CURL JQ,$(call make-lazy,$(VAR)))
$(foreach VAR,CURL JD JQ,$(call make-lazy,$(VAR)))

GIT = $(call which,GIT,git)
GIT_LS = $(GIT) ls-files
Expand Down

0 comments on commit 65e0114

Please sign in to comment.