diff --git a/README.md b/README.md index b378d39..f52cf96 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bpkg-getdeps b/bpkg-getdeps new file mode 120000 index 0000000..b2e988c --- /dev/null +++ b/bpkg-getdeps @@ -0,0 +1 @@ +lib/getdeps/getdeps.sh \ No newline at end of file diff --git a/lib/getdeps/getdeps.sh b/lib/getdeps/getdeps.sh new file mode 100755 index 0000000..13d0d0f --- /dev/null +++ b/lib/getdeps/getdeps.sh @@ -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 diff --git a/lib/install/install.sh b/lib/install/install.sh index 73d60a8..8fb7d21 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -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