mirror of
https://github.com/bpkg/bpkg
synced 2024-11-08 01:10:36 +00:00
added files array support to install/package.json
updated readme with files entry moved package.json copy near the start of install moved directory creation to the start of install moved getdeps to the start of install
This commit is contained in:
parent
b25c484cb8
commit
5b707579cb
@ -202,6 +202,14 @@ This is an array of scripts that will be installed into a project.
|
|||||||
"scripts": ["script.sh"]
|
"scripts": ["script.sh"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### files
|
||||||
|
|
||||||
|
This is an array of files that will be installed into a project.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"files": ["bar.txt", "foo.txt"]
|
||||||
|
```
|
||||||
|
|
||||||
### dependencies (optional)
|
### 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.
|
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.
|
||||||
|
@ -168,6 +168,7 @@ bpkg_install_from_remote () {
|
|||||||
declare -a local pkg_parts=()
|
declare -a local pkg_parts=()
|
||||||
declare -a local remote_parts=()
|
declare -a local remote_parts=()
|
||||||
declare -a local scripts=()
|
declare -a local scripts=()
|
||||||
|
declare -a local files=()
|
||||||
|
|
||||||
## get version if available
|
## get version if available
|
||||||
{
|
{
|
||||||
@ -272,6 +273,28 @@ bpkg_install_from_remote () {
|
|||||||
json=$(curl $auth_param -sL "${url}/package.json?`date +%s`")
|
json=$(curl $auth_param -sL "${url}/package.json?`date +%s`")
|
||||||
|
|
||||||
if (( 1 == $has_pkg_json )); then
|
if (( 1 == $has_pkg_json )); then
|
||||||
|
## get package name from `package.json'
|
||||||
|
name="$(
|
||||||
|
echo -n ${json} |
|
||||||
|
bpkg-json -b |
|
||||||
|
grep 'name' |
|
||||||
|
awk '{ $1=""; print $0 }' |
|
||||||
|
tr -d '\"' |
|
||||||
|
tr -d ' '
|
||||||
|
)"
|
||||||
|
|
||||||
|
## copy package.json over
|
||||||
|
curl $auth_param -sL "${url}/package.json" -o "${cwd}/deps/${name}/package.json"
|
||||||
|
|
||||||
|
## make `deps/' directory if possible
|
||||||
|
mkdir -p "${cwd}/deps/${name}"
|
||||||
|
|
||||||
|
## make `deps/bin' directory if possible
|
||||||
|
mkdir -p "${cwd}/deps/bin"
|
||||||
|
|
||||||
|
# install package dependencies
|
||||||
|
(cd "${cwd}/deps/${name}" && bpkg getdeps)
|
||||||
|
|
||||||
## check if forced global
|
## check if forced global
|
||||||
if [ ! -z $(echo -n $json | bpkg-json -b | grep '\["global"\]' | awk '{ print $2 }' | tr -d '"') ]; then
|
if [ ! -z $(echo -n $json | bpkg-json -b | grep '\["global"\]' | awk '{ print $2 }' | tr -d '"') ]; then
|
||||||
needs_global=1
|
needs_global=1
|
||||||
@ -290,6 +313,21 @@ bpkg_install_from_remote () {
|
|||||||
## account for existing space
|
## account for existing space
|
||||||
scripts=($(echo ${scripts[@]}))
|
scripts=($(echo ${scripts[@]}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## construct files array
|
||||||
|
{
|
||||||
|
files=$(echo -n $json | bpkg-json -b | grep '\["files' | awk '{$1=""; print $0 }' | tr -d '"')
|
||||||
|
OLDIFS="${IFS}"
|
||||||
|
|
||||||
|
## comma to space
|
||||||
|
IFS=','
|
||||||
|
files=($(echo ${files[@]}))
|
||||||
|
IFS="${OLDIFS}"
|
||||||
|
|
||||||
|
## account for existing space
|
||||||
|
files=($(echo ${files[@]}))
|
||||||
|
}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## build global if needed
|
## build global if needed
|
||||||
@ -325,26 +363,8 @@ bpkg_install_from_remote () {
|
|||||||
## clean up
|
## clean up
|
||||||
rm -rf ${name}-${version}
|
rm -rf ${name}-${version}
|
||||||
)}
|
)}
|
||||||
elif [ "${#scripts[@]}" -gt "0" ]; then
|
fi
|
||||||
## get package name from `package.json'
|
if [ "${#scripts[@]}" -gt "0" ]; then
|
||||||
name="$(
|
|
||||||
echo -n ${json} |
|
|
||||||
bpkg-json -b |
|
|
||||||
grep 'name' |
|
|
||||||
awk '{ $1=""; print $0 }' |
|
|
||||||
tr -d '\"' |
|
|
||||||
tr -d ' '
|
|
||||||
)"
|
|
||||||
|
|
||||||
## make `deps/' directory if possible
|
|
||||||
mkdir -p "${cwd}/deps/${name}"
|
|
||||||
|
|
||||||
## make `deps/bin' directory if possible
|
|
||||||
mkdir -p "${cwd}/deps/bin"
|
|
||||||
|
|
||||||
## copy package.json over
|
|
||||||
curl $auth_param -sL "${url}/package.json" -o "${cwd}/deps/${name}/package.json"
|
|
||||||
|
|
||||||
## grab each script and place in deps directory
|
## grab each script and place in deps directory
|
||||||
for (( i = 0; i < ${#scripts[@]} ; ++i )); do
|
for (( i = 0; i < ${#scripts[@]} ; ++i )); do
|
||||||
(
|
(
|
||||||
@ -358,10 +378,22 @@ bpkg_install_from_remote () {
|
|||||||
chmod u+x "${cwd}/deps/bin/${scriptname}"
|
chmod u+x "${cwd}/deps/bin/${scriptname}"
|
||||||
)
|
)
|
||||||
done
|
done
|
||||||
# install package dependencies
|
|
||||||
(cd ${cwd}/deps/${name} && bpkg getdeps)
|
|
||||||
fi
|
fi
|
||||||
|
if [ "${#files[@]}" -gt "0" ]; then
|
||||||
|
## grab each file
|
||||||
|
for (( i = 0; i < ${#files[@]} ; ++i )); do
|
||||||
|
(
|
||||||
|
local file="$(echo ${files[$i]})"
|
||||||
|
local filedir="$(dirname "${cwd}/deps/${name}/${file}")"
|
||||||
|
info "fetch" "${url}/${file}"
|
||||||
|
if [ ! -d "$filedir" ]; then
|
||||||
|
mkdir -p "$filedir"
|
||||||
|
fi
|
||||||
|
info "write" "${filedir}/${file}"
|
||||||
|
curl $auth_param -sL "${url}/${script}" -o "${filedir}/${file}"
|
||||||
|
)
|
||||||
|
done
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user