Skip to content

Commit

Permalink
refactor(): support custom 'deps/' dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Mar 18, 2022
1 parent afd194b commit 093f376
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _JavaScript has npm, Ruby has Gems, Python has pip and now Shell has bpkg!_

`bpkg` is a lightweight bash package manager. It takes care of fetching the shell scripts, installing them appropriately, setting the execution permission and more.

You can install shell scripts globally (on `/usr/local/bin`) or use them on a _per-project basis_ (on `./deps/`), as a lazy-man "copy and paste".
You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use them on a _per-project basis_ (on `${BPKG_DEPS:-./deps/}`), as a lazy-man "copy and paste".

<!-- BEGIN-MARKDOWN-TOC -->
* [Install](#install)
Expand Down Expand Up @@ -78,8 +78,8 @@ You use `bpkg` by simply sending commands, pretty much like `npm` or `pip`.

### Installing packages

Packages can either be global (on `/usr/local/bin` if installed as root or
`$HOME/.local/bin` otherwize) or local (under `./deps`).
Packages can either be global (on `${PREFIX:-/usr/local/bin}` if installed as root or
`${PREFIX:-$HOME/.local/bin}` otherwize) or local (under `${BPKG_DEPS:-./deps}`).

For example, here's a **global install for the current user** of the [term package][term]:

Expand Down
27 changes: 14 additions & 13 deletions lib/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if [[ ${#BPKG_REMOTES[@]} -eq 0 ]]; then
BPKG_GIT_REMOTES[0]=${BPKG_GIT_REMOTE-https://github.com}
fi
BPKG_USER="${BPKG_USER:-bpkg}"
BPKG_DEPS="${BPKG_DEPS:-deps}"

## check parameter consistency
validate_parameters () {
Expand Down Expand Up @@ -436,17 +437,17 @@ bpkg_install_from_remote () {
## perform local install otherwise
else
## copy 'bpkg.json' or 'package.json' over
save_remote_file "$url/$package_file" "$cwd/deps/$name/$package_file" "$auth_param"
save_remote_file "$url/$package_file" "$cwd/$BPKG_DEPS/$name/$package_file" "$auth_param"

## make 'deps/' directory if possible
mkdir -p "$cwd/deps/$name"
## make '$BPKG_DEPS/' directory if possible
mkdir -p "$cwd/$BPKG_DEPS/$name"

## make 'deps/bin' directory if possible
mkdir -p "$cwd/deps/bin"
## make '$BPKG_DEPS/bin' directory if possible
mkdir -p "$cwd/$BPKG_DEPS/bin"

# install package dependencies
info "Install dependencies for $name"
(cd "$cwd/deps/$name" && bpkg getdeps)
(cd "$cwd/$BPKG_DEPS/$name" && bpkg getdeps)

## grab each script and place in deps directory
for script in "${scripts[@]}"; do
Expand All @@ -455,13 +456,13 @@ bpkg_install_from_remote () {
local scriptname="$(echo "$script" | xargs basename )"

info "fetch" "$url/$script"
info "write" "$cwd/deps/$name/$script"
save_remote_file "$url/$script" "$cwd/deps/$name/$script" "$auth_param"
info "write" "$cwd/$BPKG_DEPS/$name/$script"
save_remote_file "$url/$script" "$cwd/$BPKG_DEPS/$name/$script" "$auth_param"

scriptname="${scriptname%.*}"
info "$scriptname to PATH" "$cwd/deps/bin/$scriptname"
ln -si "$cwd/deps/$name/$script" "$cwd/deps/bin/$scriptname"
chmod u+x "$cwd/deps/bin/$scriptname"
info "$scriptname to PATH" "$cwd/$BPKG_DEPS/bin/$scriptname"
ln -si "$cwd/$BPKG_DEPS/$name/$script" "$cwd/$BPKG_DEPS/bin/$scriptname"
chmod u+x "$cwd/$BPKG_DEPS/bin/$scriptname"
fi
)
done
Expand All @@ -472,8 +473,8 @@ bpkg_install_from_remote () {
(
if [[ "$file" ]];then
info "fetch" "$url/$file"
info "write" "$cwd/deps/$name/$file"
save_remote_file "$url/$file" "$cwd/deps/$name/$file" "$auth_param"
info "write" "$cwd/$BPKG_DEPS/$name/$file"
save_remote_file "$url/$file" "$cwd/$BPKG_DEPS/$name/$file" "$auth_param"
fi
)
done
Expand Down

0 comments on commit 093f376

Please sign in to comment.