diff --git a/scripts/bower/publish.sh b/scripts/bower/publish.sh index 0170f6183174..f1ad9d5d47fd 100755 --- a/scripts/bower/publish.sh +++ b/scripts/bower/publish.sh @@ -29,6 +29,11 @@ function init { angular-touch angular-messages ) + MOCK_MODULES=( + ngMock + ngMockE2E + ngAnimateMock + ) } @@ -75,6 +80,37 @@ function prepare { replaceJsonProp "bower.json" "angular.*" ".*" "$NEW_VERSION" replaceJsonProp "package.json" "version" ".*" "$NEW_VERSION" replaceJsonProp "package.json" "angular.*" ".*" "$NEW_VERSION" + deleteJsonProp "package.json" "main" + + if [ $repo != "angular-mocks" ] + then + echo "-- Adding $repo CommonJS index file" + echo "require('./$repo');" > index.js + echo "" >> index.js + fi + + if [ $repo == "angular" ] + then + echo "module.exports = angular;" >> index.js + else + # convert to module names (angular-animate >> ngAnimate) + suffix=`echo $repo | cut -c9-` + first=`echo $suffix | cut -c1 | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + tail=`echo $suffix | cut -c2-` + + if [ $repo != "angular-mocks" ] + then + echo "module.exports = 'ng$first$tail';" >> index.js + else + for mock in "${MOCK_MODULES[@]}" + do + echo "-- Adding $repo/$mock CommonJS file" + echo "require('./$repo');" > $mock.js + echo "" >> $mock.js + echo "module.exports = '$mock';" >> $mock.js + done + fi + fi git add -A diff --git a/scripts/utils.inc b/scripts/utils.inc index 919f7df9799e..4aedca9cead0 100644 --- a/scripts/utils.inc +++ b/scripts/utils.inc @@ -46,6 +46,7 @@ # Utility functions: # - readJsonProp # - replaceJsonProp +# - deleteJsonProp # - resolveDir # - getVar # - serVar @@ -207,6 +208,12 @@ function replaceJsonProp { replaceInFile $1 '"('$2')"[ ]*:[ ]*"'$3'"' '"\1": "'$4'"' } +# deleteJsonProp(jsonFile, property) +# - restriction: property needs to be on a single line! +function deleteJsonProp { + sed -i '' -e /\"$2\"\:/d $1 +} + # replaceInFile(file, findPattern, replacePattern) function replaceInFile { sed -i .tmp -E "s/$2/$3/" $1