Commit 433de5e9 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm-restore: add require.json (npm) support

parent f51b0d50
...@@ -110,6 +110,76 @@ __epm_restore_pip() ...@@ -110,6 +110,76 @@ __epm_restore_pip()
docmd epm install $ilist docmd epm install $ilist
} }
__epm_print_npm_list()
{
local reqmacro="$1"
local req_file="$2"
local l
while read l ; do
# "tap": "^14.10.7"
echo "$l" | grep -q '"\(.*\)": "\(.*\)"' || continue
local name="$(echo "$l" | sed -e 's|.*"\(.*\)": ".*|\1|')"
[ -z "$name" ] && continue
local ver="$(echo "$l" | sed -e 's|.*"\(.*\)": "\(.*\)".*|\2|')" #'
[ -z "$name" ] && continue
if [ -n "$dryrun" ] ; then
local pi=''
local sign
if echo "$ver" | grep -q "^\^" ; then
sign=">="
else
sign="="
fi
ll=$(echo "$ver" | sed -e 's|^[^~]||')
pi="$pi$reqmacro node-$name $sign $ll"
# [ -n "$pi" ] && pi="$pi
#"
# [ -n "$pi" ] || pi="$pi$reqmacro: node-$t"
echo "$pi"
continue
else
local pi="node-$name"
#echo " $l -> $name -> $pi"
fi
[ -n "$name" ] || continue
ilist="$ilist $pi"
done < $req_file
[ -n "$dryrun" ] || echo "$ilist"
}
__epm_restore_npm()
{
local req_file="$1"
epm assure jq
if [ -n "$dryrun" ] ; then
local lt=$(mktemp)
a= jq .dependencies <$req_file >$lt
echo
echo "# generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file"
__epm_print_npm_list "Requires:" $lt
echo
echo "# devDependencies generated by epm --restore --dry-run from $(basename $(dirname $(realpath $req_file)))/$req_file"
a= jq .devDependencies <$req_file >$lt
__epm_print_npm_list "BuildRequires:" $lt
rm -f $lt
return
fi
info "Install requirements from $req_file ..."
local lt=$(mktemp)
a= jq .dependencies <$req_file >$lt
ilist="$(__epm_print_npm_list "" $lt)"
a= jq .devDependencies <$req_file >$lt
ilist="$ilist $(__epm_print_npm_list "" $lt)"
rm -f $lt
docmd epm install $ilist
}
__epm_restore_by() __epm_restore_by()
{ {
local req_file="$1" local req_file="$1"
...@@ -132,6 +202,9 @@ __epm_restore_by() ...@@ -132,6 +202,9 @@ __epm_restore_by()
requirements.txt|requirements_dev.txt|requires.txt) requirements.txt|requirements_dev.txt|requires.txt)
[ -s "$req_file" ] && __epm_restore_pip "$req_file" [ -s "$req_file" ] && __epm_restore_pip "$req_file"
;; ;;
package.json)
[ -s "$req_file" ] && __epm_restore_npm "$req_file"
;;
Gemfile|package.json) Gemfile|package.json)
info "$req_file support is not implemented yet" info "$req_file support is not implemented yet"
;; ;;
...@@ -158,7 +231,7 @@ epm_restore() ...@@ -158,7 +231,7 @@ epm_restore()
# TODO: nowhere works: python3 setup.py --requires # TODO: nowhere works: python3 setup.py --requires
# if run with empty args # if run with empty args
for i in requirements.txt requirements_dev.txt Gemfile requires.txt; do for i in requirements.txt requirements_dev.txt Gemfile requires.txt package.json; do
__epm_restore_by $i __epm_restore_by $i
done done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment