onelaraveljs 1.0.0 → 1.1.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 (119) hide show
  1. package/README.md +1 -1
  2. package/bin/onejs-build.js +32 -0
  3. package/package.json +11 -3
  4. package/scripts/README-template-compiler.md +133 -0
  5. package/scripts/README.md +61 -0
  6. package/scripts/__pycache__/build.cpython-314.pyc +0 -0
  7. package/scripts/__pycache__/compile.cpython-313.pyc +0 -0
  8. package/scripts/__pycache__/compile.cpython-314.pyc +0 -0
  9. package/scripts/build.py +573 -0
  10. package/scripts/check-system-errors.php +214 -0
  11. package/scripts/compile.py +101 -0
  12. package/scripts/compiler/README_CONFIG.md +196 -0
  13. package/scripts/compiler/__init__.py +18 -0
  14. package/scripts/compiler/__pycache__/__init__.cpython-313.pyc +0 -0
  15. package/scripts/compiler/__pycache__/__init__.cpython-314.pyc +0 -0
  16. package/scripts/compiler/__pycache__/binding_directive_service.cpython-314.pyc +0 -0
  17. package/scripts/compiler/__pycache__/class_binding_handler.cpython-314.pyc +0 -0
  18. package/scripts/compiler/__pycache__/compiler_utils.cpython-313.pyc +0 -0
  19. package/scripts/compiler/__pycache__/compiler_utils.cpython-314.pyc +0 -0
  20. package/scripts/compiler/__pycache__/conditional_handlers.cpython-313.pyc +0 -0
  21. package/scripts/compiler/__pycache__/conditional_handlers.cpython-314.pyc +0 -0
  22. package/scripts/compiler/__pycache__/config.cpython-313.pyc +0 -0
  23. package/scripts/compiler/__pycache__/config.cpython-314.pyc +0 -0
  24. package/scripts/compiler/__pycache__/declaration_tracker.cpython-314.pyc +0 -0
  25. package/scripts/compiler/__pycache__/directive_processors.cpython-313.pyc +0 -0
  26. package/scripts/compiler/__pycache__/directive_processors.cpython-314.pyc +0 -0
  27. package/scripts/compiler/__pycache__/echo_processor.cpython-314.pyc +0 -0
  28. package/scripts/compiler/__pycache__/event_directive_processor.cpython-313.pyc +0 -0
  29. package/scripts/compiler/__pycache__/event_directive_processor.cpython-314.pyc +0 -0
  30. package/scripts/compiler/__pycache__/function_generators.cpython-313.pyc +0 -0
  31. package/scripts/compiler/__pycache__/function_generators.cpython-314.pyc +0 -0
  32. package/scripts/compiler/__pycache__/loop_handlers.cpython-313.pyc +0 -0
  33. package/scripts/compiler/__pycache__/loop_handlers.cpython-314.pyc +0 -0
  34. package/scripts/compiler/__pycache__/main_compiler.cpython-313.pyc +0 -0
  35. package/scripts/compiler/__pycache__/main_compiler.cpython-314.pyc +0 -0
  36. package/scripts/compiler/__pycache__/parsers.cpython-313.pyc +0 -0
  37. package/scripts/compiler/__pycache__/parsers.cpython-314.pyc +0 -0
  38. package/scripts/compiler/__pycache__/php_converter.cpython-313.pyc +0 -0
  39. package/scripts/compiler/__pycache__/php_converter.cpython-314.pyc +0 -0
  40. package/scripts/compiler/__pycache__/php_js_converter.cpython-313.pyc +0 -0
  41. package/scripts/compiler/__pycache__/php_js_converter.cpython-314.pyc +0 -0
  42. package/scripts/compiler/__pycache__/register_parser.cpython-313.pyc +0 -0
  43. package/scripts/compiler/__pycache__/register_parser.cpython-314.pyc +0 -0
  44. package/scripts/compiler/__pycache__/section_handlers.cpython-313.pyc +0 -0
  45. package/scripts/compiler/__pycache__/section_handlers.cpython-314.pyc +0 -0
  46. package/scripts/compiler/__pycache__/show_directive_handler.cpython-314.pyc +0 -0
  47. package/scripts/compiler/__pycache__/style_directive_handler.cpython-314.pyc +0 -0
  48. package/scripts/compiler/__pycache__/template_analyzer.cpython-313.pyc +0 -0
  49. package/scripts/compiler/__pycache__/template_analyzer.cpython-314.pyc +0 -0
  50. package/scripts/compiler/__pycache__/template_processor.cpython-313.pyc +0 -0
  51. package/scripts/compiler/__pycache__/template_processor.cpython-314.pyc +0 -0
  52. package/scripts/compiler/__pycache__/template_processors.cpython-313.pyc +0 -0
  53. package/scripts/compiler/__pycache__/template_processors.cpython-314.pyc +0 -0
  54. package/scripts/compiler/__pycache__/utils.cpython-313.pyc +0 -0
  55. package/scripts/compiler/__pycache__/utils.cpython-314.pyc +0 -0
  56. package/scripts/compiler/__pycache__/wrapper_parser.cpython-313.pyc +0 -0
  57. package/scripts/compiler/__pycache__/wrapper_parser.cpython-314.pyc +0 -0
  58. package/scripts/compiler/binding_directive_service.py +103 -0
  59. package/scripts/compiler/class_binding_handler.py +347 -0
  60. package/scripts/compiler/cli.py +34 -0
  61. package/scripts/compiler/code_generator.py +141 -0
  62. package/scripts/compiler/compiler.config.json +36 -0
  63. package/scripts/compiler/compiler_utils.py +55 -0
  64. package/scripts/compiler/conditional_handlers.py +252 -0
  65. package/scripts/compiler/config.py +107 -0
  66. package/scripts/compiler/declaration_tracker.py +420 -0
  67. package/scripts/compiler/directive_processors.py +603 -0
  68. package/scripts/compiler/echo_processor.py +667 -0
  69. package/scripts/compiler/event_directive_processor.py +1099 -0
  70. package/scripts/compiler/fetch_parser.py +49 -0
  71. package/scripts/compiler/function_generators.py +310 -0
  72. package/scripts/compiler/loop_handlers.py +224 -0
  73. package/scripts/compiler/main_compiler.py +1763 -0
  74. package/scripts/compiler/parsers.py +1418 -0
  75. package/scripts/compiler/php_converter.py +470 -0
  76. package/scripts/compiler/php_js_converter.py +603 -0
  77. package/scripts/compiler/register_parser.py +480 -0
  78. package/scripts/compiler/section_handlers.py +122 -0
  79. package/scripts/compiler/show_directive_handler.py +85 -0
  80. package/scripts/compiler/style_directive_handler.py +169 -0
  81. package/scripts/compiler/template_analyzer.py +162 -0
  82. package/scripts/compiler/template_processor.py +1167 -0
  83. package/scripts/compiler/template_processors.py +1557 -0
  84. package/scripts/compiler/test_compiler.py +69 -0
  85. package/scripts/compiler/utils.py +54 -0
  86. package/scripts/compiler/variables_analyzer.py +135 -0
  87. package/scripts/compiler/view_identifier_generator.py +278 -0
  88. package/scripts/compiler/wrapper_parser.py +78 -0
  89. package/scripts/dev-context.js +311 -0
  90. package/scripts/dev.js +109 -0
  91. package/scripts/generate-assets-order.js +200 -0
  92. package/scripts/migrate-namespace.php +146 -0
  93. package/scripts/node/MIGRATION.md +190 -0
  94. package/scripts/node/README.md +269 -0
  95. package/scripts/node/build.js +208 -0
  96. package/scripts/node/compiler/compiler-utils.js +38 -0
  97. package/scripts/node/compiler/conditional-handlers.js +45 -0
  98. package/scripts/node/compiler/config.js +178 -0
  99. package/scripts/node/compiler/directive-processors.js +51 -0
  100. package/scripts/node/compiler/event-directive-processor.js +182 -0
  101. package/scripts/node/compiler/function-generators.js +239 -0
  102. package/scripts/node/compiler/loop-handlers.js +45 -0
  103. package/scripts/node/compiler/main-compiler.js +236 -0
  104. package/scripts/node/compiler/parsers.js +358 -0
  105. package/scripts/node/compiler/php-converter.js +227 -0
  106. package/scripts/node/compiler/register-parser.js +32 -0
  107. package/scripts/node/compiler/section-handlers.js +46 -0
  108. package/scripts/node/compiler/template-analyzer.js +50 -0
  109. package/scripts/node/compiler/template-processor.js +371 -0
  110. package/scripts/node/compiler/template-processors.js +219 -0
  111. package/scripts/node/compiler/utils.js +203 -0
  112. package/scripts/node/compiler/wrapper-parser.js +25 -0
  113. package/scripts/node/package.json +24 -0
  114. package/scripts/node/test-compiler.js +52 -0
  115. package/scripts/node-run.cjs +28 -0
  116. package/scripts/standardize-directories.php +92 -0
  117. package/templates/view.module.js +2 -0
  118. package/templates/view.tpl-raw.js +13 -0
  119. package/templates/wraper.js +71 -0
package/README.md CHANGED
@@ -71,7 +71,7 @@ Ensure your main layout file injects the configuration:
71
71
  OneJS comes with a built-in Event Service for cross-component communication:
72
72
 
73
73
  ```javascript
74
- import { App } from '@onelaravel/onejs';
74
+ import { App } from 'onelaraveljs';
75
75
 
76
76
  // Listen
77
77
  App.Event.on('user:logged-in', (user) => {
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'child_process';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ // Path to the python script in the library
10
+ const scriptPath = path.resolve(__dirname, '../scripts/build.py');
11
+
12
+ // Get arguments passed to the CLI
13
+ const args = process.argv.slice(2);
14
+
15
+ console.log('🚀 OneJS Build System');
16
+ console.log('Script:', scriptPath);
17
+
18
+ // Spawn python process
19
+ const pythonProcess = spawn('python3', [scriptPath, ...args], {
20
+ stdio: 'inherit',
21
+ env: {
22
+ ...process.env,
23
+ // PASS THE PROJECT ROOT (Current Working Directory of the user)
24
+ ONEJS_PROJECT_ROOT: process.cwd(),
25
+ // PASS THE LIBRARY ROOT (Where the script lives)
26
+ ONEJS_LIB_ROOT: path.resolve(__dirname, '..')
27
+ }
28
+ });
29
+
30
+ pythonProcess.on('close', (code) => {
31
+ process.exit(code);
32
+ });
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "onelaraveljs",
3
- "version": "1.0.0",
4
- "description": "OneLaravel JS Framework Core",
3
+ "version": "1.1.1",
4
+ "description": "OneLaravel JS Framework Core & Compiler",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "onejs-build": "./bin/onejs-build.js"
8
+ },
6
9
  "type": "module",
7
10
  "scripts": {
8
11
  "test": "echo \"Error: no test specified\" && exit 1"
9
12
  },
10
- "keywords": ["framework", "laravel", "spa"],
13
+ "keywords": [
14
+ "framework",
15
+ "laravel",
16
+ "spa",
17
+ "compiler"
18
+ ],
11
19
  "author": "OneLaravel",
12
20
  "license": "MIT"
13
21
  }
@@ -0,0 +1,133 @@
1
+ # Template Compiler
2
+
3
+ Python compiler để chuyển đổi Blade `@template` và `@useTemplate` thành JavaScript.
4
+
5
+ ## 🎯 Tính năng
6
+
7
+ - ✅ Chuyển đổi `@template` thành JavaScript function
8
+ - ✅ Chuyển đổi `@useTemplate` thành `this.renderTemplate()`
9
+ - ✅ Hỗ trợ `@params`, `@subscribe`, `@props`
10
+ - ✅ Xóa `@template` blocks khỏi view sau khi compile
11
+ - ✅ Tự động detect array type (indexed/associative)
12
+ - ✅ Context fallback mechanism
13
+ - ✅ Watch mode để tự động compile
14
+
15
+ ## 🚀 Sử dụng
16
+
17
+ ### 1. Compile một lần
18
+ ```bash
19
+ python3 scripts/compile-templates.py
20
+ ```
21
+
22
+ ### 2. Watch mode (tự động compile khi có thay đổi)
23
+ ```bash
24
+ python3 scripts/watch-templates.py
25
+ ```
26
+
27
+ ### 3. Compile file cụ thể
28
+ ```bash
29
+ python3 scripts/compiler/template_compiler.py input.js output.js
30
+ ```
31
+
32
+ ## 📝 Cú pháp Blade
33
+
34
+ ### Template Definition
35
+ ```blade
36
+ @template('profile', @params($userState, $isEditModalOpen), @subscribe($userState, $isEditModalOpen))
37
+ <div class="profile">
38
+ <h1>{{ $userState['name'] }}</h1>
39
+ <p>{{ $userState['email'] }}</p>
40
+ @if($isEditModalOpen)
41
+ <div class="modal">Edit Mode</div>
42
+ @endif
43
+ </div>
44
+ @endtemplate
45
+ ```
46
+
47
+ ### Template Usage
48
+ ```blade
49
+ @useTemplate('profile', [$userState, $isEditModalOpen])
50
+ @useTemplate('sidebar', ['items' => $items])
51
+ @useTemplate('header')
52
+ ```
53
+
54
+ ## 🔄 Kết quả compile
55
+
56
+ ### Template Engine Setup
57
+ ```javascript
58
+ const templateEngine = new TemplateEngine(App, View, self, subscribe);
59
+ templateEngine.setTemplates({
60
+ "profile": function(context, data) {
61
+ let {userState, isEditModalOpen} = context;
62
+ const userState = Array.isArray(data) ? data[0] : (data.userState || null);
63
+ const isEditModalOpen = Array.isArray(data) ? data[1] : (data.isEditModalOpen || null);
64
+ // Subscribe to: userState, isEditModalOpen
65
+ return `<div class="profile">
66
+ <h1>${userState?.name || 'Unknown'}</h1>
67
+ <p>${userState?.email || 'No email'}</p>
68
+ <p>Role: ${userState?.role || 'User'}</p>
69
+ <p>Modal open: ${isEditModalOpen ? 'Yes' : 'No'}</p>
70
+ </div>`;
71
+ }
72
+ });
73
+ self.setTemplateEngine(templateEngine);
74
+ ```
75
+
76
+ ### Template Usage
77
+ ```javascript
78
+ this.renderTemplate('profile', [userState, isEditModalOpen])
79
+ this.renderTemplate('sidebar', ['items' => items])
80
+ this.renderTemplate('header')
81
+ ```
82
+
83
+ ## 🛠️ Cấu trúc file
84
+
85
+ ```
86
+ scripts/
87
+ ├── compiler/
88
+ │ └── template_compiler.py # Main compiler
89
+ ├── compile-templates.py # One-time compile script
90
+ ├── watch-templates.py # Watch mode script
91
+ └── README-template-compiler.md # Documentation
92
+ ```
93
+
94
+ ## 📋 Requirements
95
+
96
+ - Python 3.6+
97
+ - No external dependencies
98
+
99
+ ## 🔧 Cấu hình
100
+
101
+ ### Input/Output Directories
102
+ - **Input**: `resources/js/app/views/`
103
+ - **Output**: `public/build/views/`
104
+
105
+ ### Supported File Types
106
+ - `.js` files only
107
+
108
+ ## 🐛 Troubleshooting
109
+
110
+ ### Lỗi thường gặp
111
+
112
+ 1. **Template không được compile**
113
+ - Kiểm tra cú pháp Blade
114
+ - Đảm bảo `@template` và `@endtemplate` đúng
115
+
116
+ 2. **Variable không hiển thị**
117
+ - Kiểm tra `@params` declaration
118
+ - Đảm bảo variable được pass vào `@useTemplate`
119
+
120
+ 3. **Array type detection sai**
121
+ - Compiler tự động detect array type
122
+ - Kiểm tra data format khi pass vào template
123
+
124
+ ### Debug
125
+
126
+ Để debug, kiểm tra file output trong `public/build/views/`:
127
+ ```bash
128
+ cat public/build/views/YourView.js
129
+ ```
130
+
131
+ ## 📚 Examples
132
+
133
+ Xem file `resources/js/app/views/ExampleView.js` để tham khảo cú pháp và cách sử dụng.
@@ -0,0 +1,61 @@
1
+ # Scripts Directory
2
+
3
+ Thư mục này chứa các script Python để build và compile Blade templates.
4
+
5
+ ## Cấu trúc
6
+
7
+ ```
8
+ scripts/
9
+ ├── build.py # Script chính để build Blade templates
10
+ ├── compile.py # Wrapper cho Blade compiler
11
+ ├── dev.js # Development server với hot reload
12
+ └── compiler/ # Thư mục chứa compiler modules
13
+ ├── __init__.py
14
+ ├── config.py # Configuration cho compiler
15
+ ├── compiler.config.json # File config JSON
16
+ └── ... # Các module compiler khác
17
+ ```
18
+
19
+ ## Sử dụng
20
+
21
+ ### Từ thư mục gốc:
22
+ ```bash
23
+ npm run build:templates # Build Blade templates
24
+ npm run compile # Build templates + webpack
25
+ npm run dev:blade # Development server
26
+ ```
27
+
28
+ ### Từ thư mục scripts:
29
+ ```bash
30
+ cd scripts
31
+ python3 build.py # Build Blade templates
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ File `compiler/compiler.config.json` chứa cấu hình đường dẫn:
37
+
38
+ - `views_input`: Thư mục chứa Blade templates (`resources/views`)
39
+ - `js_input`: Thư mục chứa JavaScript modules (`resources/js/app`)
40
+ - `build_output`: Thư mục build tạm thời (`resources/js/build`)
41
+ - `app_output`: Thư mục output cuối cùng (`public/static/app`)
42
+
43
+ ## Development
44
+
45
+ Script `dev.js` cung cấp development server với:
46
+ - Hot reload khi file Blade templates thay đổi
47
+ - Auto-rebuild khi có thay đổi
48
+ - Vite dev server cho frontend
49
+
50
+ ## Notes
51
+
52
+ - Tất cả đường dẫn được tính từ project root
53
+ - Compiler tự động detect và build tất cả `.blade.php` files
54
+ - Output được copy vào `resources/js/app/views/templates.js`
55
+
56
+
57
+
58
+
59
+
60
+
61
+