File size: 4,445 Bytes
32e4bbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
"""
Quick Start Script for Cloudflare Manager
This script provides the fastest way to:
1. Deploy a Pages project
2. Bind a domain
3. Get nameservers
"""

import sys
from cloudflare_manager import CloudflareManager, CloudflareAccount


def quickstart():
    """Quick start deployment"""
    print("""
╔══════════════════════════════════════════════════════════╗
β•‘     Cloudflare Manager - Quick Start                    β•‘
β•‘     Deploy Pages + Bind Domain + Get Nameservers        β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
    """)
    
    # Configuration
    print("\nπŸ“ Configuration")
    print("="*60)
    
    email = input("Cloudflare Email: ").strip()
    token = input("Cloudflare API Token: ").strip()
    
    if not email or not token:
        print("βœ— Email and Token are required!")
        return
    
    print("\nπŸ“ Project Information")
    print("="*60)
    
    project_name = input("Pages Project Name: ").strip()
    directory = input("Directory to deploy (default: .): ").strip() or "."
    domain = input("Domain to bind (optional): ").strip()
    
    if not project_name:
        print("βœ— Project name is required!")
        return
    
    # Initialize
    print("\nπŸ”§ Initializing Cloudflare Manager...")
    account = CloudflareAccount(email=email, token=token)
    cf = CloudflareManager(account)
    
    # Step 1: Create project
    print(f"\nπŸ“ Step 1/4: Creating Pages project '{project_name}'...")
    project = cf.create_pages_project(project_name, "main")
    
    if not project:
        print("βœ— Failed to create project")
        return
    
    print(f"βœ“ Project created: https://{project.get('subdomain')}")
    
    # Step 2: Deploy
    print(f"\nπŸ“¦ Step 2/4: Deploying from '{directory}'...")
    deployment = cf.deploy_pages_project(
        project_name=project_name,
        directory=directory,
        branch="main",
        commit_message="Quickstart deployment"
    )
    
    if not deployment:
        print("βœ— Failed to deploy")
        return
    
    print(f"βœ“ Deployed: {deployment.get('url')}")
    
    # Step 3: Domain (if provided)
    zone_id = None
    if domain:
        print(f"\n🌐 Step 3/4: Setting up domain '{domain}'...")
        
        # Create zone
        zone = cf.create_zone(domain)
        if zone:
            zone_id = zone.get("id")
            nameservers = zone.get("name_servers", [])
            
            print(f"\nπŸ“‹ Nameservers (add these to your domain registrar):")
            print("="*60)
            for ns in nameservers:
                print(f"   {ns}")
            print("="*60)
            
            # Bind to Pages
            result = cf.add_pages_domain(project_name, domain)
            if result:
                print(f"βœ“ Domain bound to Pages project")
                
                if result.get('validation_data'):
                    val = result['validation_data']
                    print(f"\nπŸ“‹ DNS Validation Record:")
                    print(f"  Type: {val.get('type')}")
                    print(f"  Name: {val.get('name')}")
                    print(f"  Value: {val.get('value')}")
    else:
        print("\n⏭️  Step 3/4: Skipping domain setup (no domain provided)")
    
    # Step 4: Summary
    print(f"\nβœ… Step 4/4: Summary")
    print("="*60)
    print(f"βœ“ Project: {project_name}")
    print(f"βœ“ URL: {deployment.get('url')}")
    
    if domain:
        print(f"βœ“ Domain: {domain}")
        print(f"\nπŸ“ Next steps:")
        print(f"  1. Update nameservers at your domain registrar")
        print(f"  2. Wait for DNS propagation (5-30 minutes)")
        print(f"  3. Visit https://{domain}")
    else:
        print(f"\nπŸ“ Next steps:")
        print(f"  1. Visit {deployment.get('url')}")
        print(f"  2. (Optional) Add a custom domain later")
    
    print("="*60)
    print("\nπŸŽ‰ Quickstart completed successfully!")


if __name__ == "__main__":
    try:
        quickstart()
    except KeyboardInterrupt:
        print("\n\n⚠️  Interrupted by user")
        sys.exit(0)
    except Exception as e:
        print(f"\nβœ— Error: {e}")
        sys.exit(1)