onelaraveljs 1.1.9 → 1.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.
package/package.json
CHANGED
|
@@ -16,22 +16,37 @@ class WrapperParser:
|
|
|
16
16
|
self.wrapper_function_content = ""
|
|
17
17
|
self.wrapper_config_content = ""
|
|
18
18
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
# Logic tìm kiếm file template:
|
|
20
|
+
# 1. Tìm theo đường dẫn được cung cấp (thường là User Custom Override trong project)
|
|
21
|
+
# 2. Nếu không thấy, tìm file mặc định trong thư mục templates của library (onejs/templates/wraper.js)
|
|
22
|
+
|
|
23
|
+
found_path = None
|
|
24
|
+
|
|
25
|
+
# 1. Check đường dẫn user cung cấp (relative to Project Root)
|
|
26
|
+
if os.path.exists(file_path):
|
|
27
|
+
found_path = file_path
|
|
28
|
+
else:
|
|
29
|
+
# 2. Check đường dẫn mặc định trong library
|
|
30
|
+
# __file__ = .../onejs/scripts/compiler/wrapper_parser.py
|
|
31
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
32
|
+
# library_root = .../onejs
|
|
33
|
+
# template_path = .../onejs/templates/wraper.js
|
|
34
|
+
lib_template_path = os.path.normpath(os.path.join(script_dir, "..", "..", "templates", "wraper.js"))
|
|
35
|
+
|
|
36
|
+
if os.path.exists(lib_template_path):
|
|
37
|
+
found_path = lib_template_path
|
|
38
|
+
else:
|
|
39
|
+
# 3. Fallback: check alt_path (giữ tương thích cũ)
|
|
40
|
+
alt_path = os.path.normpath(os.path.join(script_dir, "..", "..", file_path))
|
|
26
41
|
if os.path.exists(alt_path):
|
|
27
|
-
|
|
42
|
+
found_path = alt_path
|
|
28
43
|
|
|
29
|
-
if not
|
|
30
|
-
print(f"Warning: Wrapper file not found: {file_path}")
|
|
44
|
+
if not found_path:
|
|
45
|
+
print(f"Warning: Wrapper file not found. Checked: {file_path} and library defaults.")
|
|
31
46
|
return "", ""
|
|
32
47
|
|
|
33
48
|
try:
|
|
34
|
-
with open(
|
|
49
|
+
with open(found_path, 'r', encoding='utf-8') as f:
|
|
35
50
|
content = f.read()
|
|
36
51
|
except Exception as e:
|
|
37
52
|
print(f"Error reading wrapper file: {e}")
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack Plugin to Generate View Registry
|
|
3
|
+
* Automatically creates viewRegistry.js with all views for lazy loading
|
|
4
|
+
*
|
|
5
|
+
* @author OneLaravel Team
|
|
6
|
+
* @since 2025-12-29
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = path.dirname(__filename);
|
|
15
|
+
|
|
16
|
+
class ViewRegistryPlugin {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
// Use process.cwd() to default to the project root, making this plugin portable
|
|
19
|
+
this.viewsDir = options.viewsDir || path.resolve(process.cwd(), 'resources/js/views');
|
|
20
|
+
this.outputFile = options.outputFile || path.resolve(process.cwd(), 'resources/js/.generated/config/viewRegistry.js');
|
|
21
|
+
this.preloadViews = options.preloadViews || [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(compiler) {
|
|
25
|
+
compiler.hooks.beforeCompile.tapAsync('ViewRegistryPlugin', (params, callback) => {
|
|
26
|
+
this.generateViewRegistry();
|
|
27
|
+
callback();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
generateViewRegistry() {
|
|
32
|
+
const views = this.scanViews(this.viewsDir);
|
|
33
|
+
const content = this.generateContent(views);
|
|
34
|
+
|
|
35
|
+
// Ensure directory exists
|
|
36
|
+
const dir = path.dirname(this.outputFile);
|
|
37
|
+
if (!fs.existsSync(dir)) {
|
|
38
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fs.writeFileSync(this.outputFile, content, 'utf8');
|
|
42
|
+
console.log(`✅ Generated view registry with ${views.length} views`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
scanViews(dir, basePath = '') {
|
|
46
|
+
const views = [];
|
|
47
|
+
const files = fs.readdirSync(dir);
|
|
48
|
+
|
|
49
|
+
files.forEach(file => {
|
|
50
|
+
const fullPath = path.join(dir, file);
|
|
51
|
+
const stat = fs.statSync(fullPath);
|
|
52
|
+
|
|
53
|
+
if (stat.isDirectory()) {
|
|
54
|
+
views.push(...this.scanViews(fullPath, path.join(basePath, file)));
|
|
55
|
+
} else if (file.endsWith('.js')) {
|
|
56
|
+
const fileName = file.replace('.js', '');
|
|
57
|
+
const relativePath = path.join(basePath, file);
|
|
58
|
+
|
|
59
|
+
// Convert filename to view path
|
|
60
|
+
// WebPagesHome.js -> web.pages.home
|
|
61
|
+
const viewPath = fileName
|
|
62
|
+
.replace(/([A-Z])/g, '.$1')
|
|
63
|
+
.toLowerCase()
|
|
64
|
+
.replace(/^\./, '');
|
|
65
|
+
|
|
66
|
+
views.push({
|
|
67
|
+
viewPath,
|
|
68
|
+
fileName,
|
|
69
|
+
relativePath: relativePath.replace(/\\/g, '/'),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return views;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
generateContent(views) {
|
|
78
|
+
const imports = views.map(view => {
|
|
79
|
+
return ` '${view.viewPath}': () => import(/* webpackChunkName: "view.${view.viewPath}" */ '../views/${view.relativePath}'),`;
|
|
80
|
+
}).join('\n');
|
|
81
|
+
|
|
82
|
+
const preloadList = this.preloadViews.map(v => ` '${v}',`).join('\n');
|
|
83
|
+
|
|
84
|
+
return `/**
|
|
85
|
+
* Auto-generated View Registry
|
|
86
|
+
* DO NOT EDIT MANUALLY - Generated by ViewRegistryPlugin
|
|
87
|
+
*
|
|
88
|
+
* @module config/viewRegistry
|
|
89
|
+
* @generated ${new Date().toISOString()}
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* View registry with dynamic imports
|
|
94
|
+
* Maps view paths to webpack dynamic import functions
|
|
95
|
+
*
|
|
96
|
+
* @type {Object<string, () => Promise<any>>}
|
|
97
|
+
*/
|
|
98
|
+
export const viewRegistry = {
|
|
99
|
+
${imports}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Views to preload for better initial performance
|
|
104
|
+
*/
|
|
105
|
+
export const preloadViews = [
|
|
106
|
+
${preloadList}
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Total registered views
|
|
111
|
+
*/
|
|
112
|
+
export const totalViews = ${views.length};
|
|
113
|
+
|
|
114
|
+
export default viewRegistry;
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default ViewRegistryPlugin;
|