Skip to content

Commit

Permalink
add recursive dependency resolution via package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
thoward committed Jan 30, 2016
1 parent cd9fdc7 commit af0efc5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ $ bpkg install stephenmathieson/git-standup -g
cp -f git-standup /usr/local/bin
```
### Packages With Dependencies
You can install a packages dependencies with the `bpkg getdeps` command. These will recursively install in `deps/` sub-folders to resolve all dependencies.
_Note: There is no protection against circular dependencies, so be careful!_
### Retrieving package info
After installing a package, you can obtain info from it using `bpkg`.
Expand Down Expand Up @@ -195,6 +202,17 @@ This is an array of scripts that will be installed into a project.
"scripts": ["script.sh"]
```

### dependencies (optional)

This is a hash of dependencies. The keys are the package names, and the values are the version specifiers. If you want the latest code use `'master'` in the version specifier. Otherwise, use a tagged release identifier. This works the same as `bpkg install`'s package/version specifiers.

```json
"dependencies": {
"term": "0.0.1"
}
```


## Packaging best practices

These are guidelines that we strongly encourage developers to follow.
Expand Down
1 change: 1 addition & 0 deletions bpkg-getdeps
47 changes: 47 additions & 0 deletions lib/getdeps/getdeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

## output usage
usage () {
echo "Installs dependencies for a package."
echo "usage: bpkg-getdeps [-h|--help]"
echo " or: bpkg-getdeps"
}

## Read a package property
bpkg_getdeps () {
local cwd="`pwd`"
local pkg="${cwd}/package.json"

## parse flags
case "$1" in
-h|--help)
usage
return 0
;;
esac

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

dependencies=$(cat "${pkg}" | bpkg-json -b | grep '\[\"dependencies' | sed "s/\[\"dependencies\",//" | sed "s/\"\]$(printf '\t')\"/@/" | tr -d '"')
dependencies=($(echo ${dependencies[@]}))

## run bpkg install for each dependency
for (( i = 0; i < ${#dependencies[@]} ; ++i )); do
(
local package=${dependencies[$i]}
bpkg install ${package}
)
done
return 0
}

if [[ ${BASH_SOURCE[0]} != $0 ]]; then
export -f bpkg_getdeps
else
bpkg_getdeps "${@}"
exit $?
fi
2 changes: 2 additions & 0 deletions lib/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ bpkg_install_from_remote () {
chmod u+x "${cwd}/deps/bin/${scriptname}"
)
done
# install package dependencies
(cd ${cwd}/deps/${name} && bpkg getdeps)
fi

return 0
Expand Down

0 comments on commit af0efc5

Please sign in to comment.