Skip to content

Commit

Permalink
refactor(): support 'bpkg.json'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Mar 18, 2022
1 parent 0f28252 commit afd194b
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 248 deletions.
4 changes: 4 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Allow unsued variables
disable=SC2034
## Allow declare and assign separately to avoid masking return values
disable=SC2155
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Here we lay down some info on the structure of a package.
## bpkg.json
Every package must have a file called `bpkg.json` (for backward-compatibility
Every package must have a file called `bpkg.json` (for backward-compatibility
`package.json` can also be used); it specifies package metadata on the [JSON format][json].
Here's an example of a well-formed `bpkg.json`:
Expand Down
File renamed without changes.
18 changes: 7 additions & 11 deletions lib/getdeps/getdeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ usage () {

## Read a package property
bpkg_getdeps () {
local cwd pkg

cwd="$(pwd)"
pkg="${cwd}/bpkg.json"

if ! test -f "${pkg}"; then
pkg="${cwd}/package.json"
fi

local cwd="$(pwd)"
local pkg="${cwd}/bpkg.json"

## parse flags
case "$1" in
Expand All @@ -29,8 +22,11 @@ bpkg_getdeps () {

## ensure there is a package to read
if ! test -f "${pkg}"; then
echo 2>&1 "error: Unable to find 'bpkg.json' or 'package.json' in $(pwd)"
return 1
pkg="${cwd}/package.json"
if ! test -f "${pkg}"; then
echo 2>&1 "error: Unable to find \`bpkg.json' or \`package.json' in $cwd"
return 1
fi
fi

# shellcheck disable=SC2002
Expand Down
15 changes: 6 additions & 9 deletions lib/init/init.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

## sets optional variable from environment
opt () { eval "if [ -z \"\${$1}\" ]; then ${1}='${2}'; fi"; }
opt () { eval "if [ -z "\${"$1"}" ]; then $1='$2'; fi"; }

## output usage
usage () {
Expand All @@ -22,8 +22,8 @@ prompt () {

value="${value//\"/\'}";
} 2>&1
if [ -n "${value}" ]; then
eval "${var}=\"${value}\""
if [ -n "$value" ]; then
eval "$var=\"$value\""
fi
}

Expand Down Expand Up @@ -84,7 +84,7 @@ intro () {
echo "defaults."
echo
echo "See github.com/bpkg/bpkg for more information on defining the bpkg"
echo "\`bpkg.json' file."
echo "'bpkg.json' file."
echo
echo "You can press ^C anytime to quit this prompt. The 'bpkg.json' file"
echo "will only be written upon completion."
Expand Down Expand Up @@ -138,9 +138,8 @@ csv () {
SCRIPTS="${SCRIPTS//,/ }"
SCRIPTS="${SCRIPTS//\"/}"
SCRIPTS="${SCRIPTS//\'/}"
# shellcheck disable=SC2086
SCRIPTS=($(wrap ${SCRIPTS}))
(( len=${#SCRIPTS[@]} ))
SCRIPTS=($(wrap "${SCRIPTS}"))
let len=${#SCRIPTS[@]}
for (( i = 0; i < len; i++ )); do
word=${SCRIPTS[$i]}
if (( i + 1 != len )); then
Expand Down Expand Up @@ -275,7 +274,6 @@ create_repo () {
fi
}


## main
bpkg_init () {
local cwd
Expand Down Expand Up @@ -341,4 +339,3 @@ else
bpkg_init "${@}"
exit $?
fi

Loading

0 comments on commit afd194b

Please sign in to comment.