Files
scripts/newproject
T

181 lines
4.3 KiB
Bash
Executable File

#!/bin/zsh
# Dependencies:
# quaxlyqueen/templates
#
# quaxlyqueen/scripts/mark
# quaxlyqueen/scripts/goto
# quaxlyqueen/scripts/ginit
# Supported languages.
TYPES=("c", "rust", "c-sharp", "aspnet", "java", "js", "t3", "python", "flutter", "go", "php")
# Catch case where there are too many arguments.
if [[ $# -gt 2 ]]; then
echo "Improper usage. Try:"
echo "\nnewproject { language } { projectname }"
echo " newproject"
echo " newproject c"
echo " newproject c app"
echo " newproject -h"
echo " newproject --help\n"
echo "Supported languages/stacks: $TYPES"
exit
# Help page
elif [[ $1 == "-h" || $1 == "--help" ]]; then
echo "\nAbstracting away command line tools to create projects in various languages."
echo "User can use with or without arguments."
echo "With no arguments, 'newproject' will prompt for a supported language, project name,"
echo " and if a git repo should be created."
echo "Bookmarks the new project directory using the 'mark' script."
echo "Detects required tools to use based upon language selected.\n"
echo "Usage:"
echo "\nnewproject { language } { projectname }"
echo " newproject"
echo " newproject c"
echo " newproject c app"
echo " newproject -h"
echo " newproject --help\n"
echo "Supported languages/stacks: $TYPES"
exit
elif [[ $# -eq 0 ]]; then
read "?Language: " LANG
read "?Project name: " NAME
# User provides the project's language.
elif [[ $# -eq 1 ]]; then
LANG=$1
read "?Project name: " NAME
# User provides arguments for the language and project name.
elif [[ $# -eq 2 ]]; then
LANG=$1
NAME=$2
fi
# Check if the language the user has provided is supported.
if [[ ${TYPES[@]} =~ $LANG ]]; then
echo Creating $LANG project $NAME
# Language unsupported, prompt user to create a Github issue.
else
read "?Language is not supported. Create a GH issue (y/N): " GH
if [[ $GH == "y" || $GH == "" ]]; then
gh issue create --web
fi
fi
# Create a new C project.
if [[ $LANG == "c" ]]; then
mkdir $NAME
cd $NAME
cp -r ~/templates/c/main.c . # Copy the template C file.
mark; # Bookmark new project.
# Create a new Rust project.
elif [[ $LANG == "rust" ]]; then
read "?Is this an Arduino project? (y/N): " ARDUINO
if [[ $ARDUINO == "y" ]]; then
cargo generate --git https://github.com/Rahix/avr-hal-template.git
else
cargo new $NAME
fi
# Create a new C# project with dotnet.
elif [[ $LANG == "c-sharp" ]]; then
mkdir $NAME
cd $NAME
mark; # Bookmark new project.
dotnet new console # Create a new console app with dotnet.
# Create a new ASP.NET project.
elif [[ $LANG == "aspnet" ]]; then
dotnet new globaljson --output $NAME
dotnet new web --no-https --output $NAME
dotnet new sln -o $NAME
dotnet sln $NAME add $NAME
cd $NAME
# Create a new Java project with Gradle.
elif [[ $LANG == "java" ]]; then
mkdir $NAME;
cd $NAME;
gradle init
mark;
# Create a new HTML, CSS, JS project.
elif [[ $LANG == "html" ]]; then
mkdir $NAME;
cd $NAME;
cp -r ~/templates/web/public_html .
cd public_html;
mark;
# Create a new JavaScript project.
elif [[ $LANG == "js" ]]; then
mkdir $NAME;
cd $NAME;
touch main.js;
mark;
# Create a new Python project.
elif [[ $LANG == "python" ]]; then
mkdir $NAME;
cd $NAME;
touch main.py;
touch requirements.txt
python -m venv env
mark;
# Create a new Flutter/Dart project.
elif [[ $LANG == "flutter" ]]; then
flutter create $NAME
cd $NAME
mark;
# Create a new t3 web app.
elif [[ $LANG == "t3" ]]; then
npm create t3-app@latest
elif [[ $LANG == "go" ]]; then
mkdir $NAME;
cd $NAME;
go mod init;
elif [[ $LANG == "react" ]]; then
npm create vite@latest $NAME
cd $NAME
npm install
mark
# Create a new PHP project.
elif [[ $LANG == "php" ]]; then
cp -r ~/templates/web/php/ $NAME
cd $NAME
read "?Use Composer (y/N): " COMPOSER
if [[ $COMPOSER == "y" ]]; then
composer init
fi
mark
fi
read "?Git project (y/N): " GIT
# If the user indicated the project will be a Git project, then run the ginit script.
if [[ $GIT == "y" || $GIT == "Y" ]]; then
ginit;
fi