@africode/core 5.0.2 → 5.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/core/cli/commands/build.js +2 -1
- package/core/cli/commands/dev.js +23 -3
- package/core/sdk-browser.js +140 -0
- package/dist/africode.js +184 -183
- package/dist/africode.js.map +16 -9
- package/dist/build-info.json +3 -3
- package/package.json +6 -5
- package/templates/starter/package.json +1 -1
- package/templates/starter/src/pages/index.html +14 -4
- package/templates/starter/src/pages/index.js +13 -28
- package/templates/starter-3d/package.json +1 -1
- package/templates/starter-3d/src/pages/index.html +13 -3
- package/templates/starter-react/package.json +1 -1
- package/templates/starter-react/src/pages/index.html +13 -3
- package/templates/starter-tailwind/package.json +1 -1
- package/templates/starter-tailwind/src/pages/index.html +13 -3
- package/src/index.ts +0 -196
|
@@ -30,7 +30,8 @@ export async function build() {
|
|
|
30
30
|
const __filename = fileURLToPath(import.meta.url);
|
|
31
31
|
const __dirname = path.dirname(__filename);
|
|
32
32
|
const frameworkCoreDir = path.resolve(__dirname, '../../');
|
|
33
|
-
|
|
33
|
+
// Use sdk-browser.js for browser builds to avoid server-only imports
|
|
34
|
+
const sdkPath = path.join(frameworkCoreDir, 'sdk-browser.js');
|
|
34
35
|
const projectComponentsPath = path.resolve(cwd, `${componentsDir}/index.js`);
|
|
35
36
|
|
|
36
37
|
// Check if paths exist before building
|
package/core/cli/commands/dev.js
CHANGED
|
@@ -36,7 +36,8 @@ export async function dev() {
|
|
|
36
36
|
// 3. JS-First Page Rendering
|
|
37
37
|
const pageName = pathname.replace(/^\//, '').replace(/\.html$/, '');
|
|
38
38
|
const cwd = process.cwd();
|
|
39
|
-
const
|
|
39
|
+
const { existsSync } = await import('node:fs');
|
|
40
|
+
const hasSrc = existsSync(nodePath.join(cwd, 'src/pages'));
|
|
40
41
|
const pagesDir = hasSrc ? 'src/pages' : 'pages';
|
|
41
42
|
const jsPagePath = `./${pagesDir}/${pageName}.js`;
|
|
42
43
|
|
|
@@ -74,7 +75,7 @@ export async function dev() {
|
|
|
74
75
|
return new Response(htmlContent, { headers: { 'Content-Type': 'text/html' } });
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
// 5. Static Assets
|
|
78
|
+
// 5. Static Assets (project root)
|
|
78
79
|
const file = Bun.file('.' + url.pathname);
|
|
79
80
|
if (await file.exists()) {
|
|
80
81
|
if (pathname.endsWith('.html')) {
|
|
@@ -93,7 +94,26 @@ export async function dev() {
|
|
|
93
94
|
return new Response(file, { headers: { 'Content-Type': types[ext] || 'application/octet-stream' } });
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
// 6.
|
|
97
|
+
// 6. node_modules serving (for bare import resolution via importmap)
|
|
98
|
+
if (pathname.startsWith('/node_modules/')) {
|
|
99
|
+
const nmFile = Bun.file('.' + pathname);
|
|
100
|
+
if (await nmFile.exists()) {
|
|
101
|
+
const ext = pathname.split('.').pop();
|
|
102
|
+
const types = {
|
|
103
|
+
css: 'text/css', js: 'application/javascript', mjs: 'application/javascript',
|
|
104
|
+
json: 'application/json', svg: 'image/svg+xml', woff: 'font/woff',
|
|
105
|
+
woff2: 'font/woff2', ttf: 'font/ttf'
|
|
106
|
+
};
|
|
107
|
+
return new Response(nmFile, {
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': types[ext] || 'application/octet-stream',
|
|
110
|
+
'Access-Control-Allow-Origin': '*'
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 7. Framework Fallback (for linked projects)
|
|
97
117
|
const frameworkFile = Bun.file(nodePath.join(frameworkRoot, url.pathname));
|
|
98
118
|
if (await frameworkFile.exists()) {
|
|
99
119
|
const ext = pathname.split('.').pop();
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AfriCode Browser SDK
|
|
3
|
+
* Client-side only entry point. Does not include server-only APIs.
|
|
4
|
+
*
|
|
5
|
+
* Use this for Bun.build({ target: 'browser' })
|
|
6
|
+
* Use the full sdk.js for server/SSR contexts
|
|
7
|
+
*
|
|
8
|
+
* Philosophy: Browser-safe, tree-shakeable, zero server APIs
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createReactiveState, subscribe, createSignal, createEffect } from './state.js';
|
|
12
|
+
import { store, actions } from './store.js';
|
|
13
|
+
import patterns from './patterns.js';
|
|
14
|
+
import * as motion from './motion.js';
|
|
15
|
+
import { hydrate } from './hydration.js';
|
|
16
|
+
import { html, Layout } from './html.js';
|
|
17
|
+
import { schemas, Validation, rules, afri, AfriFieldBuilder, normalizeInput, buildSchema } from './validation.js';
|
|
18
|
+
import { createFramework, getConfig } from './config.js';
|
|
19
|
+
import { getRequestIdentity, parseCookieHeader, createSessionId, SESSION_COOKIE_NAME } from './request-identity.js';
|
|
20
|
+
import { sessionStore } from './session-store.js';
|
|
21
|
+
import { actions as runtimeActions } from './actions.js';
|
|
22
|
+
import { MiddlewareManager, loggerMiddleware, authMiddleware } from './middleware.js';
|
|
23
|
+
import {
|
|
24
|
+
AfriCodeError, ValidationError, InvalidUrlError,
|
|
25
|
+
SecurityError, CsrfError, RateLimitError,
|
|
26
|
+
DatabaseError, ComponentError
|
|
27
|
+
} from './errors.js';
|
|
28
|
+
|
|
29
|
+
// v5.0.0 Browser-safe exports (A2UI protocol)
|
|
30
|
+
import { initA2UI, A2UIRenderer, A2UIProtocol } from './a2ui.js';
|
|
31
|
+
|
|
32
|
+
import { componentMap as coreMap } from '../components/index.js';
|
|
33
|
+
|
|
34
|
+
// Utility to initialize the browser framework
|
|
35
|
+
export function init(projectComponentMap = {}) {
|
|
36
|
+
if (typeof window !== 'undefined') {
|
|
37
|
+
console.log('🌍 AfriCode Browser SDK Initialized');
|
|
38
|
+
|
|
39
|
+
// Merge project map with core map
|
|
40
|
+
const finalMap = { ...coreMap, ...projectComponentMap };
|
|
41
|
+
|
|
42
|
+
if (Object.keys(finalMap).length > 0) {
|
|
43
|
+
hydrate(finalMap);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Browser-safe grouped exports
|
|
49
|
+
export {
|
|
50
|
+
createReactiveState,
|
|
51
|
+
subscribe,
|
|
52
|
+
createSignal,
|
|
53
|
+
createEffect
|
|
54
|
+
} from './state.js';
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
store,
|
|
58
|
+
actions,
|
|
59
|
+
patterns,
|
|
60
|
+
motion,
|
|
61
|
+
html,
|
|
62
|
+
Layout,
|
|
63
|
+
schemas,
|
|
64
|
+
Validation,
|
|
65
|
+
rules,
|
|
66
|
+
afri,
|
|
67
|
+
AfriFieldBuilder,
|
|
68
|
+
normalizeInput,
|
|
69
|
+
buildSchema,
|
|
70
|
+
createFramework,
|
|
71
|
+
getConfig,
|
|
72
|
+
getRequestIdentity,
|
|
73
|
+
parseCookieHeader,
|
|
74
|
+
createSessionId,
|
|
75
|
+
SESSION_COOKIE_NAME,
|
|
76
|
+
sessionStore,
|
|
77
|
+
runtimeActions,
|
|
78
|
+
MiddlewareManager,
|
|
79
|
+
loggerMiddleware,
|
|
80
|
+
authMiddleware,
|
|
81
|
+
AfriCodeError,
|
|
82
|
+
ValidationError,
|
|
83
|
+
InvalidUrlError,
|
|
84
|
+
SecurityError,
|
|
85
|
+
CsrfError,
|
|
86
|
+
RateLimitError,
|
|
87
|
+
DatabaseError,
|
|
88
|
+
ComponentError
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Browser-only exports (A2UI for AI-safe rendering)
|
|
92
|
+
export {
|
|
93
|
+
initA2UI,
|
|
94
|
+
A2UIRenderer,
|
|
95
|
+
A2UIProtocol
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Default Export (Browser-safe)
|
|
99
|
+
export default {
|
|
100
|
+
createReactiveState,
|
|
101
|
+
subscribe,
|
|
102
|
+
createSignal,
|
|
103
|
+
createEffect,
|
|
104
|
+
store,
|
|
105
|
+
actions,
|
|
106
|
+
patterns,
|
|
107
|
+
motion,
|
|
108
|
+
html,
|
|
109
|
+
Layout,
|
|
110
|
+
schemas,
|
|
111
|
+
Validation,
|
|
112
|
+
rules,
|
|
113
|
+
afri,
|
|
114
|
+
AfriFieldBuilder,
|
|
115
|
+
normalizeInput,
|
|
116
|
+
buildSchema,
|
|
117
|
+
createFramework,
|
|
118
|
+
getConfig,
|
|
119
|
+
getRequestIdentity,
|
|
120
|
+
parseCookieHeader,
|
|
121
|
+
createSessionId,
|
|
122
|
+
SESSION_COOKIE_NAME,
|
|
123
|
+
sessionStore,
|
|
124
|
+
runtimeActions,
|
|
125
|
+
MiddlewareManager,
|
|
126
|
+
loggerMiddleware,
|
|
127
|
+
authMiddleware,
|
|
128
|
+
AfriCodeError,
|
|
129
|
+
ValidationError,
|
|
130
|
+
InvalidUrlError,
|
|
131
|
+
SecurityError,
|
|
132
|
+
CsrfError,
|
|
133
|
+
RateLimitError,
|
|
134
|
+
DatabaseError,
|
|
135
|
+
ComponentError,
|
|
136
|
+
initA2UI,
|
|
137
|
+
A2UIRenderer,
|
|
138
|
+
A2UIProtocol,
|
|
139
|
+
init
|
|
140
|
+
};
|