baraqex 2.0.3 → 2.0.4
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/browser.js +11 -9
- package/dist/browser.js.map +2 -2
- package/dist/core/jsx-runtime.d.ts +1 -1
- package/dist/core/jsx-runtime.d.ts.map +1 -1
- package/dist/index.js +11 -9
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/templates/fullstack-app/README.md +62 -37
- package/templates/fullstack-app/build-wasm.js +80 -0
- package/templates/fullstack-app/build.mjs +133 -0
- package/templates/fullstack-app/go/main.go +53 -0
- package/templates/fullstack-app/index.html +16 -36
- package/templates/fullstack-app/package.json +41 -35
- package/templates/fullstack-app/postcss.config.js +6 -6
- package/templates/fullstack-app/public/wasm/.gitkeep +1 -0
- package/templates/fullstack-app/server.ts +220 -474
- package/templates/fullstack-app/src/App.tsx +77 -0
- package/templates/fullstack-app/src/main.tsx +31 -155
- package/templates/fullstack-app/src/pages/About.tsx +40 -0
- package/templates/fullstack-app/src/pages/Home.tsx +67 -0
- package/templates/fullstack-app/src/pages/WasmDemo.tsx +81 -0
- package/templates/fullstack-app/src/styles.css +12 -5
- package/templates/fullstack-app/tailwind.config.js +8 -11
- package/templates/fullstack-app/tsconfig.json +18 -18
- package/templates/fullstack-app/api/hello.js +0 -11
- package/templates/fullstack-app/api/hello.ts +0 -18
- package/templates/fullstack-app/api/users/[id].ts +0 -73
- package/templates/fullstack-app/api/users/index.ts +0 -32
- package/templates/fullstack-app/build/main.css +0 -874
- package/templates/fullstack-app/build/main.css.map +0 -7
- package/templates/fullstack-app/build/main.js +0 -967
- package/templates/fullstack-app/build/main.js.map +0 -7
- package/templates/fullstack-app/build.ts +0 -210
- package/templates/fullstack-app/process-tailwind.js +0 -45
- package/templates/fullstack-app/public/_redirects +0 -1
- package/templates/fullstack-app/public/route-handler.js +0 -47
- package/templates/fullstack-app/public/spa-fix.html +0 -17
- package/templates/fullstack-app/public/styles.css +0 -975
- package/templates/fullstack-app/public/tailwind.css +0 -15
- package/templates/fullstack-app/server.js +0 -267
- package/templates/fullstack-app/src/README.md +0 -55
- package/templates/fullstack-app/src/client.js +0 -87
- package/templates/fullstack-app/src/components/ClientHome.tsx +0 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.tsx +0 -36
- package/templates/fullstack-app/src/components/Layout.tsx +0 -42
- package/templates/fullstack-app/src/components/StateDemo.tsx +0 -207
- package/templates/fullstack-app/src/components/UserList.tsx +0 -44
- package/templates/fullstack-app/src/config.ts +0 -42
- package/templates/fullstack-app/src/data/api.ts +0 -206
- package/templates/fullstack-app/src/middleware.ts +0 -28
- package/templates/fullstack-app/src/pages/404.tsx +0 -28
- package/templates/fullstack-app/src/pages/[id].tsx +0 -0
- package/templates/fullstack-app/src/pages/_app.tsx +0 -11
- package/templates/fullstack-app/src/pages/_document.tsx +0 -25
- package/templates/fullstack-app/src/pages/_error.tsx +0 -45
- package/templates/fullstack-app/src/pages/about/index.tsx +0 -67
- package/templates/fullstack-app/src/pages/about.tsx +0 -71
- package/templates/fullstack-app/src/pages/api/users/[id].ts +0 -73
- package/templates/fullstack-app/src/pages/api/users/index.ts +0 -43
- package/templates/fullstack-app/src/pages/index.tsx +0 -110
- package/templates/fullstack-app/src/pages/users/[id].tsx +0 -153
- package/templates/fullstack-app/src/pages/users.tsx +0 -60
- package/templates/fullstack-app/src/pages/wasm-demo.tsx +0 -1
- package/templates/fullstack-app/src/router.ts +0 -255
- package/templates/fullstack-app/vite.config.js +0 -87
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'frontend-hamroun';
|
|
2
|
-
// Use dynamic import to ensure it's available
|
|
3
|
-
// import UsersPage from './pages/users';
|
|
4
|
-
|
|
5
|
-
// Type definitions for page components
|
|
6
|
-
export interface PageProps {
|
|
7
|
-
initialState: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface PageComponent {
|
|
11
|
-
(props: PageProps): any;
|
|
12
|
-
getInitialData?: (path: string) => Promise<any>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Define router interface for type safety
|
|
16
|
-
interface RouteParams {
|
|
17
|
-
[key: string]: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Define router class for handling routes
|
|
21
|
-
export class Router {
|
|
22
|
-
private routes: Record<string, PageComponent> = {};
|
|
23
|
-
private notFoundComponent: PageComponent | null = null;
|
|
24
|
-
|
|
25
|
-
// Register a component for a specific route
|
|
26
|
-
register(path: string, component: PageComponent): Router {
|
|
27
|
-
const normalizedPath = path === '/' ? 'index' : path.replace(/^\//, '');
|
|
28
|
-
this.routes[normalizedPath] = component;
|
|
29
|
-
console.log(`[Router] Registered component for path: ${normalizedPath}`);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Set the not found component
|
|
34
|
-
setNotFound(component: PageComponent): Router {
|
|
35
|
-
this.notFoundComponent = component;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Get the not found component
|
|
40
|
-
getNotFound(): PageComponent | null {
|
|
41
|
-
return this.notFoundComponent;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Get all registered routes
|
|
45
|
-
getAllRoutes(): Record<string, PageComponent> {
|
|
46
|
-
return this.routes;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Find component for a given path
|
|
50
|
-
async resolve(path: string): Promise<PageComponent | null> {
|
|
51
|
-
const normalizedPath = path === '/' ? 'index' : path.replace(/^\//, '');
|
|
52
|
-
|
|
53
|
-
console.log(`[Router] Resolving component for path: ${normalizedPath}`);
|
|
54
|
-
|
|
55
|
-
// Check for exact match first
|
|
56
|
-
if (this.routes[normalizedPath]) {
|
|
57
|
-
return this.routes[normalizedPath];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Check for nested routes (e.g., "users/123" should match a "users/[id]" route)
|
|
61
|
-
const pathSegments = normalizedPath.split('/');
|
|
62
|
-
const registeredRoutes = Object.keys(this.routes);
|
|
63
|
-
|
|
64
|
-
// Try to find dynamic route matches
|
|
65
|
-
for (const route of registeredRoutes) {
|
|
66
|
-
const routeSegments = route.split('/');
|
|
67
|
-
|
|
68
|
-
// Skip routes with different segment count
|
|
69
|
-
if (routeSegments.length !== pathSegments.length) continue;
|
|
70
|
-
|
|
71
|
-
let isMatch = true;
|
|
72
|
-
const params: RouteParams = {};
|
|
73
|
-
|
|
74
|
-
// Compare each segment
|
|
75
|
-
for (let i = 0; i < routeSegments.length; i++) {
|
|
76
|
-
const routeSegment = routeSegments[i];
|
|
77
|
-
const pathSegment = pathSegments[i];
|
|
78
|
-
|
|
79
|
-
// Handle dynamic segments (e.g., [id])
|
|
80
|
-
if (routeSegment.startsWith('[') && routeSegment.endsWith(']')) {
|
|
81
|
-
const paramName = routeSegment.slice(1, -1);
|
|
82
|
-
params[paramName] = pathSegment;
|
|
83
|
-
}
|
|
84
|
-
// Regular segment, must match exactly
|
|
85
|
-
else if (routeSegment !== pathSegment) {
|
|
86
|
-
isMatch = false;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (isMatch) {
|
|
92
|
-
console.log(`[Router] Found dynamic route match: ${route}`);
|
|
93
|
-
// Return the component with params
|
|
94
|
-
return this.routes[route];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// If no match found yet, try to dynamically import the component
|
|
99
|
-
try {
|
|
100
|
-
let component = null;
|
|
101
|
-
let resolvedPath = normalizedPath;
|
|
102
|
-
|
|
103
|
-
// Next.js-style dynamic route resolution
|
|
104
|
-
try {
|
|
105
|
-
// First, try direct file match (e.g., ./pages/users.tsx)
|
|
106
|
-
// Focus on .tsx since that's what this project uses
|
|
107
|
-
try {
|
|
108
|
-
console.log(`[Router] Trying direct import: ./pages/${resolvedPath}.tsx`);
|
|
109
|
-
const directModule = await import(/* @vite-ignore */ `./pages/${resolvedPath}.tsx`)
|
|
110
|
-
.catch(() => null);
|
|
111
|
-
|
|
112
|
-
if (directModule) {
|
|
113
|
-
component = directModule.default || directModule;
|
|
114
|
-
}
|
|
115
|
-
} catch (e) {
|
|
116
|
-
console.warn(`[Router] Error importing ./pages/${resolvedPath}.tsx:`, e);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Next, try index file in directory (e.g., ./pages/about/index.tsx)
|
|
120
|
-
if (!component && !resolvedPath.endsWith('index')) {
|
|
121
|
-
try {
|
|
122
|
-
console.log(`[Router] Trying index file: ./pages/${resolvedPath}/index.tsx`);
|
|
123
|
-
const indexModule = await import(/* @vite-ignore */ `./pages/${resolvedPath}/index.tsx`)
|
|
124
|
-
.catch(() => null);
|
|
125
|
-
|
|
126
|
-
if (indexModule) {
|
|
127
|
-
component = indexModule.default || indexModule;
|
|
128
|
-
}
|
|
129
|
-
} catch (e) {
|
|
130
|
-
console.warn(`[Router] Error importing ./pages/${resolvedPath}/index.tsx:`, e);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
} catch (routeError) {
|
|
134
|
-
console.warn(`[Router] Error resolving Next.js style route:`, routeError);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Register and return component if found
|
|
138
|
-
if (component) {
|
|
139
|
-
this.routes[normalizedPath] = component;
|
|
140
|
-
return component;
|
|
141
|
-
}
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.warn(`[Router] Error importing component for ${normalizedPath}:`, error);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// If we reach here, no component was found
|
|
147
|
-
console.warn(`[Router] No component found for path: ${normalizedPath}`);
|
|
148
|
-
return this.notFoundComponent;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Auto-discover components in the pages directory
|
|
152
|
-
async discoverRoutes(): Promise<Record<string, PageComponent>> {
|
|
153
|
-
console.log('[Router] Auto-discovering routes from pages directory...');
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
// Use a more conventional approach instead of relying on import.meta.glob
|
|
157
|
-
await this.tryLoadCoreRoutes();
|
|
158
|
-
|
|
159
|
-
console.log('[Router] Route discovery complete. Available routes:', Object.keys(this.routes));
|
|
160
|
-
return this.routes;
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error('[Router] Error discovering routes:', error);
|
|
163
|
-
await this.tryLoadCoreRoutes();
|
|
164
|
-
return this.routes;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Fallback method to load core routes
|
|
169
|
-
async tryLoadCoreRoutes(): Promise<void> {
|
|
170
|
-
// First try the auto-discovery approach with dynamic imports
|
|
171
|
-
const pageModules = [
|
|
172
|
-
{ path: './pages/index', route: 'index' },
|
|
173
|
-
{ path: './pages/about/index', route: 'about' },
|
|
174
|
-
{ path: './pages/users', route: 'users' }
|
|
175
|
-
];
|
|
176
|
-
|
|
177
|
-
// Try importing each module dynamically - focus on .tsx files
|
|
178
|
-
for (const { path, route } of pageModules) {
|
|
179
|
-
if (!this.routes[route]) {
|
|
180
|
-
try {
|
|
181
|
-
console.log(`[Router] Attempting to load route: ${route}`);
|
|
182
|
-
|
|
183
|
-
// Only try .tsx imports since that's what the project uses
|
|
184
|
-
const module = await import(/* @vite-ignore */ `${path}.tsx`)
|
|
185
|
-
.catch(() => null);
|
|
186
|
-
|
|
187
|
-
if (module && module.default) {
|
|
188
|
-
this.routes[route] = module.default;
|
|
189
|
-
console.log(`[Router] Registered route: ${route}`);
|
|
190
|
-
}
|
|
191
|
-
} catch (error) {
|
|
192
|
-
console.warn(`[Router] Could not load route: ${route}`, error);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Create and export a router instance
|
|
200
|
-
export const router = new Router();
|
|
201
|
-
|
|
202
|
-
// NotFound component as fallback (using jsx function instead of JSX syntax)
|
|
203
|
-
export const NotFound: PageComponent = ({ initialState }) => {
|
|
204
|
-
return jsx('div', { className: 'container mx-auto px-4 py-12 max-w-4xl' }, [
|
|
205
|
-
jsx('div', { className: 'bg-white shadow-lg rounded-lg overflow-hidden p-8' }, [
|
|
206
|
-
jsx('h1', { className: 'text-3xl font-bold text-gray-800 mb-4' }, ['Page Not Found']),
|
|
207
|
-
jsx('p', { className: 'text-gray-600 mb-6' }, [`No component found for path: ${initialState?.route || 'unknown'}`]),
|
|
208
|
-
jsx('a', { href: '/', className: 'text-blue-600 hover:text-blue-800 hover:underline transition-colors' }, ['Go to Home']),
|
|
209
|
-
jsx('div', { className: 'mt-8 p-6 bg-gray-50 rounded-lg border border-gray-200' }, [
|
|
210
|
-
jsx('h3', { className: 'text-lg font-medium text-gray-700 mb-3' }, ['Available Routes']),
|
|
211
|
-
jsx('ul', { className: 'space-y-2' }, [
|
|
212
|
-
jsx('li', {}, [jsx('a', { href: '/', className: 'text-blue-600 hover:text-blue-800 hover:underline' }, ['Home'])]),
|
|
213
|
-
jsx('li', {}, [jsx('a', { href: '/about', className: 'text-blue-600 hover:text-blue-800 hover:underline' }, ['About'])]),
|
|
214
|
-
jsx('li', {}, [jsx('a', { href: '/users', className: 'text-blue-600 hover:text-blue-800 hover:underline' }, ['Users'])])
|
|
215
|
-
])
|
|
216
|
-
])
|
|
217
|
-
])
|
|
218
|
-
]);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// Set NotFound as the default fallback
|
|
222
|
-
router.setNotFound(NotFound);
|
|
223
|
-
|
|
224
|
-
// Improved router initialization with auto-discovery
|
|
225
|
-
export async function initializeRouter(): Promise<Router> {
|
|
226
|
-
try {
|
|
227
|
-
console.log('[Router] Initializing router with auto-discovery...');
|
|
228
|
-
|
|
229
|
-
// Auto-discover routes
|
|
230
|
-
await router.discoverRoutes();
|
|
231
|
-
|
|
232
|
-
// Register fallback pages for key routes if they weren't discovered
|
|
233
|
-
const routes = router.getAllRoutes();
|
|
234
|
-
|
|
235
|
-
if (!routes['index']) {
|
|
236
|
-
router.register('index', ({ initialState }: PageProps) => jsx('div', {}, [
|
|
237
|
-
jsx('h1', {}, ['Welcome']),
|
|
238
|
-
jsx('p', {}, ['This is the home page.'])
|
|
239
|
-
]));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (!routes['about']) {
|
|
243
|
-
router.register('about', ({ initialState }: PageProps) => jsx('div', {}, [
|
|
244
|
-
jsx('h1', {}, ['About']),
|
|
245
|
-
jsx('p', {}, ['This is the about page.'])
|
|
246
|
-
]));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
console.log('[Router] Router initialized with routes:', Object.keys(router.getAllRoutes()));
|
|
250
|
-
return router;
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.error('[Router] Error initializing router:', error);
|
|
253
|
-
return router;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
// Server configuration
|
|
6
|
-
server: {
|
|
7
|
-
port: 5173,
|
|
8
|
-
proxy: {
|
|
9
|
-
'/api': 'http://localhost:3000',
|
|
10
|
-
'/socket.io': {
|
|
11
|
-
target: 'http://localhost:3000',
|
|
12
|
-
ws: true
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
// Using jsx transform with frontend-hamroun's jsx function
|
|
18
|
-
esbuild: {
|
|
19
|
-
jsxFactory: 'jsx',
|
|
20
|
-
jsxFragment: 'Fragment',
|
|
21
|
-
jsxInject: `import { jsx, Fragment } from 'frontend-hamroun'`
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
// Build configuration
|
|
25
|
-
build: {
|
|
26
|
-
outDir: 'dist',
|
|
27
|
-
assetsDir: 'assets',
|
|
28
|
-
// Generate SPA-friendly build that works with client-side routing
|
|
29
|
-
rollupOptions: {
|
|
30
|
-
input: {
|
|
31
|
-
main: resolve(__dirname, 'index.html')
|
|
32
|
-
},
|
|
33
|
-
output: {
|
|
34
|
-
manualChunks: {
|
|
35
|
-
vendor: ['frontend-hamroun']
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
// Make sure CSS is properly processed
|
|
40
|
-
cssCodeSplit: true
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
// CSS preprocessing
|
|
44
|
-
css: {
|
|
45
|
-
postcss: './postcss.config.js',
|
|
46
|
-
// Include module CSS as well as global CSS
|
|
47
|
-
modules: {
|
|
48
|
-
scopeBehaviour: 'local',
|
|
49
|
-
localsConvention: 'camelCaseOnly',
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// Resolve aliases
|
|
54
|
-
resolve: {
|
|
55
|
-
alias: {
|
|
56
|
-
'@': resolve(__dirname, 'src'),
|
|
57
|
-
'@components': resolve(__dirname, 'src/components'),
|
|
58
|
-
'@pages': resolve(__dirname, 'src/pages'),
|
|
59
|
-
'@utils': resolve(__dirname, 'src/utils')
|
|
60
|
-
},
|
|
61
|
-
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
// Optimize dependencies
|
|
65
|
-
optimizeDeps: {
|
|
66
|
-
include: ['frontend-hamroun']
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
// This is a critical plugin for SPA routing - much simpler than before
|
|
70
|
-
plugins: [{
|
|
71
|
-
name: 'spa-fallback',
|
|
72
|
-
configureServer(server) {
|
|
73
|
-
return () => {
|
|
74
|
-
server.middlewares.use((req, res, next) => {
|
|
75
|
-
if (req.url.includes('.') || req.url.startsWith('/api/') || req.url.startsWith('/socket.io/')) {
|
|
76
|
-
next();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
console.log(`[SPA] Handling route: ${req.url}`);
|
|
81
|
-
req.url = '/'; // Rewrite all routes to root
|
|
82
|
-
next();
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}]
|
|
87
|
-
});
|