Skip to content

Commit

Permalink
Merge pull request #31 from upm-packages/fix/#28-skip_modify_package_…
Browse files Browse the repository at this point in the history
…json

Skip modify Assets/package.json if not exists
  • Loading branch information
monry authored Jun 23, 2019
2 parents 14ece63 + c514412 commit 6e31d48
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
6 changes: 4 additions & 2 deletions scripts/upm-add-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ version=${VERSION}

manifest_json=$(cat ${manifest_file} | jq ".dependencies |= . + {\"${package_id}\": \"${version}\"}")
echo ${manifest_json} | jq -M '.' > ${manifest_file}
package_json=$(cat ${package_json_file} | jq ".dependencies |= . + {\"${package_id}\": \"${version}\"}")
echo ${package_json} | jq -M '.' > ${package_json_file}
if [ -f ${package_json_file} ]; then
package_json=$(cat ${package_json_file} | jq ".dependencies |= . + {\"${package_id}\": \"${version}\"}")
echo ${package_json} | jq -M '.' > ${package_json_file}
fi

cat << __MESSAGE__
Successfully add package "${package_id}@${version}" to project 📦
Expand Down
14 changes: 8 additions & 6 deletions scripts/upm-remove-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ else
echo ${manifest_json} | jq -M '.' > ${manifest_file}
fi

current_version_package=$(cat ${package_json_file} | jq -r ".dependencies.\"${package_id}\"")
if [ "${current_version_package}" = "null" ]; then
cat << __WARNING__
if [ -f ${package_json_file} ]; then
current_version_package=$(cat ${package_json_file} | jq -r ".dependencies.\"${package_id}\"")
if [ "${current_version_package}" = "null" ]; then
cat << __WARNING__
WARNING: "${package_id}" does not contains in "${package_json_file}"
__WARNING__
else
package_json=$(cat ${package_json_file} | jq "del(.dependencies.\"${package_id}\")")
echo ${package_json} | jq -M '.' > ${package_json_file}
else
package_json=$(cat ${package_json_file} | jq "del(.dependencies.\"${package_id}\")")
echo ${package_json} | jq -M '.' > ${package_json_file}
fi
fi

cat << __MESSAGE__
Expand Down
14 changes: 14 additions & 0 deletions tests/upm-add-package.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ function teardown() {

assert_output --partial "Could not find registry for dev.sample2.upm.foo"
}

@test "upm-add-package / ignore Assets/package.json if not exists" {
cp "$( dirname ${BATS_TEST_DIRNAME} )"/fixtures/single.upm-config.json ~/.upm-config.json
cwd=$(pwd)
cd $TEST_TEMP_DIR
mkdir -p $TEST_TEMP_DIR/Test-Project/Packages
echo '{}' > $TEST_TEMP_DIR/Test-Project/Packages/manifest.json
cd $TEST_TEMP_DIR/Test-Project
run ${cwd}/upm add registry
run ${cwd}/upm add package dev.sample.upm.foo 1.2.3

[ ! -f $TEST_TEMP_DIR/Test-Project/Assets/package.json ]
assert_file_contains "${TEST_TEMP_DIR}/Test-Project/Packages/manifest.json" "\"dev.sample.upm.foo\": \"1.2.3\""
}

0 comments on commit 6e31d48

Please sign in to comment.