Skip to content

Instantly share code, notes, and snippets.

@rachel-fenichel
Last active February 21, 2022 21:23
Show Gist options
  • Save rachel-fenichel/73a716676c1af9471238e59e640fb855 to your computer and use it in GitHub Desktop.
Save rachel-fenichel/73a716676c1af9471238e59e640fb855 to your computer and use it in GitHub Desktop.
Rename scripts for Blockly release 2.20190722

Rename scripts for Blockly release 2.20190722

In the June 2019 release we renamed a significant number of utility functions. These scripts should help with your renaming, but you should still check that the output is what you expect.

Use blockly_rename_bash_v3.sh if you are on a Mac.

Note that the script does not rename goog.math.Rect to Blockly.utils.Rect because the constructor format has changed. You will need to do that rename manually.

The full list of renames:

  • Blockly.utils.toRadians -> Blockly.utils.math.toRadians

  • Blockly.utils.toDegrees -> Blockly.utils.math.toDegrees

  • Blockly.utils.clampNumber -> Blockly.utils.math.clamp

  • Blockly.SVG_NS -> Blockly.utils.dom.SVG_NS

  • Blockly.HTML_NS -> Blockly.utils.dom.HTML_NS

  • Blockly.utils.createSvgElement -> Blockly.utils.dom.createSvgElement

  • Blockly.utils.addClass -> Blockly.utils.dom.addClass

  • Blockly.utils.removeClass -> Blockly.utils.dom.removeClass

  • Blockly.utils.hasClass -> Blockly.utils.dom.hasClass

  • Blockly.utils.removeNode -> Blockly.utils.dom.removeNode

  • Blockly.utils.insertAfter -> Blockly.utils.dom.insertAfter

  • Blockly.utils.containsNode -> Blockly.utils.dom.containsNode

  • Blockly.utils.setCssTransform -> Blockly.utils.dom.setCssTransform

  • Blockly.utils.startsWith -> Blockly.utils.string.startsWith

  • Blockly.utils.shortestStringLength -> Blockly.utils.string.shortestStringLength

  • Blockly.utils.commonWordPrefix -> Blockly.utils.string.commonWordPrefix

  • Blockly.utils.commonWordSuffix -> Blockly.utils.string.commonWordSuffix

  • Blockly.utils.wrap -> Blockly.utils.string.wrap

  • Blockly.Xml.utils -> Blockly.utils.xml

  • Blockly.BlockAnimations => Blockly.blockAnimations

Additionally, as part of our drive to eliminate Closure, the following dependencies are no longer being used. If you have your own uses of these components, then you should either use the new Blockly equivalents, or else explicitly 'require' these from Closure.

  • goog.math.Coordinate -> Blockly.utils.Coordinate

  • goog.math.Rect -> Blockly.utils.Rect

Note the constructor format has changed:

new goog.math.Rect(left, top, width, height) -> new Blockly.utils.Rect(top, bottom, left, right)

  • goog.userAgent -> Blockly.utils.userAgent

  • goog.color -> Blockly.utils.colour

  • goog.global -> Blockly.utils.global

#!/bin/bash
echo "Renaming Blockly functions in all .js files in this directory and subdirectories"
# Warning: this script does not rename goog.math.Rect to Blockly.utils.Rect
# because the constructor format has changed:
# goog.math.Rect -> Blockly.utils.Rect
# new goog.math.Rect(left, top, width, height)
# new Blockly.utils.Rect(top, bottom, left, right)
# You may want to apply this change manually.
nameKeys=(
Blockly.utils.toRadians
Blockly.utils.toDegrees
Blockly.utils.clampNumber
Blockly.SVG_NS
Blockly.HTML_NS
Blockly.utils.createSvgElement
Blockly.utils.addClass
Blockly.utils.removeClass
Blockly.utils.hasClass
Blockly.utils.removeNode
Blockly.utils.insertAfter
Blockly.utils.containsNode
Blockly.utils.setCssTransform
Blockly.utils.startsWith
Blockly.utils.shortestStringLength
Blockly.utils.commonWordPrefix
Blockly.utils.commonWordSuffix
Blockly.utils.wrap
Blockly.Xml.utils
Blockly.BlockAnimations
goog.math.Coordinate
goog.userAgent
goog.color
goog.global
)
nameValues=(
Blockly.utils.math.toRadians
Blockly.utils.math.toDegrees
Blockly.utils.math.clamp
Blockly.utils.dom.SVG_NS
Blockly.utils.dom.HTML_NS
Blockly.utils.dom.createSvgElement
Blockly.utils.dom.addClass
Blockly.utils.dom.removeClass
Blockly.utils.dom.hasClass
Blockly.utils.dom.removeNode
Blockly.utils.dom.insertAfter
Blockly.utils.dom.containsNode
Blockly.utils.dom.setCssTransform
Blockly.utils.string.startsWith
Blockly.utils.string.shortestStringLength
Blockly.utils.string.commonWordPrefix
Blockly.utils.string.commonWordSuffix
Blockly.utils.string.wrap
Blockly.utils.xml
Blockly.blockAnimations
Blockly.utils.Coordinate
Blockly.utils.userAgent
Blockly.utils.colour
Blockly.utils.global
)
for (( i=0; i<${#nameKeys[@]}; i++ ))
do
old_name=${nameKeys[$i]}
new_name=${nameValues[$i]}
echo "$old_name -> $new_name"
find . -type f -name "*.js" -exec sed -i '' "s/$old_name/$new_name/g" {} +
done
git status
#!/bin/bash
echo "Renaming Blockly functions in all .js files in this directory and subdirectories"
declare -A names
# Warning: this script does not rename goog.math.Rect to Blockly.utils.Rect
# because the constructor format has changed:
# goog.math.Rect -> Blockly.utils.Rect
# new goog.math.Rect(left, top, width, height)
# new Blockly.utils.Rect(top, bottom, left, right)
# You may want to apply this change manually.
names=(
[Blockly.utils.toRadians]=Blockly.utils.math.toRadians
[Blockly.utils.toDegrees]=Blockly.utils.math.toDegrees
[Blockly.utils.clampNumber]=Blockly.utils.math.clamp
[Blockly.SVG_NS]=Blockly.utils.dom.SVG_NS
[Blockly.HTML_NS]=Blockly.utils.dom.HTML_NS
[Blockly.utils.createSvgElement]=Blockly.utils.dom.createSvgElement
[Blockly.utils.addClass]=Blockly.utils.dom.addClass
[Blockly.utils.removeClass]=Blockly.utils.dom.removeClass
[Blockly.utils.hasClass]=Blockly.utils.dom.hasClass
[Blockly.utils.removeNode]=Blockly.utils.dom.removeNode
[Blockly.utils.insertAfter]=Blockly.utils.dom.insertAfter
[Blockly.utils.containsNode]=Blockly.utils.dom.containsNode
[Blockly.utils.setCssTransform]=Blockly.utils.dom.setCssTransform
[Blockly.utils.startsWith]=Blockly.utils.string.startsWith
[Blockly.utils.shortestStringLength]=Blockly.utils.string.shortestStringLength
[Blockly.utils.commonWordPrefix]=Blockly.utils.string.commonWordPrefix
[Blockly.utils.commonWordSuffix]=Blockly.utils.string.commonWordSuffix
[Blockly.utils.wrap]=Blockly.utils.string.wrap
[Blockly.Xml.utils]=Blockly.utils.xml
[Blockly.BlockAnimations]=Blockly.blockAnimations
[goog.math.Coordinate]=Blockly.utils.Coordinate
[goog.userAgent]=Blockly.utils.userAgent
[goog.color]=Blockly.utils.colour
[goog.global]=Blockly.utils.global
)
for i in "${!names[@]}"
do
old_name=$i
new_name=${names[$i]}
echo "$old_name -> $new_name"
find . -type f -name "*.js" -exec sed -i "s/$old_name/$new_name/g" {} +
done
git status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment