2
0
mirror of https://github.com/bpkg/bpkg synced 2024-11-04 06:00:18 +00:00

add recursive dependency resolution via package.json

This commit is contained in:
Troy Howard 2016-01-30 12:47:10 -08:00
parent cd9fdc79fe
commit af0efc54c5
4 changed files with 68 additions and 0 deletions

View File

@ -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`.
@ -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.

1
bpkg-getdeps Symbolic link
View File

@ -0,0 +1 @@
lib/getdeps/getdeps.sh

47
lib/getdeps/getdeps.sh Executable file
View File

@ -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

View File

@ -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