feat: Deploy-Script für automatisches Deployment zu main
- Prüft ob auf develop Branch - Prüft auf uncommitted changes - Führt Build aus - Kopiert dist/ nach main - Committed und pusht automatisch - Wechselt sicher zurück zu develop
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
"build:js": "node scripts/build.js --js-only",
|
"build:js": "node scripts/build.js --js-only",
|
||||||
"build:css": "node scripts/build.js --css-only",
|
"build:css": "node scripts/build.js --css-only",
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
"watch": "node scripts/watch.js"
|
"watch": "node scripts/watch.js",
|
||||||
|
"deploy": "node scripts/deploy.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"javascript-obfuscator": "^4.1.1",
|
"javascript-obfuscator": "^4.1.1",
|
||||||
|
|||||||
187
scripts/deploy.js
Normal file
187
scripts/deploy.js
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Deploy-Script für HexaHost Backend
|
||||||
|
*
|
||||||
|
* Dieses Script:
|
||||||
|
* 1. Prüft ob wir auf develop sind
|
||||||
|
* 2. Führt den Build aus (npm run build)
|
||||||
|
* 3. Wechselt zu main
|
||||||
|
* 4. Kopiert die dist/ Dateien
|
||||||
|
* 5. Committed und pusht
|
||||||
|
* 6. Wechselt zurück zu develop
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Farben für die Konsole
|
||||||
|
const colors = {
|
||||||
|
reset: '\x1b[0m',
|
||||||
|
green: '\x1b[32m',
|
||||||
|
red: '\x1b[31m',
|
||||||
|
yellow: '\x1b[33m',
|
||||||
|
blue: '\x1b[34m',
|
||||||
|
cyan: '\x1b[36m'
|
||||||
|
};
|
||||||
|
|
||||||
|
function log(message, color = 'reset') {
|
||||||
|
console.log(`${colors[color]}${message}${colors.reset}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function exec(command, options = {}) {
|
||||||
|
try {
|
||||||
|
return execSync(command, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
stdio: options.silent ? 'pipe' : 'inherit',
|
||||||
|
...options
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (!options.ignoreError) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentBranch() {
|
||||||
|
return exec('git branch --show-current', { silent: true }).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasUncommittedChanges() {
|
||||||
|
const status = exec('git status --porcelain', { silent: true });
|
||||||
|
return status && status.trim().length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyRecursive(src, dest) {
|
||||||
|
if (!fs.existsSync(src)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = fs.statSync(src);
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
if (!fs.existsSync(dest)) {
|
||||||
|
fs.mkdirSync(dest, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = fs.readdirSync(src);
|
||||||
|
for (const file of files) {
|
||||||
|
copyRecursive(
|
||||||
|
path.join(src, file),
|
||||||
|
path.join(dest, file)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fs.copyFileSync(src, dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deploy() {
|
||||||
|
log('\n🚀 HexaHost Deploy Script\n', 'cyan');
|
||||||
|
log('=' .repeat(50), 'cyan');
|
||||||
|
|
||||||
|
const startBranch = getCurrentBranch();
|
||||||
|
|
||||||
|
// 1. Prüfen ob wir auf develop sind
|
||||||
|
log('\n📋 Schritt 1: Branch prüfen...', 'blue');
|
||||||
|
if (startBranch !== 'develop') {
|
||||||
|
log(`❌ Du bist auf '${startBranch}', nicht auf 'develop'!`, 'red');
|
||||||
|
log(' Bitte wechsle erst zu develop: git checkout develop', 'yellow');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
log('✅ Auf develop Branch', 'green');
|
||||||
|
|
||||||
|
// 2. Prüfen ob uncommitted changes existieren
|
||||||
|
log('\n📋 Schritt 2: Uncommitted Changes prüfen...', 'blue');
|
||||||
|
if (hasUncommittedChanges()) {
|
||||||
|
log('❌ Es gibt uncommitted changes!', 'red');
|
||||||
|
log(' Bitte erst committen oder stashen.', 'yellow');
|
||||||
|
exec('git status --short');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
log('✅ Keine uncommitted changes', 'green');
|
||||||
|
|
||||||
|
// 3. Build ausführen
|
||||||
|
log('\n📋 Schritt 3: Build ausführen...', 'blue');
|
||||||
|
try {
|
||||||
|
exec('npm run build');
|
||||||
|
log('✅ Build erfolgreich', 'green');
|
||||||
|
} catch (error) {
|
||||||
|
log('❌ Build fehlgeschlagen!', 'red');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Zu main wechseln
|
||||||
|
log('\n📋 Schritt 4: Zu main wechseln...', 'blue');
|
||||||
|
exec('git checkout main');
|
||||||
|
log('✅ Auf main gewechselt', 'green');
|
||||||
|
|
||||||
|
// 5. dist/ Dateien kopieren
|
||||||
|
log('\n📋 Schritt 5: dist/ Dateien aktualisieren...', 'blue');
|
||||||
|
|
||||||
|
// Alte dist/ löschen
|
||||||
|
const distPath = path.join(process.cwd(), 'dist');
|
||||||
|
if (fs.existsSync(distPath)) {
|
||||||
|
fs.rmSync(distPath, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zurück zu develop um dist zu holen
|
||||||
|
exec('git checkout develop -- dist/', { silent: true });
|
||||||
|
log('✅ dist/ Dateien aktualisiert', 'green');
|
||||||
|
|
||||||
|
// 6. Prüfen ob es Änderungen gibt
|
||||||
|
log('\n📋 Schritt 6: Änderungen prüfen...', 'blue');
|
||||||
|
if (!hasUncommittedChanges()) {
|
||||||
|
log('ℹ️ Keine Änderungen in dist/ - nichts zu deployen', 'yellow');
|
||||||
|
exec('git checkout develop');
|
||||||
|
log('\n✅ Zurück auf develop', 'green');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. Commit erstellen
|
||||||
|
log('\n📋 Schritt 7: Commit erstellen...', 'blue');
|
||||||
|
const timestamp = new Date().toISOString().split('T')[0];
|
||||||
|
const commitMessage = `deploy: Produktions-Update ${timestamp}`;
|
||||||
|
|
||||||
|
exec('git add dist/');
|
||||||
|
exec(`git commit -m "${commitMessage}"`);
|
||||||
|
log(`✅ Commit erstellt: "${commitMessage}"`, 'green');
|
||||||
|
|
||||||
|
// 8. Push zu origin
|
||||||
|
log('\n📋 Schritt 8: Push zu origin...', 'blue');
|
||||||
|
try {
|
||||||
|
exec('git push origin main');
|
||||||
|
log('✅ Push erfolgreich', 'green');
|
||||||
|
} catch (error) {
|
||||||
|
log('⚠️ Push fehlgeschlagen - manuell pushen mit: git push origin main', 'yellow');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. Zurück zu develop
|
||||||
|
log('\n📋 Schritt 9: Zurück zu develop...', 'blue');
|
||||||
|
exec('git checkout develop');
|
||||||
|
log('✅ Zurück auf develop', 'green');
|
||||||
|
|
||||||
|
// Fertig!
|
||||||
|
log('\n' + '=' .repeat(50), 'cyan');
|
||||||
|
log('🎉 Deploy erfolgreich abgeschlossen!', 'green');
|
||||||
|
log('=' .repeat(50) + '\n', 'cyan');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Script starten
|
||||||
|
deploy().catch(error => {
|
||||||
|
log(`\n❌ Fehler: ${error.message}`, 'red');
|
||||||
|
|
||||||
|
// Versuche zurück zu develop zu wechseln
|
||||||
|
try {
|
||||||
|
const currentBranch = getCurrentBranch();
|
||||||
|
if (currentBranch !== 'develop') {
|
||||||
|
log('🔄 Versuche zurück zu develop zu wechseln...', 'yellow');
|
||||||
|
exec('git checkout develop', { ignoreError: true });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Ignorieren
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user