Automate Your Flask Project Setup with This Simple Batch Script

Code Snippet with Copy Button

@echo off
:: Display welcome message in green using PowerShell
powershell -command "Write-Host 'Welcome to Ripon Sarkar Portfolio' -ForegroundColor Green"
powershell -command "Write-Host 'by this tool you can create a standard level flask project structure' -ForegroundColor Cyan"
powershell -command "Write-Host 'Happy Coding :)' -ForegroundColor Yellow"

echo ---------------------------------------------------------------------

:: Prompt the user to enter the project name
set /p projectName="Enter the Flask project name: "

:: Create main project folder
mkdir %projectName%
cd %projectName%

:: Create Flask folders
mkdir app
mkdir app\static
mkdir app\static\css
mkdir app\static\js
mkdir app\static\images
mkdir app\templates
mkdir app\files

:: Create basic HTML file
echo ^<!DOCTYPE html^> > app\templates\index.html
echo ^<html lang="en"^> >> app\templates\index.html
echo ^<head^> >> app\templates\index.html
echo    ^<meta charset="UTF-8"^> >> app\templates\index.html
echo    ^<meta name="viewport" content="width=device-width, initial-scale=1.0"^> >> app\templates\index.html
echo    ^<title^>Flask Project^</title^> >> app\templates\index.html
echo    ^<link rel="stylesheet" href="^^{{ url_for('static', filename='css/style.css') ^^}}"^> >> app\templates\index.html
echo ^</head^> >> app\templates\index.html
echo ^<body^> >> app\templates\index.html
echo    ^<h1^>Welcome to %projectName%^</h1^> >> app\templates\index.html
echo    ^<script src="^^{{ url_for('static', filename='js/script.js') ^^}}"^>^</script^> >> app\templates\index.html
echo ^</body^> >> app\templates\index.html
echo ^</html^> >> app\templates\index.html


:: Create basic CSS file
echo /* Basic styling */ > app\static\css\style.css
echo body { >> app\static\css\style.css
echo    font-family: Arial, sans-serif; >> app\static\css\style.css
echo    background-color: #f4f4f4; >> app\static\css\style.css
echo    color: #333; >> app\static\css\style.css
echo } >> app\static\css\style.css

:: Create basic JS file
echo // Basic JavaScript file > app\static\js\script.js
echo console.log("JavaScript is connected!"); >> app\static\js\script.js

:: Create a basic Flask app file
echo from flask import Flask, render_template > app\__init__.py
echo. >> app\__init__.py
echo app = Flask(__name__) >> app\__init__.py
echo. >> app\__init__.py
echo @app.route("/") >> app\__init__.py
echo def home(): >> app\__init__.py
echo     return render_template("index.html") >> app\__init__.py
echo. >> app\__init__.py
echo if __name__ == "__main__": >> app\__init__.py
echo     app.run(debug=True) >> app\__init__.py

:: Create run script
echo from app import app > run.py

:: Create placeholder data file
echo Data placeholder > app\files\data.txt

:: Create requirements.txt file
echo flask > requirements.txt

:: Create readme.txt file with VSCode instructions
echo Instruction for VSCode Editor User > readme.txt
echo. >> readme.txt
echo 1. Select Project folder and open in VSCode Editor >> readme.txt
echo. >> readme.txt
echo 2. Open New Terminal >> readme.txt
echo. >> readme.txt
echo Create Virtual Environment for run Python. >> readme.txt
echo     python -m venv venv (hit Enter on keyboard) >> readme.txt
echo. >> readme.txt
echo     # you get a prompt down-right side of the vscode editor >> readme.txt
echo     # We noticed a new environment has been created. Do you want to select it for the workspace folder >> readme.txt
echo     # click on Yes button. >> readme.txt
echo. >> readme.txt
echo Set Execution Policy >> readme.txt
echo     Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned (hit Enter on keyboard) >> readme.txt
echo. >> readme.txt
echo Activate Virtual Environment >> readme.txt
echo     .\venv\Scripts\Activate (hit Enter on keyboard) >> readme.txt
echo. >> readme.txt
echo     # after this command you can see in terminal (venv) is in green color, means it activated. >> readme.txt
echo. >> readme.txt
echo Install Required Packages >> readme.txt
echo     pip install -r requirements.txt >> readme.txt

echo Project structure for %projectName% created successfully!
pause