create-rari-app 0.1.4 → 0.1.5

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.
package/dist/index.js CHANGED
@@ -116,7 +116,6 @@ async function copyTemplate(templatePath, projectPath, options) {
116
116
  "src/components/ServerTime.tsx",
117
117
  "src/pages/index.tsx",
118
118
  "src/pages/about.tsx",
119
- "src/pages/examples.tsx",
120
119
  "gitignore"
121
120
  ];
122
121
  await mkdir(join(projectPath, "src", "components"), { recursive: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-rari-app",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "description": "Create Runtime Accelerated Rendering Infrastructure (Rari) applications with no build configuration",
6
6
  "author": "Ryan Skinner",
7
7
  "license": "MIT",
@@ -1,19 +1,61 @@
1
- import { RouterProvider } from 'rari/client'
2
- import { routes } from './.rari/routes'
1
+ import { RouterProvider, useRouter } from 'rari/client'
2
+ import { routes } from '../.rari/routes'
3
+
4
+ function NotFoundPage() {
5
+ return (
6
+ <div className="min-h-screen bg-[#0d1117] text-[#f0f6fc] flex items-center justify-center">
7
+ <div className="text-center">
8
+ <h1 className="text-4xl font-bold mb-4">404 - Page Not Found</h1>
9
+ <p className="text-gray-400 mb-8">
10
+ The page you're looking for doesn't exist.
11
+ </p>
12
+ <a
13
+ href="/"
14
+ className="bg-[#fd7e14] hover:bg-[#e8590c] text-white px-6 py-3 rounded-lg font-semibold transition-colors"
15
+ >
16
+ Go Home
17
+ </a>
18
+ </div>
19
+ </div>
20
+ )
21
+ }
22
+
23
+ const routerConfig = {
24
+ notFoundComponent: NotFoundPage,
25
+ basePath: '',
26
+ useHash: false,
27
+ caseSensitive: false,
28
+ }
3
29
 
4
30
  function App() {
5
31
  return (
6
- <RouterProvider
7
- routes={routes}
8
- config={{
9
- basePath: '',
10
- useHash: false,
11
- caseSensitive: false,
12
- }}
13
- >
14
- <div id="app" />
32
+ <RouterProvider config={routerConfig} routes={routes}>
33
+ <Routes />
15
34
  </RouterProvider>
16
35
  )
17
36
  }
18
37
 
38
+ function Routes() {
39
+ const { currentRoute } = useRouter()
40
+
41
+ if (!currentRoute) {
42
+ return <NotFoundPage />
43
+ }
44
+
45
+ const Component = currentRoute.route.component
46
+ const { params, searchParams } = currentRoute
47
+
48
+ if (!Component) {
49
+ return <NotFoundPage />
50
+ }
51
+
52
+ return (
53
+ <Component
54
+ params={params}
55
+ searchParams={searchParams}
56
+ meta={currentRoute.route.meta}
57
+ />
58
+ )
59
+ }
60
+
19
61
  export default App
@@ -1,68 +1,13 @@
1
1
  import React from 'react'
2
2
  import ReactDOM from 'react-dom/client'
3
- import App from './App'
3
+ import App from './App.tsx'
4
4
  import './styles/index.css'
5
5
 
6
6
  import 'virtual:rsc-integration'
7
7
  import 'virtual:rsc-client-components'
8
8
 
9
- export function RouterErrorBoundary({
10
- children,
11
- }: {
12
- children: React.ReactNode
13
- }) {
14
- const [hasError, setHasError] = React.useState(false)
15
- const [error, setError] = React.useState<Error | null>(null)
16
-
17
- React.useEffect(() => {
18
- const handleError = (event: ErrorEvent) => {
19
- if (
20
- event.error?.message?.includes('router')
21
- || event.error?.message?.includes('navigation')
22
- ) {
23
- setHasError(true)
24
- setError(event.error)
25
- }
26
- }
27
-
28
- window.addEventListener('error', handleError)
29
- return () => window.removeEventListener('error', handleError)
30
- }, [])
31
-
32
- if (hasError) {
33
- return (
34
- <div className="min-h-screen bg-red-50 flex items-center justify-center p-8">
35
- <div className="bg-white rounded-xl p-8 shadow-sm border border-red-200 max-w-2xl">
36
- <h1 className="text-2xl font-bold text-red-900 mb-4">Router Error</h1>
37
- <p className="text-red-700 mb-4">
38
- There was an error with the routing system:
39
- </p>
40
- <pre className="bg-red-100 p-4 rounded-lg text-sm text-red-800 overflow-auto">
41
- {error?.message || 'Unknown router error'}
42
- </pre>
43
- <button
44
- type="button"
45
- onClick={() => {
46
- setHasError(false)
47
- setError(null)
48
- window.location.reload()
49
- }}
50
- className="mt-4 px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors"
51
- >
52
- Reload Page
53
- </button>
54
- </div>
55
- </div>
56
- )
57
- }
58
-
59
- return <>{children}</>
60
- }
61
-
62
9
  ReactDOM.createRoot(document.getElementById('root')!).render(
63
10
  <React.StrictMode>
64
- <RouterErrorBoundary>
65
- <App />
66
- </RouterErrorBoundary>
11
+ <App />
67
12
  </React.StrictMode>,
68
13
  )
@@ -38,9 +38,9 @@ export default function AboutPage({ params, searchParams }: PageProps) {
38
38
  🚀 What is Rari?
39
39
  </h2>
40
40
  <p className="text-gray-600 mb-4">
41
- Rari is a next-generation React framework powered by a custom-built
42
- Rust runtime. It provides performance-optimized server-side rendering with
43
- seamless client-side hydration.
41
+ Rari is a next-generation React framework powered by a
42
+ custom-built Rust runtime. It provides performance-optimized
43
+ server-side rendering with seamless client-side hydration.
44
44
  </p>
45
45
  <ul className="space-y-2 text-gray-600">
46
46
  <li className="flex items-center">
@@ -165,9 +165,7 @@ export default function AboutPage({ params, searchParams }: PageProps) {
165
165
  />
166
166
  </svg>
167
167
  </div>
168
- <h3 className="font-semibent text-gray-900 mb-2">
169
- Zero Config
170
- </h3>
168
+ <h3 className="font-semibent text-gray-900 mb-2">Zero Config</h3>
171
169
  <p className="text-sm text-gray-600">
172
170
  Works out of the box with pre-built binaries
173
171
  </p>
@@ -184,7 +182,9 @@ export default function AboutPage({ params, searchParams }: PageProps) {
184
182
  <div className="mb-2">
185
183
  <strong>File:</strong>
186
184
  {' '}
187
- <code className="bg-gray-200 px-2 py-1 rounded">src/pages/about.tsx</code>
185
+ <code className="bg-gray-200 px-2 py-1 rounded">
186
+ src/pages/about.tsx
187
+ </code>
188
188
  </div>
189
189
  <div className="mb-2">
190
190
  <strong>Route:</strong>
@@ -233,14 +233,6 @@ export default function AboutPage({ params, searchParams }: PageProps) {
233
233
  </svg>
234
234
  Back to Home
235
235
  </Link>
236
- <div className="mt-4">
237
- <Link
238
- to="/examples"
239
- className="text-blue-600 hover:text-blue-700 transition-colors"
240
- >
241
- Explore Server Components →
242
- </Link>
243
- </div>
244
236
  </div>
245
237
  </div>
246
238
  </div>
@@ -43,7 +43,8 @@ export default function HomePage({ params, searchParams }: PageProps) {
43
43
  Client Interaction
44
44
  </h2>
45
45
  <p className="text-gray-600 mb-6">
46
- This counter runs in the browser with React's client-side interactivity.
46
+ This counter runs in the browser with React's client-side
47
+ interactivity.
47
48
  </p>
48
49
  <div className="flex items-center gap-4">
49
50
  <button
@@ -101,23 +102,6 @@ export default function HomePage({ params, searchParams }: PageProps) {
101
102
  <code className="bg-gray-100 px-2 py-1 rounded">/about</code>
102
103
  </div>
103
104
  </Link>
104
-
105
- <Link
106
- to="/examples"
107
- className="bg-white rounded-xl p-6 shadow-sm border border-gray-200 hover:shadow-md transition-shadow block"
108
- >
109
- <h3 className="text-lg font-semibold text-gray-900 mb-3">
110
- 🧩 Server Components
111
- </h3>
112
- <p className="text-gray-600 mb-4">
113
- Explore React Server Components in action
114
- </p>
115
- <div className="text-sm text-gray-500">
116
- Route:
117
- {' '}
118
- <code className="bg-gray-100 px-2 py-1 rounded">/examples</code>
119
- </div>
120
- </Link>
121
105
  </div>
122
106
 
123
107
  <div className="bg-white rounded-xl p-8 shadow-sm border border-gray-200 mb-8">
@@ -151,12 +135,6 @@ export default function HomePage({ params, searchParams }: PageProps) {
151
135
  </div>
152
136
  <div className="text-gray-500">→ Routes to "/about"</div>
153
137
  </div>
154
- <div className="p-3 bg-gray-50 rounded-lg">
155
- <div className="font-mono text-gray-700 mb-1">
156
- pages/examples.tsx
157
- </div>
158
- <div className="text-gray-500">→ Routes to "/examples"</div>
159
- </div>
160
138
  </div>
161
139
  </div>
162
140
 
@@ -169,9 +147,7 @@ export default function HomePage({ params, searchParams }: PageProps) {
169
147
  <div>
170
148
  Path:
171
149
  {' '}
172
- <code className="bg-blue-100 px-2 py-1 rounded">
173
- /
174
- </code>
150
+ <code className="bg-blue-100 px-2 py-1 rounded">/</code>
175
151
  </div>
176
152
  {Object.keys(params).length > 0 && (
177
153
  <div className="mt-1">
@@ -201,11 +177,15 @@ export default function HomePage({ params, searchParams }: PageProps) {
201
177
  <p className="text-gray-500 text-sm">
202
178
  Edit
203
179
  {' '}
204
- <code className="bg-gray-100 px-2 py-1 rounded text-xs">src/pages/index.tsx</code>
180
+ <code className="bg-gray-100 px-2 py-1 rounded text-xs">
181
+ src/pages/index.tsx
182
+ </code>
205
183
  {' '}
206
184
  or create new files in
207
185
  {' '}
208
- <code className="bg-gray-100 px-2 py-1 rounded text-xs">src/pages/</code>
186
+ <code className="bg-gray-100 px-2 py-1 rounded text-xs">
187
+ src/pages/
188
+ </code>
209
189
  {' '}
210
190
  to see file-based routing in action!
211
191
  </p>
@@ -1,238 +0,0 @@
1
- import type { PageProps } from 'rari/client'
2
- import { Link } from 'rari/client'
3
- import ServerTime from '../components/ServerTime'
4
- import Welcome from '../components/Welcome'
5
-
6
- export default function ExamplesPage({ params, searchParams }: PageProps) {
7
- return (
8
- <div className="min-h-screen bg-gradient-to-br from-purple-50 to-pink-100 py-8 px-4">
9
- <div className="max-w-4xl mx-auto">
10
- <div className="text-center mb-12">
11
- <h1 className="text-5xl font-bold text-gray-900 mb-4">
12
- Server
13
- {' '}
14
- <span className="bg-gradient-to-r from-purple-600 to-pink-600 bg-clip-text text-transparent">
15
- Components
16
- </span>
17
- </h1>
18
- <p className="text-xl text-gray-600 mb-8">
19
- Explore React Server Components running on the Rust runtime
20
- </p>
21
- <div className="inline-flex items-center px-4 py-2 bg-purple-100 text-purple-800 rounded-lg">
22
- <svg
23
- className="w-5 h-5 mr-2"
24
- fill="currentColor"
25
- viewBox="0 0 20 20"
26
- >
27
- <path
28
- fillRule="evenodd"
29
- d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z"
30
- clipRule="evenodd"
31
- />
32
- </svg>
33
- Powered by Rust runtime
34
- </div>
35
- </div>
36
-
37
- <div className="grid gap-8 mb-12">
38
- <div className="bg-white rounded-xl p-8 shadow-sm">
39
- <h2 className="text-2xl font-semibold mb-6 text-gray-900">
40
- 🕒 Real-time Server Component
41
- </h2>
42
- <p className="text-gray-600 mb-6">
43
- This component is rendered on the server and shows the current server time.
44
- Each time you navigate to this page, you'll see the time when the component
45
- was rendered on the Rust runtime.
46
- </p>
47
- <ServerTime />
48
- </div>
49
-
50
- <div className="bg-white rounded-xl p-8 shadow-sm">
51
- <h2 className="text-2xl font-semibold mb-6 text-gray-900">
52
- 👋 Welcome Component
53
- </h2>
54
- <p className="text-gray-600 mb-6">
55
- This component demonstrates server-side rendering with dynamic content.
56
- The performance stats and system information are computed on the server.
57
- </p>
58
- <Welcome />
59
- </div>
60
- </div>
61
-
62
- <div className="bg-white rounded-xl p-8 shadow-sm border border-gray-200 mb-8">
63
- <h2 className="text-2xl font-bold text-gray-900 mb-6">
64
- 🔍 How Server Components Work
65
- </h2>
66
-
67
- <div className="grid gap-6 md:grid-cols-2">
68
- <div>
69
- <h3 className="text-lg font-semibold text-gray-900 mb-3">
70
- Server Execution
71
- </h3>
72
- <p className="text-gray-600 mb-4">
73
- Components marked with
74
- {' '}
75
- <code className="bg-gray-100 px-2 py-1 rounded">'use server'</code>
76
- {' '}
77
- run entirely on the Rust runtime. They can:
78
- </p>
79
- <ul className="space-y-2 text-gray-600">
80
- <li className="flex items-center">
81
- <span className="text-green-500 mr-2">✓</span>
82
- Access databases directly
83
- </li>
84
- <li className="flex items-center">
85
- <span className="text-green-500 mr-2">✓</span>
86
- Read from the filesystem
87
- </li>
88
- <li className="flex items-center">
89
- <span className="text-green-500 mr-2">✓</span>
90
- Make server-side API calls
91
- </li>
92
- <li className="flex items-center">
93
- <span className="text-green-500 mr-2">✓</span>
94
- Access environment variables
95
- </li>
96
- </ul>
97
- </div>
98
-
99
- <div>
100
- <h3 className="text-lg font-semibold text-gray-900 mb-3">
101
- Performance Benefits
102
- </h3>
103
- <div className="space-y-3">
104
- <div className="p-3 bg-green-50 rounded-lg">
105
- <div className="font-semibold text-green-800">Zero Client JS</div>
106
- <div className="text-sm text-green-600">
107
- Server components don't send any JavaScript to the client
108
- </div>
109
- </div>
110
- <div className="p-3 bg-blue-50 rounded-lg">
111
- <div className="font-semibold text-blue-800">Instant Rendering</div>
112
- <div className="text-sm text-blue-600">
113
- Rendered in ~3ms on the Rust runtime
114
- </div>
115
- </div>
116
- <div className="p-3 bg-purple-50 rounded-lg">
117
- <div className="font-semibold text-purple-800">Automatic Caching</div>
118
- <div className="text-sm text-purple-600">
119
- Intelligent caching and invalidation
120
- </div>
121
- </div>
122
- </div>
123
- </div>
124
- </div>
125
- </div>
126
-
127
- <div className="bg-white rounded-xl p-8 shadow-sm border border-gray-200 mb-8">
128
- <h2 className="text-2xl font-bold text-gray-900 mb-6">
129
- 🛠️ Creating Server Components
130
- </h2>
131
-
132
- <div className="bg-gray-50 rounded-lg p-6">
133
- <h3 className="text-lg font-semibold text-gray-900 mb-3">
134
- Example: ServerTime.tsx
135
- </h3>
136
- <pre className="bg-gray-800 text-gray-100 p-4 rounded-lg text-sm overflow-x-auto">
137
- {`'use server'
138
-
139
- export default async function ServerTime() {
140
- // This runs on the Rust runtime!
141
- const now = new Date()
142
-
143
- // Simulate some async server work
144
- await new Promise(resolve => setTimeout(resolve, 100))
145
-
146
- return (
147
- <div className="p-4 bg-blue-50 rounded-lg">
148
- <h2 className="text-lg font-semibold">Server Time</h2>
149
- <p>Generated at: {now.toISOString()}</p>
150
- </div>
151
- )
152
- }`}
153
- </pre>
154
- </div>
155
- </div>
156
-
157
- <div className="bg-white rounded-xl p-8 shadow-sm border border-gray-200 mb-8">
158
- <h2 className="text-2xl font-bold text-gray-900 mb-6">
159
- Route Information
160
- </h2>
161
- <div className="p-4 bg-gray-50 rounded-lg">
162
- <div className="text-sm text-gray-700">
163
- <div className="mb-2">
164
- <strong>File:</strong>
165
- {' '}
166
- <code className="bg-gray-200 px-2 py-1 rounded">src/pages/examples.tsx</code>
167
- </div>
168
- <div className="mb-2">
169
- <strong>Route:</strong>
170
- {' '}
171
- <code className="bg-gray-200 px-2 py-1 rounded">/examples</code>
172
- </div>
173
- {Object.keys(params).length > 0 && (
174
- <div className="mb-2">
175
- <strong>Params:</strong>
176
- {' '}
177
- <code className="bg-gray-200 px-2 py-1 rounded">
178
- {JSON.stringify(params)}
179
- </code>
180
- </div>
181
- )}
182
- {Object.keys(searchParams).length > 0 && (
183
- <div>
184
- <strong>Search Params:</strong>
185
- {' '}
186
- <code className="bg-gray-200 px-2 py-1 rounded">
187
- {JSON.stringify(searchParams)}
188
- </code>
189
- </div>
190
- )}
191
- </div>
192
- </div>
193
- </div>
194
-
195
- <div className="text-center">
196
- <Link
197
- to="/"
198
- className="inline-flex items-center px-6 py-3 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors mr-4"
199
- >
200
- <svg
201
- className="w-5 h-5 mr-2"
202
- fill="none"
203
- stroke="currentColor"
204
- viewBox="0 0 24 24"
205
- >
206
- <path
207
- strokeLinecap="round"
208
- strokeLinejoin="round"
209
- strokeWidth={2}
210
- d="M10 19l-7-7m0 0l7-7m-7 7h18"
211
- />
212
- </svg>
213
- Back to Home
214
- </Link>
215
- <Link
216
- to="/about"
217
- className="inline-flex items-center px-6 py-3 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition-colors"
218
- >
219
- Learn More About Rari
220
- <svg
221
- className="w-5 h-5 ml-2"
222
- fill="none"
223
- stroke="currentColor"
224
- viewBox="0 0 24 24"
225
- >
226
- <path
227
- strokeLinecap="round"
228
- strokeLinejoin="round"
229
- strokeWidth={2}
230
- d="M14 5l7 7m0 0l-7 7m7-7H3"
231
- />
232
- </svg>
233
- </Link>
234
- </div>
235
- </div>
236
- </div>
237
- )
238
- }