Skip to content

Instantly share code, notes, and snippets.

@brotoo25
Last active May 6, 2021 01:28
Show Gist options
  • Save brotoo25/4c1f4cb983ce56936851308713ef595e to your computer and use it in GitHub Desktop.
Save brotoo25/4c1f4cb983ce56936851308713ef595e to your computer and use it in GitHub Desktop.
Script to create Flutter Project + Github Repo
#!/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