Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(npm): Make modules Browserify compatible#10732

Closed
36 changes: 36 additions & 0 deletions scripts/bower/publish.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,11 @@ function init {
angular-touch
angular-messages
)
MOCK_MODULES=(
ngMock
ngMockE2E
ngAnimateMock
)
}


Expand DownExpand Up@@ -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-`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to comment these lines clearly to indicate that you're transforming the repo name into a module name, alright?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, good idea.


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

Expand Down
7 changes: 7 additions & 0 deletions scripts/utils.inc
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,7 @@
# Utility functions:
# - readJsonProp
# - replaceJsonProp
# - deleteJsonProp
# - resolveDir
# - getVar
# - serVar
Expand DownExpand Up@@ -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
Expand Down
close