97 lines
2.5 KiB
Bash
97 lines
2.5 KiB
Bash
#!/bin/sh
|
|
|
|
# Bestimme das aktuelle Verzeichnis
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
DIR_NAME=$(basename "$DIR")
|
|
|
|
# Entferne vorhandenes Git-Repository, falls vorhanden
|
|
rm -rf .git
|
|
|
|
# Erstelle eine neue React-App mit dem PWA-Template und TypeScript
|
|
npx create-react-app frontend --template cra-template-pwa-typescript
|
|
|
|
# Entferne das automatisch initialisierte Git-Repository
|
|
rm -rf ./frontend/.git
|
|
|
|
# Installiere zusätzliche Abhängigkeiten im Frontend-Verzeichnis
|
|
npm install --prefix frontend
|
|
|
|
# Erstelle das Backend-Verzeichnis und dessen src-Ordner
|
|
mkdir -p backend/src
|
|
|
|
# Initialisiere ein neues npm-Projekt im Backend-Verzeichnis
|
|
npm init -y --prefix backend
|
|
|
|
# Installiere die notwendigen Backend-Abhängigkeiten inklusive TypeScript und Typendefinitionen
|
|
npm i --prefix backend express dotenv @types/express @types/dotenv typescript ts-node
|
|
|
|
|
|
|
|
# Erstelle eine TypeScript-Konfigurationsdatei für das Backend
|
|
echo '{
|
|
"compilerOptions": {
|
|
"target": "esnext",
|
|
"module": "commonjs",
|
|
"strict": true,
|
|
"esModuleInterop": true,
|
|
"skipLibCheck": true,
|
|
"forceConsistentCasingInFileNames": true,
|
|
"outDir": "./dist",
|
|
"rootDir": "./src"
|
|
},
|
|
"include": ["src/**/*"],
|
|
"exclude": ["node_modules", "dist"]
|
|
}' > backend/tsconfig.json
|
|
|
|
# Füge ein Start-Skript zum Backend package.json hinzu
|
|
echo '{
|
|
"scripts": {
|
|
"start": "ts-node src/index.ts",
|
|
"build": "tsc",
|
|
"dev": "nodemon src/index.ts"
|
|
}
|
|
}' > backend/package.json
|
|
|
|
# Erstelle die index.ts Datei im Backend/src-Verzeichnis
|
|
cat <<EOT > backend/src/index.ts
|
|
// Standard-Einstiegspunkt für die App
|
|
import express from 'express';
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
const app = express();
|
|
const NODE_ENV = process.env.NODE_ENV || 'dev';
|
|
const Port = NODE_ENV === "production" ? parseInt(process.env.PORT || '') || 507 : 2210;
|
|
|
|
app.listen(Port, () => {
|
|
console.log(\`Server läuft auf Port \${Port}\`);
|
|
});
|
|
EOT
|
|
|
|
cat <<EOF > docker-compose.yml
|
|
version: "3.3"
|
|
services:
|
|
$DIR_NAME:
|
|
image: $DIR_NAME
|
|
container_name: ${DIR_NAME}_container
|
|
restart: unless-stopped
|
|
networks:
|
|
- Backend
|
|
labels:
|
|
- "traefik.enable=true"
|
|
- "traefik.http.routers.$DIR_NAME.rule=Host(\`${DIR_NAME}.example.com\`)"
|
|
- "traefik.http.routers.$DIR_NAME.entrypoints=websecure"
|
|
- "traefik.http.services.$DIR_NAME.loadbalancer.server.port=80"
|
|
- "traefik.http.routers.$DIR_NAME.service=$DIR_NAME"
|
|
- "traefik.http.routers.$DIR_NAME.tls.certresolver=acme"
|
|
networks:
|
|
Backend:
|
|
external: true
|
|
EOF
|
|
|
|
|
|
git init
|
|
git add .
|
|
git commit -m "Initial template setup"
|