-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext_setup.py
More file actions
157 lines (135 loc) · 4.79 KB
/
next_setup.py
File metadata and controls
157 lines (135 loc) · 4.79 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import subprocess
import os
import sys
import json
import tkinter as tk
from tkinter import filedialog
def run_command(command, cwd=None):
try:
process = subprocess.Popen(
command,
cwd=cwd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
stdout, stderr = process.communicate()
if process.returncode != 0:
print(f"Command failed: {stderr}")
return False
return True
except Exception as e:
print(f"Error executing command: {str(e)}")
return False
def setup_nextjs(folder_name="nextjs-app"):
try:
# Create and configure root window with HiDPI support
try:
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(2)
except:
pass
root = tk.Tk()
try:
root.tk.call('tk', 'scaling', root.winfo_fpixels('1i')/72.0)
except:
pass
root.withdraw()
path = filedialog.askdirectory(
title="Select Directory for Next.js Project"
)
if not path:
return False
full_path = os.path.join(path, folder_name)
print(f"Creating Next.js project in: {full_path}")
# Create Next.js project with TypeScript and Tailwind
create_command = f"npx create-next-app@latest {folder_name} --ts --tailwind --eslint --app --src-dir --import-alias '@/*' -y --no-turbopack --use-npm --yes"
if not run_command(create_command, cwd=path):
return False
# Update the page.tsx with custom content
page_content = """import Image from 'next/image'
export default function Home() {
return (
<main className="min-h-screen bg-gray-50 flex flex-col items-center justify-center p-4">
<div className="flex gap-8 mb-8">
<div className="hover:scale-110 transition-transform">
<Image
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
</div>
<h1 className="text-4xl font-bold mb-8">
Next.js + TypeScript + Tailwind project initialized by{' '}
<span className="text-purple-600">Scripty</span>
</h1>
<div className="bg-white rounded-xl shadow-lg p-6 mb-8">
<p className="text-gray-600">
Edit <code className="bg-gray-100 px-2 py-1 rounded">src/app/page.tsx</code> and save to test HMR
</p>
</div>
<div className="grid grid-cols-4 gap-4">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className="mb-3 text-2xl font-semibold">
Docs{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
->
</span>
</h2>
<p className="m-0 max-w-[30ch] text-sm opacity-50">
Find in-depth information about Next.js features and API.
</p>
</a>
</div>
</main>
)
}"""
with open(os.path.join(full_path, 'src', 'app', 'page.tsx'), 'w') as f:
f.write(page_content)
return True
except Exception as e:
print(f"Error setting up Next.js project: {e}")
return False
async def func(args):
"""Handler function for Next.js project setup"""
try:
path = args.get("path", os.path.expanduser("~"))
folder_name = args.get("folder_name", "next_project")
if setup_nextjs(folder_name):
return json.dumps({
"success": True,
"message": f"Next.js project created successfully in {folder_name}"
})
else:
return json.dumps({
"success": False,
"error": "Project setup failed"
})
except Exception as e:
return json.dumps({
"success": False,
"error": str(e)
})
object = {
"name": "next_setup",
"description": "Create a new Next.js project with TypeScript and TailwindCSS",
"parameters": {
"type": "object",
"properties": {
"folder_name": {
"type": "string",
"description": "Name of the project folder",
"default": "next_project"
}
}
}
}