Skip to content

Instantly share code, notes, and snippets.

@nikku
Created October 8, 2020 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikku/6103cd0cc7a5b081b35b5cdbc3d13946 to your computer and use it in GitHub Desktop.
Save nikku/6103cd0cc7a5b081b35b5cdbc3d13946 to your computer and use it in GitHub Desktop.
A supporting script to migrate the bpmn.io code base to ES6 features
#!/usr/bin/env bash
shopt -s globstar
# loop all files to perform transformation
for i in lib/**/*.js
do
echo "Processing $i"
# we need to replace occurences of default function exports, as lebab does not support them:
#
# export default function SomeClass(...) { }
#
# =>
#
# export default SomeClass /*CLS*/; function SomeClass(...) { }
#
#
# Afterwards we're going to transform stuff back again
#
cp "$i" "$i.bak"
cat "$i" | \
sed 's/export default function \([A-Z]\+[^ ]*\)(/export default \1 \/*CLS*\/; function \1(/' | \
lebab -t class | \
tr '\n' '\r' | \
sed 's/export default \([A-Z]\+[^ ]*\) \/\*CLS\*\/;\r\rclass/export default class/' | \
tr '\r' '\n' \
> "$i"
if [ "$(grep -q inherits "$i" ] or [ grep -q '/*CLS*/' "$i" ]; then
echo "$i: needs additional migration (inherits)"
fi
if cmp -s "$i.bak" "$i"; then
rm "$i.bak"
continue;
fi
$EDITOR $i
read -p "Keep $i it? Y/n: " keep
if [[ $keep != "y" ]] && [[ -n $keep ]]; then
echo "restored original $i"
mv -f "$i.bak" "$i"
else
rm "$i.bak"
fi
done
# perform linting fixes (correct whitespace and stuff)
npm run lint -- --fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment