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
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions scripts/bower/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ function prepare {
replaceJsonProp "bower.json" "angular.*" ".*" "$NEW_VERSION"
replaceJsonProp "package.json" "version" ".*" "$NEW_VERSION"
replaceJsonProp "package.json" "angular.*" ".*" "$NEW_VERSION"
deleteJsonProp "package.json" "main"

echo "-- Adding CommonJS index file"
if [ -f "index.js" ]
then
rm index.js
fi

touch index.js
echo "require('./$repo');" >> index.js
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of removing index.js, touching it and then appending to it, you could just do this:

echo "require('./$repo');" > index.js --- that would shave off a few lines of code and be a bit easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very nice, done.

echo "" >> index.js
echo "module.exports = $repo;" >> index.js
if [ $repo == "angular" ]
then
echo "module.exports = angular;"
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you need to pipe these echos to index.js with >>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks! Fixed.

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
Contributor Author

Choose a reason for hiding this comment

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

Sure, good idea.


echo "module.exports = 'ng$first$tail';"
fi

git add -A

Expand Down
6 changes: 6 additions & 0 deletions scripts/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,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