quantum-framework 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. quantum/__init__.py +1 -0
  2. quantum/cli/__init__.py +2 -0
  3. quantum/cli/commands/__init__.py +15 -0
  4. quantum/cli/commands/build.py +417 -0
  5. quantum/cli/commands/dev.py +185 -0
  6. quantum/cli/commands/docs.py +329 -0
  7. quantum/cli/commands/lint.py +523 -0
  8. quantum/cli/commands/migrate.py +527 -0
  9. quantum/cli/commands/new.py +622 -0
  10. quantum/cli/commands/serve.py +190 -0
  11. quantum/cli/commands/test.py +193 -0
  12. quantum/cli/deploy.py +810 -0
  13. quantum/cli/hot_reload.py +951 -0
  14. quantum/cli/jobs.py +356 -0
  15. quantum/cli/mq.py +582 -0
  16. quantum/cli/pkg.py +390 -0
  17. quantum/cli/runner.py +547 -0
  18. quantum/cli/server_process.py +159 -0
  19. quantum/cli/utils.py +334 -0
  20. quantum/compiler/__init__.py +30 -0
  21. quantum/compiler/base_generator.py +367 -0
  22. quantum/compiler/cli.py +295 -0
  23. quantum/compiler/expression_transformer.py +444 -0
  24. quantum/compiler/javascript/__init__.py +10 -0
  25. quantum/compiler/javascript/generator.py +659 -0
  26. quantum/compiler/optimizer.py +270 -0
  27. quantum/compiler/python/__init__.py +10 -0
  28. quantum/compiler/python/generator.py +883 -0
  29. quantum/compiler/python/runtime.py +863 -0
  30. quantum/compiler/transpiler.py +330 -0
  31. quantum/core/__init__.py +3 -0
  32. quantum/core/ast_nodes.py +2611 -0
  33. quantum/core/expression_diagnostics.py +87 -0
  34. quantum/core/expression_stdlib.py +148 -0
  35. quantum/core/expressions.py +591 -0
  36. quantum/core/features/agents/src/__init__.py +30 -0
  37. quantum/core/features/agents/src/ast_node.py +540 -0
  38. quantum/core/features/conditionals/src/__init__.py +8 -0
  39. quantum/core/features/conditionals/src/ast_node.py +68 -0
  40. quantum/core/features/data_fetching/src/__init__.py +21 -0
  41. quantum/core/features/data_fetching/src/ast_node.py +312 -0
  42. quantum/core/features/data_fetching/src/desktop_adapter.py +351 -0
  43. quantum/core/features/data_fetching/src/html_adapter.py +474 -0
  44. quantum/core/features/data_fetching/src/parser.py +225 -0
  45. quantum/core/features/data_import/src/__init__.py +0 -0
  46. quantum/core/features/data_import/src/ast_node.py +291 -0
  47. quantum/core/features/data_import/src/runtime.py +538 -0
  48. quantum/core/features/dump/src/__init__.py +12 -0
  49. quantum/core/features/dump/src/ast_node.py +106 -0
  50. quantum/core/features/dump/src/parser.py +61 -0
  51. quantum/core/features/dump/src/runtime.py +246 -0
  52. quantum/core/features/functions/src/__init__.py +8 -0
  53. quantum/core/features/functions/src/ast_node.py +149 -0
  54. quantum/core/features/game_engine_2d/src/__init__.py +19 -0
  55. quantum/core/features/game_engine_2d/src/ast_nodes.py +1719 -0
  56. quantum/core/features/game_engine_2d/src/parser.py +983 -0
  57. quantum/core/features/invocation/src/__init__.py +0 -0
  58. quantum/core/features/invocation/src/ast_node.py +146 -0
  59. quantum/core/features/invocation/src/runtime.py +327 -0
  60. quantum/core/features/knowledge_base/src/__init__.py +6 -0
  61. quantum/core/features/knowledge_base/src/ast_node.py +113 -0
  62. quantum/core/features/knowledge_base/src/parser.py +82 -0
  63. quantum/core/features/logging/src/__init__.py +12 -0
  64. quantum/core/features/logging/src/ast_node.py +111 -0
  65. quantum/core/features/logging/src/parser.py +50 -0
  66. quantum/core/features/logging/src/runtime.py +190 -0
  67. quantum/core/features/loops/src/__init__.py +8 -0
  68. quantum/core/features/loops/src/ast_node.py +60 -0
  69. quantum/core/features/query/src/__init__.py +0 -0
  70. quantum/core/features/query/src/database_service.py +322 -0
  71. quantum/core/features/query/src/query_validators.py +20 -0
  72. quantum/core/features/state_management/src/__init__.py +11 -0
  73. quantum/core/features/state_management/src/ast_node.py +228 -0
  74. quantum/core/features/terminal_engine/src/__init__.py +21 -0
  75. quantum/core/features/terminal_engine/src/ast_nodes.py +560 -0
  76. quantum/core/features/terminal_engine/src/parser.py +361 -0
  77. quantum/core/features/testing_engine/src/__init__.py +41 -0
  78. quantum/core/features/testing_engine/src/ast_nodes.py +1212 -0
  79. quantum/core/features/testing_engine/src/parser.py +604 -0
  80. quantum/core/features/theming/src/__init__.py +48 -0
  81. quantum/core/features/theming/src/ast_node.py +137 -0
  82. quantum/core/features/theming/src/presets.py +405 -0
  83. quantum/core/features/ui_engine/src/__init__.py +20 -0
  84. quantum/core/features/ui_engine/src/ast_nodes.py +1854 -0
  85. quantum/core/features/ui_engine/src/parser.py +1106 -0
  86. quantum/core/features/websocket/src/__init__.py +24 -0
  87. quantum/core/features/websocket/src/ast_node.py +247 -0
  88. quantum/core/html_compat.py +299 -0
  89. quantum/core/parser.py +1235 -0
  90. quantum/core/parser_registry.py +213 -0
  91. quantum/core/parsers/__init__.py +76 -0
  92. quantum/core/parsers/ai/__init__.py +12 -0
  93. quantum/core/parsers/ai/agent_parser.py +106 -0
  94. quantum/core/parsers/ai/knowledge_parser.py +86 -0
  95. quantum/core/parsers/ai/llm_parser.py +78 -0
  96. quantum/core/parsers/ai/team_parser.py +88 -0
  97. quantum/core/parsers/base.py +322 -0
  98. quantum/core/parsers/composition/__init__.py +10 -0
  99. quantum/core/parsers/composition/import_parser.py +50 -0
  100. quantum/core/parsers/composition/slot_parser.py +48 -0
  101. quantum/core/parsers/control_flow/__init__.py +11 -0
  102. quantum/core/parsers/control_flow/if_parser.py +68 -0
  103. quantum/core/parsers/control_flow/loop_parser.py +105 -0
  104. quantum/core/parsers/control_flow/set_parser.py +89 -0
  105. quantum/core/parsers/data/__init__.py +12 -0
  106. quantum/core/parsers/data/data_parser.py +217 -0
  107. quantum/core/parsers/data/invoke_parser.py +116 -0
  108. quantum/core/parsers/data/query_parser.py +188 -0
  109. quantum/core/parsers/data/transaction_parser.py +77 -0
  110. quantum/core/parsers/events/__init__.py +9 -0
  111. quantum/core/parsers/events/dispatch_event_parser.py +44 -0
  112. quantum/core/parsers/forms/__init__.py +11 -0
  113. quantum/core/parsers/forms/action_parser.py +54 -0
  114. quantum/core/parsers/forms/flash_parser.py +34 -0
  115. quantum/core/parsers/forms/redirect_parser.py +33 -0
  116. quantum/core/parsers/functions/__init__.py +11 -0
  117. quantum/core/parsers/functions/function_parser.py +137 -0
  118. quantum/core/parsers/functions/param_parser.py +66 -0
  119. quantum/core/parsers/functions/return_parser.py +31 -0
  120. quantum/core/parsers/html/__init__.py +10 -0
  121. quantum/core/parsers/html/component_call_parser.py +130 -0
  122. quantum/core/parsers/html/html_parser.py +115 -0
  123. quantum/core/parsers/jobs/__init__.py +11 -0
  124. quantum/core/parsers/jobs/job_parser.py +71 -0
  125. quantum/core/parsers/jobs/schedule_parser.py +62 -0
  126. quantum/core/parsers/jobs/thread_parser.py +57 -0
  127. quantum/core/parsers/messaging/__init__.py +17 -0
  128. quantum/core/parsers/messaging/message_ack_parser.py +30 -0
  129. quantum/core/parsers/messaging/message_nack_parser.py +30 -0
  130. quantum/core/parsers/messaging/message_parser.py +114 -0
  131. quantum/core/parsers/messaging/queue_parser.py +61 -0
  132. quantum/core/parsers/messaging/websocket_parser.py +121 -0
  133. quantum/core/parsers/persistence/__init__.py +9 -0
  134. quantum/core/parsers/persistence/persist_parser.py +64 -0
  135. quantum/core/parsers/routing/__init__.py +9 -0
  136. quantum/core/parsers/routing/route_parser.py +41 -0
  137. quantum/core/parsers/scripting/__init__.py +12 -0
  138. quantum/core/parsers/scripting/pyclass_parser.py +62 -0
  139. quantum/core/parsers/scripting/pydecorator_parser.py +68 -0
  140. quantum/core/parsers/scripting/pyimport_parser.py +52 -0
  141. quantum/core/parsers/scripting/python_parser.py +49 -0
  142. quantum/core/parsers/services/__init__.py +12 -0
  143. quantum/core/parsers/services/dump_parser.py +52 -0
  144. quantum/core/parsers/services/file_parser.py +48 -0
  145. quantum/core/parsers/services/log_parser.py +46 -0
  146. quantum/core/parsers/services/mail_parser.py +65 -0
  147. quantum/core/tiers.py +82 -0
  148. quantum/packages/__init__.py +28 -0
  149. quantum/packages/manager.py +413 -0
  150. quantum/packages/manifest.py +351 -0
  151. quantum/packages/registry.py +399 -0
  152. quantum/packages/resolver.py +336 -0
  153. quantum/plugins/__init__.py +33 -0
  154. quantum/plugins/hooks.py +329 -0
  155. quantum/plugins/loader.py +479 -0
  156. quantum/plugins/manifest.py +336 -0
  157. quantum/plugins/registry.py +371 -0
  158. quantum/runtime/__init__.py +28 -0
  159. quantum/runtime/action_handler.py +443 -0
  160. quantum/runtime/adapters/__init__.py +88 -0
  161. quantum/runtime/adapters/memory_adapter.py +690 -0
  162. quantum/runtime/adapters/rabbitmq_adapter.py +715 -0
  163. quantum/runtime/adapters/redis_adapter.py +582 -0
  164. quantum/runtime/adapters/sqlite_adapter.py +414 -0
  165. quantum/runtime/agent_service.py +1133 -0
  166. quantum/runtime/api_server.py +86 -0
  167. quantum/runtime/ast_cache.py +506 -0
  168. quantum/runtime/auth_service.py +267 -0
  169. quantum/runtime/component.py +990 -0
  170. quantum/runtime/component_composer.py +319 -0
  171. quantum/runtime/component_resolver.py +174 -0
  172. quantum/runtime/database_service.py +598 -0
  173. quantum/runtime/email_service.py +162 -0
  174. quantum/runtime/error_handler.py +295 -0
  175. quantum/runtime/execution_context.py +286 -0
  176. quantum/runtime/executor_registry.py +171 -0
  177. quantum/runtime/executors/__init__.py +71 -0
  178. quantum/runtime/executors/ai/__init__.py +12 -0
  179. quantum/runtime/executors/ai/agent_executor.py +217 -0
  180. quantum/runtime/executors/ai/knowledge_executor.py +114 -0
  181. quantum/runtime/executors/ai/llm_executor.py +153 -0
  182. quantum/runtime/executors/ai/team_executor.py +171 -0
  183. quantum/runtime/executors/base.py +262 -0
  184. quantum/runtime/executors/control_flow/__init__.py +11 -0
  185. quantum/runtime/executors/control_flow/if_executor.py +93 -0
  186. quantum/runtime/executors/control_flow/loop_executor.py +307 -0
  187. quantum/runtime/executors/control_flow/set_executor.py +412 -0
  188. quantum/runtime/executors/data/__init__.py +12 -0
  189. quantum/runtime/executors/data/data_executor.py +145 -0
  190. quantum/runtime/executors/data/invoke_executor.py +176 -0
  191. quantum/runtime/executors/data/query_executor.py +256 -0
  192. quantum/runtime/executors/data/transaction_executor.py +91 -0
  193. quantum/runtime/executors/jobs/__init__.py +11 -0
  194. quantum/runtime/executors/jobs/job_executor.py +190 -0
  195. quantum/runtime/executors/jobs/schedule_executor.py +132 -0
  196. quantum/runtime/executors/jobs/thread_executor.py +127 -0
  197. quantum/runtime/executors/messaging/__init__.py +17 -0
  198. quantum/runtime/executors/messaging/message_ack_executor.py +51 -0
  199. quantum/runtime/executors/messaging/message_executor.py +174 -0
  200. quantum/runtime/executors/messaging/queue_executor.py +103 -0
  201. quantum/runtime/executors/messaging/websocket_executor.py +197 -0
  202. quantum/runtime/executors/scripting/__init__.py +11 -0
  203. quantum/runtime/executors/scripting/pyclass_executor.py +90 -0
  204. quantum/runtime/executors/scripting/pyimport_executor.py +81 -0
  205. quantum/runtime/executors/scripting/python_executor.py +249 -0
  206. quantum/runtime/executors/services/__init__.py +12 -0
  207. quantum/runtime/executors/services/dump_executor.py +72 -0
  208. quantum/runtime/executors/services/file_executor.py +89 -0
  209. quantum/runtime/executors/services/log_executor.py +77 -0
  210. quantum/runtime/executors/services/mail_executor.py +81 -0
  211. quantum/runtime/expression_cache.py +498 -0
  212. quantum/runtime/file_upload_service.py +326 -0
  213. quantum/runtime/function_registry.py +118 -0
  214. quantum/runtime/game_builder.py +166 -0
  215. quantum/runtime/game_code_generator.py +2371 -0
  216. quantum/runtime/game_templates.py +2006 -0
  217. quantum/runtime/godot_code_generator.py +4681 -0
  218. quantum/runtime/godot_templates.py +1449 -0
  219. quantum/runtime/job_executor.py +1599 -0
  220. quantum/runtime/knowledge_service.py +500 -0
  221. quantum/runtime/llm_cache.py +100 -0
  222. quantum/runtime/llm_providers.py +704 -0
  223. quantum/runtime/llm_service.py +287 -0
  224. quantum/runtime/logging_setup.py +140 -0
  225. quantum/runtime/message_broker.py +364 -0
  226. quantum/runtime/message_queue_service.py +571 -0
  227. quantum/runtime/param_validation.py +184 -0
  228. quantum/runtime/pypy_compat.py +315 -0
  229. quantum/runtime/python_bridge.py +698 -0
  230. quantum/runtime/query_validators.py +304 -0
  231. quantum/runtime/renderer.py +733 -0
  232. quantum/runtime/service_container.py +444 -0
  233. quantum/runtime/terminal_builder.py +76 -0
  234. quantum/runtime/terminal_code_generator.py +607 -0
  235. quantum/runtime/terminal_templates.py +243 -0
  236. quantum/runtime/testing_builder.py +77 -0
  237. quantum/runtime/testing_code_generator.py +833 -0
  238. quantum/runtime/testing_templates.py +85 -0
  239. quantum/runtime/ui_builder.py +188 -0
  240. quantum/runtime/ui_desktop_adapter.py +1730 -0
  241. quantum/runtime/ui_desktop_templates.py +307 -0
  242. quantum/runtime/ui_html_adapter.py +2691 -0
  243. quantum/runtime/ui_html_templates.py +2297 -0
  244. quantum/runtime/ui_mobile_adapter.py +1832 -0
  245. quantum/runtime/ui_mobile_templates.py +1003 -0
  246. quantum/runtime/ui_textual_adapter.py +1866 -0
  247. quantum/runtime/ui_textual_templates.py +45 -0
  248. quantum/runtime/ui_tokens.py +465 -0
  249. quantum/runtime/ui_validator.py +365 -0
  250. quantum/runtime/validators.py +256 -0
  251. quantum/runtime/web_server.py +1766 -0
  252. quantum/runtime/websocket_adapter.py +501 -0
  253. quantum/runtime/websocket_service.py +585 -0
  254. quantum/runtime/websocket_transport.py +289 -0
  255. quantum/runtime/wsgi.py +101 -0
  256. quantum/utils/__init__.py +1 -0
  257. quantum_framework-0.9.0.dist-info/METADATA +244 -0
  258. quantum_framework-0.9.0.dist-info/RECORD +262 -0
  259. quantum_framework-0.9.0.dist-info/WHEEL +5 -0
  260. quantum_framework-0.9.0.dist-info/entry_points.txt +2 -0
  261. quantum_framework-0.9.0.dist-info/licenses/LICENSE +21 -0
  262. quantum_framework-0.9.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,622 @@
1
+ """
2
+ Quantum CLI - New Command
3
+
4
+ Create new Quantum projects with templates.
5
+ """
6
+
7
+ import os
8
+ import shutil
9
+ from pathlib import Path
10
+ from typing import Optional
11
+
12
+ import click
13
+
14
+ from quantum.cli.utils import get_console, validate_project_name
15
+
16
+
17
+ # Project templates
18
+ TEMPLATES = {
19
+ 'default': 'Basic Quantum web application',
20
+ 'api': 'REST API with microservices',
21
+ 'game': '2D game with canvas',
22
+ 'terminal': 'Terminal TUI application',
23
+ 'component-lib': 'Reusable component library',
24
+ }
25
+
26
+
27
+ @click.command('new')
28
+ @click.argument('project_name')
29
+ @click.option('--template', '-t', type=click.Choice(list(TEMPLATES.keys())), default='default',
30
+ help='Project template to use')
31
+ @click.option('--directory', '-d', type=click.Path(), default=None,
32
+ help='Directory to create project in (default: project name)')
33
+ @click.option('--no-git', is_flag=True, help='Skip git initialization')
34
+ @click.option('--quiet', '-q', is_flag=True, help='Quiet mode - minimal output')
35
+ def new(project_name: str, template: str, directory: Optional[str], no_git: bool, quiet: bool):
36
+ """Create a new Quantum project.
37
+
38
+ PROJECT_NAME is the name of your new project.
39
+
40
+ Examples:
41
+
42
+ quantum new my-app
43
+
44
+ quantum new my-api --template api
45
+
46
+ quantum new my-game -t game -d ./projects
47
+ """
48
+ console = get_console(quiet=quiet)
49
+
50
+ # Validate project name
51
+ is_valid, error = validate_project_name(project_name)
52
+ if not is_valid:
53
+ console.error(error)
54
+ raise click.Abort()
55
+
56
+ # Determine project directory
57
+ if directory:
58
+ project_dir = Path(directory) / project_name
59
+ else:
60
+ project_dir = Path.cwd() / project_name
61
+
62
+ # Check if directory exists
63
+ if project_dir.exists():
64
+ console.error(f"Directory already exists: {project_dir}")
65
+ raise click.Abort()
66
+
67
+ console.header(
68
+ "Creating Quantum Project",
69
+ f"Template: {template} | Location: {project_dir}"
70
+ )
71
+
72
+ try:
73
+ with console.spinner("Creating project structure..."):
74
+ _create_project_structure(project_dir, project_name, template)
75
+
76
+ if not no_git:
77
+ with console.spinner("Initializing git repository..."):
78
+ _init_git(project_dir)
79
+
80
+ console.success(f"Project '{project_name}' created successfully!")
81
+ console.print()
82
+ console.panel(
83
+ f"[bold]Next steps:[/bold]\n\n"
84
+ f" cd {project_name}\n"
85
+ f" quantum dev\n\n"
86
+ f"[dim]Open http://localhost:8080 in your browser[/dim]",
87
+ title="Get Started"
88
+ )
89
+
90
+ except Exception as e:
91
+ console.error(f"Failed to create project: {e}")
92
+ # Cleanup on failure
93
+ if project_dir.exists():
94
+ shutil.rmtree(project_dir)
95
+ raise click.Abort()
96
+
97
+
98
+ def _create_project_structure(project_dir: Path, project_name: str, template: str) -> None:
99
+ """Create the project directory structure."""
100
+ # Create directories
101
+ dirs = [
102
+ 'components',
103
+ 'pages',
104
+ 'layouts',
105
+ 'assets/css',
106
+ 'assets/js',
107
+ 'assets/images',
108
+ 'data',
109
+ ]
110
+
111
+ for d in dirs:
112
+ (project_dir / d).mkdir(parents=True, exist_ok=True)
113
+
114
+ # Create quantum.config.yaml
115
+ config_content = f"""# Quantum Configuration
116
+ # Generated for: {project_name}
117
+
118
+ app:
119
+ name: {project_name}
120
+ version: 1.0.0
121
+ type: {_get_app_type(template)}
122
+
123
+ server:
124
+ port: 8080
125
+ host: 0.0.0.0
126
+ debug: true
127
+ reload: true
128
+
129
+ database:
130
+ default:
131
+ driver: sqlite
132
+ path: ./data/{project_name}.db
133
+
134
+ templates:
135
+ components_dir: ./components
136
+ layouts_dir: ./layouts
137
+ pages_dir: ./pages
138
+
139
+ build:
140
+ output_dir: ./dist
141
+ minify: true
142
+ sourcemaps: true
143
+
144
+ # Environment-specific overrides
145
+ environments:
146
+ development:
147
+ server:
148
+ debug: true
149
+ reload: true
150
+ production:
151
+ server:
152
+ debug: false
153
+ reload: false
154
+ """
155
+ (project_dir / 'quantum.config.yaml').write_text(config_content)
156
+
157
+ # Create template-specific files
158
+ if template == 'default':
159
+ _create_default_template(project_dir, project_name)
160
+ elif template == 'api':
161
+ _create_api_template(project_dir, project_name)
162
+ elif template == 'game':
163
+ _create_game_template(project_dir, project_name)
164
+ elif template == 'terminal':
165
+ _create_terminal_template(project_dir, project_name)
166
+ elif template == 'component-lib':
167
+ _create_component_lib_template(project_dir, project_name)
168
+
169
+ # Create .gitignore
170
+ gitignore = """# Quantum
171
+ dist/
172
+ .quantum/
173
+ *.pyc
174
+ __pycache__/
175
+
176
+ # Environment
177
+ .env
178
+ .env.local
179
+ .env.*.local
180
+
181
+ # Databases
182
+ *.db
183
+ *.sqlite
184
+
185
+ # Logs
186
+ *.log
187
+ logs/
188
+
189
+ # OS
190
+ .DS_Store
191
+ Thumbs.db
192
+
193
+ # IDE
194
+ .idea/
195
+ .vscode/
196
+ *.swp
197
+ *.swo
198
+
199
+ # Dependencies
200
+ node_modules/
201
+ .venv/
202
+ venv/
203
+ """
204
+ (project_dir / '.gitignore').write_text(gitignore)
205
+
206
+
207
+ def _get_app_type(template: str) -> str:
208
+ """Get app type from template."""
209
+ type_map = {
210
+ 'default': 'html',
211
+ 'api': 'api',
212
+ 'game': 'game',
213
+ 'terminal': 'terminal',
214
+ 'component-lib': 'library',
215
+ }
216
+ return type_map.get(template, 'html')
217
+
218
+
219
+ def _create_default_template(project_dir: Path, project_name: str) -> None:
220
+ """Create default web application template."""
221
+ # Main layout
222
+ layout = f"""<!-- Main Layout -->
223
+ <q:component name="MainLayout" xmlns:q="https://quantum.lang/ns">
224
+ <q:param name="title" type="string" default="{project_name}" />
225
+
226
+ <html lang="en">
227
+ <head>
228
+ <meta charset="UTF-8" />
229
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
230
+ <title>{{title}}</title>
231
+ <link rel="stylesheet" href="/assets/css/style.css" />
232
+ </head>
233
+ <body>
234
+ <header>
235
+ <nav>
236
+ <a href="/" class="logo">{project_name}</a>
237
+ <ul>
238
+ <li><a href="/">Home</a></li>
239
+ <li><a href="/about">About</a></li>
240
+ </ul>
241
+ </nav>
242
+ </header>
243
+
244
+ <main>
245
+ <q:children />
246
+ </main>
247
+
248
+ <footer>
249
+ <p>Built with Quantum Framework</p>
250
+ </footer>
251
+ </body>
252
+ </html>
253
+ </q:component>
254
+ """
255
+ (project_dir / 'layouts' / 'main.q').write_text(layout)
256
+
257
+ # Home page
258
+ home = f"""<!-- Home Page -->
259
+ <q:component name="HomePage" xmlns:q="https://quantum.lang/ns">
260
+ <q:layout name="MainLayout" title="Welcome to {project_name}" />
261
+
262
+ <section class="hero">
263
+ <h1>Welcome to {project_name}</h1>
264
+ <p>Your Quantum application is ready!</p>
265
+
266
+ <q:set name="counter" value="0" />
267
+
268
+ <div class="counter">
269
+ <p>Counter: {{counter}}</p>
270
+ <q:action on="click" set="counter" value="{{counter + 1}}">
271
+ <button>Increment</button>
272
+ </q:action>
273
+ </div>
274
+ </section>
275
+ </q:component>
276
+ """
277
+ (project_dir / 'pages' / 'home.q').write_text(home)
278
+
279
+ # CSS
280
+ css = """/* Quantum Default Styles */
281
+ * {
282
+ margin: 0;
283
+ padding: 0;
284
+ box-sizing: border-box;
285
+ }
286
+
287
+ :root {
288
+ --primary: #6366f1;
289
+ --primary-hover: #4f46e5;
290
+ --bg: #f8fafc;
291
+ --text: #1e293b;
292
+ --text-muted: #64748b;
293
+ }
294
+
295
+ body {
296
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
297
+ background: var(--bg);
298
+ color: var(--text);
299
+ line-height: 1.6;
300
+ }
301
+
302
+ header {
303
+ background: white;
304
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
305
+ padding: 1rem 2rem;
306
+ }
307
+
308
+ nav {
309
+ display: flex;
310
+ justify-content: space-between;
311
+ align-items: center;
312
+ max-width: 1200px;
313
+ margin: 0 auto;
314
+ }
315
+
316
+ .logo {
317
+ font-size: 1.5rem;
318
+ font-weight: bold;
319
+ color: var(--primary);
320
+ text-decoration: none;
321
+ }
322
+
323
+ nav ul {
324
+ display: flex;
325
+ list-style: none;
326
+ gap: 2rem;
327
+ }
328
+
329
+ nav a {
330
+ color: var(--text);
331
+ text-decoration: none;
332
+ transition: color 0.2s;
333
+ }
334
+
335
+ nav a:hover {
336
+ color: var(--primary);
337
+ }
338
+
339
+ main {
340
+ max-width: 1200px;
341
+ margin: 0 auto;
342
+ padding: 2rem;
343
+ }
344
+
345
+ .hero {
346
+ text-align: center;
347
+ padding: 4rem 0;
348
+ }
349
+
350
+ .hero h1 {
351
+ font-size: 3rem;
352
+ margin-bottom: 1rem;
353
+ }
354
+
355
+ .hero p {
356
+ color: var(--text-muted);
357
+ font-size: 1.25rem;
358
+ }
359
+
360
+ .counter {
361
+ margin-top: 2rem;
362
+ padding: 2rem;
363
+ background: white;
364
+ border-radius: 8px;
365
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
366
+ display: inline-block;
367
+ }
368
+
369
+ button {
370
+ background: var(--primary);
371
+ color: white;
372
+ border: none;
373
+ padding: 0.75rem 1.5rem;
374
+ border-radius: 6px;
375
+ font-size: 1rem;
376
+ cursor: pointer;
377
+ transition: background 0.2s;
378
+ }
379
+
380
+ button:hover {
381
+ background: var(--primary-hover);
382
+ }
383
+
384
+ footer {
385
+ text-align: center;
386
+ padding: 2rem;
387
+ color: var(--text-muted);
388
+ margin-top: 4rem;
389
+ }
390
+ """
391
+ (project_dir / 'assets' / 'css' / 'style.css').write_text(css)
392
+
393
+ # Application entry point
394
+ app = f"""<!-- Application Entry Point -->
395
+ <q:application id="{project_name}" type="html" xmlns:q="https://quantum.lang/ns">
396
+ <q:route path="/" page="pages/home.q" />
397
+ <q:route path="/about" page="pages/about.q" />
398
+ </q:application>
399
+ """
400
+ (project_dir / 'app.q').write_text(app)
401
+
402
+
403
+ def _create_api_template(project_dir: Path, project_name: str) -> None:
404
+ """Create API template."""
405
+ api = f"""<!-- API Application -->
406
+ <q:application id="{project_name}-api" type="api" xmlns:q="https://quantum.lang/ns">
407
+
408
+ <!-- Health check endpoint -->
409
+ <q:function name="healthCheck" rest="GET /api/health">
410
+ <q:return value='{{"status": "ok", "service": "{project_name}"}}' />
411
+ </q:function>
412
+
413
+ <!-- Users CRUD -->
414
+ <q:component name="UsersAPI">
415
+ <q:function name="listUsers" rest="GET /api/users">
416
+ <q:query name="users" datasource="default">
417
+ SELECT id, name, email, created_at FROM users ORDER BY id
418
+ </q:query>
419
+ <q:return value="{{users}}" />
420
+ </q:function>
421
+
422
+ <q:function name="getUser" rest="GET /api/users/:id">
423
+ <q:param name="id" type="number" required="true" />
424
+ <q:query name="user" datasource="default">
425
+ SELECT * FROM users WHERE id = :id
426
+ </q:query>
427
+ <q:return value="{{user}}" />
428
+ </q:function>
429
+
430
+ <q:function name="createUser" rest="POST /api/users">
431
+ <q:param name="name" type="string" required="true" />
432
+ <q:param name="email" type="string" required="true" />
433
+ <q:query datasource="default">
434
+ INSERT INTO users (name, email) VALUES (:name, :email)
435
+ </q:query>
436
+ <q:return value='{{"success": true}}' />
437
+ </q:function>
438
+ </q:component>
439
+
440
+ </q:application>
441
+ """
442
+ (project_dir / 'api.q').write_text(api)
443
+
444
+ # Update config for API
445
+ config_path = project_dir / 'quantum.config.yaml'
446
+ config = config_path.read_text()
447
+ config = config.replace('type: api', 'type: microservices')
448
+ config_path.write_text(config)
449
+
450
+
451
+ def _create_game_template(project_dir: Path, project_name: str) -> None:
452
+ """Create game template."""
453
+ game = f"""<!-- Game Application -->
454
+ <q:application id="{project_name}" type="game" xmlns:q="https://quantum.lang/ns">
455
+
456
+ <!-- Game Configuration -->
457
+ <q:config width="800" height="600" background="#1a1a2e" />
458
+
459
+ <!-- Assets -->
460
+ <q:assets>
461
+ <q:sprite id="player" src="/assets/images/player.png" />
462
+ </q:assets>
463
+
464
+ <!-- Main Scene -->
465
+ <q:scene id="main" default="true">
466
+ <!-- Player Entity -->
467
+ <q:entity id="player" x="400" y="300">
468
+ <q:sprite ref="player" width="32" height="32" />
469
+ <q:behavior type="keyboard-move" speed="200" />
470
+ </q:entity>
471
+
472
+ <!-- Score Display -->
473
+ <q:entity id="score-display" x="10" y="10">
474
+ <q:text content="Score: 0" font="24px Arial" color="white" />
475
+ </q:entity>
476
+ </q:scene>
477
+
478
+ <!-- Game Over Scene -->
479
+ <q:scene id="gameover">
480
+ <q:entity id="gameover-text" x="400" y="300" anchor="center">
481
+ <q:text content="Game Over!" font="48px Arial" color="red" />
482
+ </q:entity>
483
+ </q:scene>
484
+
485
+ </q:application>
486
+ """
487
+ (project_dir / 'game.q').write_text(game)
488
+
489
+ # Create placeholder sprite
490
+ (project_dir / 'assets' / 'images' / '.gitkeep').write_text('')
491
+
492
+
493
+ def _create_terminal_template(project_dir: Path, project_name: str) -> None:
494
+ """Create terminal TUI template."""
495
+ terminal = f"""<!-- Terminal TUI Application -->
496
+ <q:application id="{project_name}" type="terminal" xmlns:q="https://quantum.lang/ns">
497
+
498
+ <!-- Main Screen -->
499
+ <q:screen id="main" default="true">
500
+ <q:header title="{project_name}" />
501
+
502
+ <q:container layout="vertical">
503
+ <q:text>Welcome to {project_name}!</q:text>
504
+ <q:text>Press 'q' to quit, 'h' for help.</q:text>
505
+
506
+ <q:set name="items" value="['Item 1', 'Item 2', 'Item 3']" />
507
+
508
+ <q:list bind="items" selectable="true" on-select="handleSelect">
509
+ <q:template>
510
+ <q:text>{{item}}</q:text>
511
+ </q:template>
512
+ </q:list>
513
+ </q:container>
514
+
515
+ <q:footer>
516
+ <q:text>[q]uit [h]elp [Enter]select</q:text>
517
+ </q:footer>
518
+ </q:screen>
519
+
520
+ <!-- Keybindings -->
521
+ <q:keybind key="q" action="quit" />
522
+ <q:keybind key="h" action="show-help" />
523
+
524
+ </q:application>
525
+ """
526
+ (project_dir / 'app.q').write_text(terminal)
527
+
528
+
529
+ def _create_component_lib_template(project_dir: Path, project_name: str) -> None:
530
+ """Create component library template."""
531
+ # Button component
532
+ button = """<!-- Button Component -->
533
+ <q:component name="Button" xmlns:q="https://quantum.lang/ns">
534
+ <q:param name="variant" type="string" default="primary" />
535
+ <q:param name="size" type="string" default="medium" />
536
+ <q:param name="disabled" type="boolean" default="false" />
537
+
538
+ <button class="btn btn-{variant} btn-{size}" disabled="{disabled}">
539
+ <q:children />
540
+ </button>
541
+ </q:component>
542
+ """
543
+ (project_dir / 'components' / 'Button.q').write_text(button)
544
+
545
+ # Card component
546
+ card = """<!-- Card Component -->
547
+ <q:component name="Card" xmlns:q="https://quantum.lang/ns">
548
+ <q:param name="title" type="string" />
549
+ <q:param name="elevation" type="number" default="1" />
550
+
551
+ <div class="card elevation-{elevation}">
552
+ <q:if condition="{title}">
553
+ <div class="card-header">
554
+ <h3>{title}</h3>
555
+ </div>
556
+ </q:if>
557
+ <div class="card-body">
558
+ <q:children />
559
+ </div>
560
+ </div>
561
+ </q:component>
562
+ """
563
+ (project_dir / 'components' / 'Card.q').write_text(card)
564
+
565
+ # Input component
566
+ input_comp = """<!-- Input Component -->
567
+ <q:component name="Input" xmlns:q="https://quantum.lang/ns">
568
+ <q:param name="name" type="string" required="true" />
569
+ <q:param name="type" type="string" default="text" />
570
+ <q:param name="label" type="string" />
571
+ <q:param name="placeholder" type="string" />
572
+ <q:param name="required" type="boolean" default="false" />
573
+ <q:param name="error" type="string" />
574
+
575
+ <div class="form-group">
576
+ <q:if condition="{label}">
577
+ <label for="{name}">{label}</label>
578
+ </q:if>
579
+ <input
580
+ type="{type}"
581
+ id="{name}"
582
+ name="{name}"
583
+ placeholder="{placeholder}"
584
+ required="{required}"
585
+ class="{error ? 'has-error' : ''}"
586
+ />
587
+ <q:if condition="{error}">
588
+ <span class="error-message">{error}</span>
589
+ </q:if>
590
+ </div>
591
+ </q:component>
592
+ """
593
+ (project_dir / 'components' / 'Input.q').write_text(input_comp)
594
+
595
+ # Index file
596
+ index = f"""<!-- {project_name} Component Library -->
597
+ <q:component name="{project_name}Index" xmlns:q="https://quantum.lang/ns">
598
+ <!-- Export all components -->
599
+ <q:import component="Button" />
600
+ <q:import component="Card" />
601
+ <q:import component="Input" />
602
+ </q:component>
603
+ """
604
+ (project_dir / 'index.q').write_text(index)
605
+
606
+
607
+ def _init_git(project_dir: Path) -> None:
608
+ """Initialize git repository."""
609
+ import subprocess
610
+
611
+ try:
612
+ subprocess.run(['git', 'init'], cwd=project_dir, capture_output=True, check=True)
613
+ subprocess.run(['git', 'add', '.'], cwd=project_dir, capture_output=True, check=True)
614
+ subprocess.run(
615
+ ['git', 'commit', '-m', 'Initial commit - Quantum project'],
616
+ cwd=project_dir,
617
+ capture_output=True,
618
+ check=True
619
+ )
620
+ except (subprocess.CalledProcessError, FileNotFoundError):
621
+ # Git not available or failed - not critical
622
+ pass