robodev 0.10.0 → 0.12.0

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 (197) hide show
  1. package/package.json +1 -1
  2. package/src/collect-files.test.ts +19 -0
  3. package/src/collect-files.ts +1 -0
  4. package/src/config.test.ts +26 -0
  5. package/src/config.ts +34 -5
  6. package/src/emit-starter.test.ts +54 -0
  7. package/src/emit-starter.ts +47 -13
  8. package/src/index.ts +37 -4
  9. package/templates/auth-chat/README.md +1 -1
  10. package/templates/auth-chat/api/health.ts +1 -1
  11. package/templates/auth-chat/api/me.ts +1 -1
  12. package/templates/auth-chat/api/messages.ts +1 -1
  13. package/templates/auth-chat/package.json +1 -1
  14. package/templates/auth-chat/src/main.tsx +5 -5
  15. package/templates/backend/README.md +1 -1
  16. package/templates/backend/api/health.ts +1 -1
  17. package/templates/backend/api/launch.ts +1 -1
  18. package/templates/backend/api/me.ts +1 -1
  19. package/templates/backend/api/motto.ts +1 -1
  20. package/templates/backend/api/planets/[id].ts +1 -1
  21. package/templates/backend/api/planets.ts +1 -1
  22. package/templates/backend/api/rockets.ts +1 -1
  23. package/templates/backend/package.json +1 -1
  24. package/templates/catalog.json +2 -2
  25. package/templates/empty/README.md +1 -1
  26. package/templates/empty/api/health.ts +1 -1
  27. package/templates/empty/package.json +1 -1
  28. package/templates/space/.config/local.spa.template.yml +27 -0
  29. package/templates/space/.oxlint-base.json +29 -0
  30. package/templates/space/.oxlintrc.json +78 -0
  31. package/templates/space/.rulesync/rules/frontend-api-boundary.md +36 -0
  32. package/templates/space/.rulesync/rules/frontend-component-structure.md +38 -0
  33. package/templates/space/.rulesync/rules/frontend-forms.md +32 -0
  34. package/templates/space/.rulesync/rules/frontend-notifications.md +24 -0
  35. package/templates/space/.rulesync/rules/frontend-povio-components.md +42 -0
  36. package/templates/space/.rulesync/rules/frontend-povio-ui.md +45 -0
  37. package/templates/space/.rulesync/rules/frontend-query-autocomplete.md +29 -0
  38. package/templates/space/.rulesync/rules/frontend-tables-and-lists.md +34 -0
  39. package/templates/space/.rulesync/rules/frontend-translations.md +26 -0
  40. package/templates/space/.rulesync/rules/project-overview.md +32 -0
  41. package/templates/space/.rulesync/rules/robodev-api.md +30 -0
  42. package/templates/space/.rulesync/rules/robodev-auth.md +40 -0
  43. package/templates/space/.rulesync/rules/robodev-database.md +22 -0
  44. package/templates/space/.rulesync/rules/role-based-app-structure.md +36 -0
  45. package/templates/space/.rulesync/skills/media-feature/SKILL.md +21 -0
  46. package/templates/space/.rulesync/skills/povio-ui-styling/SKILL.md +208 -0
  47. package/templates/space/.rulesync/skills/povio-ui-styling/agents/openai.yaml +4 -0
  48. package/templates/space/.rulesync/skills/robodev-api-route/SKILL.md +13 -0
  49. package/templates/space/.rulesync/skills/robodev-table/SKILL.md +12 -0
  50. package/templates/space/README.md +26 -7
  51. package/templates/space/api/_lib.ts +359 -0
  52. package/templates/space/api/aliens/labels.ts +19 -0
  53. package/templates/space/api/files/presigned-url.ts +48 -0
  54. package/templates/space/api/files/upload.ts +29 -0
  55. package/templates/space/api/planets/[id]/like.ts +36 -0
  56. package/templates/space/api/planets/[id].ts +56 -13
  57. package/templates/space/api/planets/paginate.ts +36 -0
  58. package/templates/space/api/planets.ts +52 -44
  59. package/templates/space/apps/fe/index.html +24 -0
  60. package/templates/space/apps/fe/openapi-codegen.config.ts +37 -0
  61. package/templates/space/apps/fe/package.json +82 -0
  62. package/templates/space/apps/fe/public/apple-touch-icon.png +0 -0
  63. package/templates/space/apps/fe/public/favicon-96x96.png +0 -0
  64. package/templates/space/apps/fe/public/favicon.ico +0 -0
  65. package/templates/space/apps/fe/public/favicon.svg +3 -0
  66. package/templates/space/apps/fe/public/site.webmanifest +21 -0
  67. package/templates/space/apps/fe/public/web-app-manifest-192x192.png +0 -0
  68. package/templates/space/apps/fe/public/web-app-manifest-512x512.png +0 -0
  69. package/templates/space/apps/fe/src/assets/fonts/GeneralSans-Bold.otf +0 -0
  70. package/templates/space/apps/fe/src/assets/fonts/GeneralSans-Medium.otf +0 -0
  71. package/templates/space/apps/fe/src/assets/fonts/GeneralSans-Regular.otf +0 -0
  72. package/templates/space/apps/fe/src/assets/fonts/GeneralSans-Semibold.otf +0 -0
  73. package/templates/space/apps/fe/src/assets/locales/en/translation.json +301 -0
  74. package/templates/space/apps/fe/src/assets/locales/sl/translation.json +301 -0
  75. package/templates/space/apps/fe/src/clients/app-rest-client.ts +15 -0
  76. package/templates/space/apps/fe/src/clients/auth-token-store.ts +101 -0
  77. package/templates/space/apps/fe/src/clients/rest/app-error-handler.ts +31 -0
  78. package/templates/space/apps/fe/src/clients/rest/interceptors/authorization-header.interceptor.ts +15 -0
  79. package/templates/space/apps/fe/src/clients/rest/interceptors/refresh-token.interceptor.ts +37 -0
  80. package/templates/space/apps/fe/src/clients/rest/interceptors/response.interceptor.ts +17 -0
  81. package/templates/space/apps/fe/src/components/404.tsx +18 -0
  82. package/templates/space/apps/fe/src/components/features/auth/AuthBrandPanel.tsx +60 -0
  83. package/templates/space/apps/fe/src/components/features/auth/AuthLayout.tsx +23 -0
  84. package/templates/space/apps/fe/src/components/features/auth/LoginPage.tsx +111 -0
  85. package/templates/space/apps/fe/src/components/features/auth/RegisterPage.tsx +143 -0
  86. package/templates/space/apps/fe/src/components/features/home/HomePage.tsx +21 -0
  87. package/templates/space/apps/fe/src/components/features/planets/details/PlanetDetailsPage.tsx +139 -0
  88. package/templates/space/apps/fe/src/components/features/planets/details/PlanetEditPage.tsx +266 -0
  89. package/templates/space/apps/fe/src/components/features/planets/feed/PlanetFeedCard.tsx +131 -0
  90. package/templates/space/apps/fe/src/components/features/planets/feed/PlanetsFeedPage.tsx +119 -0
  91. package/templates/space/apps/fe/src/components/features/planets/list/PlanetCard.tsx +89 -0
  92. package/templates/space/apps/fe/src/components/features/planets/list/PlanetCreateModal.tsx +179 -0
  93. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsFilters.css +3 -0
  94. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsFilters.tsx +73 -0
  95. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsGridPage.tsx +51 -0
  96. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsInfiniteTablePage.tsx +79 -0
  97. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsPage.tsx +65 -0
  98. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsTablePage.tsx +72 -0
  99. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsTableSummary.tsx +29 -0
  100. package/templates/space/apps/fe/src/components/features/planets/list/PlanetsViewTabs.tsx +79 -0
  101. package/templates/space/apps/fe/src/components/features/planets/list/table/PlanetsTable.tsx +30 -0
  102. package/templates/space/apps/fe/src/components/features/planets/list/table/PlanetsTableActions.tsx +64 -0
  103. package/templates/space/apps/fe/src/components/features/planets/list/table/PlanetsTableInfinite.tsx +36 -0
  104. package/templates/space/apps/fe/src/components/features/planets/list/table/planetsTableColumns.tsx +72 -0
  105. package/templates/space/apps/fe/src/components/features/planets/list/table/usePlanetTableFilters.tsx +102 -0
  106. package/templates/space/apps/fe/src/components/features/profile/ProfilePage.tsx +96 -0
  107. package/templates/space/apps/fe/src/components/googleAnalytics/GoogleAnalytics.tsx +35 -0
  108. package/templates/space/apps/fe/src/components/layout/AppLayout.tsx +19 -0
  109. package/templates/space/apps/fe/src/components/layout/app-header/AppHeader.tsx +93 -0
  110. package/templates/space/apps/fe/src/components/layout/app-header/MobileNavigation.tsx +53 -0
  111. package/templates/space/apps/fe/src/components/layout/app-header/NavLink.tsx +29 -0
  112. package/templates/space/apps/fe/src/components/shared/branding/BrandLogo.tsx +13 -0
  113. package/templates/space/apps/fe/src/components/shared/error/ErrorFallback.tsx +43 -0
  114. package/templates/space/apps/fe/src/components/shared/error/ErrorText.tsx +20 -0
  115. package/templates/space/apps/fe/src/components/shared/error/NotFound.tsx +36 -0
  116. package/templates/space/apps/fe/src/components/shared/forms/RequiredLabel.tsx +21 -0
  117. package/templates/space/apps/fe/src/components/shared/forms/RowInputWrapper.tsx +50 -0
  118. package/templates/space/apps/fe/src/components/shared/head/AppHead.tsx +32 -0
  119. package/templates/space/apps/fe/src/components/shared/head/DefaultAppHead.tsx +34 -0
  120. package/templates/space/apps/fe/src/components/shared/layout/LoadingState.tsx +9 -0
  121. package/templates/space/apps/fe/src/components/shared/layout/ThinPageWrapper.tsx +5 -0
  122. package/templates/space/apps/fe/src/components/shared/page/PageHeader.tsx +69 -0
  123. package/templates/space/apps/fe/src/components/shared/ui/Card.tsx +60 -0
  124. package/templates/space/apps/fe/src/components/shared/ui/GoogleLoginButton.tsx +19 -0
  125. package/templates/space/apps/fe/src/components/shared/ui/RequiredLabel.tsx +22 -0
  126. package/templates/space/apps/fe/src/components/shared/ui/TableActions.tsx +22 -0
  127. package/templates/space/apps/fe/src/config/app.config.ts +35 -0
  128. package/templates/space/apps/fe/src/config/i18n.ts +43 -0
  129. package/templates/space/apps/fe/src/config/inits/a11y.ts +14 -0
  130. package/templates/space/apps/fe/src/config/inits/logger.ts +7 -0
  131. package/templates/space/apps/fe/src/config/inits/sentry.ts +21 -0
  132. package/templates/space/apps/fe/src/config/jwt.config.ts +2 -0
  133. package/templates/space/apps/fe/src/config/query.config.ts +20 -0
  134. package/templates/space/apps/fe/src/hooks/useAuth.ts +5 -0
  135. package/templates/space/apps/fe/src/main.tsx +52 -0
  136. package/templates/space/apps/fe/src/pages/(guest)/login.tsx +23 -0
  137. package/templates/space/apps/fe/src/pages/(guest)/register.tsx +23 -0
  138. package/templates/space/apps/fe/src/pages/(guest)/route.tsx +18 -0
  139. package/templates/space/apps/fe/src/pages/(private)/index.tsx +23 -0
  140. package/templates/space/apps/fe/src/pages/(private)/planets/$id/edit.tsx +53 -0
  141. package/templates/space/apps/fe/src/pages/(private)/planets/$id/index.tsx +41 -0
  142. package/templates/space/apps/fe/src/pages/(private)/planets/index.tsx +24 -0
  143. package/templates/space/apps/fe/src/pages/(private)/planets-feed.tsx +23 -0
  144. package/templates/space/apps/fe/src/pages/(private)/profile.tsx +23 -0
  145. package/templates/space/apps/fe/src/pages/(private)/route.tsx +18 -0
  146. package/templates/space/apps/fe/src/pages/(public)/auth.tsx +37 -0
  147. package/templates/space/apps/fe/src/pages/(public)/route.tsx +9 -0
  148. package/templates/space/apps/fe/src/pages/__root.tsx +164 -0
  149. package/templates/space/apps/fe/src/providers/AppErrorBoundary.tsx +10 -0
  150. package/templates/space/apps/fe/src/providers/OpenApiRuntimeProvider.tsx +31 -0
  151. package/templates/space/apps/fe/src/providers/index.tsx +44 -0
  152. package/templates/space/apps/fe/src/providers/jwt.provider.tsx +95 -0
  153. package/templates/space/apps/fe/src/routeTree.gen.ts +309 -0
  154. package/templates/space/apps/fe/src/styles/base.css +103 -0
  155. package/templates/space/apps/fe/src/styles/fonts/fonts.tsx +10 -0
  156. package/templates/space/apps/fe/src/styles/fonts/general-sans.css +31 -0
  157. package/templates/space/apps/fe/src/styles/globals.css +28 -0
  158. package/templates/space/apps/fe/src/styles/overrides/defaults/button.override.ts +536 -0
  159. package/templates/space/apps/fe/src/styles/overrides/defaults/checkbox.override.ts +71 -0
  160. package/templates/space/apps/fe/src/styles/overrides/defaults/input.override.ts +252 -0
  161. package/templates/space/apps/fe/src/styles/overrides/defaults/label.override.ts +91 -0
  162. package/templates/space/apps/fe/src/styles/overrides/defaults/modal.override.ts +57 -0
  163. package/templates/space/apps/fe/src/styles/overrides/defaults/radio.override.ts +46 -0
  164. package/templates/space/apps/fe/src/styles/overrides/defaults/table.override.ts +104 -0
  165. package/templates/space/apps/fe/src/styles/overrides/defaults/tag.override.ts +66 -0
  166. package/templates/space/apps/fe/src/styles/overrides/defaults/typography.override.ts +115 -0
  167. package/templates/space/apps/fe/src/styles/overrides/outline.clsx.ts +10 -0
  168. package/templates/space/apps/fe/src/styles/overrides/uiOverrides.override.ts +60 -0
  169. package/templates/space/apps/fe/src/styles/theme.css +2177 -0
  170. package/templates/space/apps/fe/src/types/i18next.d.ts +12 -0
  171. package/templates/space/apps/fe/src/types/table.d.ts +17 -0
  172. package/templates/space/apps/fe/src/types/ui.d.ts +26 -0
  173. package/templates/space/apps/fe/src/types/vite-env.d.ts +20 -0
  174. package/templates/space/apps/fe/src/utils/date.utils.ts +17 -0
  175. package/templates/space/apps/fe/src/utils/image-fallback.ts +9 -0
  176. package/templates/space/apps/fe/src/utils/media-upload.ts +63 -0
  177. package/templates/space/apps/fe/src/utils/number.utils.ts +12 -0
  178. package/templates/space/apps/fe/src/utils/string.utils.ts +5 -0
  179. package/templates/space/apps/fe/src/vite-env.d.ts +1 -0
  180. package/templates/space/apps/fe/tsconfig.app.json +32 -0
  181. package/templates/space/apps/fe/tsconfig.json +9 -0
  182. package/templates/space/apps/fe/tsconfig.node.json +31 -0
  183. package/templates/space/apps/fe/vite.config.ts +94 -0
  184. package/templates/space/database.ts +33 -13
  185. package/templates/space/openapi.json +1819 -0
  186. package/templates/space/oxfmt.config.js +23 -0
  187. package/templates/space/package.json +6 -13
  188. package/templates/space/rulesync.jsonc +18 -0
  189. package/templates/space/tsconfig.json +2 -4
  190. package/templates/space/api/health.ts +0 -7
  191. package/templates/space/api/launch.ts +0 -29
  192. package/templates/space/api/me.ts +0 -14
  193. package/templates/space/api/motto.ts +0 -9
  194. package/templates/space/api/rockets.ts +0 -43
  195. package/templates/space/index.html +0 -138
  196. package/templates/space/src/main.tsx +0 -229
  197. package/templates/space/vite.config.ts +0 -7
@@ -0,0 +1,23 @@
1
+ export default {
2
+ useTabs: false,
3
+ tabWidth: 2,
4
+ printWidth: 120,
5
+ singleQuote: false,
6
+ jsxSingleQuote: false,
7
+ quoteProps: "as-needed",
8
+ trailingComma: "all",
9
+ semi: true,
10
+ arrowParens: "always",
11
+ bracketSameLine: false,
12
+ bracketSpacing: true,
13
+ singleAttributePerLine: true,
14
+ ignorePatterns: [
15
+ "node_modules",
16
+ "dist",
17
+ "out",
18
+ ".turbo",
19
+ ".next",
20
+ "routeTree.gen.ts",
21
+ "openapi.generated.json",
22
+ ],
23
+ };
@@ -4,22 +4,15 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "deploy": "robodev deploy"
7
+ "deploy": "robodev deploy",
8
+ "rules:gen": "rulesync generate"
10
9
  },
11
10
  "dependencies": {
12
- "react": "^18.3.1",
13
- "react-dom": "^18.3.1",
14
- "@robodev-ai/sdk": "^0.6.0",
15
- "@robodev-ai/client": "^0.3.0"
11
+ "@robodev-ai/sdk": "^0.6.0"
16
12
  },
17
13
  "devDependencies": {
18
- "@types/react": "^18.3.24",
19
- "@types/react-dom": "^18.3.7",
20
- "@vitejs/plugin-react": "^4.7.0",
21
- "typescript": "^5.9.2",
22
- "vite": "^6.3.5",
23
- "robodev": "^0.10.0"
14
+ "robodev": "^0.12.0",
15
+ "rulesync": "^8.18.0",
16
+ "typescript": "^5.9.2"
24
17
  }
25
18
  }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://github.com/dyoshikawa/rulesync/releases/latest/download/config-schema.json",
3
+ "targets": {
4
+ "cursor": ["rules", "skills"],
5
+ "claudecode": ["rules", "skills"],
6
+ "codexcli": ["rules", "skills"],
7
+ },
8
+ "outputRoots": ["."],
9
+ // Clean stale outputs when source rules are removed. All sources live under .rulesync/.
10
+ "delete": true,
11
+ "verbose": false,
12
+ "silent": false,
13
+ "global": false,
14
+ "simulateCommands": false,
15
+ "simulateSubagents": false,
16
+ "simulateSkills": false,
17
+ "gitignoreTargetsOnly": true,
18
+ }
@@ -3,11 +3,9 @@
3
3
  "target": "ES2022",
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "bundler",
6
- "jsx": "react-jsx",
7
6
  "strict": true,
8
7
  "skipLibCheck": true,
9
- "noEmit": true,
10
- "types": ["vite/client"]
8
+ "noEmit": true
11
9
  },
12
- "include": ["./**/*.ts", "./**/*.tsx"]
10
+ "include": ["database.ts", "api/**/*.ts"]
13
11
  }
@@ -1,7 +0,0 @@
1
- /** GET /health — liveness check for the deployed project host. */
2
- import { defineApi, z } from "@robodev-ai/sdk";
3
-
4
- export const get = defineApi({
5
- response: z.object({ ok: z.literal(true) }),
6
- handler: async () => ({ ok: true as const }),
7
- });
@@ -1,29 +0,0 @@
1
- /** POST /launch — marks a rocket as launched. */
2
- import { rockets } from "../database";
3
- import { defineApi, eq, z } from "@robodev-ai/sdk";
4
-
5
- const Rocket = z.object({
6
- id: z.string(),
7
- name: z.string(),
8
- destinationId: z.string(),
9
- launched: z.boolean(),
10
- });
11
-
12
- export const post = defineApi({
13
- body: z.object({
14
- id: z.string().uuid(),
15
- }),
16
- response: Rocket,
17
- handler: async ({ db, body }) => {
18
- const rows = await db
19
- .update(rockets)
20
- .set({ launched: true })
21
- .where(eq(rockets.id, body.id))
22
- .returning();
23
- const row = rows[0];
24
- if (!row) {
25
- throw new Error("Rocket not found");
26
- }
27
- return Rocket.parse(row);
28
- },
29
- });
@@ -1,14 +0,0 @@
1
- /** GET /me — current project user (Robodev Auth required). */
2
- import { defineApi, z } from "@robodev-ai/sdk";
3
-
4
- export const get = defineApi({
5
- auth: "required",
6
- response: z.object({
7
- user: z.object({
8
- id: z.string(),
9
- email: z.string(),
10
- name: z.string().nullable().optional(),
11
- }),
12
- }),
13
- handler: async ({ user }) => ({ user }),
14
- });
@@ -1,9 +0,0 @@
1
- /** GET /motto — plain-text envelope response. */
2
- import { defineApi } from "@robodev-ai/sdk";
3
-
4
- export const get = defineApi({
5
- handler: async () => ({
6
- contentType: "text/plain; charset=utf-8",
7
- body: "Ad astra",
8
- }),
9
- });
@@ -1,43 +0,0 @@
1
- /** GET/POST /rockets — list (optional `?destinationId=`) and create rockets. */
2
- import { rockets } from "../database";
3
- import { defineApi, eq, z } from "@robodev-ai/sdk";
4
-
5
- const Rocket = z.object({
6
- id: z.string(),
7
- name: z.string(),
8
- destinationId: z.string(),
9
- launched: z.boolean(),
10
- });
11
-
12
- export const get = defineApi({
13
- query: z.object({
14
- destinationId: z.string().optional(),
15
- }),
16
- response: z.array(Rocket),
17
- handler: async ({ db, query }) => {
18
- const rows = query.destinationId
19
- ? await db.select().from(rockets).where(eq(rockets.destinationId, query.destinationId))
20
- : await db.select().from(rockets);
21
- return Rocket.array().parse(rows);
22
- },
23
- });
24
-
25
- export const post = defineApi({
26
- body: z.object({
27
- name: z.string().min(1),
28
- destinationId: z.string().uuid(),
29
- launched: z.boolean().optional(),
30
- }),
31
- response: Rocket,
32
- handler: async ({ db, body }) => {
33
- const [row] = await db
34
- .insert(rockets)
35
- .values({
36
- name: body.name,
37
- destinationId: body.destinationId,
38
- launched: body.launched ?? false,
39
- })
40
- .returning();
41
- return Rocket.parse(row);
42
- },
43
- });
@@ -1,138 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>{{NAME}}</title>
7
- <style>
8
- :root {
9
- color-scheme: dark;
10
- --bg: #12141a;
11
- --panel: #1b1e27;
12
- --line: #2c3140;
13
- --text: #ece8df;
14
- --muted: #9a9488;
15
- --accent: #d4a15a;
16
- }
17
- * {
18
- box-sizing: border-box;
19
- }
20
- body {
21
- margin: 0;
22
- min-height: 100vh;
23
- background: var(--bg);
24
- color: var(--text);
25
- font:
26
- 15px/1.5 ui-sans-serif,
27
- system-ui,
28
- sans-serif;
29
- }
30
- main {
31
- max-width: 920px;
32
- margin: 0 auto;
33
- padding: 32px 20px 64px;
34
- }
35
- h1 {
36
- font-size: 28px;
37
- font-weight: 600;
38
- letter-spacing: -0.03em;
39
- margin: 0 0 6px;
40
- }
41
- .lede {
42
- color: var(--muted);
43
- margin: 0 0 28px;
44
- }
45
- .grid {
46
- display: grid;
47
- gap: 20px;
48
- grid-template-columns: 1fr;
49
- }
50
- @media (min-width: 760px) {
51
- .grid {
52
- grid-template-columns: 1fr 1fr;
53
- }
54
- }
55
- section {
56
- background: var(--panel);
57
- border: 1px solid var(--line);
58
- border-radius: 10px;
59
- padding: 18px;
60
- }
61
- h2 {
62
- margin: 0 0 14px;
63
- font-size: 16px;
64
- font-weight: 600;
65
- }
66
- ul {
67
- list-style: none;
68
- margin: 0 0 16px;
69
- padding: 0;
70
- }
71
- li {
72
- display: flex;
73
- justify-content: space-between;
74
- gap: 12px;
75
- align-items: baseline;
76
- padding: 10px 0;
77
- border-top: 1px solid var(--line);
78
- }
79
- li:first-child {
80
- border-top: 0;
81
- padding-top: 0;
82
- }
83
- .meta {
84
- color: var(--muted);
85
- font-size: 13px;
86
- }
87
- form {
88
- display: grid;
89
- gap: 8px;
90
- }
91
- label {
92
- display: grid;
93
- gap: 4px;
94
- font-size: 12px;
95
- color: var(--muted);
96
- }
97
- input,
98
- select,
99
- button {
100
- font: inherit;
101
- color: var(--text);
102
- }
103
- input,
104
- select {
105
- background: var(--bg);
106
- border: 1px solid var(--line);
107
- border-radius: 6px;
108
- padding: 8px 10px;
109
- }
110
- button {
111
- background: var(--accent);
112
- color: #1a140b;
113
- border: 0;
114
- border-radius: 6px;
115
- padding: 8px 12px;
116
- font-weight: 600;
117
- cursor: pointer;
118
- }
119
- button.ghost {
120
- background: transparent;
121
- color: var(--accent);
122
- border: 1px solid var(--accent);
123
- }
124
- button:disabled {
125
- opacity: 0.5;
126
- cursor: default;
127
- }
128
- .error {
129
- color: #e08b8b;
130
- margin: 0 0 16px;
131
- }
132
- </style>
133
- </head>
134
- <body>
135
- <div id="root"></div>
136
- <script type="module" src="/src/main.tsx"></script>
137
- </body>
138
- </html>
@@ -1,229 +0,0 @@
1
- /** Starter UI. Hosted builds use the project origin; local Vite uses `VITE_API_URL`. */
2
- import { StrictMode, useEffect, useState, type FormEvent } from "react";
3
- import { createRoot } from "react-dom/client";
4
-
5
- type Planet = { id: string; name: string; climate: string; moons: number };
6
- type Rocket = { id: string; name: string; destinationId: string; launched: boolean };
7
-
8
- function projectApiUrl(): string {
9
- const fromEnv = import.meta.env.VITE_API_URL;
10
- if (typeof fromEnv === "string" && fromEnv.trim()) return fromEnv.replace(/\/+$/, "");
11
- if (typeof window !== "undefined") return window.location.origin;
12
- return "";
13
- }
14
-
15
- async function request<T>(path: string, init?: RequestInit): Promise<T> {
16
- const base = projectApiUrl();
17
- const res = await fetch(`${base}${path}`, {
18
- ...init,
19
- headers: { "Content-Type": "application/json", ...init?.headers },
20
- });
21
- if (!res.ok) {
22
- throw new Error((await res.text()) || `${res.status} ${path}`);
23
- }
24
- return res.json() as Promise<T>;
25
- }
26
-
27
- function App() {
28
- const [planets, setPlanets] = useState<Planet[]>([]);
29
- const [rockets, setRockets] = useState<Rocket[]>([]);
30
- const [error, setError] = useState<string | null>(null);
31
- const [pending, setPending] = useState(false);
32
- const [planetForm, setPlanetForm] = useState({ name: "", climate: "", moons: "0" });
33
- const [rocketForm, setRocketForm] = useState({ name: "", destinationId: "" });
34
-
35
- async function refresh() {
36
- const nextPlanets = await request<Planet[]>("/planets");
37
- const nextRockets = await request<Rocket[]>("/rockets");
38
- setPlanets(nextPlanets);
39
- setRockets(nextRockets);
40
- setRocketForm((form) => ({
41
- ...form,
42
- destinationId: form.destinationId || nextPlanets[0]?.id || "",
43
- }));
44
- }
45
-
46
- useEffect(() => {
47
- void refresh().catch((err: unknown) =>
48
- setError(err instanceof Error ? err.message : "Failed to load"),
49
- );
50
- }, []);
51
-
52
- async function onAddPlanet(event: FormEvent) {
53
- event.preventDefault();
54
- setPending(true);
55
- setError(null);
56
- try {
57
- await request("/planets", {
58
- method: "POST",
59
- body: JSON.stringify({
60
- name: planetForm.name,
61
- climate: planetForm.climate,
62
- moons: Number(planetForm.moons),
63
- }),
64
- });
65
- setPlanetForm({ name: "", climate: "", moons: "0" });
66
- await refresh();
67
- } catch (err) {
68
- setError(err instanceof Error ? err.message : "Could not add planet");
69
- } finally {
70
- setPending(false);
71
- }
72
- }
73
-
74
- async function onAddRocket(event: FormEvent) {
75
- event.preventDefault();
76
- setPending(true);
77
- setError(null);
78
- try {
79
- await request("/rockets", {
80
- method: "POST",
81
- body: JSON.stringify({
82
- name: rocketForm.name,
83
- destinationId: rocketForm.destinationId,
84
- }),
85
- });
86
- setRocketForm((form) => ({ ...form, name: "" }));
87
- await refresh();
88
- } catch (err) {
89
- setError(err instanceof Error ? err.message : "Could not add rocket");
90
- } finally {
91
- setPending(false);
92
- }
93
- }
94
-
95
- async function onLaunch(id: string) {
96
- setPending(true);
97
- setError(null);
98
- try {
99
- await request("/launch", {
100
- method: "POST",
101
- body: JSON.stringify({ id }),
102
- });
103
- await refresh();
104
- } catch (err) {
105
- setError(err instanceof Error ? err.message : "Could not launch");
106
- } finally {
107
- setPending(false);
108
- }
109
- }
110
-
111
- const planetName = (id: string) => planets.find((planet) => planet.id === id)?.name ?? id;
112
-
113
- return (
114
- <main>
115
- <h1>{"{{NAME}}"}</h1>
116
- <p className="lede">React frontend talking to your Starbase APIs at {projectApiUrl()}.</p>
117
- {error ? <p className="error">{error}</p> : null}
118
-
119
- <div className="grid">
120
- <section>
121
- <h2>Planets</h2>
122
- <ul>
123
- {planets.map((planet) => (
124
- <li key={planet.id}>
125
- <div>
126
- <strong>{planet.name}</strong>
127
- <div className="meta">
128
- {planet.climate} · {planet.moons} {planet.moons === 1 ? "moon" : "moons"}
129
- </div>
130
- </div>
131
- </li>
132
- ))}
133
- </ul>
134
- <form onSubmit={onAddPlanet}>
135
- <label>
136
- Name
137
- <input
138
- required
139
- value={planetForm.name}
140
- onChange={(event) => setPlanetForm({ ...planetForm, name: event.target.value })}
141
- />
142
- </label>
143
- <label>
144
- Climate
145
- <input
146
- required
147
- value={planetForm.climate}
148
- onChange={(event) => setPlanetForm({ ...planetForm, climate: event.target.value })}
149
- />
150
- </label>
151
- <label>
152
- Moons
153
- <input
154
- type="number"
155
- min={0}
156
- value={planetForm.moons}
157
- onChange={(event) => setPlanetForm({ ...planetForm, moons: event.target.value })}
158
- />
159
- </label>
160
- <button type="submit" disabled={pending}>
161
- Add planet
162
- </button>
163
- </form>
164
- </section>
165
-
166
- <section>
167
- <h2>Rockets</h2>
168
- <ul>
169
- {rockets.map((rocket) => (
170
- <li key={rocket.id}>
171
- <div>
172
- <strong>{rocket.name}</strong>
173
- <div className="meta">
174
- {planetName(rocket.destinationId)} · {rocket.launched ? "launched" : "on pad"}
175
- </div>
176
- </div>
177
- {rocket.launched ? null : (
178
- <button
179
- className="ghost"
180
- type="button"
181
- disabled={pending}
182
- onClick={() => onLaunch(rocket.id)}
183
- >
184
- Launch
185
- </button>
186
- )}
187
- </li>
188
- ))}
189
- </ul>
190
- <form onSubmit={onAddRocket}>
191
- <label>
192
- Name
193
- <input
194
- required
195
- value={rocketForm.name}
196
- onChange={(event) => setRocketForm({ ...rocketForm, name: event.target.value })}
197
- />
198
- </label>
199
- <label>
200
- Destination
201
- <select
202
- required
203
- value={rocketForm.destinationId}
204
- onChange={(event) =>
205
- setRocketForm({ ...rocketForm, destinationId: event.target.value })
206
- }
207
- >
208
- {planets.map((planet) => (
209
- <option key={planet.id} value={planet.id}>
210
- {planet.name}
211
- </option>
212
- ))}
213
- </select>
214
- </label>
215
- <button type="submit" disabled={pending || planets.length === 0}>
216
- Add rocket
217
- </button>
218
- </form>
219
- </section>
220
- </div>
221
- </main>
222
- );
223
- }
224
-
225
- createRoot(document.getElementById("root")!).render(
226
- <StrictMode>
227
- <App />
228
- </StrictMode>,
229
- );
@@ -1,7 +0,0 @@
1
- import react from "@vitejs/plugin-react";
2
- import { defineConfig } from "vite";
3
-
4
- export default defineConfig({
5
- plugins: [react()],
6
- server: { port: 5173 },
7
- });