Last active
May 6, 2021 01:28
-
-
Save brotoo25/4c1f4cb983ce56936851308713ef595e to your computer and use it in GitHub Desktop.
Script to create Flutter Project + Github Repo
This file contains 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 | |
############################################################# | |
# | |
# REQUIRES: | |
# - GitHub CLI (https://cli.github.com/) | |
# Script to automatically create default project structures | |
# along side its Github Repository, all integrated and with | |
# default 'first commit' pushed to remote repository. | |
# | |
############################################################# | |
HELP_MESSAGE=" | |
Usage: $(basename "$0") <PROJECT_NAME> | |
OPTIONS: | |
-t, --type Project Type - flutter | empty | |
-h, --help Show help message | |
" | |
GITHUB_USER_NAME="brotoo25" # REPLACE WITH YOUR GITHUB ID | |
PROJECT_NAME="" | |
PROJECT_TYPE="flutter" | |
PROJECT_FOLDER="$HOME/Development" | |
function validateProjectName() { | |
echo "π: Validating Project Name..." | |
if [ "$PROJECT_NAME" == "" ]; then | |
echo -e "π Missing Project Name argument!" | |
exit 1 | |
fi | |
} | |
function createProject() { | |
echo "π: Project Type: $PROJECT_TYPE" | |
case "$PROJECT_TYPE" in | |
'empty') | |
echo "π: Creating Empty Project..." | |
mkdir "$PROJECT_FOLDER/$PROJECT_NAME" | |
echo "# $PROJECT_NAME" >"$PROJECT_FOLDER/$PROJECT_NAME/README.md" | |
;; | |
'flutter') | |
echo "π: Creating Flutter Project..." | |
PROJECT_FOLDER="$PROJECT_FOLDER/Flutter/Projects" | |
mkdir -p "$PROJECT_FOLDER" | |
cd "$PROJECT_FOLDER" | |
flutter create $PROJECT_NAME | |
;; | |
esac | |
} | |
function createGithubRepository() { | |
echo "π: Creating GitHub Repository..." | |
gh repo create "$PROJECT_NAME" --confirm --public | |
} | |
function commitAndPush() { | |
echo "π: Commiting and Pushing to Repository..." | |
git init | |
git add README.md | |
git add . | |
git commit -am 'first commit' | |
git branch -M main | |
git remote add origin [email protected]:$GITHUB_USER_NAME/$PROJECT_NAME.git | |
git push -u origin main | |
} | |
function create() { | |
createProject | |
cd "$PROJECT_FOLDER/$PROJECT_NAME" | |
createGithubRepository | |
commitAndPush | |
} | |
function openProject() { | |
code "$PROJECT_FOLDER/$PROJECT_NAME" | |
} | |
case "$1" in | |
-t | --type) | |
shift | |
PROJECT_TYPE="$1" | |
shift | |
;; | |
-h | --help) | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
echo -e "${GREEN}$HELP_MESSAGE${NC}" | |
exit 0 | |
;; | |
esac | |
PROJECT_NAME=$1 | |
validateProjectName | |
create | |
openProject |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment