@nitronjs/framework 0.1.24 → 0.2.1

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 (41) hide show
  1. package/README.md +331 -253
  2. package/lib/Build/CssBuilder.js +129 -0
  3. package/lib/Build/FileAnalyzer.js +395 -0
  4. package/lib/Build/HydrationBuilder.js +173 -0
  5. package/lib/Build/Manager.js +290 -943
  6. package/lib/Build/colors.js +10 -0
  7. package/lib/Build/jsxRuntime.js +116 -0
  8. package/lib/Build/plugins.js +264 -0
  9. package/lib/Console/Commands/BuildCommand.js +6 -5
  10. package/lib/Console/Commands/DevCommand.js +151 -311
  11. package/lib/Console/Stubs/page-hydration-dev.tsx +72 -0
  12. package/lib/Console/Stubs/page-hydration.tsx +9 -10
  13. package/lib/Console/Stubs/vendor-dev.tsx +50 -0
  14. package/lib/Core/Environment.js +29 -2
  15. package/lib/Core/Paths.js +12 -4
  16. package/lib/Database/Drivers/MySQLDriver.js +5 -4
  17. package/lib/Database/Migration/MigrationRepository.js +2 -6
  18. package/lib/Database/Model.js +7 -8
  19. package/lib/Database/QueryBuilder.js +2 -3
  20. package/lib/Database/Seeder/SeederRepository.js +2 -6
  21. package/lib/Filesystem/Manager.js +32 -7
  22. package/lib/HMR/Server.js +87 -0
  23. package/lib/Http/Server.js +9 -5
  24. package/lib/Logging/Manager.js +68 -18
  25. package/lib/Route/Loader.js +3 -4
  26. package/lib/Route/Manager.js +24 -3
  27. package/lib/Runtime/Entry.js +26 -1
  28. package/lib/Session/File.js +18 -7
  29. package/lib/View/Client/hmr-client.js +166 -0
  30. package/lib/View/Client/spa.js +142 -0
  31. package/lib/View/Layout.js +94 -0
  32. package/lib/View/Manager.js +390 -46
  33. package/lib/index.d.ts +55 -0
  34. package/package.json +2 -1
  35. package/skeleton/.env.example +0 -2
  36. package/skeleton/app/Controllers/HomeController.js +4 -4
  37. package/skeleton/config/app.js +15 -14
  38. package/skeleton/config/session.js +1 -1
  39. package/skeleton/globals.d.ts +3 -63
  40. package/skeleton/resources/views/Site/Home.tsx +62 -42
  41. package/skeleton/tsconfig.json +5 -1
@@ -5,20 +5,21 @@ export default {
5
5
  /**
6
6
  * Content Security Policy (CSP) Whitelist
7
7
  *
8
- * Add trusted external domains for each resource type.
9
- * These will be appended to the default secure CSP policy.
8
+ * Format 1 - Simple URL array (applies to all resource types):
9
+ * csp: ["https://fonts.googleapis.com", "https://fonts.gstatic.com"]
10
10
  *
11
- * Examples:
12
- * - Google Fonts: styles: ["https://fonts.googleapis.com"], fonts: ["https://fonts.gstatic.com"]
13
- * - Cloudflare CDN: scripts: ["https://cdnjs.cloudflare.com"]
14
- * - Google Analytics: scripts: ["https://www.googletagmanager.com"], connect: ["https://www.google-analytics.com"]
11
+ * Format 2 - Wildcard (allows all external resources - not recommended for production):
12
+ * csp: ["*"]
13
+ *
14
+ * Format 3 - Detailed per-type configuration:
15
+ * csp: {
16
+ * styles: ["https://fonts.googleapis.com"],
17
+ * fonts: ["https://fonts.gstatic.com"],
18
+ * scripts: ["https://cdnjs.cloudflare.com"],
19
+ * images: [],
20
+ * connect: [],
21
+ * frames: [],
22
+ * }
15
23
  */
16
- csp: {
17
- styles: [],
18
- fonts: [],
19
- images: [],
20
- scripts: [],
21
- connect: [],
22
- frames: [],
23
- },
24
+ csp: [],
24
25
  }
@@ -6,7 +6,7 @@ export default {
6
6
  cookieName: "session",
7
7
  cookie: {
8
8
  httpOnly: true,
9
- secure: process.env.APP_DEV !== "true",
9
+ secure: false, // Set to true in production with HTTPS
10
10
  sameSite: "lax",
11
11
  path: "/",
12
12
  maxAge: SESSION_LIFETIME
@@ -1,68 +1,8 @@
1
1
  /**
2
2
  * NitronJS Global Types
3
3
  *
4
- * Framework types are provided by @nitronjs/framework package.
5
- * This file only contains global function declarations.
4
+ * This file imports global type declarations from the framework.
5
+ * All global functions (csrf, route, request) are available without import.
6
6
  */
7
7
 
8
- /**
9
- * Returns the CSRF token for the current request.
10
- * Works on both SSR and client-side.
11
- *
12
- * @example
13
- * // In a form
14
- * <input type="hidden" name="_csrf" value={csrf()} />
15
- *
16
- * // In a fetch request
17
- * fetch('/api/action', {
18
- * method: 'POST',
19
- * headers: { 'X-CSRF-Token': csrf() }
20
- * })
21
- */
22
- declare function csrf(): string;
23
-
24
- /**
25
- * Returns the URL for a named route.
26
- * Works on both SSR and client-side.
27
- *
28
- * @param name - The route name as defined in routes/web.js
29
- * @param params - Optional route parameters
30
- * @example
31
- * <a href={route('home')}>Home</a>
32
- * <a href={route('admin.dashboard')}>Dashboard</a>
33
- * <a href={route('admin.users.edit', { id: 1 })}>Edit User</a>
34
- */
35
- declare function route(name: string, params?: Record<string, any>): string;
36
-
37
- /**
38
- * Returns the current request object.
39
- * Only works in Server Components during SSR.
40
- *
41
- * @example
42
- * // Get query parameters
43
- * const tab = request().query.tab || 'general';
44
- *
45
- * // Get URL parameters
46
- * const id = request().params.id;
47
- *
48
- * // Get request method
49
- * const method = request().method;
50
- */
51
- declare function request(): {
52
- path: string;
53
- method: string;
54
- query: Record<string, any>;
55
- params: Record<string, any>;
56
- body: Record<string, any>;
57
- headers: Record<string, string>;
58
- cookies: Record<string, string>;
59
- ip: string;
60
- isAjax: boolean;
61
- session: {
62
- get<T = any>(key: string, defaultValue?: T): T;
63
- set(key: string, value: any): void;
64
- has(key: string): boolean;
65
- forget(key: string): void;
66
- flash(key: string, value: any): void;
67
- };
68
- };
8
+ /// <reference types="@nitronjs/framework" />
@@ -1,65 +1,85 @@
1
1
  type HomeProps = {
2
- name?: string;
2
+ version?: string;
3
3
  };
4
4
 
5
- export default function Home({ name = "NitronJS" }: HomeProps) {
5
+ export default function Home({ version = "0.2.0" }: HomeProps) {
6
6
  return (
7
7
  <main style={{
8
8
  minHeight: "100vh",
9
+ background: "#0a0a0a",
10
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
11
+ color: "#e4e4e7",
9
12
  display: "flex",
10
13
  flexDirection: "column",
11
14
  alignItems: "center",
12
15
  justifyContent: "center",
13
- gap: "1.5rem",
14
- color: "#fff",
15
- background: "radial-gradient(circle at top, #111827, #0b0f19)",
16
- fontFamily: "system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif",
17
- padding: "4rem 1.5rem"
16
+ padding: "2rem",
17
+ boxSizing: "border-box"
18
18
  }}>
19
+ <div style={{
20
+ width: 64,
21
+ height: 64,
22
+ background: "#fff",
23
+ borderRadius: 14,
24
+ display: "flex",
25
+ alignItems: "center",
26
+ justifyContent: "center",
27
+ marginBottom: "2rem"
28
+ }}>
29
+ <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="#0a0a0a" strokeWidth="2.5">
30
+ <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
31
+ </svg>
32
+ </div>
33
+
19
34
  <h1 style={{
20
- fontSize: "3.5rem",
21
- lineHeight: "1.1",
35
+ fontSize: "2.5rem",
36
+ fontWeight: 700,
22
37
  margin: 0,
23
- textAlign: "center"
38
+ color: "#fff",
39
+ letterSpacing: "-0.02em"
24
40
  }}>
25
- Welcome to {name}
41
+ Welcome to NitronJS
26
42
  </h1>
43
+
27
44
  <p style={{
28
- maxWidth: "680px",
29
- textAlign: "center",
30
- color: "#94a3b8",
31
- margin: 0,
32
- fontSize: "1.125rem"
45
+ fontSize: "1.1rem",
46
+ color: "#71717a",
47
+ maxWidth: 400,
48
+ margin: "1.5rem 0 2rem",
49
+ lineHeight: 1.6,
50
+ textAlign: "center"
33
51
  }}>
34
- Your project is ready. Start building pages with React SSR and the NitronJS MVC structure.
52
+ Your application is ready. Start building by editing the files in <code style={{ color: "#a1a1aa", background: "#1a1a1a", padding: "2px 6px", borderRadius: 4 }}>resources/views</code>
35
53
  </p>
36
- <div style={{
37
- display: "flex",
38
- gap: "0.75rem",
39
- flexWrap: "wrap",
40
- justifyContent: "center"
41
- }}>
42
- <a href="https://nitronjs.dev/docs" style={{
43
- padding: "0.75rem 1.5rem",
44
- borderRadius: "10px",
45
- background: "#3b82f6",
46
- color: "#fff",
47
- textDecoration: "none",
48
- fontWeight: 600
49
- }}>
50
- Documentation
51
- </a>
52
- <a href="https://nitronjs.dev" style={{
54
+
55
+ <a
56
+ href="https://nitronjs.dev/docs"
57
+ style={{
58
+ display: "inline-flex",
59
+ alignItems: "center",
60
+ gap: "0.5rem",
53
61
  padding: "0.75rem 1.5rem",
54
- borderRadius: "10px",
55
- background: "transparent",
56
- color: "#e2e8f0",
62
+ background: "#fff",
63
+ color: "#0a0a0a",
57
64
  textDecoration: "none",
58
- border: "1px solid #334155",
59
- fontWeight: 600
60
- }}>
61
- Website
62
- </a>
65
+ fontWeight: 600,
66
+ fontSize: "0.9rem",
67
+ borderRadius: 8
68
+ }}
69
+ >
70
+ Documentation
71
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
72
+ <path d="M5 12h14M12 5l7 7-7 7"/>
73
+ </svg>
74
+ </a>
75
+
76
+ <div style={{
77
+ position: "fixed",
78
+ bottom: "1.5rem",
79
+ color: "#3f3f46",
80
+ fontSize: "0.8rem"
81
+ }}>
82
+ v{version}
63
83
  </div>
64
84
  </main>
65
85
  );
@@ -10,7 +10,11 @@
10
10
  "esModuleInterop": true,
11
11
  "skipLibCheck": true,
12
12
  "forceConsistentCasingInFileNames": true,
13
- "noEmit": true
13
+ "noEmit": true,
14
+ "baseUrl": ".",
15
+ "paths": {
16
+ "@/*": ["./*"]
17
+ }
14
18
  },
15
19
  "include": [
16
20
  "./globals.d.ts",