Last active
December 10, 2021 05:43
-
-
Save chooyan-eng/12c73011cbc6ef2d081803b64da86cc9 to your computer and use it in GitHub Desktop.
Shell script for create Flutter sample project of given Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "USAGE: a single Widget name must be given as an argument. See example below" 1>&2 | |
echo "USAGE: sh flutter_creater.sh InkWell" 1>&2 | |
exit 1 | |
fi | |
WIDGET_NAME=$1 | |
WIDGET_NAME_LOWER=`echo ${WIDGET_NAME} | tr '[:upper:]' '[:lower:]'` | |
FOLDER_NAME="mysample_${WIDGET_NAME_LOWER}" | |
BASE_URL="https://api.flutter.dev/flutter/" | |
CATEGORY="material" | |
STATUS_CODE_MATERIAL=`curl -s ${BASE_URL}/${CATEGORY}/${WIDGET_NAME}-class.html -o /dev/null -w '%{http_code}\n' -s` | |
if [ $STATUS_CODE_MATERIAL -ne 200 ]; then | |
CATEGORY="widgets" | |
fi | |
CREATE_COMMAND=`curl --silent https://api.flutter.dev/flutter/${CATEGORY}/${WIDGET_NAME}-class.html | grep snippet-create-command | sed 's/<span class="snippet-create-command">//' | sed 's/<\/span>//' | sed "s/mysample/${FOLDER_NAME}/"` | |
if [ -z "$CREATE_COMMAND" ]; then | |
echo "ERROR: create command not found." | |
exit 1 | |
fi | |
# FIXME: `sh $CREATE_COMMAND` causes an error for some reason | |
curl --silent https://api.flutter.dev/flutter/${CATEGORY}/${WIDGET_NAME}-class.html | grep snippet-create-command | sed 's/<span class="snippet-create-command">//' | sed 's/<\/span>//' | sed "s/mysample/${FOLDER_NAME}/" | sh | |
cd $FOLDER_NAME | |
flutter run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment