Fix website-creator: add missing functions and templates with IDs
This commit is contained in:
@@ -28,8 +28,11 @@ import sys
|
||||
import argparse
|
||||
import shutil
|
||||
import subprocess
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -425,7 +428,269 @@ def save_analytics_config(output_path: str, config: dict):
|
||||
print(f" ✓ Analytics config saved to context/data-services.json")
|
||||
|
||||
|
||||
# ... (rest of functions remain the same - create_project, sync_to_gitea, etc.)
|
||||
# ============================================================================
|
||||
# PROJECT CREATION FUNCTIONS
|
||||
# ============================================================================
|
||||
|
||||
def create_project(args, languages, default_locale, features):
|
||||
"""Create the Astro project structure with templates."""
|
||||
output_path = Path(args.output)
|
||||
project_name = args.name.lower().replace(' ', '-')
|
||||
site_url = f"https://{project_name}.moreminimore.com"
|
||||
|
||||
# Get template directory
|
||||
script_dir = Path(__file__).parent
|
||||
template_dir = script_dir / 'templates'
|
||||
|
||||
print("\n📁 Creating project structure...")
|
||||
|
||||
# Create directories
|
||||
dirs = [
|
||||
output_path / 'public' / 'images',
|
||||
output_path / 'src' / 'components' / 'common',
|
||||
output_path / 'src' / 'components' / 'consent',
|
||||
output_path / 'src' / 'components' / 'ui',
|
||||
output_path / 'src' / 'layouts',
|
||||
output_path / 'src' / 'pages',
|
||||
output_path / 'src' / 'pages' / default_locale,
|
||||
output_path / 'src' / 'styles',
|
||||
output_path / 'src' / 'content' / 'blog',
|
||||
output_path / 'src' / 'lib',
|
||||
output_path / 'db',
|
||||
]
|
||||
|
||||
for d in dirs:
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
print(" ✓ Directory structure created")
|
||||
|
||||
# Copy templates if they exist
|
||||
if template_dir.exists():
|
||||
print(" 📦 Copying templates with IDs...")
|
||||
|
||||
# Copy layouts
|
||||
layout_src = template_dir / 'layouts' / 'BaseLayout.astro'
|
||||
if layout_src.exists():
|
||||
content = layout_src.read_text(encoding='utf-8')
|
||||
content = content.replace("const siteName = 'Website Name'", f"const siteName = '{args.name}'")
|
||||
content = content.replace("const siteUrl = 'https://example.com'", f"const siteUrl = '{site_url}'")
|
||||
(output_path / 'src' / 'layouts' / 'BaseLayout.astro').write_text(content, encoding='utf-8')
|
||||
|
||||
# Copy Header
|
||||
header_src = template_dir / 'components' / 'common' / 'Header.astro'
|
||||
if header_src.exists():
|
||||
shutil.copy(header_src, output_path / 'src' / 'components' / 'common' / 'Header.astro')
|
||||
|
||||
# Copy Footer
|
||||
footer_src = template_dir / 'components' / 'common' / 'Footer.astro'
|
||||
if footer_src.exists():
|
||||
shutil.copy(footer_src, output_path / 'src' / 'components' / 'common' / 'Footer.astro')
|
||||
|
||||
# Copy page templates
|
||||
page_src = template_dir / 'pages' / 'index.astro'
|
||||
if page_src.exists():
|
||||
shutil.copy(page_src, output_path / 'src' / 'pages' / default_locale / 'index.astro')
|
||||
|
||||
# Copy styles
|
||||
style_src = template_dir / 'styles' / 'global.css'
|
||||
if style_src.exists():
|
||||
shutil.copy(style_src, output_path / 'src' / 'styles' / 'global.css')
|
||||
|
||||
print(" ✓ Templates copied")
|
||||
|
||||
# Create astro.config.mjs
|
||||
locales_str = ', '.join([f"'{lang}'" for lang in languages])
|
||||
astro_config = ASTRO_CONFIG_TEMPLATE.format(
|
||||
site_url=site_url,
|
||||
locales=locales_str,
|
||||
default_locale=default_locale
|
||||
)
|
||||
(output_path / 'astro.config.mjs').write_text(astro_config, encoding='utf-8')
|
||||
print(" ✓ astro.config.mjs created")
|
||||
|
||||
# Create package.json
|
||||
package_json = PACKAGE_JSON_TEMPLATE.format(name=project_name)
|
||||
(output_path / 'package.json').write_text(package_json, encoding='utf-8')
|
||||
print(" ✓ package.json created")
|
||||
|
||||
# Create tsconfig.json
|
||||
tsconfig = """{
|
||||
"extends": "astro/tsconfigs/strict",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
(output_path / 'tsconfig.json').write_text(tsconfig, encoding='utf-8')
|
||||
|
||||
# Create env file
|
||||
env_content = f"""# Website Configuration
|
||||
SITE_NAME={args.name}
|
||||
SITE_URL={site_url}
|
||||
|
||||
# Umami Analytics (optional - get from Umami dashboard)
|
||||
# UMAMI_WEBSITE_ID=
|
||||
# UMAMI_URL=
|
||||
"""
|
||||
(output_path / '.env').write_text(env_content, encoding='utf-8')
|
||||
print(" ✓ Configuration files created")
|
||||
|
||||
# Create basic index page if no template
|
||||
if not (output_path / 'src' / 'pages' / default_locale / 'index.astro').exists():
|
||||
index_content = f"""---
|
||||
import BaseLayout from '../layouts/BaseLayout.astro';
|
||||
import Header from '../components/common/Header.astro';
|
||||
import Footer from '../components/common/Footer.astro';
|
||||
---
|
||||
|
||||
<BaseLayout title="Home" description="Welcome to {args.name}">
|
||||
<Header />
|
||||
<main id="main-content">
|
||||
<section id="hero-section" class="hero">
|
||||
<h1 id="hero-title">Welcome to {args.name}</h1>
|
||||
<p id="hero-subtitle">Your trusted partner</p>
|
||||
</section>
|
||||
</main>
|
||||
<Footer />
|
||||
</BaseLayout>
|
||||
"""
|
||||
(output_path / 'src' / 'pages' / default_locale / 'index.astro').write_text(index_content, encoding='utf-8')
|
||||
|
||||
print(" ✓ Basic pages created")
|
||||
|
||||
# Create Dockerfile
|
||||
dockerfile = f"""FROM node:20-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copy source
|
||||
COPY . .
|
||||
|
||||
# Build
|
||||
RUN npm run build
|
||||
|
||||
# Serve
|
||||
EXPOSE 80
|
||||
CMD ["npm", "run", "preview"]
|
||||
"""
|
||||
(output_path / 'Dockerfile').write_text(dockerfile, encoding='utf-8')
|
||||
print(" ✓ Dockerfile created")
|
||||
|
||||
# Create .gitignore
|
||||
gitignore = """# Dependencies
|
||||
node_modules/
|
||||
|
||||
# Build output
|
||||
dist/
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
"""
|
||||
(output_path / '.gitignore').write_text(gitignore, encoding='utf-8')
|
||||
print(" ✓ .gitignore created")
|
||||
|
||||
return output_path
|
||||
|
||||
|
||||
def sync_to_gitea(output_path: str, repo_name: str) -> str:
|
||||
"""Sync project to Gitea repository."""
|
||||
try:
|
||||
# Import gitea sync functionality
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / 'gitea-sync' / 'scripts'))
|
||||
from sync import sync_repo
|
||||
|
||||
# Use the gitea-sync script
|
||||
result = sync_repo(
|
||||
repo_name=repo_name,
|
||||
repo_path=output_path,
|
||||
description=f"Website: {repo_name}",
|
||||
auto_push=True
|
||||
)
|
||||
if result.get('success'):
|
||||
return result.get('url', f"https://git.moreminimore.com/user/{repo_name}.git")
|
||||
else:
|
||||
print(f" ⚠ Gitea sync failed: {result.get('error')}")
|
||||
return f"https://git.moreminimore.com/user/{repo_name}.git"
|
||||
except Exception as e:
|
||||
print(f" ⚠ Gitea sync error: {e}")
|
||||
print(" Continuing without Gitea sync...")
|
||||
# Return a dummy URL so deployment can continue
|
||||
return f"https://git.moreminimore.com/user/{repo_name}.git"
|
||||
|
||||
|
||||
def deploy_to_easypanel(output_path: str, project_name: str, git_url: str) -> str:
|
||||
"""Deploy project to Easypanel."""
|
||||
try:
|
||||
# Import easypanel deploy functionality
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / 'easypanel-deploy' / 'scripts'))
|
||||
from deploy import (
|
||||
get_session_token,
|
||||
create_service,
|
||||
update_git_source,
|
||||
update_build_type,
|
||||
deploy_service,
|
||||
load_env
|
||||
)
|
||||
|
||||
# Load credentials
|
||||
env = load_env()
|
||||
username = env.get('EASYPANEL_USERNAME', '')
|
||||
password = env.get('EASYPANEL_PASSWORD', '')
|
||||
|
||||
if not username or not password:
|
||||
print(" ⚠ Easypanel credentials not found")
|
||||
print(" Skipping deployment - you can deploy manually later")
|
||||
return f"https://{project_name}.moreminimore.com"
|
||||
|
||||
# Get session token
|
||||
token = get_session_token(username, password)
|
||||
if not token:
|
||||
print(" ⚠ Failed to get Easypanel session")
|
||||
return f"https://{project_name}.moreminimore.com"
|
||||
|
||||
# Create service
|
||||
create_service(project_name, 'web', token)
|
||||
|
||||
# Update git source
|
||||
update_git_source(project_name, 'web', git_url, 'main', token)
|
||||
|
||||
# Set build type to dockerfile
|
||||
update_build_type(project_name, 'web', token, 'dockerfile')
|
||||
|
||||
# Deploy
|
||||
deploy_service(project_name, 'web', token)
|
||||
|
||||
return f"https://{project_name}.moreminimore.com"
|
||||
except Exception as e:
|
||||
print(f" ⚠ Easypanel deployment error: {e}")
|
||||
print(" Continuing without deployment...")
|
||||
return f"https://{project_name}.moreminimore.com"
|
||||
|
||||
|
||||
def monitor_deployment(project_name: str):
|
||||
"""Monitor deployment status."""
|
||||
print(f" 📊 Monitoring deployment for {project_name}...")
|
||||
print(" (Deployment is running in background)")
|
||||
print(" Check status at: https://panelwebsite.moreminimore.com")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user